|
1 | | -name: tdd |
| 1 | +name: tdd-refactor |
2 | 2 | version: 1 |
3 | | -description: Test-driven development workflow - proposal → tests → implementation → docs |
| 3 | +description: Test-driven development for refactoring and fixes - proposal → design → tasks |
4 | 4 | artifacts: |
5 | 5 | - id: proposal |
6 | 6 | generates: proposal.md |
7 | | - description: Initial proposal outlining the bug or feature |
| 7 | + description: Problem statement and change overview |
8 | 8 | template: proposal.md |
9 | 9 | instruction: | |
10 | | - Create the proposal document that establishes WHY this change is needed. |
| 10 | + Create a focused proposal for the refactoring or fix. |
11 | 11 |
|
12 | | - For bugs, focus on: |
13 | | - - **Why**: What's broken? What's the observed vs. expected behavior? |
14 | | - - **What Changes**: What will be fixed? Be specific about behavior changes. |
15 | | - - **Impact**: Affected code, APIs, users, or systems. |
16 | | - - **Root Cause** (if known): Technical reason for the bug. |
| 12 | + For bugs: |
| 13 | + - **Why**: What's broken? Observed vs. expected behavior |
| 14 | + - **Root Cause**: Technical reason for the bug (if known) |
| 15 | + - **What Changes**: What will be fixed? Which files/components? |
| 16 | + - **Impact**: Who/what is affected? Is this breaking? |
17 | 17 |
|
18 | | - For features, focus on: |
19 | | - - **Why**: What problem does this solve? Why now? |
20 | | - - **What Changes**: What new capability will exist? |
21 | | - - **Impact**: Affected code, APIs, dependencies, or systems. |
| 18 | + For refactoring: |
| 19 | + - **Why**: What problem does current code have? Tech debt, maintainability, performance? |
| 20 | + - **What Changes**: What will be restructured? Be specific about scope |
| 21 | + - **Impact**: Affected code, APIs, or behavior changes (should be minimal for pure refactoring) |
22 | 22 |
|
23 | | - Keep it concise (1 page max). This is test-first, so focus on |
24 | | - observable behavior that tests will verify. |
| 23 | + Keep it concise (1 page max). This is about fixing or improving existing code, |
| 24 | + not adding new features. If you're adding features, use spec-driven instead. |
25 | 25 | requires: [] |
26 | 26 |
|
27 | | - - id: tests |
28 | | - generates: tests.md |
29 | | - description: Test specifications written before implementation |
30 | | - template: tests.md |
| 27 | + - id: design |
| 28 | + generates: design.md |
| 29 | + description: Test plan defining what needs to pass |
| 30 | + template: design.md |
31 | 31 | instruction: | |
32 | | - Define the tests that will verify the fix or feature BEFORE implementing. |
33 | | -
|
34 | | - Structure: |
35 | | - - **Test Cases**: List each test case with: |
36 | | - - Name/Description |
37 | | - - Setup/Given conditions |
38 | | - - Action/When trigger |
39 | | - - Expected/Then outcome |
40 | | - - Test type (unit/integration/e2e) |
41 | | - - Status (pending/failing/passing) |
42 | | -
|
43 | | - Write tests at appropriate levels: |
44 | | - - Unit tests for isolated logic |
45 | | - - Integration tests for component interactions |
46 | | - - E2E tests for user-facing behavior |
47 | | -
|
48 | | - Each test should be implementable and should FAIL initially. |
49 | | - Tests define the contract - implementation must make them pass. |
50 | | -
|
51 | | - Use checkboxes to track test status: |
52 | | - - [ ] Test name - pending (not written yet) |
53 | | - - [x] Test name - written and status noted |
| 32 | + Define the test cases that will verify the fix or refactoring. |
| 33 | +
|
| 34 | + For bugs: |
| 35 | + - Reproduction test (currently failing) |
| 36 | + - Edge cases related to the bug |
| 37 | + - Regression tests for related functionality |
| 38 | +
|
| 39 | + For refactoring: |
| 40 | + - Existing behavior preservation tests |
| 41 | + - Tests for improved cases (if applicable) |
| 42 | + - Performance/maintainability verification (if relevant) |
| 43 | +
|
| 44 | + Format: |
| 45 | + ``` |
| 46 | + ## Test Cases |
| 47 | +
|
| 48 | + ### Category Name |
| 49 | +
|
| 50 | + - Test name - Description (unit/integration/e2e) |
| 51 | + - **Given**: Setup/preconditions |
| 52 | + - **When**: Action/trigger |
| 53 | + - **Then**: Expected outcome |
| 54 | + ``` |
| 55 | +
|
| 56 | + Write tests that will FAIL initially (for bugs) or verify existing behavior (for refactoring). |
| 57 | + Tests define the contract - implementation must make them pass without breaking anything. |
54 | 58 | requires: |
55 | 59 | - proposal |
56 | 60 |
|
57 | | - - id: implementation |
58 | | - generates: implementation.md |
59 | | - description: Implementation plan and code changes |
60 | | - template: implementation.md |
| 61 | + - id: tasks |
| 62 | + generates: tasks.md |
| 63 | + description: Implementation task breakdown |
| 64 | + template: tasks.md |
61 | 65 | instruction: | |
62 | | - Document the implementation approach and track code changes. |
63 | | -
|
64 | | - Sections: |
65 | | - - **Approach**: High-level technical strategy |
66 | | - - **Changes**: File-by-file breakdown of modifications |
67 | | - - **Decisions**: Key technical choices and rationale |
68 | | - - **Test Status**: Track which tests pass/fail as you implement |
69 | | -
|
70 | | - Implementation follows TDD cycle: |
71 | | - 1. Write failing test |
72 | | - 2. Write minimal code to pass |
73 | | - 3. Refactor while keeping tests green |
74 | | - 4. Repeat |
75 | | -
|
76 | | - Implementation is DONE when all tests pass. |
77 | | - Do not add features beyond what tests require. |
78 | | - requires: |
79 | | - - tests |
| 66 | + Break down the implementation into trackable TDD tasks. |
80 | 67 |
|
81 | | - - id: docs |
82 | | - generates: docs.md |
83 | | - description: Documentation updates for the change |
84 | | - template: docs.md |
85 | | - instruction: | |
86 | | - Update relevant documentation after implementation is complete. |
| 68 | + **IMPORTANT: Follow the template below exactly.** Use checkbox format: `- [ ] X.Y Description` |
| 69 | +
|
| 70 | + Group tasks by phase: |
| 71 | +
|
| 72 | + ## 1. Test Setup |
| 73 | + - [ ] 1.1 Write failing test for main issue |
| 74 | + - [ ] 1.2 Add edge case tests |
| 75 | +
|
| 76 | + ## 2. Implementation |
| 77 | + - [ ] 2.1 Fix core issue (make main test pass) |
| 78 | + - [ ] 2.2 Handle edge cases (make edge tests pass) |
| 79 | +
|
| 80 | + ## 3. Refactoring |
| 81 | + - [ ] 3.1 Clean up implementation while keeping tests green |
| 82 | + - [ ] 3.2 Extract common logic/improve structure |
87 | 83 |
|
88 | | - Include: |
89 | | - - **API Changes**: Updated signatures, parameters, return values |
90 | | - - **Behavior Changes**: How user-facing behavior differs |
91 | | - - **Migration**: If breaking, how to migrate existing code |
92 | | - - **Examples**: Updated code examples reflecting new behavior |
| 84 | + ## 4. Verification |
| 85 | + - [ ] 4.1 All tests passing |
| 86 | + - [ ] 4.2 No regressions (run full test suite) |
93 | 87 |
|
94 | | - Only document what changed - don't rewrite existing docs. |
95 | | - Mark as "No documentation changes" if none are needed. |
| 88 | + Order tasks by TDD cycle: Red (failing test) → Green (make it pass) → Refactor (clean up). |
| 89 | + Each task should be completable in one session. |
96 | 90 | requires: |
97 | | - - implementation |
| 91 | + - design |
98 | 92 |
|
99 | 93 | apply: |
100 | | - requires: [tests, implementation] |
101 | | - tracks: tests.md |
| 94 | + requires: [design, tasks] |
| 95 | + tracks: tasks.md |
102 | 96 | instruction: | |
103 | 97 | Follow TDD workflow: |
104 | | - 1. Review implementation.md to understand the technical approach and strategy |
105 | | - 2. Review tests.md to understand what needs to pass |
106 | | - 3. Write failing tests first (mark status in tests.md) |
107 | | - 4. Implement minimal code to make tests pass (following approach from implementation.md) |
108 | | - 5. Refactor while keeping tests green |
109 | | - 6. Update test status as tests pass |
110 | | -
|
111 | | - Mark test checkboxes as complete when tests are written and passing. |
112 | | - Pause if blocked or need clarification. |
| 98 | + 1. Review proposal.md - understand what's broken or needs refactoring |
| 99 | + 2. Review design.md - understand what tests need to pass |
| 100 | + 3. Work through tasks.md in order: |
| 101 | + - Write failing tests first (Red) |
| 102 | + - Implement minimal fix to pass tests (Green) |
| 103 | + - Refactor while keeping tests green |
| 104 | + 4. Mark task checkboxes as you complete them |
| 105 | +
|
| 106 | + All tests must pass before marking complete. Pause if blocked or need clarification. |
0 commit comments