Originally published on anton.qa.
When one AI session writes the code and its tests, it reads the spec once. The spec is the written rules for the code. If the session misreads a rule, its tests can repeat the mistake. One tip: ask a second agent, a fresh session, for the tests. That session sees only the spec, never the code.
The idea now has a product, too. On November 20, TestSprite released version 4.0. Its press release calls it "an independent testing agent". It checks software apart from the person or coding agent that wrote it. This article doesn't test TestSprite. It tries the do-it-yourself version of the idea, with a tool you may already use.
The demo ran 24 Claude Code sessions on four small specs. Here is the short answer. Opus 5.5 wrote correct code every time, so the second session found no real bug. There was none to find.
Then a second check planted bugs on purpose in a separate version of the code. The builder's own tests missed one of them, in all three runs. The checker's tests caught it. Reading the builders' real tests showed something else: guesses that became rules. I'd add a second session where a bug costs money or trust. For code a quick read can check, I'd skip it.
Two sessions, two jobs
Session A is the builder. It reads the spec, writes the code, then writes tests and runs them. Session B is the checker. It starts fresh, in a folder that holds only the spec.
Then B's tests run against A's code. A failing test means the two disagree. Either the code has a bug, the test is wrong, or the spec is unclear. Each one is worth knowing before a user finds it.
The four specs
Each spec is a few plain rules, with tricky cases code often gets wrong:
- Order discount: 10% off from $100, 15% from $500, and a half cent rounds up.
- Booking overlap: one stay can start the day another ends. February 30 is invalid.
- Page info: "Showing 11-20 of 45", plus no items or a page past the end.
- Password rule: length counted so an emoji is one character, plus a username rule.
Here is the password spec, exactly as both sessions saw it:
# Password rule
Write `isValidPassword(password, username)` in `src/password.mjs`, as a named export. It returns `true` or `false`.
A password is valid when all of these hold:
- It is 12 to 64 characters long. Count characters as Unicode code points, so an emoji such as 🔒 counts as one character.
- It contains at least one letter and at least one digit.
- It does not start or end with whitespace.
- It does not contain the username, ignoring case. This rule applies only when the username is 3 or more characters long.
The two prompts
node:test is the test runner built into Node.js, so nothing needs installing. The builder got this prompt:
Read SPEC.md and implement it. Then write tests for it with node:test in a test/ folder, run them with node --test, and make sure they all pass.
The checker got this one, in its own folder:
Read SPEC.md. Someone else is implementing it, and you can't see their code. Write tests for it with node:test in a test/ folder, based only on the spec. Don't write the implementation.
How the demo ran
Every session was a headless Claude Code run, started with claude -p. Headless means no chat window. They all used Opus 5.5, with Claude Code's effort setting on high. The --safe-mode flag turned off instruction files, plugins and MCP servers, which connect extra tools. So no instruction file, plugin or MCP server shaped the results.
Each spec ran three times on each side: 24 sessions in all. All 12 checker sessions ran first, so no builder code existed yet. Eleven checkers wrote a throwaway version in their own scratch folder, to try their tests. None of it reached the spec folder. Permission prompts were skipped, so a session could touch any file. The steps in "Try it" use a short tool list instead.
The results were judged against a reference version of each spec. The Claude Code session that set up the demo wrote it. Think of it as an answer key. It came with 69 checks where the specs give a clear answer. The specs leave 15 more cases open. Those were reported, but never counted as bugs.
Result 1: the code was right, so the checker found nothing
All 12 builder versions passed every check for their spec. Their own tests passed, too.
The checker's tests also passed on the builder's code, in 12 of 12 runs. Not one test disagreed. On these four specs, the second session reported no bug, because there was none.
So these small, clear specs were easy for a strong model. Opus 5.5 got the half cent, the impossible dates and the emoji length right.
Result 2: planted bugs show what each set of tests would catch
With no real bugs, the next question was simple. If the code were wrong, which tests would notice?
So the setup session planted 26 bugs, one at a time, into the reference versions. They are small, typical edits. Some turn >= into >. Others change the rounding, skip a check or count length the wrong way. Each set of tests then ran against each planted bug.
This is a second check, not the main result. The bugs were planted in the reference code, not in the builder's code. They show what each set of tests can catch. They say nothing about how often agents make these mistakes.
| Spec | Tests written, builder | Tests written, checker | Planted bugs caught, builder's tests | Planted bugs caught, checker's tests |
|---|---|---|---|---|
| Order discount | 28 | 134 | 21 of 21 | 21 of 21 |
| Booking overlap | 82 | 173 | 18 of 18 | 18 of 18 |
| Page info | 72 | 173 | 18 of 18 | 18 of 18 |
| Password rule | 42 | 195 | 18 of 21 | 21 of 21 |
| Total | 224 | 675 | 75 of 78 | 78 of 78 |
Test counts are totals across three runs. A planted bug counts once per run, so 26 bugs make 78 chances per side.
Blind spot 1: a dot in the username
All three misses were the same planted bug, once in each run. It checks the username as a pattern instead of as plain text:
if (new RegExp(username, 'i').test(password)) return false;
A regular expression, or regex, is a search pattern. In a regex, a dot matches any character. So the username a.c also matches abc, and a good password like abcdefghijk1 gets rejected.
The builder's code didn't have this bug. All three builder versions checked the username with plain text search:
if (password.toLowerCase().includes(username.toLowerCase())) return false;
So the builder never tested a username with a dot. For the code it wrote, such a test could never fail. The checker couldn't see the code, so it planned for code it might get. All three checker test files tested a dot in the username. Here is one:
it('treats the username literally, not as a regex pattern', () => {
valid('abcdefghijk1', 'a.c'); // "a.c" is not a literal substring
invalid('xxa.cxx12345', 'a.c');
valid('abcdefghijk1', '.*.');
});
This is the part I find most useful. The builder's tests fit the code it has today. The checker's tests also fit the code someone might write next month. Imagine a teammate later swaps includes for a regex. Only the checker's test would catch it.
Blind spot 2: a guess became a rule
This one is in the builders' real tests, not in a planted bug. The spec says a password needs "at least one letter." It doesn't say whether é or п counts.
All three builder sessions picked yes. Then each wrote a test that makes it a rule:
test('non-ASCII letters count as letters', () => ok('пароль123456'));
Yes is a fair reading. But it's a guess, and the test makes the guess look like the spec. If the owner meant only a to z, the test defends the wrong code.
To be fair, every builder noticed the gap. Each one named its choice in its final reply. One said a to z only meant changing "two patterns" and "the matching tests." But the test file still treats the guess as settled.
The letter rule was not the only guess. All three builders also locked in three more open points. They were a leading non-breaking space, a missing username and a username's length.
The three checkers made a different choice. Each left those rules untested and listed them as open questions. One headed its list "Not tested, because the spec doesn't settle them". That list is worth reading. It's a ready-made set of questions for whoever owns the spec.
What it costs
The checker writes more tests and takes longer:
- Tests: 675 test cases against 224, about three times as many. The checker's test files were about twice as long.
- Time: a median of 61 seconds per session against 26.
- Cost: Claude Code's own estimate was a median of $0.27 per session against $0.15.
More tests are not better tests on their own. Someone still reads them, runs them and keeps them up to date. Here, every extra test passed on correct code, so none gave a false alarm. On a messier spec, expect some to be wrong.
When I'd use a second agent
- Rules where a bug costs money or trust: prices, discounts, permissions, dates and limits. I'd add a checker session there.
- Code a quick read can verify: I'd skip it and save the time.
- Reading the results: I'd start with any checker test that fails. Next, I'd read the checker's list of open questions. Then I'd check the builder's tests for rules the spec never states.
Try it
You need Node.js 22 or later and Claude Code. The demo ran Node.js 24.22.2 and Claude Code 2.1.332 on macOS. Put your spec in SPEC.md. Name the file and the function in it, like the password spec does. Then run this from the same folder:
mkdir -p demo/app demo/spec-only
cp SPEC.md demo/app/
cp SPEC.md demo/spec-only/
# 1. The checker: a fresh session that sees only the spec
cd demo/spec-only
claude -p "Read SPEC.md. Someone else is implementing it, and you can't see their code. Write tests for it with node:test in a test/ folder, based only on the spec. Don't write the implementation." --allowedTools "Read,Write,Edit"
# 2. The builder: the code and its own tests
cd ../app
claude -p "Read SPEC.md and implement it. Then write tests for it with node:test in a test/ folder, run them with node --test, and make sure they all pass." --allowedTools "Read,Write,Edit,Bash(node *)"
# 3. Run the checker's tests against the builder's code
mkdir test-spec
cp ../spec-only/test/*.mjs test-spec/
node --test test-spec/*.mjs
--allowedTools gives each session only the tools it needs. Then no permission prompt stops it. Keep the prompt right after -p. --allowedTools takes a list. When it came first, it read the prompt as part of that list. The run then stopped with this error (-p is short for --print):
Error: Input must be provided either through stdin or as a prompt argument when using --print
To match the demo, add --model claude-opus-5-5 --effort high --safe-mode to each claude line. The steps were tested once that way, on the password spec. Your agent may name its files differently. If the copy step finds no test file, check the checker's folder first.
Limits
- Small sample: four short specs, three runs each. Real projects have longer, messier specs.
- One model: both sessions used Opus 5.5. Two sessions of one model may read a spec the same way. All three builders made the same letter choice, for example.
- Planted bugs: they were placed in the reference code, not in the builder's code.
- One author: an Opus 5.5 session also wrote the specs, reference code, checks and bugs.
- Not a product test: TestSprite was not tested here.
The second agent found no real bug this time, because the code had none. Its value showed up in two other places. With planted bugs, its tests caught a regex mistake the builder's tests missed. And it kept unclear rules open, instead of turning guesses into tests.
I'm Anton. I build AI tools and measure how fast they really run. Former Apple engineer. I make ollamatps.com and write about building and measuring AI at anton.qa.
Top comments (0)