> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refactron.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Verdicts

> SAFE, UNSAFE, and UNPROVEN: the three-way verdict at the center of Refactron, how coverage fuses with the gates, and why UNPROVEN is the honest answer.

Every verification returns exactly one of three verdicts. Two of them exist in most tools. The third, `UNPROVEN`, is the one that makes Refactron trustworthy.

> [card] SAFE
>
> ![The SAFE verdict mark](https://mintcdn.com/refactron-aaa9076d/tQw4iZ6fQIqjI0gZ/assets/verdict-safe.svg?fit=max\&auto=format\&n=tQw4iZ6fQIqjI0gZ\&q=85\&s=8c7643da88a9579fd7d210b200acf2f2)
>
> Gates pass **and** your tests exercise the changed statements.

> [card] UNSAFE
>
> ![The UNSAFE verdict mark](https://mintcdn.com/refactron-aaa9076d/tQw4iZ6fQIqjI0gZ/assets/verdict-unsafe.svg?fit=max\&auto=format\&n=tQw4iZ6fQIqjI0gZ\&q=85\&s=17e1d4a17b554e4b6f80465406c242c5)A gate failed. The change
> broke something.

> [card] UNPROVEN
>
> ![The UNPROVEN verdict mark](https://mintcdn.com/refactron-aaa9076d/tQw4iZ6fQIqjI0gZ/assets/verdict-unproven.svg?fit=max\&auto=format\&n=tQw4iZ6fQIqjI0gZ\&q=85\&s=0b51ffcd4eed4e433b4ce0550b13b8c8)
>
> Tests pass, but the changed code isn't proven safe.

## How a verdict is decided

Refactron runs two independent checks and fuses them:

1. **The gates**: syntax, then imports, then your test suite, all against the change applied in an isolated [shadow tree](https://docs.refactron.dev/concepts/safety-model.md). A gate either passes or fails.
2. **Changed-statement coverage**: did your tests actually execute the statements the change touched? Each changed line is mapped to the statement containing it first. Assessed only when the gates pass.

The fusion rule:

| Gates | Changed statements covered? | Author trusted? | Verdict | Reason |
| - | - | - | - | - |
| A gate failed | n/a | n/a | `UNSAFE` | The failing gate's blocking reason. |
| All passed | yes | yes | `SAFE` | "Tests pass and the changed code is covered." |
| All passed | yes | no (default) | `UNPROVEN` | "SAFE is withheld: coverage was measured in-process, which an untrusted diff can forge." |
| All passed | no | n/a | `UNPROVEN` | "Tests pass, but the changed code is not exercised by any test." |
| All passed | couldn't tell | n/a | `UNPROVEN` | "Tests pass, but coverage of the changed code could not be determined." |

A would-be-`SAFE` is withheld to `UNPROVEN` when the diff's author is untrusted, which is the default. Coverage and the pass/fail gates are measured by running the diff's own suite in-process, which an untrusted diff can forge, so `SAFE` is granted only when you declare the author trusted (or run the change hermetically). `UNSAFE` and `UNPROVEN` do not depend on trust.

## SAFE

Every gate passed, and every changed **statement** your suite could reach was executed by it. The change is on a tested path, and that path is green. `SAFE` additionally requires that the diff's author be declared trusted; the default is untrusted, which withholds it. See [An untrusted diff cannot be SAFE](#an-untrusted-diff-cannot-be-safe).

`SAFE` is a per-**statement** check. Every changed statement your suite could
have executed did execute. A file with some exercised and some unexercised
changed statements reads as `UNPROVEN`, and the reason names the ratio:

```
[UNPROVEN] Tests pass, but only 3 of 14 changed statements were exercised.
```

A changed statement coverage.py **excluded** floors the verdict to `UNPROVEN`.
`# pragma: no cover` bodies, `if TYPE_CHECKING:` blocks, and any line matched by a
`.coveragerc` or `pyproject` exclude rule are all part of the diff, so a change can
add the exclusion itself and mark a live line excluded that no test will ever run.
An excluded changed statement is not evidence of anything, so `SAFE` is withheld.
It is still listed in `coverage.uncovered`, tagged `excluded`, with a hint saying
to remove the exclusion or verify the change another way, not to write a test that
could never pass.

This is stricter than 0.4.x, where an excluded statement was subtracted from what
`SAFE` required. A diff that only adds a typing-only `if TYPE_CHECKING:` import now
reads `UNPROVEN`, not `SAFE`. That is the honest verdict: the exclusion set travels
inside the diff and is attacker-controlled, so any covered-count that trusts it is
forgeable.

`SAFE` also requires that changed **conditionals** were fully branched. A changed
`if`/`elif` whose header ran but one of whose branches no test entered floors at
`UNPROVEN`, even when statement coverage is complete: the behaviour that changed
sits in a branch nobody tested. The reason names the line so you know which test
to add:

```
[UNPROVEN] Tests pass, but a changed conditional has a branch no test took
(calc.py:3). Add a test that enters the other branch.
```

A conditional whose branches are all exercised still reaches `SAFE`, so this
never blocks a fully-tested change. Branch coverage is Python-only, like the rest
of the coverage check.

This covers statement-level branches — `if`, `elif`, `while`, `for`/`else`,
`match`. It does not cover an untested path inside a comprehension filter, a
ternary, or a boolean short-circuit (`a and b`): `coverage.py` does not report
those as branches, so a changed expression of that kind can still read `SAFE`
with a sub-path untested.

## `--mutate`: was the change actually asserted?

Coverage proves a changed statement *ran*. It does not prove any test would
*fail* if that statement's behaviour changed. A line a test executes but never
asserts on counts as covered and earns `SAFE`.

`refactron verify-diff --mutate` closes that gap. It perturbs the operators and
constants in your changed statements — a boundary (`<=` → `<`), an arithmetic
sign, a boolean `and`/`or`, or a constant (a number, a string, `True`/`False`/
`None`) — reruns your suite against each, and if any mutant **survives** (the
suite still passes), the verdict floors at `UNPROVEN`, naming the survivor:

```
[UNPROVEN] Tests pass, but a mutant of a changed statement survived
(calc.py:2, + to -): no test failed when its behaviour changed. Add a test
that asserts on it.
```

It is opt-in and slower — it reruns your suite once per mutant — so it is a
deep check, not the default. It is also **downgrade-only**: a surviving mutant
can move `SAFE` to `UNPROVEN`, but a clean mutation run never lifts a verdict.
An inconclusive mutant (one that times out) is skipped, not held against you.
Python-only, and bounded to the statements the diff changed.

> [!NOTE]
>
> This is stricter than it was in 0.4.0. The old rule cleared a whole file as
> soon as **one** changed statement in it ran, so a diff changing 40 statements
> with 1 exercised returned `SAFE`. If you are comparing against stored reports,
> a `SAFE` whose `coverage.changedStatements` shows `covered < total` was earned
> under the old rule.

## `--flaky-check`: was the green stable, or lucky?

A default `SAFE` assumes your tests are **deterministic**. The suite runs once; a
test that passes because of randomness, ordering, timing, or hash-seed dependence
— not because behaviour is preserved — still counts toward `SAFE`. The single-run
fast path cannot tell a stable green from a lucky one.

`refactron verify-diff --flaky-check` closes that gap. After a would-be-`SAFE`
verdict, it reruns your suite several times on fresh trees, each under a different
`PYTHONHASHSEED`, and if any test's outcome **varies** across the reruns, the
green was never stable, so the verdict floors at `UNPROVEN`, naming the flaky
test:

```
[UNPROVEN] Tests pass, but a test outcome varied across reruns
(tests/test_x.py::test_scale); the green is flaky, not stable. Fix the
flakiness or the verdict cannot be SAFE.
```

Like `--mutate` it is opt-in and slower — it reruns your whole suite K times
(default 3) — so it is a deep check, not the default. It is also
**downgrade-only**: a varied test can move `SAFE` to `UNPROVEN`, but a run where
every rerun agrees never lifts a verdict. A rerun that times out is inconclusive
(skipped), not held against you. Varying `PYTHONHASHSEED` catches dict/set
order-dependence deterministically; timing, network, and `random`-based flakes are
probabilistic, so K reruns give K chances rather than a guarantee.

> [!NOTE]
>
> Because the default gate runs the suite once, a **default** `SAFE` cannot detect a lucky-pass
> flake. It is an honest verdict on the run it observed. If your suite has any non-determinism, use
> `--flaky-check` before trusting a `SAFE`.

`SAFE` also requires that the suite was not narrowed. If your `testCmd` names a
subset of the suite, the verdict floors at `UNPROVEN` however well the changed
code is covered, because a green run of the tests you selected says nothing
about the tests you did not. See [A narrowed test command cannot be
SAFE](#a-narrowed-test-command-cannot-be-safe) below.

A `SAFE` report carries the full coverage record, and `coverage.changedStatements` gives the ratio outright:

```json theme={null}
"coverage": {
  "changedLinesCovered": true,
  "changedStatements": { "total": 40, "covered": 40 },
  "uncovered": []
}
```

Every changed statement ran. A `SAFE` no longer carries an unexercised or an excluded changed statement: either one floors the verdict to `UNPROVEN`. An unexercised statement is a plain coverage gap; an excluded one is attacker-controllable, so it is not proof of anything. The 0.4.x reports that showed a `SAFE` with `"excluded": true` in `uncovered`, or with `covered` below `total`, were produced under the older rules and no longer occur.

`SAFE` requires coverage, and [coverage is Python-only](#the-python-only-limitation). A change that isn't entirely Python can't reach `SAFE` today.

## UNSAFE

A gate rejected the change:

* **Syntax**: the changed file no longer parses.
* **Imports**: an import in the changed content doesn't resolve, or a previously-resolving import now fails.
* **Tests**: your suite went red on the change.

`UNSAFE` exits `1`, and a failing test gate prints the test output so you can see what broke. This is a real signal that the change is wrong, not merely `UNPROVEN`.

> [!NOTE]
>
> One case looks like a test failure but isn't a real one: if your suite is **already red before**
> the change, or **no test runner** is detected, Refactron can't blame the change for anything, so
> it returns `UNPROVEN`, not `UNSAFE`. A broken baseline is a "can't prove it" situation, not
> evidence the diff broke something.

## UNPROVEN

The gates passed, but Refactron won't claim the change is safe, because the evidence isn't there. This is the verdict no other gate gives you honestly.

There are three ways to land here:

* **The changed code isn't exercised.** Your tests pass, but none of them run the code you changed. A green suite tells you nothing about untested lines. Refactron lists each uncovered statement and, in the JSON report, a `missingTests` hint:

  ```json theme={null}
  "missingTests": [
    { "file": "calc.py", "hint": "add a test exercising calc.py:14" }
  ]
  ```

* **Coverage couldn't be assessed.** The change isn't entirely Python, or `coverage.py` isn't installed. Refactron can't measure whether the changed statements ran, so it declines to certify `SAFE`. The reason reads "coverage of the changed code could not be determined."

* **The run could not be isolated.** Refactron runs your tests in a copy under a directory private to your account (see [Where the copy is made](https://docs.refactron.dev/concepts/safety-model.md#where-the-copy-is-made)). When it cannot, nothing is verified, so the verdict is `UNPROVEN`, never `UNSAFE`. The reason begins with one of:

  ```
  could not create a private directory for the verification copy: ...
  could not create the verification copy (ENOSPC)
  a conftest.py above the verification copy could change the test run, so it was not run (found in ~)
  ```

  The first names the directories tried; set `REFACTRON_VERIFY_BASE` to a directory that only you can write to, with no parent writable by anyone else. The third names the file and where it was found; move it, or set `REFACTRON_VERIFY_BASE` elsewhere.

`UNPROVEN` exits `0`. It is a warning, not a rejection: nothing is known to be broken, but nothing is proven either. The right response is to add the missing test, then re-run and earn `SAFE`.

> [!TIP]
>
> `UNPROVEN` turns your test suite's blind spots into a to-do list. Every uncovered statement is a
> test you could write to move the verdict to `SAFE`.

### Coverage is judged per statement, not per line

`coverage.py` records execution against the **first line of a statement**. A statement wrapped
across several lines, which is what any formatter produces, has continuation lines, closing
brackets, and trailing commas that `coverage.py` never marks at all.

Refactron therefore maps each changed line to the statement that **contains** it, using the Python
AST, before judging it. A changed continuation line counts as exercised when the statement it
belongs to ran, and one unexercised multi-line statement produces **one** entry, at the line you
would actually write a test against, not one entry per physical line. Without this, a reformat that
only rewraps code reports every wrapped line as uncovered: a `black` run over 28 files once produced
3666 such entries, almost all of them for code that provably executed.

Containment is the load-bearing word. The cheaper version of this idea, "walk back to the nearest
statement start at or above the changed line," is wrong in a way that manufactures false `SAFE`
verdicts: it cannot tell a continuation line of that statement from a blank line, a comment, or a
dead-branch line that merely *follows* it and belongs to somewhere else entirely. Under that rule an
executed `def` vouches for a body that never ran. Real extents from the AST answer the question
exactly.

### Blank lines and comments prove nothing, and are asked to prove nothing

A changed line carrying no code at all, a blank line or a comment-only line, is **inert**. It cannot
change behavior, so Refactron never reports it as uncovered; and it cannot be exercised by a test,
so it never counts toward a file's coverage either. Formatters move blank lines constantly, and a
mechanism that let them vouch for their neighbours would turn every reformat into a free `SAFE`.

A file whose changed lines are *all* inert has nothing to attest, and gets its own reason rather
than a pass:

```
[UNPROVEN] Tests pass. The change only touches comments and blank lines; there are no added
statements for coverage to attest.
```

That is deliberately conservative. A diff exposes only the lines it **adds**, so "every added line
is inert" is not the same claim as "this file is unchanged": a deleted statement next to a moved
blank line looks identical from here. Removal-only files are treated the same way and for the same
reason.

A docstring is a real statement in Python, so a docstring-only edit lands on its own statement and
is judged like any other. `coverage.py` does not track function docstrings, so such a change
typically reads as unexercised, which is the honest answer rather than a convenient one.

### Code your suite is not allowed to reach

Some statements can never be exercised, by design. A `# pragma: no cover` block, or an import under
`if TYPE_CHECKING:`, is excluded from `coverage.py`'s judgement and never executes under test. A
diff with **any** excluded changed statement therefore **cannot reach `SAFE`**: the exclusion floors
the whole file to `UNPROVEN`, however well the rest of the change is covered. The exclusion set
travels inside the diff (an inline pragma, a `.coveragerc`, a `pyproject` rule), so an untrusted
change could mark a live line excluded and no test would ever run it. Refactron will not certify a
statement it was told to ignore.

These entries are marked, and their hints say what is actually true instead of asking for a test
that cannot exist:

```json theme={null}
"coverage": {
  "uncovered": [{ "file": "gated.py", "line": 6, "excluded": true }]
},
"missingTests": [
  {
    "file": "gated.py",
    "hint": "gated.py:6 is excluded from coverage (e.g. `# pragma: no cover`, `if TYPE_CHECKING:`), so no test can exercise it; review this change by hand"
  }
]
```

The right response is a human review of that hunk, not a new test.

Large diffs are capped so the report stays readable. When Refactron truncates, it says so rather
than shipping a short list that looks complete:

```json theme={null}
"coverage": {
  "uncoveredTruncated": { "shown": 200, "total": 412 },
  "filesWithUncovered": 37
},
"missingTestsTruncated": { "shown": 50, "total": 412 }
```

Each file is guaranteed a share of the list before any file takes a second helping, so one
pathological file cannot consume every slot and push later files out of the report entirely.
`filesWithUncovered` counts distinct files **before** the cap, so you can always tell whether the
list you are reading spans the whole diff.

## The Python-only limitation

Coverage fusion depends on `coverage.py`, so it is **Python-only** today:

* A diff where **every** changed file is `.py`, with `coverage.py` available, can be assessed, and can reach `SAFE`.
* A diff touching **any** TypeScript (or any non-Python) file, or run without `coverage.py`, returns `UNPROVEN` with `coverage.tool: "none"`. The gates still run; only the coverage half is unavailable.

Refactron never guesses here. Reporting a non-Python change as "covered" would let an unverified change through as `SAFE`: a false `SAFE`, which the engine forbids. When it can't measure, it says `UNPROVEN`.

## Coverage cannot see subprocesses

Coverage fusion measures the lines your test process executes. Code that runs only in a child process, launched through `subprocess.run`, a `multiprocessing` worker, or a spawned server, is invisible to `coverage.py` unless you wire up subprocess coverage yourself: a `COVERAGE_PROCESS_START` environment variable plus a `coverage.process_startup()` call in `sitecustomize`.

Without that wiring, a change whose only exercise happens inside a subprocess reads as `UNPROVEN`. The gates still pass, but the changed statements never register as covered, so Refactron declines to certify `SAFE`. This is the honest result, not a defect. First-class subprocess coverage is a planned fast-follow; until it lands, exercise the changed code in-process in at least one test so the verdict can reach `SAFE`.

## SAFE means suite-approved, not proven correct

`SAFE` says your suite ran the changed code and stayed green. It does not claim the change is correct in some absolute sense: it inherits exactly what your suite checks. That includes side effects your suite never observes, an extra or missing database write, an email that stopped sending, a log a downstream system parses: Refactron sees a change only through your tests, so behavior no test watches is outside the verdict. Audits of AI agent patches (for example on SWE-bench) find that a substantial share of patches which pass the project's tests are still wrong, because the suite was too weak to catch the defect.

Refactron cannot turn a weak suite into a strong one, but it refuses to overstate what a green run proves. That is why `UNPROVEN` exists, and why every uncovered statement ships with a `missingTests` hint: the path to a `SAFE` you can trust is a suite that actually exercises the behavior you care about.

A worked example from our own hardening runs, on a real library. Jinja2's `truncate` filter guards its early return with `if len(s) <= length + leeway`. Change that `<=` to `<` and the behavior genuinely changes: at the exact boundary the string is now truncated instead of returned whole. All 911 tests in Jinja2's suite still pass, because none of them lands on that precise boundary, and the changed line is covered, so the verdict is `SAFE`.

That verdict is correct about what it claims (the suite ran this line and stayed green) and it is still not a proof of correctness. Boundary conditions are exactly where suites tend to be thin. Read `SAFE` as "your tests approve this change", then decide separately whether your tests are strong where this change lives.

## An untrusted diff cannot be SAFE

Coverage and the pass/fail gates are measured by running the diff's **own** test
suite, in the same process as the coverage collector. A hostile diff therefore owns
the process the measurement runs in: a few lines of `conftest.py` can mark a
never-executed changed line as covered and earn a `SAFE` the change never deserved.
The forgery is undetectable from inside the process the forger controls.

So a would-be-`SAFE` is **withheld** and floored to `UNPROVEN` unless you declare
the diff's author trusted. The default is untrusted, because the product verifies
changes you did not write (an AI agent's, an outside contributor's), and the safe
default is the one that does not trust a forgeable measurement:

```bash theme={null}
refactron verify-diff . --diff change.diff              # untrusted (default): SAFE withheld, returns UNPROVEN
refactron verify-diff . --diff change.diff --trusted    # trusted: SAFE allowed
```

`--trusted` is asserted by you, the operator, and never inferred from the diff. The
diff is the untrusted input; it cannot certify itself. Set it only for a change
whose author you already trust (your own, or a reviewed internal one), never for an
external or agent-authored diff you are verifying precisely because you do not trust
it yet.

`UNSAFE` is unaffected: an attacker does not forge a gate failure against their own
goal, so only `SAFE` is withheld. The withheld verdict carries a distinct reason
(it contains "SAFE is withheld"), and every report stamps `trustMode` (`trusted` or
`untrusted`), so a consumer can tell a trust withhold from a real coverage gap.

A trust-grade `SAFE` over a diff you do not trust cannot be produced by a local,
in-process run at all. It needs a hermetic run whose measurement the suite cannot
reach, the planned second path to a trusted `SAFE` alongside `--trusted`.

## A narrowed test command cannot be SAFE

If you pass a `testCmd` that names a subset of the suite, the verdict floors at
`UNPROVEN`. Coverage can report the changed code as fully exercised while the
one test that would have caught the change was never selected.

> [!NOTE]
>
> **What this check can and cannot see.** Refactron reads the command string, the environment, and
> your pytest configuration. It recognises `pytest`, `unittest`, `vitest` and `jest` and their
> common flags — but not every flag of every plugin. A command carrying an option it does not
> recognise is reported `unknown` rather than `full`, and `unknown` does not floor the verdict. For a
> pytest command, your pytest configuration and `PYTEST_ADDOPTS` are still checked whatever flags
> it carries.
> Treat this as a strong check on the shapes it knows, not a guarantee that no narrowing can ever
> reach `SAFE`. If you need certainty, run the bare command.

A worked example. One file, one change (`return x * 2` to `return x * 3`), and
two tests: `test_scale` executes the changed line without pinning its value,
`test_report` pins it and fails. Only the command differs:

```bash theme={null}
# runs both tests; test_report catches the change
python3 -m pytest -q                       # UNSAFE

# runs only the weak test; the change sails through
python3 -m pytest -q tests/test_scale.py   # UNPROVEN (previously SAFE)
```

Every changed statement executed in the second run, so coverage alone cannot
tell the two apart. The scope of the run is what distinguishes them.

Refactron classifies your command into three buckets, and reports the result on
`testScope`:

| Scope | Meaning | Can be SAFE |
| - | - | - |
| `full` | Parsed, and names no filter | yes |
| `narrowed` | Names a path, node id, `-k`, `-m`, `-t`, `--onlyChanged`, … | no |
| `unknown` | Not recognised (`make test`, `npm test`, a flag on a wrapper script) | yes |

**Naming a directory counts as narrowing**, including `pytest tests/`. Tests can
live outside any single directory, so Refactron cannot treat that as the whole
suite without risking a false `SAFE`. Run the bare command (`pytest -q`) to get a
`SAFE`-eligible verdict. `pytest .` is fine: `.` collects from the root, so it is
never narrower than the default.

For `unittest` the canonical whole-suite form is different, and Refactron treats
it accordingly: `python3 -m unittest discover -s tests` is `full`. Bare `discover`
starts from the current directory, so pointing it at the test directory is how a
complete unittest run is normally written, not a narrowing of one. Naming a
module, class or method (`python3 -m unittest tests.test_scale`) is `narrowed`.

**A run that executes no tests is narrowing too.** `--collect-only` and `--help`
exit successfully while selecting zero tests, and they still import your test
modules, so coverage can mark module-level changed lines as executed. Those are
classified `narrowed`.

`unknown` does not floor the verdict. Most commands that land there are a full
suite carrying a flag we do not recognise (`pytest --doctest-modules`), and
refusing `SAFE` for every unrecognised plugin flag would be worse than the gap it
closes. The CLI says so explicitly rather than staying quiet:

```
  note: could not determine whether the test command runs the whole suite
        (make is not a recognised test runner, so the scope is unknown);
        the verdict assumes it does.
```

Refactron recognises `pytest`, `unittest`, `vitest` and `jest` by name, so
`python -m unittest tests.test_foo` and `python3 tests/runtests.py auth` are both
`narrowed`. A **flag** on an unrecognised script stays `unknown` and is not
floored: `python3 tests/runtests.py --parallel 4` could be a whole suite, and we
do not know that flag well enough to guess.

An exported `PYTEST_ADDOPTS` (or `VITEST_ADDOPTS` / `JEST_ADDOPTS`) **is** seen:
its value is scanned with the same rules as the command line, and it is checked
against the runner that variable actually feeds, so a `PYTEST_ADDOPTS` left in
your shell will not floor a vitest project.

Narrowing configured in your **pytest** configuration is also seen, and it is
read by pytest itself. A small helper uses pytest's own code to choose the
configuration file and parse it, from the same copy of your repository the tests
run in, with the change applied. Every file pytest accepts is therefore read the
way pytest reads it, in pytest's order of precedence: `pytest.toml`,
`.pytest.toml` and a native `[tool.pytest]` table (pytest 9), `pytest.ini`,
`.pytest.ini`, `pyproject.toml`, `tox.ini` and `setup.cfg`, including a file
named by `-c` / `--config-file` and values set by `-o` / `--override-ini`,
whether they appear in your command or in `PYTEST_ADDOPTS`. The helper never
imports your `conftest.py`, a plugin, or any module from your repository.

The helper runs under the interpreter your command names (`python3.12 -m pytest`,
a `PATH=` you set in the command, or the one a `pytest` script's shebang names).
When the command does not say (`poetry run pytest`, `uv run pytest`, a pyenv or
asdf shim), it uses `python3`. Either way the answer is also worked out for each
pytest generation (6, 7–8 and 9, which order their files differently), and if a
pytest that might be the one running your tests would read different settings,
the configuration counts as unreadable.

`addopts` is scanned with the same rules as the command line, so
`addopts = -q --strict-markers` stays `full` while `addopts = -k foo` does not.
One difference: a flag Refactron does not recognise is `unknown` on the command
line, which does not floor, but floors when it comes from `addopts` (for example
pydantic's `--benchmark-*` options or tox's `--no-success-flaky-report`).
`testpaths` counts as narrowing only when it leaves a test out: Refactron lists
the files pytest would discover with its default patterns (`test_*.py`,
`*_test.py`) and checks each against `testpaths`, so `testpaths = ["tests"]` in a
project whose tests all live under `tests/` stays `full`, and so does an empty
`testpaths = []`, which pytest ignores. When the file list cannot be trusted,
`testpaths` counts as narrowing: the scan was capped, no test files were found,
or `python_files` is customised so the default patterns do not apply.

**A configuration that cannot be read counts as narrowing.** If the helper cannot
give an answer, the scope is `narrowed` and the signal says the pytest
configuration "could not be read", naming the file when it is known and giving the
reason. The reasons include: no Python interpreter, pytest not importable from it,
a syntax error in the file, a timeout, settings that depend on the pytest version,
a pytest 9 format (`pytest.toml`, `[tool.pytest]`) under an older pytest, which
ignores it, and a command whose pytest arguments use shell syntax (`$VAR`, a
leading `~`, a glob, a backslash) or an `@file`, because the text Refactron holds
is not what pytest receives. Reporting `unknown` instead would not cap the
verdict, and the configuration nobody read could be the one that deselects the
failing test. If this happens because `python3` is not your project's
interpreter, run Refactron from the activated environment so that `python3` is
its interpreter.

A vitest `include` or a jest `testMatch` is still **not** seen. Those are
JavaScript and would have to be executed rather than parsed. In practice they
cannot reach a false `SAFE` today, because coverage is Python-only and a
JavaScript or TypeScript change already caps at `UNPROVEN`.

`full` therefore means "no filter was found in the command, the environment, or
the `addopts` and `testpaths` of your pytest config". It is still not a proof
that the whole suite ran. Other settings that change collection are not judged:
`python_files` without `testpaths`, `python_functions`, `python_classes` and
`norecursedirs`. A runner plugin or a `conftest.py` can also deselect tests in
ways nothing here inspects.

The `PYTHONPATH=` prefix recommended below is **not** narrowing.
`PYTHONPATH=. python3 -m pytest -q` classifies as `full`.

## Make sure the tests run the code being verified

Refactron verifies a change in an isolated copy of your project. If your tests import the package from somewhere else, they will exercise the original code and the run proves nothing about your change.

The common cause is a project installed into the environment, including an editable install (`pip install -e .`), because `import yourpackage` then resolves to the installed location rather than the copy under verification. We hit this on Django: the same diff read `UNPROVEN` when the tests loaded the installed copy, and `UNSAFE` (correctly, since the auth suite catches the change) once the verified copy came first on `sys.path`.

Refactron detects the case rather than guessing: if a changed file is never even measured by coverage, the verdict reports that coverage could not be determined instead of claiming the code is untested, and the report carries the reason and this remedy in `coverage.unknownReason`.

To get a real verdict, make the verified tree win on `sys.path`. Either export `PYTHONPATH=.` before you run Refactron, or prefix the test command itself:

```bash theme={null}
PYTHONPATH=. python3 -m pytest -q      # or PYTHONPATH=src for a src layout
```

Both forms work from the CLI. Over MCP only the prefix form is available, because the client spawns `refactron-mcp` itself and there is no shell of yours to export into. Relative paths are resolved from the copy being verified, which is what you want here.

Write the command in **module form** (`python3 -m pytest`) rather than as a bare console script (`pytest`). Coverage has to run the same program the test gate ran, and a console script is only runnable under coverage when it resolves to a Python file. It does not on Windows, where console scripts are native `.exe` launchers, nor under pyenv, asdf or nix, which install shell shims. Refactron declines to measure rather than measure a different program, so a bare console script reports that coverage could not be determined on those setups. Module form is measurable everywhere.

## Exit codes

The verdict maps to a process exit code so it can gate CI directly:

| Verdict | Exit code |
| - | - |
| `SAFE` | `0` |
| `UNPROVEN` | `0` |
| `UNSAFE` | `1` |

Both `SAFE` and `UNPROVEN` pass, so a green suite on untested lines never silently blocks a merge. To fail CI on `UNPROVEN` too, read the `verdict` field from the [JSON report](https://docs.refactron.dev/verification/verify-diff.md#the-json-report) and decide for yourself.

> [!NOTE]
>
> Bad input (a diff that doesn't apply, a missing flag) exits `2`; an unauthenticated CLI run exits
> `7`. Those are operational errors, not verdicts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.