refactor-verify

alexanderjamesmcleod's avatarfrom alexanderjamesmcleod

Before/after verification for refactoring - ensures nothing breaks

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 8, 2026⬇️2downloads

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.
namerefactor-verify
descriptionBefore/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

  1. Runs all tests → saves pass/fail count
  2. Runs code-analyze metrics → saves file/line counts
  3. Runs code-analyze complexity → saves complexity scores
  4. Captures git status
  5. Saves snapshot to .refactor-baseline.json

After Phase

  1. Runs all tests → compares to baseline
  2. Runs code-analyze metrics → compares
  3. Runs code-analyze complexity → compares
  4. Generates diff report
  5. 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:

  1. Read task file
  2. Search AI Kitchen RAG for patterns
  3. Run refactor-verify before
  4. Do refactoring work
  5. Run refactor-verify after
  6. 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)