Validates that refactoring achieved its goals without introducing bugs or unintended behavior changes.
Validates refactoring results by running tests, comparing metrics, and checking for regressions. Use after refactoring to verify goals were met without introducing bugs or behavior changes.
/plugin marketplace add avovello/cc-plugins/plugin install refactor@cc-pluginsValidates that refactoring achieved its goals without introducing bugs or unintended behavior changes.
✅ DOES:
❌ DOES NOT:
Before/After Comparison:
npm test # All tests
npm run test:coverage # With coverage
npm run lint # Linting
npm run type-check # Type checking (TS)
## Before Refactoring
- Cyclomatic Complexity: 15
- Lines of Code: 87
- Test Coverage: 82%
- Duplicate Code: 15%
- Linter Warnings: 3
## After Refactoring
- Cyclomatic Complexity: 5 ✅ (67% improvement)
- Lines of Code: 47 ✅ (46% reduction)
- Test Coverage: 87% ✅ (6% improvement)
- Duplicate Code: 2% ✅ (87% reduction)
- Linter Warnings: 0 ✅ (fixed all)
## Validation: ✅ PASS
## Refactoring Goal
Reduce complexity of processOrder() from 15 to ≤ 5
## Result
- **Target**: Complexity ≤ 5
- **Achieved**: Complexity = 5
- **Status**: ✅ GOAL MET
## Additional Improvements
- Test coverage increased: 82% → 87%
- Code duplication reduced: 15% → 2%
- Linter warnings eliminated: 3 → 0
# Run behavior comparison tests
npm run test:regression
# Compare API responses
curl localhost:3000/api/test > after.json
diff before.json after.json # Should be identical
# Refactoring Validation Report
## Summary
**Status**: ✅ PASSED
**Date**: 2025-11-05
**Refactoring**: Reduce complexity in processOrder()
## Test Results
- **Total Tests**: 127
- **Passing**: 127 ✅
- **Failing**: 0
- **Skipped**: 0
- **Execution Time**: 4.2s (was 4.3s)
## Metric Improvements
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Complexity | 15 | 5 | ✅ -67% |
| Coverage | 82% | 87% | ✅ +6% |
| Duplication | 15% | 2% | ✅ -87% |
| Linter Warnings | 3 | 0 | ✅ -100% |
## Validation Checks
- ✅ All tests pass
- ✅ No behavior changes
- ✅ Goal achieved (complexity ≤ 5)
- ✅ Coverage maintained
- ✅ No new linter errors
## Recommendation
**APPROVED** - Refactoring successful, ready to commit.
## Validation: ❌ FAILED
**Issue**: 3 tests failing
**Failing Tests**:
1. processOrder_withDiscount_calculatesCorrectly
2. processOrder_withInvalidItem_throwsError
3. processOrder_savesOrderToDatabase
**Recommendation**:
- Review test failures
- Check if behavior intentionally changed
- If behavior should change: update tests
- If regression: revert refactoring
## Validation: ⚠️ WARNING
**Issue**: Code coverage decreased
**Coverage**:
- Before: 82%
- After: 74% ⚠️ (8% decrease)
**Recommendation**:
- Add tests for extracted functions
- Ensure all code paths covered
- Target: return to ≥82% coverage
## Validation: ❌ FAILED
**Goal**: Reduce complexity to ≤ 5
**Achieved**: Complexity = 7
**Recommendation**:
- Continue refactoring
- Apply additional simplifications
- Consider breaking function further
# ✅ Refactoring Validation: PASSED
**Date**: 2025-11-05 10:30:00
**Target**: src/services/OrderService.js
**Goal**: Reduce complexity from 15 to ≤ 5
## Test Validation ✅
- All 127 tests passing
- 0 failures, 0 skipped
- Execution time: 4.2s
## Goal Achievement ✅
- **Target Complexity**: ≤ 5
- **Achieved**: 5
- **Status**: GOAL MET
## Improvements ✅
| Metric | Before | After | Improvement |
|--------|--------|-------|-------------|
| Complexity | 15 | 5 | 67% ↓ |
| LOC (main) | 87 | 12 | 86% ↓ |
| Test Coverage | 82% | 87% | 6% ↑ |
| Duplication | 15% | 2% | 87% ↓ |
## Quality Checks ✅
- No behavior changes detected
- No API changes
- No new linter errors
- Code style consistent
- Documentation appropriate
## Recommendation
✅ **APPROVED** - Refactoring successful, ready to commit.
## Next Steps
1. Review generated commit message
2. Commit changes
3. Update technical debt tracking
4. Close related issues/tickets
Use this agent when analyzing conversation transcripts to find behaviors worth preventing with hooks. Examples: <example>Context: User is running /hookify command without arguments user: "/hookify" assistant: "I'll analyze the conversation to find behaviors you want to prevent" <commentary>The /hookify command without arguments triggers conversation analysis to find unwanted behaviors.</commentary></example><example>Context: User wants to create hooks from recent frustrations user: "Can you look back at this conversation and help me create hooks for the mistakes you made?" assistant: "I'll use the conversation-analyzer agent to identify the issues and suggest hooks." <commentary>User explicitly asks to analyze conversation for mistakes that should be prevented.</commentary></example>