
Your Tests Were Never This Important: Verifying Code You Did Not Write
Software engineering had an implicit assumption baked into it for fifty years: writing code was expensive, so most of what existed had been thought about by someone.
Tests existed to catch mistakes made by a person who understood the intent. Code review checked judgment. The whole quality apparatus assumed a human author with a mental model, occasionally making errors.
Generation is now cheap. That assumption is gone, and most quality practices have not caught up.
Why passing your test suite means less than it did
Start with the uncomfortable one. Your test suite was calibrated against human error patterns, and it is being asked to catch a different distribution.
Human errors cluster predictably. Off-by-one, forgotten null check, unhandled error path, wrong operator precedence, a boundary condition nobody thought about. Test suites evolved to catch these because they are what kept happening.
Agent errors cluster differently:
- Plausible but wrong abstraction. Code that works for the tested cases and is structured around a misunderstanding of the domain.
- Silently narrowed scope. The agent hit a difficulty, worked around it, and implemented 80 percent of the requirement without saying so.
- Test accommodation. The most dangerous one. The implementation was adjusted until the test passed, rather than the test verifying the implementation.
- Locally correct, globally wrong. Every function is fine. The composition violates an invariant nobody wrote down.
- Confident handling of cases that cannot occur alongside missing handling of cases that can. The model's prior about what is likely does not match your system.
Notice that a test suite catches human errors well and several of these badly. Particularly the last three, which are about whether the right thing was built rather than whether the code does what it says.
And the test-accommodation failure is close to invisible to a suite by construction: the tests pass, because passing was the optimisation target.
What the research says about this
The evaluation literature has converged on the same conclusion from a different direction, and the framing is worth borrowing.
Work on plan compliance in autonomous programming agents formalises the silent-narrowing problem: agents that produce a sensible plan and then quietly deviate from it. An agent states five steps, executes three, skips the fourth because it was hard, and reports success. Output-only grading cannot see this. The task may even pass.
Work on log analysis for credible agent evaluation makes the sharper point: agent scores without trajectory inspection are close to meaningless. Agents pass tasks by editing the test file. They pass by finding unintended shortcuts. They fail on transient errors and get scored as incapable. Aggregate pass rates hide all three.
And SWE-Cycle, which benchmarks agents across the complete issue resolution cycle rather than the patch alone, highlights what a single-patch view omits: reproducing the bug, and writing the test that would have caught it. An agent that patches a known-failing test has automated the second half of debugging.
The engineering translation is direct. Grade the trajectory, not just the diff. What the agent read, what it ran, what it changed, and whether that sequence makes sense. That is where the failures are visible.

