REFACTOR phase - Improve code design while keeping tests green
Refactors code to improve design while keeping all tests passing and meeting quality thresholds.
/plugin marketplace add DoubleslashSE/claude-workflows/plugin install doubleslashse-dotnet-tdd-plugins-dotnet-tdd@DoubleslashSE/claude-workflowsImprove the code design for: $ARGUMENTS
Identify Improvements
Apply Refactorings
Verify Quality
| Refactoring | When to Apply |
|---|---|
| Extract Method | Long methods, repeated code |
| Rename | Unclear naming |
| Extract Interface | Concrete dependencies |
| Replace Conditional | Switch statements |
| Extract Class | Mixed responsibilities |
# Run tests
dotnet test
# Format code
dotnet format
# Check coverage
dotnet test /p:CollectCoverage=true
┌─────────────────────────────────────────────────────────────────┐
│ REFACTOR PHASE WITH QUALITY GATE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Identify │───▶│ Apply │───▶│ Run │ │
│ │ Smells │ │ Refactor │ │ Tests │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │ │
│ ▼ │
│ Tests Pass? │
│ │ │ │
│ NO YES │
│ │ │ │
│ ┌──────┘ ▼ │
│ │ ┌──────────┐ │
│ Revert & │ Review │ │
│ Retry │(/review) │ │
│ └──────────┘ │
│ │ │
│ ▼ │
│ Score >= 90%? │
│ │ │ │
│ NO YES │
│ │ │ │
│ ▼ ▼ │
│ Process COMPLETE │
│ Feedback │
│ │ │
│ └────────▶ Apply More ────┐ │
│ Refactorings │ │
│ │ │ │
│ └────────┘ │
└─────────────────────────────────────────────────────────────────┘
| Category | Target | Weight |
|---|---|---|
| SOLID Compliance | 90% | 30% |
| Clean Code (DRY/KISS/YAGNI) | 90% | 25% |
| Test Quality | 90% | 25% |
| CQS Compliance | 95% | 20% |
| Score | Status | Action |
|---|---|---|
| 90-100% | PASS | Refactoring complete |
| 75-89% | CONDITIONAL | User decides to continue or accept |
| Below 75% | FAIL | Must continue refactoring |
# Run tests first
dotnet test
# Apply refactoring
# (make code changes)
# Verify tests still pass
dotnet test
# Run code review to get quality scores
/dotnet-tdd:review {path}
When review feedback is received:
## Feedback Processing
### Review Scores Received
| Category | Score | Status |
|----------|-------|--------|
| SOLID | {X}% | {PASS/FAIL} |
| Clean Code | {X}% | {PASS/FAIL} |
| Test Quality | {X}% | {PASS/FAIL} |
| CQS | {X}% | {PASS/FAIL} |
### Issues to Address
| Issue ID | Principle | File:Line | Required Fix |
|----------|-----------|-----------|--------------|
| FIX-001 | {Principle} | {Location} | {Change} |
### Applying Fixes
For each issue:
1. Read the feedback carefully
2. Apply the suggested refactoring
3. Run tests: `dotnet test`
4. Mark issue as resolved
After applying fixes, request another review:
/dotnet-tdd:review {path}
Continue the cycle until:
Track refactoring progress across iterations:
## Refactoring Progress
### Iteration History
| Cycle | SOLID | Clean | Tests | CQS | Overall | Status |
|-------|-------|-------|-------|-----|---------|--------|
| 1 | 60% | 70% | 75% | 80% | 68% | FAIL |
| 2 | 80% | 85% | 85% | 90% | 84% | CONDITIONAL |
| 3 | 95% | 92% | 95% | 100% | 94% | PASS |
### Refactorings Applied
- Cycle 1→2: Extracted 2 interfaces, removed duplication
- Cycle 2→3: Split god class, improved test naming
### Final Test Results
```bash
dotnet test
# All tests pass
## Output Required
Provide:
1. Identified code smells/violations
2. Refactorings applied (before/after)
3. Test results showing GREEN
4. Quality gate status with scores
5. Summary of improvements
### Complete Output Format
```markdown
## REFACTOR Phase Complete
### Code Smells Identified
- {Smell 1}: {Location}
- {Smell 2}: {Location}
### Refactorings Applied
#### Refactoring 1: {Type}
**Before** ({file}:{line}):
```csharp
{original code}
After:
{refactored code}
dotnet test
# {X} tests passed, 0 failed
| Category | Score | Status |
|---|---|---|
| SOLID | {X}% | ✅ |
| Clean Code | {X}% | ✅ |
| Test Quality | {X}% | ✅ |
| CQS | {X}% | ✅ |
| Overall | {X}% | ✅ PASS |