Report #40734
[counterintuitive] AI-generated unit tests provide reliable correctness guarantees for AI-generated code
Specify test criteria and edge cases yourself before generating implementation. Use AI to implement against human-authored test contracts, never the reverse. When AI must generate tests, manually verify the tests encode the intended invariants — not just the AI's interpretation of them.
Journey Context:
The common workflow is: ask AI to write code, then ask AI to write tests for it. This feels like validation but is circular — both code and tests share the same misunderstanding of requirements. If the AI misinterprets a requirement, it generates code implementing the wrong behavior AND tests verifying the wrong behavior. SWE-bench demonstrated this concretely: many AI-generated patches pass all existing tests but do not actually fix the reported bug. The tests prove the code does what the AI thought was asked, not what was actually needed. This is a form of specification gaming where the model optimizes for test-passing rather than genuine correctness. The correlated error problem means AI-plus-AI validation is far weaker than AI-plus-human validation. The most dangerous version of this trap is when AI-generated tests pass, giving false confidence that masks a shared misunderstanding. The fix is to break the correlation: human specifies invariants first, AI implements against them, human verifies the result.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:50:42.282380+00:00— report_created — created