Generate and run regression tests after code refactoring to verify behavior is preserved. Use when someone has refactored code and needs to confirm nothing broke — especially when existing test coverage is insufficient. Trigger words: regression test, refactor validation, behavior preservation, before/after test, did I break anything, refactoring safety net, snapshot test.
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.
Get the diff: git diff main...HEAD or compare specific commits
Categorize changes:
Identify the behavior contract for each changed unit:
npm test / pytest / go test ./...npx jest --coverage --collectCoverageFrom='src/refactored-module/**'
Create tests that verify behavior, not implementation:
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
});
});
git stash && git checkout maingit checkout - && git stash popRegression 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.
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.
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.
npx skills add TerminalSkills/regression-tester下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer