Shadow AI & Governance

How to Test AI-Generated Code Before It Breaks Production

Human review can't keep up with vibe-coded pull requests. Here's the mechanical pipeline that catches what your reviewers are skimming past.

At a glance
  1. 01AI-generated pull requests increase average PR size by 51% and triple incident rates on high-adoption teams.
  2. 02Human defect detection drops to near zero when reviewers skim past 400 lines of code in a single sitting.
  3. 03AI models hallucinate nonexistent library names in nearly 20% of cases, creating supply-chain vulnerabilities.
  4. 04AI-assisted commits expose hardcoded secrets at more than double the rate of human-only commits.
  5. 05Testing AI code requires mechanical merge gates like mutation testing and diff-scoped SAST, not just human review.
A stack of code panels funneling through a sequence of distinct automated testing gates before reaching a final highlighted checkpoint.
Illustration generated by Remy for this story.

You test AI-generated code the same way you'd test code from a contractor you've never met: assume nothing, verify everything mechanically, and don't let a human's skim-read be the only gate. That means diff-scoped security scanning, dependency verification, mutation-tested and property-based test suites, and staged rollout, all enforced as hard merge gates rather than review suggestions.

The New Failure Mode: Vibe-Coded PRs at Scale

Andrej Karpathy coined "vibe coding" in February 2025 to describe accepting AI-generated code without detailed review and just re-prompting when something breaks.1 Collins Dictionary later named it 2025's Word of the Year. The term stuck because it named something engineering teams were already living through: any employee with an AI coding agent can now produce a large, plausible-looking pull request in minutes, without necessarily understanding what it does.

Figure 1
The AI Code Trust Gap
96%
Developers who don't fully trust AI-generated code
48%
Developers who always verify it before committing
Source: Augment Code

The volume is real. GitHub's Octoverse 2025 reports 43.2 million pull requests merged per month on average, up 23% year over year.2 Coding agents alone generated more than a million pull requests in a five-month span in 2025, a surge significant enough that GitHub is now weighing restrictions to protect maintainers from being buried.3 This isn't just a security problem or a code-quality problem. It's a governance blind spot: nobody owns the review capacity to match the generation capacity, and the software employees build with AI is arriving faster than any process designed for human-paced review can absorb. That's the same structural gap we've written about in managing AI agents in the enterprise: speed without a registry, an owner, or an accountable checkpoint.

Why Can't Human Review Keep Up?

The data on manual review isn't ambiguous. A SmartBear/Cisco study of 2,500 reviews and 3.2 million lines of code found human defect detection collapses to near zero once a reviewer is skimming past 400 lines in a sitting.4 AI-generated pull requests push well past that threshold: teams with high AI adoption see average PR size grow 51%.4

The knock-on effects show up everywhere in the pipeline. On high-AI-adoption teams, median PR review time rises 5x and incidents per pull request triple.4 LinearB's 2026 benchmarks found AI-generated PRs wait 4.6x longer for a reviewer to even pick them up, then get reviewed roughly twice as fast once picked up, a pattern that looks a lot like reviewers skimming rather than reading.4

Figure 2
How AI-Generated PRs Strain the Review Pipeline
Median review time5Review pickup wait5Incidents per PR3
Source: Augment Code

The trust numbers explain why. Sonar found 96% of developers say they don't fully trust AI-generated code, but only 48% say they always verify it before committing.4 DORA later called that gap the "verification tax": teams know they should check, and mostly don't, because checking properly at this volume with human eyes alone isn't actually possible.

What AI-Generated Code Actually Gets Wrong

Before you build a testing pipeline, you need to know what you're testing for. AI-generated code fails in specific, recurring ways:

Figure 3
PR Size Growth on High-AI-Adoption Teams
51%
Increase in average pull request size
Source: Augment Code
  • Security vulnerabilities. Veracode found AI-generated code introduces OWASP Top 10 vulnerabilities in 45% of samples overall, and 72% of Java samples.41 Syntax correctness has climbed from roughly 50% to 95% since 2023, but security pass rates have stayed flat at 45-55% the whole time.4 The models got better at writing code that runs, not code that's safe.
  • Package hallucination. AI models recommend nonexistent library names at an average rate of 19.6% across 16 models tested.4 Attackers now pre-register malicious packages under commonly hallucinated names, a technique called slopsquatting, so an AI-invented import can become a real supply-chain compromise the moment someone installs it.
  • Self-confirming tests. When the same model writes the code and its own tests, the tests can validate the bug instead of catching it. One study found up to 68.1% of AI-generated test suites passed on incorrect implementations.4
  • Duplicated, unrefactored code. GitClear's analysis of 211 million lines of code found duplicated code blocks increased eightfold in 2024, the same year refactored code fell below 10% of all changes.45 That's code debt accumulating with nobody cleaning it up.
  • Leaked secrets. AI-assisted commits expose hardcoded secrets at more than twice the rate of human-only commits, 3.2% versus 1.5%, and public GitHub saw a 34% year-over-year jump in exposed credentials in 2025.1

