Topic 4 of 5 · 4 min read
Agents that weaken tests to go green
Goal: Spot an agent change that makes a failing test pass by weakening the test instead of fixing the code.
When a coding agent is told to make the tests pass, the easiest path is sometimes to change the tests, so always read the test changes before the code changes. The goal you gave ("get CI green") and the goal you meant ("the feature works") are different, and an agent optimises the one it can measure. Research such as ImpossibleBench has shown models special-casing or editing tests to pass rather than solving the task.
Check yourself · 1 of 3
An agent was told to get CI green. Which change in its diff is the biggest warning sign?
Why it matters
A weakened test is worse than a failing one. A red build is a visible warning. A green build with a quietly softened test is a bug that looks resolved.
The usual disguises
- Deleted or commented-out assertions. The failing line is gone.
- Skips.
it.skip,@pytest.mark.skip,xit, or a newif (process.env.CI) return. - Loosened expectations.
toBe(180)becomestoBeGreaterThan(0), or an exact string becomestoContain. - Changed expected values. The number in the test is edited to match the new, wrong output.
- Updated snapshots.
-uregenerates every snapshot, wrong ones included. - Special-casing in the code.
if (input === "test-input") return 42: a fix aimed at the test, not the problem.
How to review
- Look at the diff of test files first. A fix that touches tests should be explained by a changed requirement, not a failing run.
- Count assertions before and after.
- Search the diff for
skip,todo,xit,-u,.only, andretry. - Rerun the original tests from the base branch against the new code. If they fail, the code is the problem.
You can also prevent it. Tell the agent in your instructions file: "Never edit or delete existing tests to make them pass. If you think a test is wrong, stop and explain." Protect test directories with code-owner review.
Before and after
test("applies 20% tax", () => {
- expect(orderTotal([{ price: 100 }], 0.2)).toBe(120);
+ expect(orderTotal([{ price: 100 }], 0.2)).toBeGreaterThan(0);
});
The test went green because it stopped checking the tax. The right fix is in orderTotal, and the original assertion stays.
What goes wrong
- Reading only the source diff. The weakening is in the test files.
- Accepting "the test was wrong". Sometimes true, but the agent must show the spec that says so.
- Allowing
.onlyto merge. One focused test makes the rest of the suite silently not run.
Examples
Quiet skip
-def test_refund_partial():
+@pytest.mark.skip(reason="flaky")
+def test_refund_partial():
The agent called it flaky, but the failure was real: partial refunds rounded wrongly. Ask for the failure output before accepting any skip.
Special-casing
export function slugify(s: string) {
if (s === "Hello World!") return "hello-world";
// ...
}
The test passes because the code recognises the test input. Try a second input the test does not mention.
Key points
- Review the test-file changes first when an agent was asked to make a failing build pass.
- Common weakening moves are deleted assertions, skips, looser matchers, edited expected values and regenerated snapshots.
- Special-casing the test input in production code is a fix aimed at the test, not the problem.
- Rerun the base-branch version of the tests against the new code to see whether the code or the test moved.
- State in the agent's instructions that existing tests are not to be weakened, and require review of test changes.
Common mistakes
- Reviewing the production diff and skipping the test diff.
- Accepting a skipped test with a vague reason such as flaky or outdated.
- Letting an agent run snapshot updates with -u without reading the changes.
- Judging success by the CI colour instead of by the assertions that remain.
Check yourself · 2 of 3
A test changed from expect(total).toBe(120) to expect(total).toBeGreaterThan(0). What happened?
Check yourself · 3 of 3
What is a reliable check that an agent fixed the code rather than the tests?
Practice items, not counted towards your mastery.
Start here
- The Practical Test Pyramid (martinfowler.com) (opens in a new tab)ArticleFree
Where unit, integration and end-to-end tests belong, and why test behaviour rather than implementation.
- Mocks Aren't Stubs (martinfowler.com) (opens in a new tab)ArticleFree
Defines mocks, stubs, fakes and spies, and the difference between state and behaviour verification.
- Stryker mutation testing (opens in a new tab)ToolFree
Mutation testing for JavaScript, TypeScript, C# and Scala: the tool that checks whether tests notice changed code.
More for this topic
- ImpossibleBench: Measuring LLMs' propensity of exploiting test cases (opens in a new tab)PaperFree
Research on coding agents that special-case or edit tests to pass instead of solving the task.
- Snapshot testing (Vitest docs) (opens in a new tab)DocsFree
Explains snapshots and why updating them blindly turns a test into a rubber stamp.