Generate regression tests when bugs are discovered during /debug or continuous checks. Auto-detects test framework, creates Arrange-Act-Assert tests, and links to error-log.md entries. (project)
tests/regression/ and update error-log.mdKey principle: Tests should FAIL before the fix is applied (proves bug exists).
Check error-log.md to avoid duplicate tests for same error.
Extract from debug context:
StudentProgressService.fetchExternalData)Example:
error_id: ERR-0042
title: Dashboard timeout due to missing pagination
symptoms: Dashboard fails to load, timeout after 30s
root_cause: Missing pagination parameter causes over-fetching
component: src/services/StudentProgressService.ts:fetchExternalData
reproduction:
- Navigate to /dashboard/student/123
- Click "Load Data" button
- Observe timeout error
Check project configuration (in priority order):
docs/project/tech-stack.md (if exists):
grep -i "test\|jest\|vitest\|pytest\|playwright" docs/project/tech-stack.md
package.json (JavaScript/TypeScript):
# Check devDependencies
grep -E '"(jest|vitest|@playwright/test|mocha)"' package.json
pyproject.toml / requirements.txt (Python):
grep -E "(pytest|unittest|nose)" pyproject.toml requirements.txt
Existing test file patterns:
# JavaScript patterns
find . -name "*.test.ts" -o -name "*.spec.ts" | head -1
# Python patterns
find . -name "*_test.py" -o -name "test_*.py" | head -1
Defaults:
Output: Framework name and test file extension (e.g., Jest → .test.ts)
Find appropriate location:
tests/regression/ exists → use ittests/ directory → tests/regression/__tests__/ directory → __tests__/regression/src/__tests__/regression/tests/regression/ if no pattern foundFile naming:
regression-ERR-{ID}-{slug}.{ext}regression-ERR-0042-dashboard-timeout.test.tstest_regression_err_0042_dashboard_timeout.pyUse framework-appropriate template from references/framework-templates.md.
Structure (Arrange-Act-Assert):
Header: Error ID, title, description, root cause, link to error-log
describe/class: "Regression: ERR-XXXX - {title_short}"
test: "should {expected} when {condition}"
ARRANGE: Set up bug scenario (data, mocks, state)
ACT: Execute action that caused bug
ASSERT: Verify correct behavior (would have failed before fix)
Required elements:
See references/framework-templates.md for complete templates.
Display generated test:
=== Regression Test Generated ===
Error: ERR-0042 - Dashboard Timeout Due to Missing Pagination
File: tests/regression/regression-ERR-0042-dashboard-timeout.test.ts
--- Generated Test Code ---
[Full test code here]
---
This test will:
- {describe what test validates}
- {explain why test would have failed before fix}
What would you like to do?
[A] Save test and continue
[B] Edit test before saving
[C] Skip generation (add to debt tracker)
>
If user chooses:
After user approval:
**Regression Test**:
- **File**: `tests/regression/regression-ERR-0042-dashboard-timeout.test.ts`
- **Status**: Generated
- **Validates**: Pagination parameter prevents timeout
Validation: Test file exists, runs without syntax errors, linked in error-log.md.
// BAD: Tests internal method name
test('calls _fetchWithPagination', () => {
expect(service._fetchWithPagination).toHaveBeenCalled();
});
Do: Test observable behavior
// GOOD: Tests behavior user expects
test('should return paginated results within 5 seconds', async () => {
const result = await service.fetchData(studentId);
expect(result.length).toBeLessThanOrEqual(10);
});
Why: Implementation can change; behavior should remain stable.
// BAD: Breaks if CSS class changes
await page.locator('.btn-primary-xl-dashboard').click();
Do: Use accessible selectors
// GOOD: Stable, user-focused
await page.getByRole('button', { name: 'Load Data' }).click();
Why: Regression tests should be stable across refactors.
// BAD: No reference to error-log.md
test('dashboard loads', () => { /* ... */ });
Do: Include error ID and link
/**
* Regression Test for ERR-0042
* @see specs/my-feature/error-log.md#ERR-0042
*/
test('should load dashboard within 5s (ERR-0042)', () => { /* ... */ });
Why: Traceability enables understanding why test exists.
Do: Match test type to bug scope:
Why: Faster feedback, more stable tests, easier maintenance.
should {expected} when {condition}should return paginated results when dataset exceeds 100 recordsshould complete within 5 seconds when loading dashboardshould show error message when API returns 500Result: Test serves as documentation, failures are self-explanatory.
// Include: State that triggers bug
const service = new StudentProgressService();
const result = await service.fetchData(studentWithLargeDataset);
// Exclude: Unrelated setup
// const userPrefs = loadPreferences(); // Not needed for this test
Result: Faster tests, clearer intent, easier maintenance.
// BAD: Vague assertion
expect(result).toBeTruthy();
// GOOD: Specific to bug being prevented
expect(result.length).toBeLessThanOrEqual(10); // Pagination limit
expect(response.time).toBeLessThan(5000); // No timeout
Result: Test catches regressions, not false positives.
/**
* Regression Test for ERR-0042: Dashboard Timeout
*
* Bug: Dashboard failed to load due to missing pagination
* Root Cause: API call fetched all records (1000+) instead of paginated (10)
* Fixed: Added page_size parameter to API call
*
* @see specs/001-dashboard/error-log.md#ERR-0042
*/
Result: Future developers understand why test exists.
Bad regression test:
test1, dashboard test)toBeTruthy)Issue: No existing test directory
Solution: Create tests/regression/ and document in test file comment
Issue: Test passes before fix applied Solution: Test may not be reproducing bug correctly; review reproduction steps
Issue: Test fails after fix applied Solution: Assertion may be testing wrong behavior; adjust to match expected post-fix state
Issue: User skips too many regression tests Solution: Track in NOTES.md as tech debt; surface during /optimize phase