Regression Tester
Overview
This skill creates a safety net around refactoring work. It analyzes what changed, identifies the public API surface and behavior contracts of the refactored code, generates targeted regression tests that verify behavior is preserved, and runs them against both the old and new implementations to confirm equivalence.
Instructions
Step 1: Analyze the Refactoring Scope
Get the diff: git diff main...HEAD or compare specific commits
Categorize changes:
- Signature changes — function/method names, parameters, return types
- Internal restructuring — same API, different implementation
- Extracted modules — code moved to new files/functions
- Behavioral changes — intentional behavior modifications (flag these!)
Identify the behavior contract for each changed unit:
- What inputs does it accept?
- What outputs does it produce?
- What side effects does it have? (DB writes, API calls, file I/O)
- What errors does it throw and under what conditions?
Step 2: Check Existing Coverage
- Run existing tests:
npm test / pytest / go test ./...
- If tests pass, check coverage of the refactored code:
npx jest --coverage --collectCoverageFrom='src/refactored-module/**'
- Identify untested code paths in the refactored area:
- Uncovered branches (if/else, switch cases, error handling)
- Edge cases (empty input, null, boundary values, concurrent access)
- Integration points (function calls to other modules)
Step 3: Generate Regression Tests
Create tests that verify behavior, not implementation:
- Input/output tests — For pure functions, test that same inputs produce same outputs
- Contract tests — For APIs, verify request/response shape and status codes
- Side-effect tests — For stateful code, verify correct DB operations, events emitted
- Error path tests — Verify error handling behavior is preserved
- Boundary tests — Empty arrays, zero values, maximum lengths, unicode strings
Test structure:
describe('[ModuleName] regression', () => {
describe('preserved behavior', () => {
// Tests that MUST pass identically before and after refactor
});
describe('edge cases', () => {
// Tests for boundary conditions
});
describe('error handling', () => {
// Tests for error paths
});
});
Step 4: Verify Against Old Implementation
- Stash or commit current changes
- Checkout the pre-refactor code:
git stash && git checkout main
- Run the new regression tests against the OLD code — they should all pass
- Return to refactored code:
git checkout - && git stash pop
- Run the regression tests again — they should still all pass
- If any test fails on the refactored code but passed on the old code → regression found
Step 5: Report
Regression Test Report
═══════════════════════
Refactored: src/services/billing.ts (4 functions, 187 lines changed)
Tests generated: 24
Passed (old code): 24/24 ✓
Passed (new code): 23/24 ✗
❌ REGRESSION FOUND:
test: "calculates prorated amount for mid-cycle upgrade"
Expected: 14.52
Received: 14.50
Location: src/services/billing.ts:89 (rounding changed from Math.ceil to Math.round)
✓ All other behavior preserved.
Examples
Example 1: Refactored Utility Functions
User prompt:
I refactored our date utility module from moment.js to dayjs. Can you make sure nothing broke?
Agent actions:
git diff main -- src/utils/dates.ts
Agent analysis:
Refactoring scope: src/utils/dates.ts
- Import changed: moment → dayjs
- 8 exported functions, all signatures preserved
- Internal parsing logic changed
Existing test coverage: 3 tests covering 2 of 8 functions (25%)
Generated 18 regression tests covering:
✓ formatDate() — 4 formats × 3 edge cases (null, invalid, timezone)
✓ diffInDays() — positive, negative, same day, DST boundary
✓ startOfWeek() — Sunday vs Monday locale, year boundary
✓ parseISO() — valid, invalid, with/without timezone offset
✓ isBusinessDay() — weekday, Saturday, Sunday, holiday handling
✓ addBusinessDays() — skip weekends, cross month boundary
Results against old code (moment.js): 18/18 passed
Results against new code (dayjs): 17/18 passed
❌ Regression: startOfWeek('2024-01-01') returns Sunday with dayjs
but returned Monday with moment (locale-dependent).
Fix: Add dayjs.extend(weekOfYear) and set locale explicitly.
Example 2: Extracted Service Layer
User prompt:
I split our monolithic UserController into UserService + UserController. Did I break anything?
Agent output:
Analyzed refactoring: 1 file → 2 files
Old: src/controllers/UserController.ts (342 lines)
New: src/controllers/UserController.ts (98 lines) + src/services/UserService.ts (267 lines)
Public API surface: 6 endpoints unchanged (routes, params, response shapes)
Internal: Business logic extracted to UserService, controller delegates
Generated 22 regression tests:
POST /users — creation with valid data, duplicate email, missing fields
GET /users/:id — existing user, non-existent (404), invalid ID format
PUT /users/:id — partial update, full update, unauthorized (403)
DELETE /users/:id — soft delete, already deleted, cascade check
GET /users — pagination, filtering, sorting, empty result
Results: 22/22 passed on both old and new code ✓
No regressions detected. Refactoring is safe.
Guidelines
- Test behavior, not implementation — don't assert on internal method calls
- Run tests against BOTH old and new code to confirm equivalence
- Flag intentional behavior changes separately from regressions
- Focus test generation on the changed code, not the entire codebase
- Include edge cases that the original code may not have tested
- For database-touching code, use transactions that roll back after each test
- If the refactoring changes performance characteristics, add benchmark comparisons
- Keep regression tests permanent — they protect against future changes too
1---2name: regression-tester3description: >-4 Generate and run regression tests after code refactoring to verify behavior5 is preserved. Use when someone has refactored code and needs to confirm nothing6 broke — especially when existing test coverage is insufficient. Trigger words:7 regression test, refactor validation, behavior preservation, before/after test,8 did I break anything, refactoring safety net, snapshot test.9license: Apache-2.010compatibility: "Works with any test framework (Jest, Vitest, pytest, Go test). Requires git for diff analysis."11metadata:12 source: https://skillmd.com/skills/eliferjunior/regression-tester13 author: terminal-skills14 version: "1.0.0"15 category: development16 tags: ["regression-testing", "refactoring", "testing", "code-quality"]17---1819# Regression Tester2021## Overview2223This skill creates a safety net around refactoring work. It analyzes what changed, identifies the public API surface and behavior contracts of the refactored code, generates targeted regression tests that verify behavior is preserved, and runs them against both the old and new implementations to confirm equivalence.2425## Instructions2627### Step 1: Analyze the Refactoring Scope28291. Get the diff: `git diff main...HEAD` or compare specific commits302. Categorize changes:31 - **Signature changes** — function/method names, parameters, return types32 - **Internal restructuring** — same API, different implementation33 - **Extracted modules** — code moved to new files/functions34 - **Behavioral changes** — intentional behavior modifications (flag these!)35363. Identify the **behavior contract** for each changed unit:37 - What inputs does it accept?38 - What outputs does it produce?39 - What side effects does it have? (DB writes, API calls, file I/O)40 - What errors does it throw and under what conditions?4142### Step 2: Check Existing Coverage43441. Run existing tests: `npm test` / `pytest` / `go test ./...`452. If tests pass, check coverage of the refactored code:46 ```bash47 npx jest --coverage --collectCoverageFrom='src/refactored-module/**'48 ```493. Identify untested code paths in the refactored area:50 - Uncovered branches (if/else, switch cases, error handling)51 - Edge cases (empty input, null, boundary values, concurrent access)52 - Integration points (function calls to other modules)5354### Step 3: Generate Regression Tests5556Create tests that verify behavior, not implementation:57581. **Input/output tests** — For pure functions, test that same inputs produce same outputs592. **Contract tests** — For APIs, verify request/response shape and status codes603. **Side-effect tests** — For stateful code, verify correct DB operations, events emitted614. **Error path tests** — Verify error handling behavior is preserved625. **Boundary tests** — Empty arrays, zero values, maximum lengths, unicode strings6364**Test structure:**65```66describe('[ModuleName] regression', () => {67 describe('preserved behavior', () => {68 // Tests that MUST pass identically before and after refactor69 });70 describe('edge cases', () => {71 // Tests for boundary conditions72 });73 describe('error handling', () => {74 // Tests for error paths75 });76});77```7879### Step 4: Verify Against Old Implementation80811. Stash or commit current changes822. Checkout the pre-refactor code: `git stash && git checkout main`833. Run the new regression tests against the OLD code — they should all pass844. Return to refactored code: `git checkout - && git stash pop`855. Run the regression tests again — they should still all pass866. If any test fails on the refactored code but passed on the old code → regression found8788### Step 5: Report8990```91Regression Test Report92═══════════════════════93Refactored: src/services/billing.ts (4 functions, 187 lines changed)9495Tests generated: 2496 Passed (old code): 24/24 ✓97 Passed (new code): 23/24 ✗9899❌ REGRESSION FOUND:100 test: "calculates prorated amount for mid-cycle upgrade"101 Expected: 14.52102 Received: 14.50103 Location: src/services/billing.ts:89 (rounding changed from Math.ceil to Math.round)104105✓ All other behavior preserved.106```107108## Examples109110### Example 1: Refactored Utility Functions111112**User prompt:**113```114I refactored our date utility module from moment.js to dayjs. Can you make sure nothing broke?115```116117**Agent actions:**118```bash119git diff main -- src/utils/dates.ts120```121122**Agent analysis:**123```124Refactoring scope: src/utils/dates.ts125 - Import changed: moment → dayjs126 - 8 exported functions, all signatures preserved127 - Internal parsing logic changed128129Existing test coverage: 3 tests covering 2 of 8 functions (25%)130131Generated 18 regression tests covering:132 ✓ formatDate() — 4 formats × 3 edge cases (null, invalid, timezone)133 ✓ diffInDays() — positive, negative, same day, DST boundary134 ✓ startOfWeek() — Sunday vs Monday locale, year boundary135 ✓ parseISO() — valid, invalid, with/without timezone offset136 ✓ isBusinessDay() — weekday, Saturday, Sunday, holiday handling137 ✓ addBusinessDays() — skip weekends, cross month boundary138139Results against old code (moment.js): 18/18 passed140Results against new code (dayjs): 17/18 passed141142❌ Regression: startOfWeek('2024-01-01') returns Sunday with dayjs143 but returned Monday with moment (locale-dependent).144 Fix: Add dayjs.extend(weekOfYear) and set locale explicitly.145```146147### Example 2: Extracted Service Layer148149**User prompt:**150```151I split our monolithic UserController into UserService + UserController. Did I break anything?152```153154**Agent output:**155```156Analyzed refactoring: 1 file → 2 files157 Old: src/controllers/UserController.ts (342 lines)158 New: src/controllers/UserController.ts (98 lines) + src/services/UserService.ts (267 lines)159160Public API surface: 6 endpoints unchanged (routes, params, response shapes)161Internal: Business logic extracted to UserService, controller delegates162163Generated 22 regression tests:164 POST /users — creation with valid data, duplicate email, missing fields165 GET /users/:id — existing user, non-existent (404), invalid ID format166 PUT /users/:id — partial update, full update, unauthorized (403)167 DELETE /users/:id — soft delete, already deleted, cascade check168 GET /users — pagination, filtering, sorting, empty result169170Results: 22/22 passed on both old and new code ✓171No regressions detected. Refactoring is safe.172```173174## Guidelines175176- Test behavior, not implementation — don't assert on internal method calls177- Run tests against BOTH old and new code to confirm equivalence178- Flag intentional behavior changes separately from regressions179- Focus test generation on the changed code, not the entire codebase180- Include edge cases that the original code may not have tested181- For database-touching code, use transactions that roll back after each test182- If the refactoring changes performance characteristics, add benchmark comparisons183- Keep regression tests permanent — they protect against future changes too