Reviewed twice, 100% coverage, and 12 mutants still survived
We let Claude Code agents build an iPhone app in Swift, a language I can't write. What made me trust the result wasn't code review. It was a mutation runner that fails the build.
The runner lives in the repo and is built on swift-syntax. It changes the source one site at a time: flips a comparison, swaps && for ||, nudges an integer, or deletes a statement. Then it reruns the tests. If no test notices, the mutant survives and the build goes red. The only way out is an allowlist entry with a one-line justification, and stale entries also fail the gate, so the list can't rot.
The number that convinced me: one batch of eight tasks, each one implemented, reviewed, fixed and re-reviewed, with 100% line, function and region coverage. The full mutation run still found 12 survivors. An agent wrote tests that killed ten of them and justified two as equivalent.
At one pull request the core package had 1,730 mutants, 1,706 killed, 8 timeouts, and 16 survivors, each with a written reason.
Two rules came from watching the runner itself fail:
- It aborts if the unmodified suite fails, times out, or reports zero tests. Scoring mutants against a broken baseline is worse than not running at all.
- A timeout counts as a kill only once it confirms the whole process tree is dead. An orphaned test helper once idled for three hours, and a CI job hung until GitHub cancelled it at 240 minutes.
The cost is time: a full run takes about three hours on a loaded Mac. So pull requests run only the changed files, and the full gate runs on main and weekly.
You don't need to write your own runner. Swift had nothing that fit, so we built one. For a client we run the same gate on Java with PIT (pitest) and on TypeScript with Stryker:
- PIT has Maven and Gradle plugins, and its history files make reruns incremental. Arcmutate's commercial extensions add mutating only the lines a pull request changed, plus Kotlin and Spring support.
- Stryker has an
--incrementalmode, and its TypeScript checker discards mutants that don't compile before running any tests. Our Swift runner does the same with mutants that won't build. - Both fail the build on a mutation score threshold rather than on any single survivor. Moving from "score ≥ 85%" to "zero unexplained survivors" is the part that changes how agents write tests. A threshold leaves room for the agent to skip the hard cases.
Does anyone run mutation testing on agent-written code in CI, or is it too slow for you outside a nightly job?
Full write-up: saasforge.cz/blog/dark-factory-the-wall/






Comments
0 comments