Skip to content

False SAFE: an unparsed test command with arguments still narrows #115

Closed

Description

@omsherikar

Problem

A test command that Refactron cannot parse but which carries positional arguments narrows the suite and still reaches SAFE. This is the same defect as #110, surviving under a runner the classifier does not recognise.

Reproduction

Executed against main at 83bf98e (after #112 and #113 merged), via verifyDiff. Same repo, same diff (return x * 2 → return x * 3), two unittest test modules: test_scale executes the changed line without pinning its value, test_report pins it and fails. Only the command differs.

python3 -m unittest discover -s tests   -> UNSAFE
python3 -m unittest tests.test_scale    -> SAFE
     testScope = {"scope":"unknown","source":"override",
                  "signals":["python3 is not a recognised test runner, so the scope is unknown"]}
     coverage  = coverage.py  {"total":1,"covered":1}

The second command runs one test, misses the one that catches the change, measures full statement coverage of the changed line, and earns SAFE.

Django's python3 tests/runtests.py auth is the same shape.

Why this was left open

ADR-12 (dev-docs/decisions/12-narrowed-testcmd-policy.md) decided that unknown does not floor the verdict, and recorded this exact hole as Alternative C. That decision was correct for the reason given: most unknown commands are a full suite carrying a plugin flag we do not recognise (pytest --doctest-modules), and flooring them would turn every unrecognised flag in the wild into a SAFE-killer fixable only by a PR to us.

The deferral was on risk, not merit: #112 already shipped one change to what SAFE means and a third heuristic in the same PR compounded risk on the one verdict we cannot get wrong.

Direction

unknown is not one situation, it is three. Only the third is dangerous:

Bucket Example Reaches SAFE today Action
1. Unrecognised runner, no positional args make test, tox No — toCoverageRunArgs declines it, so coverage is unknown and the verdict is already UNPROVEN Leave
2. Recognised runner, unrecognised flag pytest --doctest-modules Yes, and it is a full suite Must not floor
3. Unrecognised runner with positional args python -m unittest tests.test_scale, python3 tests/runtests.py auth Yes, and it is narrowed Floor at UNPROVEN

Flooring only bucket 3 closes the reproduction, leaves bucket 2 untouched, and degrades with a named reason rather than a guess — the house doctrine everywhere else in this engine.

The care this needs

The failure mode of getting bucket 3 wrong is a user losing a deserved SAFE, so what counts as a "positional argument" has to be right:

  • python3 -m unittest discover -s tests is a full suite. discover is a subcommand, the way vitest's run already is in src/verify/test-scope.ts.
  • python3 tests/runtests.py with no arguments is a full suite; with auth it is narrowed.
  • -s tests is a flag with a value, not a filter.

Acceptance criteria

  1. Red-first. An integration test reproducing the case above, proven failing against main (where it returns SAFE), asserting UNPROVEN after. Use the two-module fixture so the full-suite control returns UNSAFE on the identical diff.
  2. A unit table in tests/unit/verify/test-scope.test.ts covering: python -m unittest tests.test_foo → narrowed; python -m unittest discover → full; python -m unittest discover -s tests → full; python3 tests/runtests.py auth → narrowed; python3 tests/runtests.py → full.
  3. Negative, non-negotiable: bucket 2 is untouched. pytest --doctest-modules, pytest -q --forked stay unknown and stay able to reach SAFE.
  4. Negative: bucket 1 is untouched. make test, npm test, tox, ./run-tests.sh stay unknown and unfloored.
  5. Every newly floored command carries a signal string naming why.
  6. ADR-12 updated: Alternative C moves from "deferred" to the implemented decision, with the reproduction recorded.
  7. npm run prepublishOnly green.

Verdict integrity

  • Verdict at risk: SAFE, and it is going wrong today on a shipped release, reachable through the unauthenticated MCP tool.
  • Direction is fail-safe: this can only move SAFE → UNPROVEN.
  • The risk this change introduces is the opposite one — a false narrowed costing a legitimate SAFE — which criteria 3 and 4 exist to pin.

Non-goals

  • Making the floor adversary-proof. sh -c "pytest tests/x.py" still lands in unknown. This is a mistake-catcher, not an adversary-stopper, and ADR-12 says so. Tracked separately.
  • Narrowing configured outside the command string (pytest.ini addopts, exported PYTEST_ADDOPTS, vitest include). Separate issue.
  • Adding unittest or runtests.py as fully-parsed runners with their own flag tables. The point is to detect arguments, not to model every runner's CLI.

Activity

  1. added
    bug
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions