Reading a Mutation Report: 176 Mutants ufo's Tests Missed
StrykerJS on unjs/ufo: 1011 mutants, 82.59% on two runs. What Survived, NoCoverage and Timeout mean, where to look first, and which survivors are worth a test.
A mutation report is a list of questions, not a list of bugs. I ran StrykerJS on unjs/ufo, a URL library with 489 tests, and it scored 82.59% on both runs: 176 of 1011 mutants went undetected. This post reads that report: what each status means, where to look first, and which survivors are worth a test.
Chapter 3 of Mutation Testing for the AI Era. The pinned copy of ufo, the measure script and the raw reports are in the PoC repo.
The subject
ufo at commit f06c800 (v1.6.4), copied unchanged, with its own Vitest suite. Stryker mutated every file in src/ except index.ts, which only re-exports the others.
Survivors in an OSS subject are suite gaps, not bugs. Each one is a change to the code that no test noticed. It says nothing about whether ufo is wrong.
| Mutants | Killed | Timeout | Survived | No coverage | Errors | Mutation score | Score of covered code |
|---|---|---|---|---|---|---|---|
| 1011 | 823 | 12 | 112 | 64 | 0 | 82.59% | 88.17% |
What each status means
Stryker gives each mutant one status:
- Killed: at least one test failed with the mutant in place. The suite noticed.
- Survived: tests ran the mutated code, and all of them passed. The report's own tooltip says it plainly: "You're missing a test for them."
- No coverage: no test ran the mutated code at all.
- Timeout: the mutated code ran far longer than the normal run, usually an endless loop. Stryker counts it as detected.
- Runtime error and compile error: the mutant broke the run or the build. They are left out of the score. There were none here.
The score is (killed + timeout) / (killed + timeout + survived + no coverage). "Score of covered code" leaves out the no-coverage mutants. The gap between those two numbers is the first thing to read.
Where to look first: the two scores per file
The HTML report shows both scores for each file. Their gap tells you what kind of work each file needs.
| File | Mutants | Survived | No coverage | Score | Score of covered code |
|---|---|---|---|---|---|
| encoding.ts | 43 | 1 | 1 | 95.35% | 97.62% |
| parse.ts | 150 | 6 | 15 | 86% | 95.56% |
| punycode.ts | 180 | 28 | 19 | 73.89% | 82.61% |
| query.ts | 78 | 9 | 2 | 85.9% | 88.16% |
| url.ts | 90 | 8 | 14 | 75.56% | 89.47% |
| utils.ts | 470 | 60 | 13 | 84.47% | 86.87% |
- A wide gap means code no test runs.
url.tsscores 75.56% of all mutants but 89.47% of covered ones. 14 of its 22 undetected mutants have no coverage. The fix is a test that calls that code. - A narrow gap means tests that run the code but do not check it.
utils.tsscores 84.47% and 86.87%. 60 of its 73 undetected mutants survived. The fix is a sharper assertion in a test that already exists. - Check what the file is before you read its survivors.
punycode.tshas the lowest score and 47 undetected mutants. Its header comment explains why: "Tree-shaked + Minified version of punycode@2.1.1". It is vendored, minified code. Read its survivors last, or leave it out ofmutate.
What the mutator tells you
The mutator name says what kind of check is missing:
- ConditionalExpression: 41 of 112 survivors. Stryker replaces a condition with
trueorfalse. A survivor means no test needed the other outcome. - StringLiteral: 34 of 64 no-coverage mutants. Many are default parameters such as
input = "". They only run when a caller leaves the argument out. These are cheap to cover and rarely matter.
The file tells you where the gap is. The mutator tells you what to write.
Same gap, two statuses
Line 62 of query.ts, the if, has 7 undetected mutants: 6 survived and 1 has no coverage.
const key = decodeQueryKey(s[1]);
if (key === "__proto__" || key === "constructor") {
continue;
}Mutant #397 replaces the condition with false. It survived, and 38 tests cover it. Mutant #405 empties { continue; }. It has no coverage. Both point at the same gap: no test sends a __proto__ or constructor key. The condition runs for every key, so the tests cover it. The body never runs, so the tests do not.
When one line holds a cluster of statuses, read it as one gap. Write one test, not seven:
it('drops __proto__ and constructor keys', () => {
expect(parseQuery('__proto__=x&constructor=y&a=1')).toEqual({ a: '1' });
});It passes on ufo as it is. With #397 in place, it fails: AssertionError: expected { __proto__: 'x', …(2) } to deeply equal { a: '1' }.
Timeouts count as detected
All 12 timeouts are in punycode.ts. Mutant #221 empties the body of this loop:
for (n = o ? e(n / 700) : n >> 1, n += e(n / t); n > 455; r += 36) {
n = e(n / 35);
}With the body empty, n never changes and the loop never ends. Stryker stops the run and counts the mutant as detected. A timeout is not a gap: a caller would hang, and a hanging test run is a failing one. Skip them when you triage.
Timeouts also depend on the machine. One rerun ran while the machine was busy, with a load average of 32. In its second Stryker run, 9 mutants timed out that had not timed out in the first: 8 had survived and 1 had been killed. The score rose from 82.59% to 83.38%. All 9 were static mutants: module-level code, such as a regex constant, that runs once when the module loads. Stryker runs every test against a static mutant, so these are the slowest to finish. The measure script compares the two runs and refused to write results. If the timeout count changes between runs, suspect the machine before the suite.
The survivors that matter
Rank survivors by what the code promises, not by count.
#397, the prototype guard. The doc comment on parseQuery says: "The __proto__ and constructor keys are ignored to prevent prototype pollution." No test checks that promise. Without the guard, __proto__ comes back as a key in the result. This is the first test I would add.
#595, isScriptProtocol. The function says if a protocol, such as javascript:, can run script:
export function isScriptProtocol(protocol?: string) {
return !!protocol && PROTOCOL_SCRIPT_RE.test(protocol);
}Stryker replaced the whole expression with true, and it survived. All 6 test cases expect true. The doc comment shows isScriptProtocol("https://example.com"); // false, but no test checks a false result. The mutant fails safe, since it flags every protocol. The gap is that the test table has only one side:
it('https: is not a script protocol', () => {
expect(isScriptProtocol('https:')).toBe(false);
});This one fails with #595 in place: AssertionError: expected true to be false // Object.is equality.
The survivors to leave
#95 is an equivalent mutant. In parse.ts, Stryker removed the ? from /([^#/?]*)(.*)?/. With the ?, an empty match gives undefined. Without it, the match gives "". The destructuring default path = "" turns both into "", so the result is the same for every input. No test can kill it, and 104 tests cover it. Stryker can skip it with a disable comment and a reason. Either way, 100% is not always reachable.
#258 looks like a gap and mostly is not. In punycode.ts, Stryker replaced the surrogate-pair check r >= 55296 && r <= 56319 && o < e with true. An emoji domain seems the obvious test. I ran toASCII on the original and the mutant. Emoji, münchen.de and other valid input gave the same output. Only a lone low surrogate after another character, which is malformed UTF-16, gave a different one. A test for it would test punycode, not ufo.
What didn't work
- The first summary had a "killing tests" count from the report's Tests view. The two final runs gave 168 and 170. Stryker stops at the first failing test for each mutant, so which test gets the kill can change between runs. The mutant statuses did not change. The summary now keeps only the stable numbers.
- The Tests view lists 487 tests, but Vitest runs 489. Stryker keys tests by their full name, and two pairs of ufo's tests share a name.
- My first note for #258 said an emoji test would kill it. Running the mutant showed it would not.
Limits: one library, one commit, Stryker's default mutators. The score belongs to this suite at this commit, not to ufo in general. Stryker ran twice, scored 82.59% both times, and every mutant had the same status in both runs.
Read the two scores per file first, then the mutator, then the line. Chapter 1 covers why coverage misses these gaps, and chapter 2 runs the same check on tests an AI agent wrote.
Everything above is reproducible: qa-gary-parker/poc-mutation-testing-ufo. Measured with StrykerJS 10.1.1 and Vitest 4.1.5 on ufo f06c800.
related
QA Ark Newsletter
Test automation, AI in testing and quality engineering practice. No spam, unsubscribe any time.