Repository navigation
fix(verify): a narrowed test command cannot earn SAFE - #112
Conversation
A caller-supplied testCmd naming a subset of the suite scoped the whole verification run. Coverage could report the changed code as fully exercised while the one test that would have caught the change was never selected, so the verdict read SAFE. Reproduced against the published 0.4.0 binary: one repo, one diff, two test files, only the command differing. python3 -m pytest -q -> UNSAFE python3 -m pytest -q tests/test_scale.py -> SAFE The narrowed run reported changedStatements 1/1, full statement coverage, so the stricter rule in #109 does not cover this case. Classify the command as full / narrowed / unknown in a pure module and floor narrowed at UNPROVEN. unknown does not floor: that would put SAFE out of reach for any project running `make test`. The gap is disclosed on the new testScope report field and recorded in ADR-12. The classifier degrades to unknown on anything it does not recognise, because a false narrowed costs a user their SAFE. Two negative tables guard the PYTHONPATH= forms established by #95 and #98, and the parallelism flags: -n is xdist worker count, not a filter. testScope is additive, so reportVersion stays 1 and contracts.ts is untouched. Exit codes are unchanged; SAFE and UNPROVEN both exit 0. Closes #110 Closes #111
Three-lens review found the classifier's `full` verdict is now the permission to be SAFE, and two table entries granted it wrongly. Both reproduced end to end before fixing. --collect-only selects zero tests, exits 0 so the tests gate passes on exit code alone, and still imports every test module, so coverage marks module-level changed lines executed: python3 -m pytest -q -> UNSAFE python3 -m pytest -q --collect-only -> SAFE, coverage 1/1 PYTEST_ADDOPTS is appended to pytest's argv, so its value is a filter. The leading NAME=VALUE strip discarded it and answered `full`: PYTEST_ADDOPTS="-k test_scale" python3 -m pytest -q -> SAFE That one arrives through the form issues #95 and #98 tell users to adopt, and the only in-band way to pass env over MCP. Values of PYTEST_ADDOPTS / VITEST_ADDOPTS / JEST_ADDOPTS now go through the same argument scanner as the command line. PYTHONPATH stays inert. Also fixed, each with rows: - pytest -o/--override-ini testpaths= and addopts= were consumed unexamined and read `full` - the zero-test-run rule applied to pytest only; `npx jest -h` was `full` - vitest -w is --watch and takes no value; filed as value-taking it swallowed the next token and read `full` - pytest --cov takes an optional value, so `--cov src` was a false `narrowed` on a very common CI command - shell composites read operators as paths; now share SHELL_COMPOSITE_RE with the coverage runner so the two parsers cannot disagree - `pytest .`, `pytest ""` and `pytest -q #comment` were false `narrowed` - every `unknown` now carries a reason; the CLI says so instead of letting a SAFE on an unparsed command read as clean - an empty override is falsy at detect.ts:26, so it is `detected`, not a claim about a caller command - fuseVerdict's scope parameter is required: an optional one makes a forgotten argument a silent false SAFE ADR-12's rejection of flooring `unknown` cited a cost that does not exist. Measured: coverage already declines make/npm/tox, so flooring them costs nothing; the real cost is unrecognised plugin flags on recognised runners. Rationale rewritten, and the residual hole (unrecognised runner carrying arguments) recorded as Alternative C with follow-ups rather than left implied. Suite 370 -> 407.
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (14)
Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughChangesTest Scope Policy
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The change makes narrowed test commands report UNPROVEN instead of SAFE and adds scope disclosure; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Caller
participant verifyDiff
participant assessTestScope
participant fuseVerdict
participant CLI
Caller->>verifyDiff: provide testCmd
verifyDiff->>assessTestScope: classify testCmd
assessTestScope-->>verifyDiff: TestScopeAssessment
verifyDiff->>fuseVerdict: combine results, coverage, and scope
fuseVerdict-->>CLI: VerdictReport with testScope
CLI-->>Caller: verdict and scope advisory
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
What
A caller-supplied
testCmdthat names a subset of the suite scoped the entire verification run, and the report said nothing about it. Coverage could report the changed code as fully exercised while the one test that would have caught the change was never selected, so the verdict readSAFE.This adds a pure classifier (
src/verify/test-scope.ts) that reads the command asfull/narrowed/unknown, floorsnarrowedatUNPROVEN, and discloses the result on a new additiveVerdictReport.testScope.Closes #110
Closes #111
Why
Reproduced against the published 0.4.0 binary before any code was written. One repo, one diff (
return x * 2becomesreturn x * 3), two tests:test_scaleexecutes the changed line without pinning its value,test_reportpins it and fails. Only the command differs.A change that provably breaks a test sitting in the same repository returned
SAFE, through the MCPverify_changetool, which applies no authentication.The narrowed run reported
changedStatements {total: 1, covered: 1}— full statement coverage — so the stricter statement rule proposed in #109 does not touch this case. The two defects are independent, and there is a test pinning that fact.Three false SAFEs, not one
The first was the reported bug. Review found two more, each reproduced end to end before being fixed:
--collect-only. It selects zero tests, exits0so the tests gate passes on exit code alone, and still imports every test module, so coverage marks module-level changed lines as executed. The original flag table listed it as an ordinary boolean, i.e. explicitly non-narrowing.PYTEST_ADDOPTS. pytest appends this variable's value to its own argv, so it is a filter. The leadingNAME=VALUEstrip discarded it and the classifier then answeredfull, its strongest claim.This one matters more than an ordinary gap: the leading-assignment prefix is what issues #95 and #98 tell users to adopt for shadow bypass, and it is the only in-band way to pass environment over MCP.
PYTEST_ADDOPTS/VITEST_ADDOPTS/JEST_ADDOPTSvalues now go through the same argument scanner as the command line.PYTHONPATHstays inert, with a regression row guarding it.Evidence
Red-first, verified by restoring
main'ssrc/under the branch's tests:The
--collect-onlytest is red against the pre-fix classifier in the same way (expected 'SAFE' not to be 'SAFE').Gate:
typecheck,lint --max-warnings 0,format:check, and 407 tests across 27 files, all green. Suite was 333 before this branch.The rule
fullnarrowed-k,-m,-t,--onlyChanged,--collect-only, …unknownmake test, a plugin flag, a wrapper script)unknowndeliberately does not floor. ADR-12 originally justified that by saying wrapper commands would otherwise all loseSAFE; review showed that is false —toCoverageRunArgsalready declinesmake test,npm testandtox, so they cannot reachSAFEtoday anyway. The real cost is unrecognised plugin flags on recognised runners (pytest --doctest-modules), which flooring would turn into SAFE-killers fixable only by a PR to us. The ADR now carries the measured table rather than the intuition.Known limitations, stated rather than implied
python -m unittest tests.test_fooandpython3 tests/runtests.py authboth narrow, both reachSAFE, and both classifyunknown. Recorded as Alternative C in ADR-12 with a follow-up; it needs its own red-first fixture and should not ride in on this branch.SAFEcan writesh -c "pytest tests/x.py". This is a mistake-catcher, not an adversary-stopper, and the ADR says so.pytest.iniaddopts, an exportedPYTEST_ADDOPTS, or a vitestincludeis not detected.fullmeans "this command names no filters", not "this run was the whole suite".pytest tests/counts as narrowed, deliberately: tests can live outside that directory, and calling itfullwould be a falseSAFE.pytest .isfull. Documented.SAFE. They buy disclosure only.Blast radius
VerdictReport.testScopeis additive;reportVersionstays1.src/contracts.tsuntouched.fuseVerdict's scope parameter is required, so a future call site that forgets it is a compile error rather than a silent false SAFE.SAFEandUNPROVENboth exit0. Pipelines that parse the verdict string will see moreUNPROVEN.SAFEwill now readUNPROVEN. That is the point, and it is a behaviour change every user of--test-cmdsees.What I could not verify locally
basenamesplits on/only.testScopestructurally (the report is serialized verbatim) but no test asserts it on that surface;tests/unit/mcp/verify-change.test.tsdoes not mention the field.runVerifyDiffCommandhas no test coverage, so the CLI wiring of the new note is unasserted even thoughformatTestScopeNoteitself is tested.src/mcp/tools/verify-change.tsstill describestestCmdas "Override the test command" with no caveat. That description is what an agent reads, and the ADR's threat model is an agent choosing its own command. Worth a follow-up.Summary by CodeRabbit
New Features
SAFEverdict; they are capped atUNPROVEN.SAFEresult.testScopedetails to verification reports.Documentation
Tests