Skip to content

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

Merged
KaykCaputo merged 2 commits into
KaykCaputo:masterfrom
AnshBajpai05:feat/universal-run
Jul 16, 2026
Merged

Universal run: trace any Python entry point, not only pytest#89
KaykCaputo merged 2 commits 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

@KaykCaputo
KaykCaputo self-requested a review July 13, 2026 15:38

@KaykCaputo KaykCaputo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests not passing:

=========================== short test summary info ============================
FAILED tests/test_run_command.py::TestLauncherDetection::test_python_launchers_recognized[C:\Python311\python.exe] - AssertionError: assert False

  • where False = _is_python_launcher('C:\Python311\python.exe')
    ======================== 1 failed, 106 passed in 6.81s =========================

@AnshBajpai05

Copy link
Copy Markdown
Contributor Author

Fixed in 6478d2aos.path.basename only splits the platform's native separator, so the Windows-style path in the launcher-detection tests wasn't recognized on the Linux runners. Detection now normalizes both separators before taking the basename, so behavior is identical across platforms.

@KaykCaputo
KaykCaputo merged commit c1f187a into KaykCaputo:master Jul 16, 2026
4 checks passed
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