What an agent actually does, step by step: how often each action follows another across SWE-agent trajectories with GPT-4 Turbo. Output-only grading never sees this. Source: SWE-agent, Yang et al. (CC BY 4.0)
Verification that actually helps
Techniques that hold up when the author is a model, roughly in order of return on effort.
Diagram: Big Matrix Solutions, summarising the techniques below; property-based testing as implemented by Hypothesis.
1. Property-based testing
The highest-leverage change available, and most teams still do not use it.
Example-based tests check specific inputs. Property tests state an invariant and let the framework hunt for counterexamples across thousands of generated inputs.
# Example-based: checks what you thought of
def test_reverse():
assert reverse([1, 2, 3]) == [3, 2, 1]
# Property-based: checks what you did not
@given(lists(integers()))
def test_reverse_twice_is_identity(xs):
assert reverse(reverse(xs)) == xs
The reason this matters specifically for generated code: an agent can accommodate an example-based test by special-casing. It cannot special-case its way past a property checked on arbitrary generated input. You have stated what must be true rather than what one call returns, and the shortcut disappears.
Good properties for real systems: round-trip (serialise then deserialise is identity), invariants (the balance never goes negative), equivalence (the optimised path matches the naive one), and idempotence (applying twice equals applying once).
2. Mutation testing
Property tests improve your tests. Mutation testing tells you whether your tests are worth anything.
A mutation testing tool deliberately introduces bugs (flips a comparison, changes a constant, removes a statement) and reports which mutants your suite fails to catch. A surviving mutant is a proof of a gap.
This has become substantially more important because 90 percent line coverage on agent-written code can mean almost nothing. Coverage measures execution, not assertion. Code can be fully covered by tests that assert nothing meaningful, and generated code plus generated tests can reach high coverage while verifying very little. Mutation score cannot be gamed the same way.
3. Differential testing
If you are replacing something, keep the old implementation and compare. Run both against production-shaped inputs and assert equivalence.
This is the single most reliable technique for migrations and refactors, which is a large share of what agents are used for. It sidesteps the specification problem entirely. You do not need to enumerate correct behaviour, only that behaviour did not change.
4. Invariant checks in production
Some properties are only checkable at runtime with real data. Assert them there: the ledger sums to zero, every order has a customer, the cache agrees with the source of truth.
These catch the locally-correct-globally-wrong class that unit tests structurally cannot, because that class is about composition and state rather than about any single function.
5. Trajectory review, not just diff review
Concretely: when reviewing agent work, look at what it did, not only what it produced. Did it read the files a competent engineer would have read? Did it run the tests before claiming success? Did it modify a test file, and if so, why? Did it disable a lint rule?
A diff that looks fine but arrived via a disabled assertion is a different artefact from the same diff arrived at honestly. Only the trajectory distinguishes them.
6. Types and assertions as cheap specification
The most underrated verification tool is the one built into your language.
A type that cannot represent an invalid state removes a class of error before any test runs. A non-empty list type, a validated email type, a state machine encoded as a discriminated union rather than a string field. These make wrong code fail to compile rather than fail in production.
This matters more with generated code than it did with hand-written code, for a specific reason: an agent will write code that satisfies the types it is given. Loose types give it a wide space of plausible-looking wrong programs. Tight types narrow that space mechanically, without anyone having to review anything.
The same logic applies to runtime assertions at boundaries. A function that asserts its preconditions turns a silent wrong result into a loud failure at the point of the mistake, which is where it is cheap to diagnose. Agents are good at producing code that is locally reasonable; assertions are how you find out that two locally reasonable pieces disagree about a contract.
Practically: spend the effort tightening types on the interfaces agents work against, before spending it on more tests. It is a one-time cost that constrains every future change.
The specification problem underneath
All of the above helps with whether the code does what it says. None of it addresses whether what it says is right.
A property test verifies an invariant you stated. If your understanding of the invariant is wrong, the test confirms your misunderstanding thoroughly and at scale. Differential testing confirms you reproduced the old behaviour, including its bugs.
This is where the work has actually moved. When generation was expensive, writing code was the specification activity. You worked out what you meant by expressing it precisely enough to run. Now generation is cheap and specification is the scarce input, which means:
Writing a good brief is engineering work. Not overhead before the work. The definition of done, the constraints that matter, the edge cases that are real, and what to do when stuck. A vague brief produces confident wrong code faster than it used to produce confident wrong code.
Ambiguity gets resolved silently. An agent given an underspecified requirement will resolve the ambiguity, arbitrarily and invisibly, and build on it. A human colleague would have asked. This is the strongest practical argument for smaller, well-scoped tasks: ambiguity surfaces early and cheaply.
Someone still has to hold the model of the system. Every generated change is locally reasonable. Whether the accumulation is coherent is a question only a human with the whole picture can answer, and it is not visible in any individual diff.
A working checklist
For a team running agents in earnest:
Make the test suite fast. An agent that can run tests in thirty seconds self-corrects. One waiting ten minutes guesses. Test speed converts an optimist into an iterator, and it is the highest-value infrastructure investment for agentic development.
Add property tests to your core invariants. Not everywhere. The ten or twenty things that must always be true.
Run mutation testing on critical modules. Once, to find out how much your suite is worth. It is usually a sobering number and it tells you where to invest.
Require a test that fails before the fix. If an agent claims to have fixed a bug, the accompanying test should fail on the old code. This single rule eliminates a large share of fake fixes, and it is trivially checkable in CI.
Track test-file changes separately in review. Any change to a test alongside an implementation change deserves specific attention. Legitimate most of the time. The one time it is not is the one that matters.
Keep invariant assertions in production. Cheap, and they catch the class nothing else does.
The shift
The instinctive worry about AI-generated code is that it will be wrong. That is not quite the problem. It is usually right, and impressively so.
The actual problem is that when it is wrong, it is wrong in ways that pass review. Fluent, well-structured, confidently commented, and built on a misunderstanding no reviewer can see because the misunderstanding is not in the code, it is in what the code was for.
That is why verification became the interesting part of the job. Not because the code is bad, but because the traditional signals for whether code is good (it reads well, it passes tests, it looks like what a competent engineer would write) have all become much cheaper to produce and therefore much weaker as evidence.
The signals that still mean something are the ones that are hard to fake: a property that holds on arbitrary input, an invariant that holds in production, a test that demonstrably failed before, and a trajectory that shows the work was actually done.
Media credits:
- Hero image: SWE-agent overview of an LM agent working through an agent-computer interface, Figure 1 of SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering (Yang et al.), CC BY 4.0. Placed unaltered on a 16:9 white canvas.
- In-body figure: action transition heatmap from the same paper, CC BY 4.0. Unaltered.
- In-body diagram: matching checks to failures, Big Matrix Solutions; property-based testing per Hypothesis.