Killing Survivors Without Chasing the Score: 31 Tests, 62 Mutants
31 tests in ufo's own style detect 62 of the 176 mutants its suite missed. The other 114 stay undetected on purpose, each with a written reason.
31 tests in ufo's own style detect 62 of the 176 mutants its suite missed, and move the score from 82.59% to 88.72%. The other 114 stay undetected on purpose, and each one has a written reason. Chapter 3 read the report. This chapter acts on it, and stops well short of 100%.
Chapter 4 of Mutation Testing for the AI Era. The tests, the list of accepted mutants and the raw reports are in the PoC repo.
The rule
A new test has to check something ufo promises: a doc comment, an example, or behaviour a caller relies on. If the only test that kills a mutant would pin odd behaviour, the mutant stays alive and I write down why.
Survivors in an OSS subject are suite gaps, not bugs. All 31 tests pass on ufo as it is. They check behaviour ufo already has, which its own suite did not check.
Triage before tests
I sorted the 176 before I wrote a test. The order: the file, then equivalence, then the contract.
- The file. 47 undetected mutants are in
punycode.ts, a minified copy of punycode 2.1.1 vendored into ufo. Their gaps belong to punycode's tests, so they are out of scope. 22 more are inurl.ts, whose$URLandcreateURLare marked@deprecatedupstream. A new test for deprecated code is cost with no return. Accepted. - Equivalence. 22 mutants behave like the original for every input. No test can kill them. Accepted.
- The contract. 23 mutants can be killed, but only by a test that pins behaviour nobody relies on. Low value. Accepted.
That leaves 62, and each one now has a test. 53 of them had survived and 9 had no coverage.
Where the tests live
subject/ stays a byte-identical copy of ufo at f06c800. The 31 tests are in kills/, written the way ufo writes its own: describe and test, tables of { input, out }, and an import from "../src". Each file drops into ufo's test/ folder unchanged.
Stryker normally stops at the first test that kills a mutant. This chapter sets disableBail: true, so the report lists every test that kills each mutant. That is where the per-test counts below come from.
The measure script fails if a new test kills nothing that ufo's suite missed. It also fails if the accepted list does not match the undetected mutants exactly. CI runs it on every push, so the list cannot drift from the report.
Results
| Mutants | Killed | Timeout | Survived | No coverage | Mutation score | Score of covered code | |
|---|---|---|---|---|---|---|---|
| Before (ufo's suite) | 1011 | 823 | 12 | 112 | 64 | 82.59% | 88.17% |
| After (+ 31 tests) | 1011 | 881 | 16 | 59 | 55 | 88.72% | 93.83% |
Stryker ran twice on a GitHub-hosted runner and scored 88.72% both times. Every mutant had the same status in both runs.
One test, eight mutants
Chapter 3 found 7 undetected mutants on one line of parseQuery: the guard that drops __proto__ and constructor keys. The doc comment promises that guard. The test from chapter 3 is now in kills/:
test("ignores __proto__ and constructor keys", () => {
expect(parseQuery("__proto__=x&constructor=y&a=1")).toEqual({ a: "1" });
});It kills 8 mutants: all 7 on that line, and #375, which makes parseQuery always drop the first character. 7 of the 8 die to this test alone. Across all 31 tests the range is 1 to 8 mutants each. Some mutants die to more than one test, so the 62 work out at 2 per test added.
Overlap is fine
For 7 of the 31 tests, every mutant they kill is also killed by another new test. isScriptProtocol("https:") is one of them. It kills #595 from chapter 3, but so does the xjavascript: case in the same table.
I kept all 7. Each one checks a different promise, and a higher score is not the reason a test exists. Deleting a test because another test already covers its mutants is chasing the score in the other direction.
The 22 no test can kill
An equivalent mutant changes the code but not what the code does. Here is #1000, in withFragment:
if (!hash || hash === "#") {
return input;
}
const parsed = parseURL(input);
parsed.hash = hash === "" ? "" : "#" + encodeHash(hash);Stryker replaced hash === "" on the last line with false. The guard above already returns when hash is empty, so that comparison is never true. The mutant changes nothing that a test can see.
The other 21 are the same kind of difference that no input can reach. A default value that the regex always fills. A fallback array that the code only reads from index 1. A regex match that always has 3 entries, so < 2 and <= 2 give the same answer (#393). #95 from chapter 3 is on the list too.
The 23 a test could kill, but should not
Low value means the only killing test would pin behaviour that no caller relies on.
- 11 default arguments, such as
input = "". A test would call the function with nothing. Chapter 3 called these cheap to cover. They are also cheap to leave. - #70,
mailto:.parseURLturns a URL without//after the scheme into all-empty fields. The mutant changes a default that only that path uses. A test that kills it would pinmailto:a@b.comparsing to six empty strings. - Fast paths.
resolveURLreturns early when there is nothing to resolve. Without the early return, the slow path parses and rebuilds the base.HTTP://a.com/xcomes back ashttp://a.com/x, andmailto:a@b.comcomes back as//, the #70 behaviour again. A killing test would pin whatresolveURLdoes with a base and no segments, which is not what the function is for.
Each of the 23 has its reason in the accepted list, next to its mutant id.
Why a list and not disable comments
Stryker can skip a mutant with a comment in the source, such as // Stryker disable next-line ConditionalExpression: equivalent, guard above. That edits the code. Here the code is ufo's, and the copy must stay identical to upstream. So the reasons live in results/ch4-kills/accepted.json, by mutant id.
Ids only hold while the source and the mutators stay the same. The measure script checks that every id still points at the same mutant as in chapter 3. In your own repo, the comment is the better place: it sits next to the code and moves with it.
Timeouts went up
Timeouts rose from 12 to 16. Four punycode.ts mutants (#323, #325, #359, #369) went from Killed to Timeout. With disableBail, Stryker runs every covering test against a mutant instead of stopping at the first failure. For these 4, the full set ran past the time limit. Both statuses count as detected, so the score is the same either way.
Each Stryker run took the CI runner 395 to 407 seconds, with disableBail on.
What didn't work
- The CI check passed when it should have failed. The step runs
git diff --exit-codeonsummary.jsonto prove that a fresh run matches the committed numbers. On the first run, nosummary.jsonwas committed yet, andgit diffignores untracked files.git add -Nmarks the file as intent-to-add, so the diff sees it. The next run failed as it should, and printed the numbers it found. - The first full runs were on a laptop with other work running. Static mutants timed out there that survive on a quiet runner, so the count of newly detected mutants was too high. One of them, #549, is on the equivalent list: on the runner it survives. Every "after" number in this post comes from the CI runner. The "before" row is the chapter 3 report.
Limits: one library, one commit, Stryker's default mutators. The 67 accepted mutants reflect my reading of ufo's contract. Another reader could move a few of the 23 low-value mutants into the "write a test" pile.
Triage first: the file, then equivalence, then the contract. Write tests only for what is left, and write down why the rest stays.
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, 2 Stryker runs.
related
QA Ark Newsletter
Test automation, AI in testing and quality engineering practice. No spam, unsubscribe any time.