Safe Refactoring
Perform a refactoring with test safety net.
What This Skill Does
Guides a safe refactoring process:
- •Ensures tests exist and pass before changes
- •Performs the refactoring in small, verified steps
- •Verifies tests still pass after each step
Process
Pre-Refactor
- •Identify the code to refactor
- •Run existing tests: verify they pass
- •If no tests exist: write characterization tests first
- •Record the refactoring decision:
cwa memory add "<what and why>" --type decision
During Refactor
- •Make one small change at a time
- •Run tests after each change
- •If tests fail: revert the last change
- •Commit after each successful step
Post-Refactor
- •Run full test suite
- •Check for any new warnings
- •Update documentation if APIs changed
- •Move task to review:
cwa task move <id> review
Rules
- •Never refactor and add features simultaneously
- •Keep commits atomic (one logical change each)
- •If tests don't exist, write them first (separate commit)
- •Preserve all existing behavior unless explicitly changing it