Green Tests, Wrong Code: The Migration Trap
A migration changes a contract your typical tests never touch — so passing proves little.
Reviewed by Abhijith N M · 24 October 2026 · Editorial standards
Say a function used to throw an error on bad input and now returns null instead. Your test calls it with a normal input like "42", checks the result, and passes. The code runs cleanly. The result is wrong. Nothing in the test suite noticed, because the test only ever exercised the easy path. A preregistered study (the design is fixed and registered before running) looked at 73 repair tasks covering 60 documented changes in CPython, Node.js and SQLite. Each candidate repair ran on the real runtime and was checked against contracts the repairer never saw. Gating on all the typical-input assertions still let 0.410 of wrong repairs through. Adding one edge input written from the release note dropped that to 0.065. Three inputs from a blind frontier-model writer that never saw the program reached 0.070; two local-model writers failed their preregistered tests. The mechanism is simple. A migration changes a contract: a return type, what an error means, the order of results. Typical inputs don't reach the changed part. So a green suite certifies that the easy path still works, not that the contract holds. Release notes are where the contract change is written down. "Now returns null instead of throwing" is a test you can write. One adversarial input per documented change is cheap and it targets exactly the gap. The limits matter. On the hard-distractor set — 233 distractors built to match the legacy output on typical inputs — the edge input still let 0.168 of wrong programs pass (0.153 for the frontier-model writer). An AI reviewer that could not see the intended answers flagged 34 contracts as stricter than their requirements; dropping those checks changed 0 verdicts, though the class-label disputes remain open. One input is a big improvement, not a guarantee. This is an arXiv preprint, and artifacts are available from the authors on request.
Green Tests, Wrong Code: The Migration Trap — Visual Breakdown
const assert = require('node:assert');
// Before the migration: parseCount threw on bad input.
// After: it returns null. Typical tests never pass bad input.
function parseCount(s) {
const n = Number(s);
return Number.isFinite(n) ? n : null; // was: throw new Error(...)
}
// Typical input — passes under both the old throw-on-bad-input
// and new return-null behaviour, so it cannot tell them apart.
assert.equal(parseCount("42"), 42);
// Edge input derived from the release note: error semantics changed.
assert.equal(parseCount("abc"), null); // fails on the old throw-based repairQuick Concept Check
Test your understanding in 15 seconds
Why does an all-assertions gate on typical test inputs release wrong repairs after an API migration?
Related Concepts
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.