Repository navigation
Description
Problem
Coverage measurement silently fails whenever testCmd carries a leading environment assignment, for example PYTHONPATH=. python3 -m pytest -q. The tests gate passes, coverage reports tool: "none", and the verdict caps at UNPROVEN. Nothing in the output attributes this to the command shape.
Same change, same suite, only the prefix differs:
testCmd |
verdict | coverage.tool |
changed statements |
|---|---|---|---|
python3 -m pytest -q |
SAFE |
coverage.py |
4 of 5 covered |
PYTHONPATH=. python3 -m pytest -q |
UNPROVEN |
none |
not determined |
UNPROVEN reason: "Tests pass, but coverage of the changed code could not be determined."
Reproduced via the refactron MCP server against playground/legacy-python, with a behaviour-preserving f-string modernization of formatting.py.
Why this matters now
The PYTHONPATH= prefix is our own documented remedy for shadow bypass. docs/verification/verdicts.mdx:209 ("Make sure the tests run the code being verified") exists because a project installed into the environment, editable pip install -e . included, makes the suite import the installed copy instead of the shadow copy, so the run proves nothing about the change.
So the documented remedy for one correctness problem, written in the prefix form, silently disables the measurement the verdict depends on. The affected population is exactly the projects that need the remedy, and nothing looks broken because the tests gate stays green.
Over MCP this is the only in-band form available. src/mcp/tools/verify-change.ts:15 declares testCmd: z.string().optional() with no per-call env field, so an agent that wants the shadow tree first on sys.path has no way to express it except the prefix. Nine pages under docs/mcp/ instruct exactly that, and they are on main as of #94.
Evidence
The two execution paths disagree about what a command is.
-
Tests gate:
src/verify/runners/detect.ts:27returns{ cmd: 'sh', args: ['-c', opts.override], ... }. Shell semantics apply, the assignment is honored, tests run correctly. -
Coverage runner:
src/analyze/coverage/python-line-coverage.tsuses no shell.toCoverageRunArgstokenizes and classifies module-form vs script-form, and has no concept of a leadingNAME=VALUEtoken.PYTHONPATH=.is notpython3, does not end in.py, and contains no slash, so it falls through topython-line-coverage.ts:114,return ['-m', ...rest], treating the assignment as a module name.
Classifier output, produced by running the exported function against dist/analyze/coverage/python-line-coverage.js:
'python3 -m pytest -q' -> coverage run -m pytest -q correct
'PYTHONPATH=. python3 -m pytest -q' -> coverage run -m PYTHONPATH=. python3 -m pytest -q broken
'PYTHONPATH=src python3 -m pytest -q' -> coverage run -m PYTHONPATH=src python3 -m pytest -q broken
'PYTHONPATH=./src python3 -m pytest -q' -> coverage run PYTHONPATH=./src python3 -m pytest -q broken (script-form branch, because of the slash)
'COVERAGE_CORE=sysmon python3 -m pytest' -> coverage run -m COVERAGE_CORE=sysmon python3 -m pytest broken
coverage run cannot import a module by that name, writes no data file, measurementFailed is set, and verdict-fuse honestly degrades to UNPROVEN.
Nuance: only the inline prefix form is affected. python-line-coverage.ts:188 builds const env = { ...process.env, COVERAGE_FILE: dataFile }, so a PYTHONPATH exported into the shell before invoking refactron is inherited and works. That is why docs/verification/verdicts.mdx:215 (the export form) is correct today and the MCP prompts are not.
Acceptance criteria
- A leading run of
NAME=VALUEtokens is hoisted off the command into the child environment before classification, and the remainder classifies exactly as today. Unit tests assert the classified result for all five commands in Evidence, proven red against the current code. - Hoisting stops at the first token that is not an assignment.
pytest -k a=bkeepsa=bas an argument and hoists nothing. Test. - Hoisted vars are merged into the inherited env, not substituted for it:
COVERAGE_FILEis still set to the temp data file and inheritedPATHsurvives. Test. - End to end: a
verify-diffrun over a committed fixture withtestCmdPYTHONPATH=. python3 -m pytest -qreportscoverage.tool"coverage.py"and reaches the same verdict as the unprefixed form. Red before the fix, where it reportstool: "none"andUNPROVEN. - The coverage run and the tests gate execute with the same effective environment for the same
testCmd. If they diverge, the measured run is not the verified run. State how this is enforced, not just that it holds. - Relative values such as
PYTHONPATH=.resolve against the shadow root. Proof: the changed file appears inreport.measuredFiles, so the shadow-bypass guard insrc/verify/verify-diff.tsdoes not fire. - A command containing real shell metacharacters still returns
nulland reports unknown. ExistingSHELL_COMPOSITE_REtests stay green, unmodified.
Use a committed fixture for the end-to-end test. playground/ is untracked, so a CI test cannot reach it. tests/fixtures/verify-diff-mini and tests/fixtures/coverage-mini are the candidates; playground/legacy-python stays as the manual repro only.
Verdict integrity
The existing bug fails safe. measurementFailed routes through unknownCoverage() to UNPROVEN and cannot produce a false SAFE. This is a capability defect, not a trust defect, and the cardinal rule holds today.
The fix moves in the dangerous direction: it converts UNPROVEN into SAFE for a class of commands that previously could not reach SAFE at all. That is the risk this issue must discharge.
-
SAFEis produced only when coverage was genuinely measured. The end-to-end test assertscoverage.tool === 'coverage.py'and a non-emptymeasuredFilescontaining the changed file, not merely the verdict string. A test that only checksverdict === 'SAFE'does not discharge this. - Adversarial case: a hoisted variable that points the suite at code outside the shadow tree, for example an absolute
PYTHONPATH=<original repoRoot>, must not readSAFE. Expected: the changed file is never measured under the shadow-relative path, the shadow-bypass guard fires, and the verdict isUNPROVEN. If it readsSAFE, stop and escalate toprincipal-engineerbefore continuing. That is a falseSAFEintroduced by this fix, which is the exact shape of the two regressions rounds 3 and 4 shipped. -
src/verify/verdict-fuse.tsis untouched. This change is confined to coverage acquisition.
Blast radius
VerdictReportis unchanged: no new, renamed, retyped, or removed fields. Not a public-contract change, noreportVersionbump.- Locked contracts untouched:
src/contracts.ts,src/core/models.ts,src/adapters/interface.ts. toCoverageRunArgsis exported fromsrc/analyze/coverage/python-line-coverage.tsbut is not re-exported fromsrc/index.ts, andpackage.jsonexportspublishes.only. A signature change, returning args plus env, is therefore internal. One existing consumer to update:tests/integration/coverage-reporter.test.ts:192.reportCoveragehas a second caller,src/analyze/engine.ts:99, which passes notestCmdand defaults to'pytest -q'. It must remain unaffected; confirm rather than assume.
Non-goals
- Shell emulation. Only a leading run of assignments is handled. Commands with real metacharacters remain declined by
SHELL_COMPOSITE_REand correctly report unknown. - Quoting or escaping beyond what
tokenizeCommandalready does. - Any documentation change. Tracked separately and blocked on this one.
- Adding an
envfield to the MCPverify_changeinput schema. If that turns out to be the better shape, it is a public-contract decision forprincipal-engineerand gets its own issue. - Making TypeScript or mixed-language diffs measurable.
Tests to write first
Unit, on the classifier, all five commands from Evidence, plus the pytest -k a=b non-hoist case and the env-merge case. Then the end-to-end verify-diff assertion. Each must be shown failing against main before implementation. test-engineer owns the red-first proof.
Activity
omsherikar commentedon Aug 4, 2026
Docs reconciliation split out to #96, which is blocked on this one: the correct wording differs depending on whether this lands or is declined.
Note that 11 of the 13 doc mentions already recommend the prefix form, so they become correct the moment this merges. #96 covers the two that would remain inconsistent.
fix(verify): close two more false SAFEs found reviewing the scope rule