# Mutation probe (Phase 3 Step 1.763, opt-in)

A passing suite says the changed code runs, not that a test checks what it
decides. `mutation-probe.mjs` inverts a few changed lines one at a time and
reruns the tests; a mutant that still passes marks a line no test pins down.

Runs only when `prefs.global.mutationProbe.enabled` is true, and only when the
stack adapter names a test command.

```bash
MP_FILE="$WORKTREE/.pipeline/mutation-probe-$ITERATION.json"
STACK=$(node $HOME/.claude/scripts/_stack-adapter.mjs resolve --dir "$WORKTREE" | cut -d' ' -f1)
TEST_CMD=$(node $HOME/.claude/scripts/_stack-adapter.mjs command --dir "$WORKTREE" --stack "$STACK" --kind test)
[ -n "$TEST_CMD" ] && node $HOME/.claude/scripts/mutation-probe.mjs --repo "$WORKTREE" \
  --base "origin/$BASE_BRANCH" --head worktree --test-cmd "$TEST_CMD" --out "$MP_FILE"
```

`--max-mutants` and `--timeout-sec` default to `mutationProbe.maxMutants` (5)
and `mutationProbe.timeoutSec` (120 per test run). Each mutant costs one full
test run, so the bound is the cost bound.

## Mutations

Textual, single-site, and only on lines the diff added or changed (test files
excluded). The operator needs whitespace on both sides, so generics, arrows and
unary signs are left alone; comment lines and string contents are skipped.

| Kind | Change |
|---|---|
| comparison | `==` `!=` `===` `!==` `<` `<=` `>` `>=` flipped to the opposite |
| boolean | `true`/`false`, `True`/`False` negated |
| arithmetic | binary `+` and `-` swapped |
| return | `return <number>`: 0 becomes 1, anything else 0 |

Mutants are spread across lines: one per changed line in diff order before any
line gets a second.

## Isolation

`--head worktree` snapshots the uncommitted tree through a private index (the
caller's index, HEAD and refs are untouched), and every mutant is applied in a
detached worktree under the system temp directory, removed and pruned on exit,
SIGINT/SIGTERM included. The checkout is never written.

## Output and merge

| Exit | Meaning | `$MP_FILE` |
|---|---|---|
| 0 | every mutant killed or timed out | `findings: []` |
| 1 | at least one survivor | one finding per survivor |
| 4 | nothing judged: no mutable changed line, or the tests fail before mutation | `findings: []`, `reason` set |
| 2 | usage or setup error | not written; the step is skipped |

A finding is reviewer-shaped (`severity: important`, `file`, `line`, `issue`,
`fix`) plus `mutation`, `testCommand` and `tag: mutation_probe`. Step 3.0
appends `$MP_FILE` with the other deterministic findings; triage keeps a
survivor unless the line is genuinely untestable here (logging, a default no
caller observes) and says so.
