Sub topic 13
CI as an Independent Check on Agent Changes
This chapter assumes you can run a test suite with pytest, read a Git diff, and have used a coding agent. You will set up a continuous integration (CI) job that runs your tests on every change, including changes an agent makes.
Why the agent's own test run is not enough
During a TDD cycle, the agent runs python -m pytest -q and reads the output. That run happens on the agent's machine, in its working directory, with whatever state it has built up. It can be wrong in three ways:
- The agent can report a pass it did not actually see, or summarize output loosely.
- Local state can hide problems, such as an uncommitted file, a stale cache, or a package installed by hand.
- The agent may have changed the tests or the test configuration, so "passing" no longer means what it did.
CI is a separate machine that checks out the committed code, installs dependencies from scratch, and runs the suite. The agent cannot influence it except through the commit. Because the check is independent, a green CI run is stronger evidence than a green local run.
A minimal CI workflow
This GitHub Actions workflow runs the slugify tests from earlier chapters on every push and pull request. Save it as .github/workflows/tests.yml.
name: tests
on:
push:
pull_request:
jobs:
pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install test tools
run: python -m pip install pytest
- name: Run the suite
run: python -m pytest -qThe final step is the same command the agent runs locally. That is deliberate. If the two runs disagree, something differs between the environments, and you want to find out.
If your project has a requirements.txt, install from it in the same job. Pin versions so the clean machine matches what you tested against.
What CI catches that local runs miss
| Problem | Why a local run misses it | How CI exposes it |
|---|---|---|
| Forgotten file | The file exists on disk but was never committed | Fresh checkout lacks the file, so imports fail |
| Hidden dependency | A package was installed by hand | Clean install does not include it |
| Test selection tricks | The agent ran only one test file | CI runs the whole suite |
| Skipped or deleted tests | The agent reported success anyway | The test count drops, which you can check in the log |
CI does not catch a weakened test on its own. If the agent changes an assertion so it passes, CI will also pass. Combine CI with the protections from earlier chapters: review the test diff, and consider requiring human approval for changes under tests/.
Making CI harder to game
Three settings make the check more trustworthy:
- Protect the main branch so changes merge only through a pull request with a passing CI status.
- Require a human approval on pull requests, so someone reads the diff before merge.
- Restrict who can edit the workflow file, for example with a code owners rule on
.github/workflows/.
Without the second and third, an agent with push access could change what CI runs and then pass its own check.
Using CI output as agent feedback
CI failures are useful input for the next cycle. Copy the failing test name and the assertion message into your next prompt, or let the agent read the logs if your setup allows it. The loop is the same as before: the agent reads output, makes the smallest change, and runs the suite again. CI is the final gate on that loop.
Exercise
An agent's pull request passes locally and in CI, but the diff shows it changed assert slugify("a -- b") == "a-b" to assert slugify("a -- b") == "a--b". Why did CI not catch this, and what two controls would you add?
Show answer
CI only checks that the committed tests pass, and the weakened test passes against the current code. CI cannot judge whether the test still states the intended behavior. Add a human review of any diff touching tests/ and a code owners rule or branch protection that requires approval for test and workflow changes.
Exercise
Why should the CI step run the same command the agent runs locally?
Show answer
If the commands match, a difference in results points to a difference in environment, such as a missing dependency or uncommitted file. That is the kind of problem the independent check is meant to expose.