jacksonyang.dev AboutWorksInsightsContact 中文

All 174 tests passed. The result was still wrong.

Working with AI · 8 November 2026 · Jackson Yang

When the code and its tests come from the same specification, anything the spec misses, both of them miss. Green tests only show that they are wrong in exactly the same way.

I worked on a project to rewrite the reports of a long-running legacy system in a newer programming language. The approach was very modern. First we had AI read the old code and write a specification; then we had it write the new code from that spec, and the tests from the same spec.

The result looked great: all 174 tests passed.

Then we went back to the original source code and compared it item by item. We found 11 places where the new behaviour differed from the old. Not one of those 11 was caught by a test.

The story of one field

The most telling one went like this. On the old report, the account number appeared only on the first line of each page; the detail lines below it were left blank. This rule was scattered across four places in the old code: every detail line began by clearing the account field, and only at three page-break points was the account number filled back in.

The spec never spelled this out. So the new code printed the account number on every line, the tests checked that every line had an account number, and everything stayed green. Compared against the real report, each page had 54 extra lines of differences.

Why AI makes this harder to spot

This isn’t a problem unique to AI, but AI hides it better.

  • It is too faithful. When people write tests, they often glance back at the original requirements and stumble on a gap. AI implements every word of the spec, including the blanks the spec left, in both the code and the tests.
  • It looks too complete. Line numbers, a coverage table, six categories of test cases. Completeness on the surface easily drowns out the question of whether any of it is right.
  • The errors stack three deep. If the spec itself was written by AI, then the explanatory notes, the spec, and the code plus tests all share the same blind spot.

What I do now

  1. The acceptance standard must be something the implementation can’t touch. In that project it was the old source code. Elsewhere it might be files the real system produces, or the actual responses of an upstream service. “All existing tests pass” is not evidence.
  2. After fixing something, remove the fix on purpose and run the tests again. If they still pass, they have no protective value; they are just restating what the code does.
  3. Put values in the test data that are designed to give the bug away. Take the sign of an amount: a positive number prints exactly the same under the right and the wrong implementation; only a negative number reveals the problem. If your test data is all ordinary positive numbers, the bug stays hidden until production.
  4. Say plainly what you couldn’t test. Some risks simply can’t be verified in a test environment. Write that into the handover and explain why a final check against real data is essential, instead of letting a wall of green lights suggest that everything has been verified.

What green lights prove is that both sides tell the same story. They can’t prove the story is true. To know that, you need a third party that neither of them can touch, and check the answer against it.