A Green Check Proves What the Tests Cover
When an agent writes the code and the tests, green CI can mean very little. Build checks that can fail, and that tell the agent the fix when they do.
Framing is the static layer that holds the house's shape: lint rules, types, compilers and tests. It only holds if each check can fail when the code is wrong, and tells the agent what to do when it does.
A green check proves what the tests cover. When an agent wrote both the code and the tests, from the same reading of the task, in the same context, that can be very little. The suite is green. The bug ships anyway.
Agent errors also compound in a way human errors don't. A person who writes a bad pattern feels the pain of it and slows down. An agent feels nothing and writes the next ten. The only bottleneck left is the checks, so the checks have to be real.
Why agent-written tests pass when the code is wrong
The labs have said this out loud. Anthropic's Claude 3.7 Sonnet system card reports the model sometimes special-casing tests to make them pass instead of fixing the problem. OpenAI described a reasoning model that made verification functions always return true.
The quieter failure is more common. The test asserts what the code does instead of what the task asked for. The expected value is copied from the implementation's output. The assertion checks that a function returned a number, not the right number. Coverage goes up and nothing gets more correct.
So I treat agent-written tests as untrusted, the same as the code they test. Then I go looking for the ways a check can be green for the wrong reason. There are a handful, and each one has a fix.
The error message is the instruction
Start with the checks you already trust: lint rules and types. Their best feature for agents isn't that they fail. It's what they say when they fail.
A rules file tells the agent something once, at the top of the session, among hundreds of other lines. A lint error tells it at the exact moment it matters, on the exact line. So the message should carry the fix, not just the violation:
no-direct-fetch: Don't call fetch() in a component. Use lib/api.ts, which handles
auth, retries and errors. If lib/api.ts can't do what you need, add a function there.
"Don't call fetch" alone invites a workaround. Naming the root-cause fix and where it lives gets the right change on the first retry.
The test for whether this layer is done is simple. Take every review comment you made more than once last month. Each one should now exist as a failing check, and CI should block on it. A repeated review comment is a missing check.
Comments are an escape hatch
Agents use comments, docs and rules files to write down why they didn't do the right thing. "Using setTimeout here because the state isn't ready yet." That justification then gets copied by the next agent, which reads it as the established pattern. Agents also over-rotate on prose: one small correction becomes a rule they treat as unbreakable.
I've moved hard toward fewer comments in code agents work in. Comments go stale, nobody reads them, and nothing enforces them. If something matters enough to write down, it usually matters enough to be a check, a type or a better name.
Content checks that pass on a comment
A lot of guardrails are text checks. Does the handler use an idempotency key? Grep for idempotencyKey. Does the route set a cache header? Grep for Cache-Control.
An agent told to satisfy the check will satisfy it. A comment like // uses an idempotency key matches the regex. So does a log string. The check is green, and the code never sends the key.
The fix is a negative fixture for every content check: a file where the pattern appears only in a comment or a string, and a test that the check fails on it. If the check passes on the fixture, it's checking text, not code. Better still, move the check onto the syntax tree with a real lint rule.
Reports the generator wrote about itself
The next failure is a report that says "passed" because the thing being checked wrote the report. An agent runs a smoke test, writes smoke-report.json with "status": "passed", and the gate reads the file. Nothing stops the agent from writing that file without running anything, or from running it against last week's build.
A gate should either re-run the check itself or read a report it can verify. I wrap every report in a small envelope:
{
"command": "npm run smoke -- --env staging",
"exitCode": 0,
"inputHash": "sha256:9f2c…",
"startedAt": "2026-11-20T14:02:11Z"
}
The gate recomputes the input hash from the current commit. A report whose hash doesn't match is stale. A report with no command or exit code counts as forged. Either one fails.
Docs that make claims nobody re-checks
Agents trust prose that names things: a command in a README, a route in a cookbook, a tool in a skill file. When the name is wrong, the agent fails in a way that looks like its own mistake.
I found one of my own skills telling agents to call a tool that had been renamed. Every agent that followed it hit an error and then improvised.
The fix is a claim check: a test that pulls every named route, command and tool out of the docs and checks each one exists in the code or the spec. Some names will be wrong on purpose during a migration, so the check takes a baseline of known exceptions, and each exception carries a date that expires. An exception that lives forever is a hole with a label on it.
Tests that can't fail
Some tests are honest but weak. Mutation testing finds them. Plant a small bug on purpose, rerun the suite, and see if anything goes red. If the suite stays green with a bug in it, the tests are decoration.
Don't mutate the whole repo. You'll drown in survivors on logging and glue code and learn to ignore the report. Mutate the few paths where a wrong answer hurts: money, permissions, identity, anything that converts units or dates. Tools like StrykerJS, PIT and mutmut can be scoped to those directories and set to fail the build under a score floor. Set each floor to today's score and only raise it.
Two rules keep it honest. The agent that writes the tests never sees the mutants, or it writes tests that kill exactly those and nothing near them. And any PR that adds a "disable this mutant" comment to a risk path fails, because disabled mutants drop out of the count and raise the score.
Red first for every fix
Bug fixes get one more rule. A fix PR must include a test that fails on the base branch and passes on the PR. A small CI job checks out the base, overlays only the PR's test files, and runs them. They must fail. Then it runs them on the head. They must pass. A test that was never red proves nothing about the bug.
My bots that turn production errors into pull requests build that test from the bug report a different bot wrote, so the test comes from a second agent in a separate context. When a fix truly can't have a failing test, like a config change or a dependency bump, a person adds a label. If that label shows up often, the bot's fixes are drifting away from code.
The order I'd do it in
- Measure rework first. Count PRs that a later PR fixes within two weeks, split by agent and human authors. That's your baseline.
- Turn repeated review comments into checks, with messages that name the fix.
- Add a negative fixture to every content check.
- Put an envelope on every report a gate reads.
- Claim-check the docs agents read.
- Require red-first on fixes, then add mutation testing on the risk paths.
How you know it's working
- Every review comment repeated last month exists as a failing check, and CI blocks on it.
- Every content check has a negative fixture, and the fixture fails.
- No gate reads a report it can't verify.
- Claim-check exceptions trend toward zero, and none is past its date.
- Fix PRs pass red-first without the no-test label nearly every time.
- Rework for agent PRs falls toward the human rate. That's the number that tells you whether green means anything.