Repository navigation
fix(scripts): run pytest suites under the setup-env venv, building it once when python3 lacks pytest - #9876
Conversation
… once when python3 lacks pytest run-test-file.sh and selection-audit.sh ran Python suites as python3 -m pytest, which fails on a host whose python3 has no pytest and refuses pip install --user (PEP 668). Both now take the interpreter from scripts/lib/pytest-python.sh: a setup-env venv that imports pytest (SETUP_ENV_VENV, this checkout's .work/venv, then the main checkout's, shared by every worktree), else python3 when it imports pytest, else, off CI, the main checkout's venv after one scripts/setup-env.sh run under a lock. Under CI or GITHUB_ACTIONS nothing is built, so CI keeps running python3 as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-security-review reviewed Security review: PR #9876 (head e555453)No security findings. critical-findings: 0 Scope read. I read the whole diff (6 files) and the PR context. I also read Trusted paths. No changed file matches Manifests and instruction surfaces. No Spend. No billed resources or paid plans are touched. I found no extra review or lane runs that would use prepaid credit. What I checked and why it did not become a finding
|
|
claude-review reviewed Code review: no findingsI read the full diff (6 files) and the PR context. I did not run any tests, because this lane has no shell. Everything the PR says about passing runs is author-claimed and unverified by me. What I checked
Other checks
Observation, not a finding
|
The pipefail-grep-q hygiene check rejects printf | grep -q; feed grep from a process substitution instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No related issue: a local-host gap found when
/source-control:pull-request readyrefused three PRs; no issue was filed for it.Summary
scripts/run-test-file.shandscripts/selection-audit.shran Python suites aspython3 -m pytest. On a host whosepython3has no pytest and is PEP 668 externally managed (pip install --userrefuses), every Python suite run through them fails to start.There are two observations, and they do not fully agree:
scripts/check-affected.sh --testsdoes not run.pysuites itself.affected-tests.sh --runruns only*.test.shand lists the other ecosystems as not run (exit 3), whichcheck-affected.shcounts as a pass. The*.test.shwrappers that call pytest SKIP when it is missing.check-affectedcount the 14 selected.pysuites as FAIL, and the ready gate recordedfail. Agents in the §1.5 verify step also run Python suites throughrun-test-file.shorpython3 -m pytest, and those runs fail the same way.Either way the cause is the same: no interpreter with pytest. This change gives every local Python suite run one.
Metric: ready flips refused for missing pytest. Baseline: 3 today (#9836, #9798, #9835, all passing under unittest). Expected after this change: 0.
Fix
scripts/lib/pytest-python.sh, the one place that chooses the pytest interpreter. First match wins:scripts/setup-env.shvenv that imports pytest:SETUP_ENV_VENV, then this checkout's.work/venv, then the main checkout's.work/venv;python3, when it imports pytest;setup-env.shrun that builds the venv atSETUP_ENV_VENVor the main checkout's.work/venv, underflockso parallel callers build it once. setup-env has no Python-only step, so this run also checks ShellCheck and runsnpm ciwhere the lockfile hash changed; its output goes to stderr;python3, so pytest's own error names what is missing.run-test-file.shandselection-audit.sh traceboth use it.selection-audit.shresolves the interpreter once, before any trace, and only when a.pysuite is in the corpus..work/venv(found throughgit rev-parse --git-common-dir), so every worktree of a clone shares one venv instead of building one each. It is about 114 MB on this host.CIorGITHUB_ACTIONSis set, and the workflows already install pytest (setup-env.shputs the venv onGITHUB_PATH; the lane's verify step pip-installs.github/requirements-ci.txt), so step 2 resolves topython3there as before.Verification
scripts/lib/pytest-python.test.sh: 9 cases throughrun-test-file.shin a throwaway checkout plus a linked worktree, with stubbedpython3, venv python andsetup-env.sh. It covers the checkout's venv, the main checkout's venv used from a worktree,SETUP_ENV_VENVfirst,python3with pytest, setup-env run exactly once from a worktree (building the main checkout's venv) with no second run, no build underCIorGITHUB_ACTIONS, and a failed setup-env falling back topython3. Against the oldrun-test-file.sh, 6 of the 9 fail. The 3 that pass check behavior this change leaves alone.scripts/selection-audit.test.sh: one new trace case, where a Python suite runs under the checkout's venv python. 20 of 20 pass; the new case fails against the old script.collect-base-activity.test.mjs: 127 of 127 pass, now with the helper staged besidecheckout-path.sh(the real lane copies the whole basescripts/).scripts/setup-env.test.mjs: 17 of 17 pass.live-config.test.mjs: 40 of 40 pass.scripts/run-test-file.sh scripts/test_vendor_gitleaks_rules.pyfrom a worktree built the main checkout's venv in about 11 s, then 14 passed. A second run took 1.3 s and ran no setup-env. A sweep of every trackedtest_*.pyoutside/evals/fixtures/throughrun-test-file.sh: 194 of 195 suites passed in 1164 s. In the other,plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py, 2 of 719 tests failed withvcs-state-unverified. That file then passed 717 of 717 (2 skipped) on two reruns through the same runner, and the two tests pass in isolation, so this looks like a flake in that suite's VCS probe and not something this change causes (cause UNVERIFIED).scripts/check-affected.sh --tests: 10 passed, 4 skipped.shellcheck --rcfile .shellcheckrcis clean on every touched script, andshfmt -dis clean on the new files.Related
scripts/setup-env.sh, which is unchanged; the helper reuses its venv and input-hash skip.🤖 Generated with Claude Code