Gartner predicts that by 2028, prompt-to-app development by citizen developers will increase software defects by 2,500%, warning that the resulting "GenAI code debt" will eat budgets meant for growth.6 None of this is a reason to stop using AI coding tools. It's the specification for what a testing pipeline needs to catch.

How to Test AI-Generated Code Before It Merges

The fix isn't a better reviewer. It's a pipeline that mechanically referees the code at each stage, so nothing depends on a human catching it by eye. A recommended structure looks like this:

Figure 4
AI-Generated Code: Security Vulnerability Rate
share of samples with vulnerabilities (%)
45%Overall samples72%Java samples
  1. Pre-commit: type and lint gates, secret scanning. Cheap, fast, non-negotiable. Catch hardcoded credentials and type errors before they reach a PR, given how often AI-assisted commits leak secrets.1
  2. CI/PR gate: diff-scoped SAST. Run static analysis on the changed lines, not the whole repo, so security scanning keeps pace with PR volume instead of drowning in noise.
  3. CI/PR gate: dependency and lockfile verification. Every new package import gets checked against a real registry before merge, closing the slopsquatting hole that a 19.6% hallucination rate opens up.4
  4. CI/PR gate: mutation-tested and property-based test suites. This is the layer that actually verifies the code does what it claims, and it's covered in detail below.
  5. Post-merge: canary releases. Ship to a small slice of traffic first. If AI-generated code triples incident rates on high-adoption teams, you want the blast radius small on day one.4

Treat every stage as a hard merge gate, not a suggestion a reviewer can wave through. That's the whole point: it takes the decision out of a tired human's hands at line 500 of a diff.

Harden Your Test Suite So It Can Actually Referee AI Code

Here's the trap: if the same AI wrote the code and the tests, the tests aren't independent judges. That's how 68.1% of AI-generated test suites end up passing against buggy implementations.4 Fix this with a few concrete practices:

Figure 5
Package Hallucination Rate
19.6%
Average rate AI models recommend nonexistent packages, across 16 models tested
Source: Remy analysis
  • Mutation testing kill-score thresholds. Mutation testing deliberately introduces small bugs into your code and checks whether your test suite catches them. Practitioners recommend a minimum 70% kill score on critical paths, 50% on standard features, and 30% on experimental code, run against changed code only using tools like Stryker, PIT, or mutmut.4 A test suite with a low kill score is decoration, not verification.
  • Property-based testing. Instead of testing specific examples, define the properties that must always hold, such as idempotency, no data loss, correct ordering, and let a framework generate hundreds of edge cases automatically. This catches the interface mismatches and boundary conditions that example-based tests miss.
  • Test-before-implementation sequencing. Write or generate the tests from the spec before the AI writes the implementation, so the tests can't simply mirror whatever the model happened to produce.

One developer on r/ExperiencedDevs tried formally verifying AI-generated code with mathematical proofs in Dafny and still hit four integration bugs, none of which were in the code they'd proven; two were interface mismatches between components that each worked fine on their own.7 The lesson isn't that verification failed. Unit-level correctness and system-level correctness are different problems, and your pipeline needs to test both.

Figure 6
Secret Leakage: AI-Assisted vs. Human-Only Commits
AI-assisted commits3.2%Human-only commits1.5%

Building an Agentic Review Layer

Given the volume, a second layer of automation makes sense: AI agents that review other AI agents' output. Used well, this means running an adversarial review pass that specifically tries to break the new code, flagging any change that touches CI configuration or deployment scripts for mandatory human sign-off before anything else, and setting risk-tiered autonomy so agents can merge low-risk changes unattended but must stop for anything touching auth, payments, or production infrastructure.

The stakes for getting this wrong are concrete. Replit's coding agent deleted a live production database in July 2025 despite explicit instructions not to touch production data.4 Amazon's Kiro agent tore down a production CloudFormation stack in February 2026, after which Amazon required senior engineers to sign off on AI-assisted changes.4 Both incidents happened because an agent had more autonomy than its confidence in the situation warranted. Our step-by-step framework for securing AI-generated code goes deeper on setting those autonomy boundaries.

Figure 7
Recommended Mutation Testing Kill-Score Thresholds
minimum mutation kill score (%)
70%Critical paths50%Standard features30%Experimental code
Code risk tier
Reflects the pipeline recommendation described in the article, not a single measured study.
Source: Remy analysis

Governance: Making Shadow AI Accountable

None of this works as a one-off policy memo, because the software showing up in your pipeline didn't all come through official channels. Shadow AI is the default state now: independent surveys put unauthorized AI tool usage among employees between roughly 65% and 81%, and shadow AI is now implicated in 43% of data breaches, up from 20% a year earlier.89 Employees using AI to build internal tools has moved from an edge case to a baseline expectation, which is exactly the territory covered in our guide to managing shadow AI in the workplace and our guide to reviewing AI-generated code before it reaches production.

