Skip to content

Universal run: trace any Python entry point, not only pytest#89

Open
AnshBajpai05 wants to merge 1 commit into
KaykCaputo:masterfrom
AnshBajpai05:feat/universal-run
Open

Universal run: trace any Python entry point, not only pytest#89
AnshBajpai05 wants to merge 1 commit into
KaykCaputo:masterfrom
AnshBajpai05:feat/universal-run

Conversation

@AnshBajpai05

Copy link
Copy Markdown
Contributor

First feature slice from the roadmap we agreed on in #80: universal run.

What it doesoracletrace run now accepts any Python entry point, not only pytest:

oracletrace run -- python app.py --port 8000
oracletrace run -- python -m mypackage.job
oracletrace run -- pytest tests/ -k hot_path
oracletrace run -- app.py            # bare script shorthand
oracletrace run -- -m mypackage.job  # bare -m shorthand

All existing flags (--json, --csv, --html, --compare, --fail-on-regression, --repeat, …) work unchanged; the script's own sys.exit code is propagated the same way #87 does for target mode (gate codes still win).

Design — everything executes in-process (runpy.run_path / runpy.run_module / pytest.main): sys.setprofile only observes the current process, so a subprocess would silently produce an empty trace. That's also why non-Python commands (node, cargo, …) and python -c are rejected with an error that explains the constraint instead of returning empty results.

Launcher detection handles the common spellings (python, python3, python3.12, py, python.exe, full paths). sys.argv and sys.path are patched around the run and restored after, mirroring what the real interpreter invocation would look like to the target (argv[0], script dir / cwd importability).

Structure — new oracletrace/runner.py owns command dispatch; cli.py's run handler shrinks to init-tracer → execute_command() → report. The pytest-only _run_pytest in cli.py is superseded (its behavior, including the "pytest is not installed" message, moved into the runner).

Tests — 27 new: every supported form e2e (script, python script, -m, python -m, pytest), argv passing, exit-code propagation, --json export under run, rejection paths (non-Python binary, python -c, bare python, missing script), launcher-detection unit tests, argv-restoration check. One existing test updated (test_run_unsupported_command) since the arbitrary-command rejection message changed — that's the intended behavior change.

🤖 Generated with Claude Code

oracletrace run now dispatches pytest, python <script.py>,
python -m <module>, and bare <script.py> / -m shorthands — all
in-process (runpy / pytest.main), because sys.setprofile only
observes the current process and a subprocess would silently
produce an empty trace. Non-Python commands and python -c are
rejected with an error explaining that constraint.

New oracletrace/runner.py owns dispatch; cli.py's run handler
shrinks to init-tracer -> execute_command -> report. Script exit
codes propagate as in KaykCaputo#87.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@KaykCaputo

Copy link
Copy Markdown
Owner

Pipeline failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants