Skip to main content

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

TechniqueWhat it guardsTooling examples
Golden testsOutput of a known input must stay the same (reports, exports, API responses)Approved files in tests/golden/, compared in tests
Snapshot guardsUnintended UI or structure changesVitest/Jest snapshots, Playwright visual comparisons
Property-based testsInvariants over many generated inputs (“pass rate is always between 0 and 1”)fast-check, Hypothesis
Mutation testingWhether your tests actually detect broken codeStrykerJS, PIT, mutmut
Contract testsAgreements between servicesPact

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.

Real Stryker output on TestRun Board main: surviving mutants such as an EqualityOperator change from ms < 10_000 to ms <= 10_000 in formatDuration, which no test catches, and the score table

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 --stat and 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

  1. Add one property-based test and run mutation testing on one module. What does the score tell you?
  2. Adapt the governance starter for your team and open it as a pull request.
  3. Add a CI check that fails when snapshots change in a PR without a snapshot-update label.

Walkthrough in TestRun Board

  1. Run npm run mutation on main and open reports/mutation/index.html. Find the EqualityOperator survivor in formatDuration.
  2. Kill it: add a test expect(formatDuration(10_000)).toBe('10s') to tests/lib/runs.test.ts, run npm run mutation again and check that the mutant is now killed.
  3. Do the same for one other survivor, or decide it is not worth a test and write down why.
  4. Read tests/lib/runs.property.test.ts: two properties of formatDuration checked over thousands of generated durations. Add one property of your own, for example “the result never contains a negative number”.
  5. Adapt docs/agent-governance.md for 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.