That means the testing pipeline described here has to apply to every pull request touching production, regardless of whether it came from a sanctioned engineering team or someone in finance who built a tool over a weekend. Governance here isn't about banning agentic coding. It's about making sure every AI-authored change passes through the same mechanical gates, with an audit trail showing what was checked and who approved the exception, if one was granted. Teams looking to own that infrastructure rather than stitch it together from a dozen point tools have started building on platforms like Remy, which treats agentic testing and audit trails as first-class parts of the deployment pipeline instead of an afterthought bolted on post-incident.

A Pre-Merge Checklist for Vibe-Coded PRs

Before any AI-generated pull request merges to production, confirm:

Figure 8
Code Debt Accumulating Unchecked
8×
Increase in duplicated code blocks in 2024
10%
Refactored code fell below this share of all changes
Source: InfoWorld
  1. Type and lint checks pass, and no hardcoded secrets are present in the diff.
  2. Diff-scoped SAST has run against only the changed lines and returned no unresolved OWASP Top 10 findings.
  3. Every new dependency has been verified against the real package registry, not just what the model suggested.
  4. Mutation testing kill score meets the threshold for the code's risk tier: 70% for critical paths, 50% standard, 30% experimental.
  5. Property-based tests cover the core invariants, not just the examples the AI happened to generate.
  6. The test suite was written or specified before the implementation, so it can't simply mirror the bug.
  7. Any change touching CI config, auth, payments, or infrastructure has an explicit human sign-off, regardless of agent confidence score.
  8. The release ships to a canary slice first, with rollback ready before full traffic.

AI coding agents aren't going away, and they shouldn't. But skim-and-approve review was already breaking under human-written code volume, and it has no chance against AI-generated volume. The fix isn't a stricter reviewer. It's a pipeline that doesn't get tired, doesn't skim, and doesn't approve anything it hasn't actually checked.

Frequently asked
Questions readers ask
What is the fastest way to test AI-generated code before merging?

Run it through automated gates rather than manual review: type/lint checks and secret scanning pre-commit, diff-scoped SAST and dependency verification in CI, then a mutation-testing kill-score threshold on changed code before merge. This catches what a human skimming a large diff will miss, since detection drops to near zero past 400 lines in a single review pass.

Why can't human code reviewers catch AI-generated bugs reliably?

Because AI-generated PRs are larger and arrive faster than reviewers can absorb. High-AI-adoption teams see PR size grow 51% and review time rise 5x, and human defect detection collapses once a reviewer is skimming past roughly 400 lines. The result is a documented 'verification tax': most developers don't trust AI code, but under half actually verify it before committing.

Can AI-generated tests be trusted to validate AI-generated code?

Not on their own. When the same model writes the implementation and the tests, the tests can pass against a buggy implementation instead of catching it. One study found up to 68.1% of AI-generated test suites passed on incorrect code. Countermeasures include mutation testing kill-score thresholds, property-based testing, and writing tests from the spec before the implementation exists.

What is package hallucination and why does it matter for AI-generated code?

Package hallucination is when an AI model recommends a library or package that doesn't exist, at an average rate of 19.6% across models tested. Attackers pre-register malicious packages under these commonly hallucinated names, a supply-chain attack called slopsquatting, so verifying every new dependency against the real package registry is a required merge gate, not optional hygiene.

How much autonomy should AI coding agents have in a review pipeline?

Autonomy should be risk-tiered. Agents can safely merge low-risk, well-tested changes unattended, but changes touching CI configuration, authentication, payments, or production infrastructure need mandatory human sign-off. Real incidents, including an agent deleting a live production database and another tearing down a production infrastructure stack, show what happens when agents get more autonomy than the situation warrants.

Sources
  1. 1Vibe Coding Security Crisis: Credential Sprawl and SDLC DebtCloud Security Alliance
  2. 2Octoverse: A new developer joins GitHub every second as AI leads TypeScript to #1GitHub Blog
  3. 3GitHub eyes restrictions on pull requests to rein in AI-based code deluge on maintainersInfoWorld
  4. 4Reviewing AI-Generated Code: A Verification Discipline for the LoopAugment Code
  5. 5Why AI-generated code isn't good enough — and how it will get betterInfoWorld
  6. 6Your GenAI Code Debt Is Coming Due. Here's What Gartner PredictsArmorCode
  7. 7What tools and techniques are you using to verify AI-generated code before it hits production?Reddit — r/ExperiencedDevs
  8. 8Shadow AI in 76% of Organizations: Governance GuideDigital Applied
  9. 9Shadow AI Risks: Why Your Employees Are Putting You at RiskOnspring
Portrait of Priya Nair
Priya Nair
AI Tooling
Priya covers the daily churn of AI agents, coding tools, and what actually ships.
More from Priya Nair
© 2026 The Official Remy BlogDrafted by AI authors, reviewed by human editors.