Skip to content

Commit c6049df

Browse files
iobuhovclaude
andcommitted
feat(openspec): add TDD schema for refactoring and fixes
- TDD workflow: proposal → tests → tasks - Focused on bugs and refactoring (not new features) - Red-Green-Refactor cycle built into task structure - Tests define contract, implementation makes them pass - Removed implementation.md and docs.md (not needed for fixes) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent ab34698 commit c6049df

7 files changed

Lines changed: 198 additions & 243 deletions

File tree

openspec/schemas/tdd/schema.yaml

Lines changed: 82 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,106 @@
1-
name: tdd
1+
name: tdd-refactor
22
version: 1
3-
description: Test-driven development workflow - proposal → testsimplementation → docs
3+
description: Test-driven development for refactoring and fixes - proposal → designtasks
44
artifacts:
55
- id: proposal
66
generates: proposal.md
7-
description: Initial proposal outlining the bug or feature
7+
description: Problem statement and change overview
88
template: proposal.md
99
instruction: |
10-
Create the proposal document that establishes WHY this change is needed.
10+
Create a focused proposal for the refactoring or fix.
1111
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?
1717
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)
2222
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.
2525
requires: []
2626

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
3131
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.
5458
requires:
5559
- proposal
5660

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
6165
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.
8067
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
8783
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)
9387
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.
9690
requires:
97-
- implementation
91+
- design
9892

9993
apply:
100-
requires: [tests, implementation]
101-
tracks: tests.md
94+
requires: [design, tasks]
95+
tracks: tasks.md
10296
instruction: |
10397
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.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Test Cases
2+
3+
<!--
4+
Define test cases that will verify the fix or refactoring.
5+
6+
For bugs: Start with a reproduction test (currently failing), then edge cases.
7+
For refactoring: Tests should verify existing behavior is preserved.
8+
-->
9+
10+
### Reproduction Tests
11+
12+
<!--
13+
For bugs: Tests that reproduce the issue (will fail initially)
14+
-->
15+
16+
- Test name - Description (unit/integration/e2e)
17+
- **Given**: Setup/preconditions
18+
- **When**: Action/trigger
19+
- **Then**: Expected outcome
20+
21+
### Edge Cases
22+
23+
<!--
24+
Related edge cases that should also be tested
25+
-->
26+
27+
- Test name - Description (unit/integration/e2e)
28+
- **Given**: Setup/preconditions
29+
- **When**: Action/trigger
30+
- **Then**: Expected outcome
31+
32+
### Regression Tests
33+
34+
<!--
35+
Tests to ensure related functionality isn't broken
36+
-->
37+
38+
- Test name - Description (unit/integration/e2e)
39+
- **Given**: Setup/preconditions
40+
- **When**: Action/trigger
41+
- **Then**: Expected outcome
42+
43+
## Notes
44+
45+
<!--
46+
Track observations during testing:
47+
- Unexpected behaviors discovered
48+
- Additional edge cases found
49+
- Test failures and resolutions
50+
-->

openspec/schemas/tdd/templates/docs.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

openspec/schemas/tdd/templates/implementation.md

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)