refactor-verify
Before/after verification for refactoring - ensures nothing breaks
When & Why to Use This Skill
The refactor-verify skill is a specialized developer tool designed to automate the verification process during code refactoring. It ensures software stability by capturing a comprehensive baseline of test results, code metrics, and cyclomatic complexity before changes are made, then performing a rigorous comparison after refactoring to prevent regressions and maintain high code quality standards.
Use Cases
- Legacy Code Modernization: Safely refactoring outdated codebases by ensuring existing functionality remains intact through automated before-and-after test comparisons.
- Code Complexity Reduction: Verifying that efforts to simplify complex functions actually reduce complexity scores without introducing new bugs or dead code.
- Architectural Restructuring: Validating large-scale changes, such as splitting monolithic files into smaller modules, by tracking line counts and test pass rates across the project.
- Automated Quality Gate: Integrating into the development workflow to automatically fail refactoring tasks if previously passing tests fail or if the refactor inadvertently increases technical debt.
| name | refactor-verify |
|---|---|
| description | Before/after verification for refactoring - ensures nothing breaks |
refactor-verify
Overview
Mandatory verification skill for any refactoring task. Captures state before refactor, then verifies nothing broke after.
⚠️ CRITICAL: Must Use Before Any Refactor
# BEFORE refactoring - capture baseline
refactor-verify before /path/to/project
# DO YOUR REFACTORING WORK
# AFTER refactoring - verify nothing broke
refactor-verify after /path/to/project
What It Checks
Before Phase
- Runs all tests → saves pass/fail count
- Runs code-analyze metrics → saves file/line counts
- Runs code-analyze complexity → saves complexity scores
- Captures git status
- Saves snapshot to
.refactor-baseline.json
After Phase
- Runs all tests → compares to baseline
- Runs code-analyze metrics → compares
- Runs code-analyze complexity → compares
- Generates diff report
- FAILS if:
- Any test that passed before now fails
- Complexity increased significantly
- Dead code introduced
Usage
# Step 1: Before refactoring
cd /home/alex/kapu-ti
refactor-verify before backend/src/services
# Step 2: Do your refactoring work
# ... edit files ...
# Step 3: Verify after refactoring
refactor-verify after backend/src/services
# Optional: View baseline
refactor-verify status
# Optional: Clear baseline (start fresh)
refactor-verify reset
Commands
| Command | Description |
|---|---|
before <path> |
Capture baseline before refactoring |
after <path> |
Verify after refactoring, compare to baseline |
status |
Show current baseline state |
reset |
Clear baseline, start fresh |
Output Example
📊 REFACTOR VERIFICATION REPORT
================================
Tests:
Before: 47 passed, 0 failed
After: 47 passed, 0 failed
✅ All tests still passing
Metrics:
Before: 1,473 lines in 1 file
After: 1,512 lines in 5 files
✅ Lines increased slightly (acceptable for splitting)
Complexity:
Before: Max 45, Avg 12
After: Max 18, Avg 8
✅ Complexity reduced!
Overall: ✅ REFACTOR VERIFIED
Integration with cc Workflow
cc MUST run this skill for ANY refactoring task:
- Read task file
- Search AI Kitchen RAG for patterns
- Run
refactor-verify before - Do refactoring work
- Run
refactor-verify after - Only complete task if verification passes
Files
scripts/refactor-verify.sh- Main verification script.refactor-baseline.json- Stored in project root during refactor
Dependencies
- code-analyze skill (for metrics)
- pnpm test (for test execution)
- git (for status tracking)