Our coding agent runs the tests before it says it is done. Most of the time. When a test is slow or flaky, it sometimes reports "tests pass for the changed module" after running a subset, and when a pre-commit hook fails on something unrelated, a person in a hurry commits with --no-verify. Neither is malicious. Both mean that the checks we rely on are advisory until something enforces them on a machine nobody controls interactively.

That machine is CI. This post describes the pipeline we require on every pull request, with extra attention to the failure modes of AI-written code, and the repository settings that make it impossible to merge around. Our earlier posts cover a git-hook review gate on the developer's machine and a broader DevSecOps scanning pipeline; this one is about the minimum set of required checks and how to make them stick.

What the pipeline must prove

For any pull request, regardless of who or what wrote it:

  1. It compiles and type-checks.

  2. It follows the language lint rules and the project's own rules.

  3. The full test suite passes, not a subset.

  4. The new and changed lines are tested.

  5. It introduces no known vulnerable patterns or dependencies.

  6. A human who owns the area approved it.

AI-written changes fail most often on 3 and 4 (partial test runs, tests that do not exercise the change) and on 2 for project rules the agent forgot. The pipeline treats every pull request the same; we do not try to detect which ones came from an agent.

The workflow

A single GitHub Actions workflow with parallel jobs. Each job becomes a status check that branch protection can require by name.

name: verify
on:
  pull_request:
  merge_group:

concurrency:
  group: verify-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  static:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "3.12", cache: pip }
      - run: pip install -r requirements-dev.txt
      - run: pre-commit run --all-files --show-diff-on-failure
      - run: mypy src

  test:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: actions/setup-python@v5
        with: { python-version: "3.12", cache: pip }
      - run: pip install -r requirements-dev.txt
      - run: pytest --cov=src --cov-report=xml -q
      - name: Coverage on changed lines
        run: diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --fail-under=85

  dependency-review:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-24.04
    permissions: { contents: read, pull-requests: write }
    steps:
      - uses: actions/checkout@v4
      - uses: actions/dependency-review-action@v4
        with: { fail-on-severity: high }

  codeql:
    runs-on: ubuntu-24.04
    permissions: { contents: read, security-events: write }
    steps:
      - uses: actions/checkout@v4
      - uses: github/codeql-action/init@v3
        with: { languages: python }
      - uses: github/codeql-action/analyze@v3

A few choices worth explaining.

pre-commit runs again, on all files

pre-commit run --all-files executes the same hooks the developer has locally: formatters, linters and our rule scripts. Running on all files rather than the diff catches the case where a hook was added after a file was last touched. --show-diff-on-failure prints what a formatter would change, which an agent can apply directly.

Coverage on the diff, not overall

Overall coverage barely moves when a pull request adds forty untested lines to a large codebase. diff-cover reads the coverage report and the git diff and fails if the changed lines are under the threshold. It needs the base branch history, hence fetch-depth: 0. This is the check that most often fails on AI-written changes: the agent adds a branch for an edge case and no test reaches it.

Coverage on the diff is still only coverage. It proves the lines ran, not that the tests would catch a bug in them. For high-risk modules we add a mutation testing job on changed files, run nightly rather than per pull request because it is slow.

Full test suite, always

The test job always runs the full suite. When it becomes too slow, we split it with a matrix or shard by test file, but we do not let a pull request choose which tests to run. "Only the affected tests" is a valid optimisation for a monorepo with a reliable dependency graph and a full nightly run, not a default.

SAST and dependency review

CodeQL scans for known vulnerable patterns such as injection and unsafe deserialization. dependency-review-action fails if the pull request adds a dependency with a known vulnerability at or above the configured severity. Both matter for AI-written code: models suggest packages and patterns from their training data, which can include outdated or vulnerable versions, and occasionally package names that do not exist.

Least privilege for the workflow token

permissions: contents: read at the top limits the GITHUB_TOKEN for every job; jobs that need more ask for it explicitly. A pull request that edits the workflow file cannot quietly grant itself write access on pull_request events from forks, and the principle keeps the blast radius small for same-repository branches too.

Making it required

A green pipeline that is not required is a suggestion. On GitHub, use a repository ruleset (or classic branch protection) on the default branch:

  • Require a pull request before merging, with at least one approval.

  • Require review from Code Owners, so changes to billing/ or auth/ need the owning team.

  • Dismiss stale approvals when new commits are pushed, so an approval of version one does not cover version three.

  • Require status checks to pass: static, test, dependency-review, codeql. Select them by name; a check that is not listed is not enforced.

  • Require branches to be up to date or use a merge queue, so checks run against what will actually land. The merge_group trigger in the workflow is what lets checks run in the queue.

  • Block force pushes and do not grant bypass to the agent's account or its token.

That last point deserves emphasis. If your agent opens pull requests with a token or GitHub App, make sure that identity is not in the ruleset's bypass list and cannot approve its own pull requests. The agent proposes; CI verifies; a human approves.

When checks fail

The failure output is input for the next iteration. We ask the agent to read the failing job log and fix the cause, with one firm rule in CLAUDE.md: never change a test's expected value, a coverage threshold, a lint configuration or a baseline file to make CI pass without saying so explicitly in the pull request description. A reviewer looks for those changes first.

CODEOWNERS on the CI configuration itself enforces the same thing structurally:

/.github/workflows/      @acme/platform
/.pre-commit-config.yaml @acme/platform
/tools/rules/            @acme/platform

Common mistakes

Mistake

Why it hurts

Do this instead

Checks run but are not required

Merges happen on red

Ruleset with named required checks

Only overall coverage

New untested code hides in the average

diff-cover on changed lines

Agent token can bypass rules

The verifier can be skipped

No bypass, no self-approval

Running only affected tests by default

Missed cross-module breakage

Full suite per PR, sharded if slow

Workflow token with write-all

Larger blast radius

contents: read default, per-job grants

Key takeaways

  • CI is the verifier that cannot be skipped or persuaded; treat local checks as fast feedback only.

  • Re-run pre-commit on all files, type-check, run the full suite and check coverage on the diff.

  • Add SAST and dependency review; AI suggestions can carry outdated or vulnerable patterns.

  • Enforce with required checks, code owners, stale-approval dismissal and a merge queue.

  • Never give the agent's identity a bypass, and protect the CI configuration with code owners.

References