Can You Trust AI-Written Code? The Case for an Evidence Loop

    As AI takes over most of the coding, human attention becomes the bottleneck. This article explains how teams move from reviewing code line by line to reviewing evidence: building a verifiable evidence loop around every AI output, treating tests as reusable software assets, encoding hard-won lessons into rule files and hooks, and avoiding the two failure modes that break the whole system — flaky tests and slow tests. It also covers the test types worth investing in first: end-to-end, property-based, and regression/snapshot tests.

    Introduction: The development model is shifting from “humans reading code” to “humans managing evidence”

    Code quality used to depend heavily on senior engineers reviewing every line. Today, more and more engineering teams are finding that a different division of labor works: let AI lead the coding and the self-review, while humans own the direction and the final call. In some frontier teams, roughly ninety percent of the code is written by AI and reviewed by other AI instances.

    This shift creates a direct contradiction. Once AI does the bulk of the coding work, limited human attention becomes the bottleneck. Under the traditional model, one person can supervise the output of one or two AI instances at most, because every line still has to be checked by a human eye. Breaking through that ceiling requires upgrading “humans read code” into “humans read evidence.”

    1. The core prerequisite: build an evidence loop around AI output

    An evidence loop means that every piece of AI output can be verified independently, objectively, and reproducibly. Instead of reading code line by line, the human checks one thing: did this output pass the predefined standard?

    The payoff is immediate. When verification responsibility moves from people to automated grading tools, one person can direct dozens or even a hundred AI instances working in parallel. The grader acts as a gate: output that meets the bar is let through; output that doesn’t is automatically sent back to be redone.

    Internal experience surfaced another notable pattern: when independent tooling checks AI output against explicit criteria, task success rates rise by roughly ten percentage points — and the harder the task, the bigger the gain. The reason is that explicit criteria are themselves a form of constraint and guidance, and they effectively suppress the AI’s tendency to drift off track or feel good about its own work. Without an independent grader, AI easily falls into a loop of “I wrote it, therefore I declare it done.” With a grader in place, it has to show results.

    2. Treat tests as software assets, not one-time costs

    Writing test suites, benchmark cases, and technical specifications used to be extremely expensive, often requiring large amounts of manual effort. With AI assistance, a full set of test cases can be generated in bulk within seconds. More importantly, once generated, these tests become software assets that run as programs: they can be executed repeatedly, wired into pipelines, and each additional run costs almost nothing beyond the original generation.

    The marginal cost of testing therefore drops sharply, and the team’s investment focus should shift from “can we write tests?” to “which tests are worth writing first?” Resources are always finite, so a clear priority order is necessary.

    3. Turn past mistakes into rules: constraint files and hooks

    When AI repeatedly fails in the same place — for example, always printing user privacy data into logs — repeated prompting does not fix the root cause. A more reliable approach is to codify the constraint as an enforceable rule: state the hard requirement in a project-level rules file, or add an automated hook (such as a pre-commit check or a formatting pre-validation) that blocks the same class of problem in subsequent tasks.

    An illustrative rules file might look like this:

    1. # Project rules (excerpt)
    2. - Logging must never include user privacy fields (phone numbers, ID numbers, tokens, etc.)
    3. - All external input must be validated before use
    4. - Database mutation operations must be idempotent

    This way, one hard-learned lesson becomes a long-term guardrail for the whole team instead of something each person has to remember over and over.

    4. Two failure modes to avoid: flakiness and slowness

    For this system to actually work, two failure paths must be avoided up front:

    • Flaky tests (passing sometimes, failing sometimes): once test results contain randomness, AI will “learn” to retry repeatedly until it gets a green run rather than actually fixing the code. It will prefer running a few more times until the suite goes green, masking real defects. Test cases must therefore be deterministic and reproducible.
    • Tests that are too slow: if a single test run takes a long time, the frequency at which AI can investigate problems in batches drops sharply, and root-cause analysis becomes unusually difficult. The slower the feedback loop, the lower the AI’s iteration efficiency. Coverage and execution speed need to be balanced, splitting fast and slow tests into separate tiers when necessary.

    In essence, the credibility of an evidence loop depends on whether the grading itself is both fast and stable.

    5. The test types most worth investing in first

    5.1 End-to-end tests: the hardest standard to game

    If you only have capacity for one kind of test, choose end-to-end tests. They directly simulate a real user’s path — for example, adding an item to the cart, checking out, and landing on the payment success page.

    Their biggest advantage is that they are extremely hard to work around: the entire functional chain either works or it doesn’t, and AI cannot bluff its way through with “this part looks correct locally.” The feedback is also far richer. A unit test that times out may report nothing more than “timed out after 30 seconds,” with no clue where it got stuck; an end-to-end test will provide a screenshot of the screen and the full execution trace, pointing directly at why the checkout button is disabled.

    Making this work usually means granting the AI permission to operate a real environment: browser automation plugins for web pages, mobile emulators for phone apps, desktop control for desktop software, or simply starting the backend service locally for verification.

    A complementary practice is maintaining a “feature map” that lists real user paths, key shortcuts, and expected behavior. This map serves both as construction guidance for the AI and as the grading standard, giving “correctness from the user’s perspective” an explicit, checkable basis.

    5.2 Property-based tests: built for the edge cases both humans and AI miss

    Many tests only cover the holes a human can think of. Property-based tests exist precisely to catch the extreme edge cases that both humans and AI tend to overlook.

    The approach: first write down a rule that must never be broken (the “property”), then let the property-based testing framework generate thousands of random inputs and try its hardest to break the program. Common properties include:

    1. # Serialization round-trip consistency
    2. For any object obj: deserialize(serialize(obj)) must be exactly equivalent to obj
    3. # Non-negative balance constraint
    4. For any sequence of account balance changes: the balance must never go negative at any point
    5. # Idempotency
    6. The same migration or cleanup logic must produce identical results whether executed once or twice
    7. # Refactoring equivalence
    8. The optimized new code and the unoptimized old code must produce identical output for identical input

    These randomly generated boundary conditions carry no subjective bias, which makes them well suited to guarding against AI’s “surely it works like this” style of implementation. Property-based tests are especially useful in refactoring scenarios where the existing spec has drifted away from production reality — they provide a safety net based on “behavior stays the same” rather than relying on documentation that may already be out of date.

    5.3 Regression and snapshot tests: protecting what should not change

    Beyond end-to-end and property-based tests, regression and snapshot tests make a good supplement. They establish a “golden baseline” for key outputs, and every subsequent change is automatically compared against it. This catches existing behavior that AI inadvertently breaks while “tidying things up,” at very low cost while holding the line effectively.

    Conclusion

    AI writing code is not inherently frightening. What actually determines quality is whether the team can build a fast, stable, credible, reproducible evidence loop around it. When tests become reusable software assets, when independent grading amplifies human effort into an army of AI instances, and when hard-won lessons are codified into rules and hooks, AI coding stops being a risk source that needs guarding at every turn and becomes a scalable, trustworthy source of productivity. A testing system with clear priorities is the key pivot on which this entire shift turns.