Run automated TDD cycle: test → fix → refactor.
Note: Configure project-specific test/build commands in
or
for automatic detection.
-
Detect test command (if not already configured):
- Check for (Node.js)
- Check for or (Python)
- Check for (Rust)
- Check for (Go)
- Check for test target
- If not found, ask user how to run tests
-
Run test suite:
bash
# Run detected test command
[test_command]
-
Analyze results:
If tests FAIL:
- Parse failure output
- Identify failing tests:
- Which tests failed?
- What assertions failed?
- What was expected vs actual?
- Identify root cause:
- Bug in implementation?
- Missing implementation?
- Incorrect test?
- Make minimal fix:
- Fix only what's needed to pass the failing test
- Don't add extra functionality
- Don't fix tests (fix code instead)
- Re-run tests to confirm fix
- Loop back to step 2
If tests PASS:
- Check for refactoring opportunities:
- Code duplication?
- Unclear naming?
- Long functions?
- Complex logic that can be simplified?
- Magic numbers/strings to extract?
- If refactoring identified:
- Refactor while keeping tests green
- Re-run tests after each refactoring
- Ensure tests still pass
- If no refactoring needed:
-
Repeat until:
- All tests pass AND
- No obvious refactoring opportunities
OR stop if:
- User intervention needed
- Blocked by external dependency
- Unclear how to fix failure
-
Report results:
🧪 Test Loop Results:
Cycles: [N] iterations
Fixes Applied:
- [Fix 1]: [Brief description]
- [Fix 2]: [Brief description]
Refactorings Performed:
- [Refactor 1]: [Brief description]
- [Refactor 2]: [Brief description]
Current Status:
✅ All tests pass
✅ Code refactored
📝 Ready for commit
OR
⚠️ Blocked: [Reason]
📝 Next steps: [Recommendation]