AI Regression Testing
Add tests that catch the failures AI agents commonly miss when the same model
writes code and reviews its own assumptions.
Contract
Inputs:
- Bug report, code diff, API change, route, component, feature flag, or sandbox path
- Existing test commands and project conventions
- Optional known production incident or regression id
Outputs:
- Regression test plan
- New or updated tests when implementation is requested
- Parity checklist for sandbox, mock, feature-flag, and production paths
- Verification commands and results
Creates/Modifies:
- Test files, fixtures, mocks, and minimal helpers when asked to implement
- Application code only when the user also asks to fix the failing behavior
External Side Effects:
- None by default
- Do not hit production services; use sandbox, fixtures, local test databases, or mocked providers
Confirmation Required:
- Before changing production data, external accounts, CI settings, or destructive test fixtures
Delegates To:
testing-expert for general testing strategy
react-testing-library for React component tests
playwright-e2e-init for browser setup or test-runner for existing browser tests
debug when the root cause is still unknown
When to Use
- AI modified API routes, backend logic, serializers, or response schemas.
- A bug was fixed and must not reappear.
- A feature has sandbox/mock and production paths.
- A model-generated review says the change is correct but no test proves it.
- Build and lint pass, but the user-facing contract may still be wrong.
- A feature flag, mock mode, fallback path, or error path was changed.
Core Principle
Test the contract that failed, not the implementation the agent wrote. Assume the reviewing model shares the same blind spot as the writing model.
Common AI blind spots:
- production path fixed but sandbox/mock path still wrong
- response includes a field in one path but not another
SELECT, serializer, DTO, fixture, and frontend type drift apart
- optimistic UI path works but rollback/error path is untested
- feature flag changes one branch but not the fallback branch
- tests assert status codes but not response shape or state transition
Workflow
1. Identify the Contract
State the behavior as a user or caller contract:
- endpoint returns these fields
- component shows this state after this interaction
- webhook processes duplicate events idempotently
- sandbox and production return the same shape
- failed operation rolls back visible and persisted state
Create a required-field or required-state list when useful.
2. Find All Paths
Trace every path that should satisfy the contract:
- production data path
- sandbox/mock/demo path
- feature-flag on/off path
- authenticated/unauthenticated path
- success, validation error, provider error, and retry path
- server response, client type, and UI rendering path
3. Write the Regression First
The first test should fail on the unfixed bug or on a representative broken
fixture. If the bug is already fixed, make the test specific enough that the
previous bug would have failed.
Prefer deterministic checks:
- unit or route handler tests for response shape
- integration tests for database, serializer, and service contracts
- component tests for state transitions
- E2E tests only for critical user journeys or cross-system behavior
4. Test Parity
For API and data contracts, compare path shapes:
production fields == sandbox fields == mock fixture fields
frontend type accepts exactly the returned shape
empty/error states still include documented envelope fields
Use fixtures with realistic nulls, missing optional values, and date formats.
5. Verify
Run the narrow test first, then the relevant suite:
bun test path/to/regression.test.ts
bun test
bun run typecheck
Use the repo's actual package manager and test commands. Do not invent new
tooling when the project already has a pattern.
Test Design Checklist
- Does the test fail for the old bug?
- Does it cover every branch that returns or mutates the contract?
- Does it assert the actual response/body/state, not only
200 OK?
- Does it include sandbox/mock parity when those modes exist?
- Does it cover null, empty, duplicate, retry, and provider-failure cases when relevant?
- Is the test small enough to run in a bug-check loop?
- Is the regression named after the bug or contract it protects?
Output Format
Regression target: `GET /api/profile` must include `notification_settings` in production and sandbox responses.
Tests added:
- `tests/api/profile.test.ts`: response-shape contract
- `tests/api/profile.test.ts`: sandbox/production field parity
Verification:
- `bun test tests/api/profile.test.ts` passed
- `bun run typecheck` passed
Residual risk:
- No E2E coverage for the settings page rendering this field.
Anti-Patterns
- Letting an AI review replace a mechanical test.
- Testing only the path the fix touched.
- Asserting vague success instead of the exact contract.
- Using production systems for regression tests.
- Adding broad flaky E2E coverage when a route or unit test catches the bug.
- Forgetting fixtures and generated types after changing response shape.
1---
2name: ai-regression-testing
3description: Design regression tests for AI-assisted development by targeting model blind spots such as sandbox versus production path drift, response-shape mismatches, untested bug fixes, and same-model review failures. Use after AI-generated code changes, bug fixes, API edits, or feature-flag/sandbox changes.
4metadata:
5 version: "1.0.1"
6 tags: "testing, ai, regression, quality, api"
7---
8
9# AI Regression Testing
10
11Add tests that catch the failures AI agents commonly miss when the same model
12writes code and reviews its own assumptions.
13
14## Contract
15
16Inputs:
17
18- Bug report, code diff, API change, route, component, feature flag, or sandbox path
19- Existing test commands and project conventions
20- Optional known production incident or regression id
21
22Outputs:
23
24- Regression test plan
25- New or updated tests when implementation is requested
26- Parity checklist for sandbox, mock, feature-flag, and production paths
27- Verification commands and results
28
29Creates/Modifies:
30
31- Test files, fixtures, mocks, and minimal helpers when asked to implement
32- Application code only when the user also asks to fix the failing behavior
33
34External Side Effects:
35
36- None by default
37- Do not hit production services; use sandbox, fixtures, local test databases, or mocked providers
38
39Confirmation Required:
40
41- Before changing production data, external accounts, CI settings, or destructive test fixtures
42
43Delegates To:
44
45- `testing-expert` for general testing strategy
46- `react-testing-library` for React component tests
47- `playwright-e2e-init` for browser setup or `test-runner` for existing browser tests
48- `debug` when the root cause is still unknown
49
50## When to Use
51
52- AI modified API routes, backend logic, serializers, or response schemas.
53- A bug was fixed and must not reappear.
54- A feature has sandbox/mock and production paths.
55- A model-generated review says the change is correct but no test proves it.
56- Build and lint pass, but the user-facing contract may still be wrong.
57- A feature flag, mock mode, fallback path, or error path was changed.
58
59## Core Principle
60
61Test the contract that failed, not the implementation the agent wrote. Assume the reviewing model shares the same blind spot as the writing model.
62
63Common AI blind spots:
64
65- production path fixed but sandbox/mock path still wrong
66- response includes a field in one path but not another
67- `SELECT`, serializer, DTO, fixture, and frontend type drift apart
68- optimistic UI path works but rollback/error path is untested
69- feature flag changes one branch but not the fallback branch
70- tests assert status codes but not response shape or state transition
71
72## Workflow
73
74### 1. Identify the Contract
75
76State the behavior as a user or caller contract:
77
78- endpoint returns these fields
79- component shows this state after this interaction
80- webhook processes duplicate events idempotently
81- sandbox and production return the same shape
82- failed operation rolls back visible and persisted state
83
84Create a required-field or required-state list when useful.
85
86### 2. Find All Paths
87
88Trace every path that should satisfy the contract:
89
90- production data path
91- sandbox/mock/demo path
92- feature-flag on/off path
93- authenticated/unauthenticated path
94- success, validation error, provider error, and retry path
95- server response, client type, and UI rendering path
96
97### 3. Write the Regression First
98
99The first test should fail on the unfixed bug or on a representative broken
100fixture. If the bug is already fixed, make the test specific enough that the
101previous bug would have failed.
102
103Prefer deterministic checks:
104
105- unit or route handler tests for response shape
106- integration tests for database, serializer, and service contracts
107- component tests for state transitions
108- E2E tests only for critical user journeys or cross-system behavior
109
110### 4. Test Parity
111
112For API and data contracts, compare path shapes:
113
114```text
115production fields == sandbox fields == mock fixture fields
116frontend type accepts exactly the returned shape
117empty/error states still include documented envelope fields
118```
119
120Use fixtures with realistic nulls, missing optional values, and date formats.
121
122### 5. Verify
123
124Run the narrow test first, then the relevant suite:
125
126```bash
127bun test path/to/regression.test.ts
128bun test
129bun run typecheck
130```
131
132Use the repo's actual package manager and test commands. Do not invent new
133tooling when the project already has a pattern.
134
135## Test Design Checklist
136
137- Does the test fail for the old bug?
138- Does it cover every branch that returns or mutates the contract?
139- Does it assert the actual response/body/state, not only `200 OK`?
140- Does it include sandbox/mock parity when those modes exist?
141- Does it cover null, empty, duplicate, retry, and provider-failure cases when relevant?
142- Is the test small enough to run in a bug-check loop?
143- Is the regression named after the bug or contract it protects?
144
145## Output Format
146
147```markdown
148Regression target: `GET /api/profile` must include `notification_settings` in production and sandbox responses.
149
150Tests added:
151- `tests/api/profile.test.ts`: response-shape contract
152- `tests/api/profile.test.ts`: sandbox/production field parity
153
154Verification:
155- `bun test tests/api/profile.test.ts` passed
156- `bun run typecheck` passed
157
158Residual risk:
159- No E2E coverage for the settings page rendering this field.
160```
161
162## Anti-Patterns
163
164- Letting an AI review replace a mechanical test.
165- Testing only the path the fix touched.
166- Asserting vague success instead of the exact contract.
167- Using production systems for regression tests.
168- Adding broad flaky E2E coverage when a route or unit test catches the bug.
169- Forgetting fixtures and generated types after changing response shape.