Skip to content

fix(pregate): a missing pytest is PREGATE_ENVIRONMENT, not the diff's failure - #3639

Closed
vilano93 wants to merge 1 commit into
garrytan:mainfrom
vilano93:fix/pregate-missing-pytest
Closed

vilano93 wants to merge 1 commit into
garrytan:mainfrom
vilano93:fix/pregate-missing-pytest

Conversation

@vilano93

@vilano93 vilano93 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Why (in your own words)

On a machine without pytest, lanes blames the diff. A .py-only root selection is planned as python3 -m pytest {files} with no check that python3 can import pytest. The run exits 1 with No module named pytest, and the lane reports PREGATE_LANE_FAILED with "fix the in-branch failure", even when the test itself is green. The run-time classifier can't catch this, because the command's binary, python3, is on PATH.

This change checks before the run, the same way planRuns already does for pnpm/yarn, cargo and dart/flutter. If python3 is off PATH, the missing tool is python3. If python3 can't find the pytest module, the missing tool is pytest. Either way the file stays unclaimed, and the lane is PREGATE_ENVIRONMENT (missing-binary): "install pytest on this machine and rerun, or run the lane remotely; the diff is not at fault". The probe asks the python3 the runner will use (importlib.util.find_spec("pytest")) instead of looking for a pytest script on PATH, because a script installed with pipx can belong to a different interpreter.

Fixes #3598

Live evidence

The repro from #3598: a repo with one unittest-style test, tests/test_alpha.py, touched on a branch. python3 -m unittest passes it, and this machine has no pytest.

# upstream main 1.91.313.0 (81a82727b)
$ gstack-pregate run --stage tests --only lanes --base origin/main --allow-repo-commands
    lanes: fix: read ~/.gstack/projects/repro-pytest/pregate/runs/…/lanes/lanes.log, fix the in-branch failure, rerun gstack-pregate --stage tests
PREGATE: fail tree=075ba803dd3a head=7ae1d5e297a9 checks=1
gstack-pregate: lanes: local lane exited 1 (? failed of ? ran; 1 files; pipefail); … (PREGATE_LANE_FAILED)

# this branch, same command
    lanes: fix: install pytest on this machine and rerun, or run the lane remotely; the diff is not at fault
PREGATE: incomplete tree=075ba803dd3a head=7ae1d5e297a9 checks=1
gstack-pregate: lanes: no test runner detected for 1 of 1 selected file(s): tests/test_alpha.py; not on PATH: pytest; … (PREGATE_ENVIRONMENT)

# this branch, with a throwaway venv holding pytest 9.2.0 first on PATH
    lanes: ran: python3 -m pytest 'tests/test_alpha.py'
    lanes:   ============================== 1 passed in 0.01s ===============================
PREGATE: pass tree=4b65f2237b41 head=7ae1d5e297a9 checks=1

The new tests were red first, then green:

# test/pregate-environment.test.ts on upstream main
(fail) a detected pytest runner needs pytest importable by python3 > plans pytest when python3 imports it, else names pytest or python3 as missing
(fail) a detected pytest runner needs pytest importable by python3 > a machine without pytest is PREGATE_ENVIRONMENT naming pytest, never PREGATE_LANE_FAILED
       Received: "… local lane exited 3 … fix the in-branch failure … (PREGATE_LANE_FAILED)"
# after
 11 pass  0 fail

Scope

  • Changed:
    • lib/pregate/checks/lanes.ts: a new pytestMissing(env). It resolves python3 on the runner's PATH and runs a find_spec("pytest") probe with a 10 s timeout. planRuns calls it only when the detected root runner is the pytest one. A declared runner never reaches it, because planRuns returns before this code.
    • test/pregate-environment.test.ts: a plan-level case covering pytest importable, not importable, and no python3 (with a python3 shim and an empty PATH), plus an end-to-end case showing PREGATE_ENVIRONMENT and that the lane never starts.
  • Verified live by:
    • the three runs above;
    • bun run typecheck: clean;
    • bun run typecheck:test: "814 known diagnostics, none new".
  • Compared with a clean upstream/main worktree (81a8272) on macOS:
    • The Python-touching pregate files (pregate-manifest-paths, pregate-removed-paths, pregate-selection, pregate-non-js): 88 pass and 9 fail on both, with the same names. These are the macOS-host failures noted in fix(pregate): Rust crate lanes and nested JS package runners (#3344) #3346.
    • bun run test on this branch reports failing tests in 62 files. None of them is in pregate lane planning: they are this Mac's host failures (browser settlement, gbrain, cso, qa and others). I ran those 62 files (1,975 tests) on both trees. Main fails 386 and this branch fails 385. No test fails only on this branch. The one extra failure on main is test-free-shards … settlement … timeout, which is flaky.
  • Did NOT test:
    • Windows, where the interpreter is often py/python rather than python3. That is unchanged: the runner was already python3, and the probe follows it.
    • A probe that hangs past 10 s is reported as pytest missing. I don't know of a case where that happens.
  • Notes for review:

Liveness proof (required for external contributors)

SCR-20261029-ixel

Checklist

🤖 Generated with Claude Code

… failure

A `.py`-only root selection was planned as `python3 -m pytest {files}`
without asking whether python3 can import pytest. On a machine without it
the lane exited 1 with "No module named pytest" and was reported as
PREGATE_LANE_FAILED, "fix the in-branch failure". The run-time classifier
cannot catch it: the command's binary, python3, is on PATH.

planRuns now checks before the run, as it already does for pnpm/yarn, cargo
and dart/flutter: python3 off PATH names python3, a python3 that cannot find
the pytest module names pytest. The file is unclaimed and the lane is
PREGATE_ENVIRONMENT (missing-binary), "install pytest on this machine and
rerun, or run the lane remotely; the diff is not at fault".

Fixes garrytan#3598

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Oct 30, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Thank you for this fix. A crew lane is picking it up, together with your two related pregate PRs, to land on current main with Co-authored-by credit to you.

@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Thanks @vilano93. This landed in v1.93.15.0 as #3741: a missing pytest is now PREGATE_ENVIRONMENT, not a failure of the diff. The fix was rewritten on current main rather than merged from this branch (our policy for outside code), and the idea is credited in the changelog. Closing this PR in favor of that change.

@capy-ai capy-ai Bot closed this Nov 2, 2026
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.

pregate: a missing pytest is PREGATE_LANE_FAILED (blames the diff), not PREGATE_ENVIRONMENT

1 participant