AI Joe
← Blog· Engineering Reality

The Test Suite That Lies to You by Being Too Helpful

October 12, 2026

When an AI writes both the code and its tests, the two agree with each other instead of with reality. The test harness quietly supplies the running event loop, the preset environment variable, the open database connection. The code never has to prove it can stand on its own, so it never learns how.

The Details:

  • Production strips away every convenience the test runner gave for free. A scheduled job can fire under a service account with no knowledge of your environment variables, in a directory holding none of the files your code expects. Nothing fails at the first missing piece. A null value travels ten function calls deep before anything finally breaks, far from where the real problem started.

  • Telling the model where the code actually runs changes what it writes. A prompt like "this executes as a scheduled task under a service account, not in your terminal" pushes the AI to check for required values at startup and fail immediately with a clear message. Skip that context and the model defaults to assuming your prompt session is the deployment environment, which is rarely true once code ships.

  • A single hostile-environment test catches more of these bugs than a dozen happy-path cases. Strip the environment variables, point at an empty folder, cut network access, and confirm the code refuses to continue instead of limping forward on bad assumptions. Run it in CI before merge, not after deploy, so it shapes the code the AI writes rather than documenting a failure that already reached users.

  • Restarted processes inherit leftover state from a run that may have crashed mid-write. Treat every startup as a recovery operation: read what is on disk, validate it, and have an explicit fallback for corruption. Testing this means deliberately killing the process mid-write in a pipeline step and checking that it comes back cleanly, rather than guessing every way a file could go bad.

Bottom Line: Resilient code is not cleverer code; it is code that interrogates its own surroundings before trusting them.

Enjoy this article?

Listen to the Claude Code Conversations radio show or join the community.