Revert check and mutation mode
Both ask the same question from two sides: do the tests that claim a criterion really depend on the code the PR changed? Neither calls a model.
okproof revert-check
Reverts each changed source file (or group of files) to the base, inside a temporary worktree at HEAD, and re-runs your tests. A criterion whose tests stay green with every changed file reverted is uncovered: those tests never exercised the change. Usage is in the README.
okproof revert-check --mutate
okproof revert-check --mutate --base origin/main --test "npx playwright test --reporter=junit" --results results.xml [--max-mutants 20] [--allow-survivors] [--timeout 600] [dir]
For the lines the PR added or changed (taken from git diff -U0), okproof builds small deterministic mutants, one change each:
| op | change |
|---|---|
cmp | ===/!==, ==/!=, < to >=, > to <=, <= to >, >= to < |
bool | true/false (Python True/False) |
arith | + to - and back (spaces on both sides, so ++, += and unary signs are left alone) |
return | a one-line return <expr>; becomes return undefined/null/0/'' (Python: None/0/'') |
Comment lines, imports, decorators, string contents and lines over 400 characters are never mutated. Only JavaScript/TypeScript and Python files are mutated; other changed files are listed as skipped. At most --max-mutants (default 20) are run, picked evenly across the candidates so the choice is deterministic.
In a temporary worktree at HEAD, okproof first runs the tests unmutated, then reverts each mutated file once to learn which criteria depend on it, then runs your test command once per mutant, restoring the file each time. Your working tree is never changed and the worktree is always removed.
A mutant is:
killedwhen some criterion that passed unmutated no longer passes (a mutant that makes the run time out counts as killed);survivedwhen no criterion noticed;invalidwhen the run wrote no results file (probably a broken build); it says nothing and is not counted.
Per criterion, in .okproof/mutate-<issue>.json:
strong: every mutant in the region it covers was killed;weakly-covered: some mutant there survived. The gate fails unless you pass--allow-survivors(to the command, or tookproof gate);unreached: its tests do not depend on any mutated file (revert-checkreports that case asuncovered);failing/untested: not passing unmutated.
The region a criterion covers is estimated, because okproof does not collect line coverage: in each file it depends on, it is the line span of the mutants that criterion's tests killed; a criterion that kills nothing in a file it depends on covers the whole file. A surviving mutant that another criterion killed is not held against this one. Treat a weakly-covered result as a pointer to an assertion worth strengthening, not as proof of a bug; some survivors are equivalent mutants. The result file lists every mutant, with its line and the criteria that killed it.
mutate-<issue>.json carries the proof file's criteriaHash; if the criteria change afterwards, the gate reports the file as stale until the command is re-run.
Using Stryker, PIT or mutmut instead
okproof does not depend on any mutation tool and does not run one. Those tools are more thorough (real parsers, coverage-guided selection) and can be used next to okproof:
- Run the tool on the files the PR changed, in CI.
- Turn its report into a JUnit or CTRF file in which each criterion that has surviving mutants has a failing test case named with the criterion's tag, for example
mutation score for sign-in [okproof:142.1], and each criterion with none has a passing one. - Merge those test cases into the results file you give to
okproof ingestorokproof gate --results. A failing tagged test fails its criterion, so the gate stops the PR the same way.