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