Catalog My learning Blog
AI-Assisted Coding Course: Agentic Development in 30 Days · Phase 5 · Lesson 24 · 5 min read

Quality Gates and CI for AI-Generated Code

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: One Check Command, Three Enforcement Points
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Design automated checks that keep AI-generated code at your quality bar: a fast local check command the agent runs on every change, pre-commit hooks, required CI checks and branch protection, and agent instructions and hooks that make passing them part of done.

Concept Explanation

Agents are only as good as the feedback they get, and humans can only review so much. Quality gates address both at once. A gate is an automated check that must pass before code moves forward: before the agent says it is done, before a commit, before a merge. Good gates give the agent objective signals during the work and catch what reviewers miss afterwards.

Start with one fast local command that runs the checks that matter: type checking, linting, formatting verification and the tests relevant to the change. Name it something obvious, such as make check or pnpm check, document it in the instruction file as part of the definition of done, and keep it fast, ideally under a minute, because the agent will run it many times per task. Slow checks either get skipped or burn time and tokens; move them to CI.

Make the gate hard to skip at each stage. In the session, a Stop hook can run the check command and send the agent back if it fails (Day 17). At commit time, pre-commit hooks run formatters and fast linters on the changed files. In CI, the full suite runs: all tests, coverage, static analysis, security scans, dependency checks and builds. With branch protection, the checks are required, so nothing merges until they pass, whether a person or an agent opened the pull request.

Choose gates that catch the failure modes of AI code (Days 14, 21 and 25). Type checking catches hallucinated APIs and wrong signatures. Linters with strict rules catch unused code, broad exception handling and risky patterns. Coverage on changed lines catches new code without tests. Tests that must not be modified catch weakened verification. Mutation testing, on critical modules, catches tests that pass without really checking anything. Static security analysis and secret scanning catch the vulnerabilities from Day 21. Duplication and architecture checks catch structural decay (Day 25).

Gate output is itself context for the agent. Configure tools to print concise, actionable messages with file and line, and avoid dumping thousands of lines; an agent reading the last forty lines of a clear failure fixes it faster than one wading through a full log. In CI, an agent can be asked to read the failing check's log and propose a fix, closing the loop without a human relaying errors.

GateWhereCatches in AI code
Type checkLocal check, CIHallucinated APIs, wrong signatures
Strict lint rulesLocal check, pre-commit, CIDead code, swallowed errors, risky patterns
Tests and coverage on changed linesLocal check, CIUntested new paths, broken behavior
Protected test filesHook, reviewWeakened or deleted tests
Security and secret scanningCIInjection, exposed keys
Mutation testingCI on critical modulesTests that do not really assert

Worked Example: One Check Command, Three Enforcement Points

The same checks run in the agent's loop, at commit time and as required CI status checks.

JSON
{
  "scripts": {
    "check": "pnpm run typecheck && pnpm run lint && pnpm run test:changed",
    "typecheck": "tsc --noEmit",
    "lint": "eslint . --max-warnings=0",
    "test:changed": "vitest run --changed main --reporter=dot"
  }
}
YAML
# .pre-commit-config.yaml: fast checks on staged files
repos:
  - repo: local
    hooks:
      - id: prettier
        name: prettier
        entry: npx prettier --check
        language: system
        files: \.(ts|tsx|json|md)$
      - id: eslint
        name: eslint
        entry: npx eslint --max-warnings=0
        language: system
        files: \.(ts|tsx)$
YAML
# .github/workflows/ci.yml: full suite, marked as a required check in branch protection
name: ci
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
      - run: pnpm install --frozen-lockfile
      - run: pnpm run typecheck && pnpm run lint
      - run: pnpm vitest run --coverage --coverage.thresholds.lines=80
      - run: pnpm audit --audit-level=high

The instruction file then says: "Done means pnpm check passes; show the output." The agent runs the fast gate dozens of times during a task, the commit hook catches formatting slips, and the required CI check guarantees nothing merges without the full suite, regardless of who opened the pull request.

A fast check command is the agent's definition of done and runs in its loop via a Stop hook. Pre-commit hooks catch slips at commit time, and required CI checks with branch protection guard every merge.
A fast check command is the agent's definition of done and runs in its loop via a Stop hook. Pre-commit hooks catch slips at commit time, and required CI checks with branch protection guard every merge.

Real-World Examples

  • The 2025 DORA report's AI Capabilities Model lists practices such as strong version control, working in small batches and a quality internal platform among the factors that determine whether AI adoption improves or harms delivery, all of which depend on fast automated feedback.
  • GitHub's documentation for the Copilot coding agent states that its pull requests go through the repository's usual checks and that the agent cannot approve or merge its own pull requests, so branch protection and required checks govern agent work like any other contribution.
Key TakeawaysQuality gates such as tests, linters and type checks give coding agents objective feedback and catch what human reviewers miss. Provide one fast local check command as the definition of done, enforce it in the session with hooks, at commit time with pre-commit, and at merge with required CI checks and branch protection. Choose gates that target AI failure modes, such as type checks, strict linting, changed-line coverage, protected tests, security scanning and mutation testing, and make their output concise and actionable.

Review Questions & Answers

The agent runs it many times during a task. A slow check gets skipped or wastes time and tokens, so fast checks run locally and slower ones move to CI.

Type checking, because calls to functions or options that do not exist, or with the wrong signature, fail to type check before any test runs.

Required status checks and review rules apply to every pull request, so an agent's changes cannot merge until the same gates pass and approvals exist, exactly as for human contributions.

The agent reads the output to decide what to fix. Concise messages with file and line lead to quick, targeted fixes, while huge logs consume context and slow the agent down.