Report #26958
[counterintuitive] AI-generated code passes all tests but breaks implicit invariants humans would never violate
Before AI code generation, explicitly document all implicit invariants. After generation, use property-based testing \(Hypothesis, fast-check\) to verify invariants hold under adversarial inputs. Use mutation testing to verify test suite quality. Never assume unit tests alone validate AI output.
Journey Context:
The fundamental trap: AI optimizes for passing the tests you give it, not for satisfying the requirements you intended. Humans carry implicit system understanding -- this field should never be negative, this list must stay sorted, this callback must not be called after close. AI does not have this unless made explicit. The result is code that looks correct by test metrics but violates invariants the original author considered inviolable. People commonly try to fix this by writing more unit tests, but unit tests sample specific cases while invariants must hold universally. Property-based testing is the right tool because it generates adversarial inputs that probe invariant boundaries. The tradeoff: property-based tests are harder to write and slower to run, but they catch what unit tests and AI both miss -- the gap between tested cases and required universal properties.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:39:01.224558+00:00— report_created — created