Regression Strategy and Governance Basics
Why This Matters
Agents increase the number of changes your team makes. More changes mean more chances for regressions and more pressure on review. You need a regression strategy that scales with the agent, and a few clear team agreements about how agents are used.
Regression techniques that catch agent mistakes
| Technique | What it guards | Tooling examples |
|---|---|---|
| Golden tests | Output of a known input must stay the same (reports, exports, API responses) | Approved files in tests/golden/, compared in tests |
| Snapshot guards | Unintended UI or structure changes | Vitest/Jest snapshots, Playwright visual comparisons |
| Property-based tests | Invariants over many generated inputs (“pass rate is always between 0 and 1”) | fast-check, Hypothesis |
| Mutation testing | Whether your tests actually detect broken code | StrykerJS, PIT, mutmut |
| Contract tests | Agreements between services | Pact |
Two notes for agent work:
- Snapshot updates are a classic false-green route. Treat a snapshot update in a “fix” PR like a changed assertion: it needs a reason.
- Mutation testing is the best answer to “are these agent-written tests any good?”. Run it on changed files only, so it stays fast.
// property-based test with fast-check
import fc from 'fast-check'
test('pass rate is always between 0 and 1', () => {
fc.assert(fc.property(fc.array(fc.boolean()), runs => {
const rate = passRate(runs)
return runs.length === 0 ? rate === 0 : rate >= 0 && rate <= 1
}))
})
In the example repository, npm run mutation runs Stryker on src/lib (the starting score is around 88%, with a few surviving mutants left on purpose for you to kill), and tests/lib/runs.property.test.ts contains property-based tests. The governance starter below is in docs/agent-governance.md.
Look at the EqualityOperator survivor: changing ms < 10_000 into ms <= 10_000 breaks nothing in the test suite, so exactly 10 seconds is untested. One test with formatDuration(10_000) kills it. That is the exercise for this lesson.
Stress-test agent output at the edges
Ask the agent to attack its own work in a separate session or with a reviewer subagent: “List ten inputs that could break summariseHistory and write a failing test for each one you think is a real bug.” Then you decide which bugs are real.
Governance basics
Keep the first version short enough that people read it. A starter:
# How we use coding agents
1. Ownership: the person who opens the PR owns the code, whoever wrote it.
2. Review: agent-written PRs get the same review as any PR; test changes are reviewed first.
3. Size: PRs stay reviewable (aim for under ~400 changed lines); split larger work.
4. Gates: no merge without green CI; agents never push to main.
5. Data: no secrets, customer data or production credentials in prompts, memory or MCP config.
6. Tools: approved harnesses, models, plugins and MCP servers are listed in this repo.
7. Disclosure: mention in the PR when an agent did most of the work.
8. Learning: repeated agent mistakes become a rule, skill, hook or test.
Store it in the repository, link it from CLAUDE.md and review it every quarter.
A sensible review policy
- Read
git diff --statand all test changes first. - Run or check the mutation score for changed files.
- Reject PRs that mix a feature with unrelated refactoring.
- Use a reviewer subagent as a first pass, never as the only reviewer.
Hands-on
- Add one property-based test and run mutation testing on one module. What does the score tell you?
- Adapt the governance starter for your team and open it as a pull request.
- Add a CI check that fails when snapshots change in a PR without a
snapshot-updatelabel.
Walkthrough in TestRun Board
- Run
npm run mutationonmainand openreports/mutation/index.html. Find theEqualityOperatorsurvivor informatDuration. - Kill it: add a test
expect(formatDuration(10_000)).toBe('10s')totests/lib/runs.test.ts, runnpm run mutationagain and check that the mutant is now killed. - Do the same for one other survivor, or decide it is not worth a test and write down why.
- Read
tests/lib/runs.property.test.ts: two properties offormatDurationchecked over thousands of generated durations. Add one property of your own, for example “the result never contains a negative number”. - Adapt
docs/agent-governance.mdfor your team and open it as a pull request. The repository already enforces three of its points: no pushing (hook and permission), gates (CI), and no unapproved dependencies (hook and agent policy).
Key Takeaways
- Combine golden, snapshot, property-based, mutation and contract tests.
- Mutation testing answers whether agent-written tests catch broken code.
- Governance starts small: ownership, review, size, gates, data, tools, disclosure, learning.
- Agents are reviewed like colleagues: same rules, same gates.
