ZIV LABS
Engineering notes

Testing AI-generated code against the spec

When a coding agent writes the code and its tests in one go, a green test run tells you the code agrees with the tests, not that the tests were strong. We asked Claude Code and Codex five times each to write a semantic-version comparison and its tests. All ten implementations passed an independent test suite we wrote from the specification. The tests were another matter: Claude Code's own tests missed one injected bug, a comparison that ignores letter case, in all five runs, while Codex's tests caught all seven bugs in all five. This is one small task and one model per tool, so read it as a method and a first data point.

The question

An agent that writes a function also writes the tests for it, runs them, and reports success. Three things can be wrong at once: the function, the tests, and your assumption that the two are independent. They are not: both come from the same reading of the task. The check that does not share that reading is a test suite written from the specification, and a way to measure how much of the specification the agent's own tests actually cover.

The setup

  • The task is comparing two semantic version strings. We chose it because the specification (Semantic Versioning 2.0.0, items 10 and 11) is short, public and precise, and it has a few rules that are easy to get wrong. It is also very common, which probably helps the model.
  • The prompt was one sentence and did not mention any rule. It was run in a new Git repository each time. Claude Code ran with the permission mode acceptEdits and only node commands allowed. Codex ran as codex exec -s workspace-write, which printed approval never.
Implement compare(a, b) in semver.js (CommonJS, module.exports = { compare }). It compares two semantic version strings and returns -1, 0 or 1. Also write tests in semver.test.js using node:test, and run them with node --test.
  • The oracle is a small test suite we wrote from the specification. We confirmed it passes our reference implementation and fails each of the seven bugs below.
  • The bugs are seven versions of the reference implementation with one rule broken each. We chose them from the specification's rules, so they are not a random sample and not exhaustive.
// oracle.test.js: written from semver.org 2.0.0, items 10 and 11, not from any model's output
const chain = ["1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta",
               "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0"];
// every pair in the chain compares in order
compare("1.2.10", "1.2.9") === 1                      // core is numeric
compare("1.0.0+a", "1.0.0+b") === 0                   // build metadata is ignored
compare("1.0.0-alpha.2", "1.0.0-alpha.11") === -1     // numeric identifiers compare as numbers
compare("1.0.0-1", "1.0.0-alpha") === -1              // numeric ranks below alphanumeric
compare("1.0.0-alpha", "1.0.0-alpha.1") === -1        // more fields rank higher
compare("1.0.0-Z", "1.0.0-a") === -1                  // ASCII order: uppercase before lowercase
numeric-as-string          pre-release numbers compared as text ("11" < "2")
numeric-above-alpha        a numeric identifier ranks above an alphanumeric one
core-as-string             major, minor, patch compared as text ("10" < "9")
case-insensitive           identifiers compared ignoring case
build-compared             build metadata takes part in the comparison
prerelease-above-release   1.0.0-rc.1 ranks above 1.0.0
longer-not-higher          a longer pre-release field set is not higher when the prefix is equal

What we measured

For each of the ten runs we checked three things. First, whether the agent's implementation passes the oracle. Second, whether the agent's own tests pass its implementation. Third, how many of the seven bugs the agent's own tests catch. For the third check we ran the agent's test file against the reference implementation and against each bug, and counted a bug as caught when a test that passes on the reference fails on it.

CheckClaude Code, 5 runsCodex, 5 runs
Implementation passes the oracle (8 tests)5 of 55 of 5
Own tests pass its own implementation5 of 5 (6 to 8 tests each)5 of 5 (6 or 7 tests each)
Bugs caught by the agent's own tests6 of 7 in every run7 of 7 in every run
Bug missedcase-insensitive, in all 5 runsnone

What this shows, and what it does not:

  • The code was right in all ten runs. On this task the code the agents wrote matched the specification as we tested it. The risk we set out to measure did not show up in the implementations.
  • Claude Code's tests had the same blind spot every time. None of its five test files compared two identifiers that differ only in letter case, such as 1.0.0-Z and 1.0.0-a. A change that makes the comparison case-insensitive would pass all five suites. The specification says identifiers compare in ASCII order, which puts uppercase first. Each of Codex's five test files asserted that ordering.
  • The difference is a measurement of these runs, not a ranking. One task, five runs each, and bugs we chose after reading the specification.
  • Both agents' tests also asserted things the specification does not say. Between one and three Claude tests, and two Codex tests, per run failed on our reference implementation because they check choices the agent made: invalid input throws an error, and (for Claude) a leading v is accepted. The specification's FAQ says that v1.2.3 is not a semantic version. Every Codex run, and one Claude run, also tested very large numeric identifiers. Our reference compares them as JavaScript numbers and fails that test, so that failure is a limit of our reference, and our oracle does not test that property at all.

What to do with this

  1. Write the oracle before you read the agent's tests. Derive it from the specification or from cases you already know are right. A dozen lines per rule is enough.
  2. Break the code on purpose and see what turns red. A handful of injected bugs, one per rule, shows which rules the agent's tests never exercise. It takes minutes and does not need a mutation-testing tool.
  3. Read the tests for decisions. If a test asserts how invalid input is handled or which spellings are accepted, ask whether you chose that.
  4. Ask for the gap. After the first pass, ask the agent which rules its tests do not cover. We did not test whether it finds the case-sensitivity gap; that is an experiment worth running.

Re-checked on 2026-11-15 by reading: Semantic Versioning 2.0.0 is still the current specification, so the oracle and the seven bugs are unchanged. We did not repeat the ten agent runs (they send the prompt to the providers), and Claude Code and Codex CLI have newer versions since (2.1.325 and 0.167.0 on that day), so the table above describes the versions named at the top, not the current ones.

What we did not verify

  • Which Codex model ran. The tool printed gpt-6.1-sol; we did not choose or check it.
  • Any other model or tool, a longer or less well-known task, or code that has to deal with state, I/O or concurrency.
  • Whether a more detailed prompt, or a request for edge-case tests, closes the gap. We used one sentence on purpose.
  • Whether the oracle is complete. It tests the rules we chose; a bug in a rule we did not think of would pass.
  • Five runs per tool give a rough picture, not a rate.

Independence

Nothing here is sponsored, and no vendor saw this note before it was published. We use Claude Code ourselves, so we are not neutral about it. The results are limited to the runs described.

Reproduce it

Create five new Git repositories per tool and run the prompt in each. Write the oracle from the specification. For the bugs, copy your reference implementation five or six times and break one rule in each copy. Run each agent's test file with node --test against the reference and against each broken copy; a bug counts as caught when a test that passes on the reference fails on it. Everything uses Node.js built-ins.

References

Related notes

From the build logs