Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions openspec/schemas/tdd/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: tdd-refactor
version: 1
description: Test-driven development for refactoring and fixes - proposal → design → tasks
artifacts:
- id: proposal
generates: proposal.md
description: Problem statement and change overview
template: proposal.md
instruction: |
Create a focused proposal for the refactoring or fix.

For bugs:
- **Why**: What's broken? Observed vs. expected behavior
- **Root Cause**: Technical reason for the bug (if known)
- **What Changes**: What will be fixed? Which files/components?
- **Impact**: Who/what is affected? Is this breaking?

For refactoring:
- **Why**: What problem does current code have? Tech debt, maintainability, performance?
- **What Changes**: What will be restructured? Be specific about scope
- **Impact**: Affected code, APIs, or behavior changes (should be minimal for pure refactoring)

Keep it concise (1 page max). This is about fixing or improving existing code,
not adding new features. If you're adding features, use spec-driven instead.
requires: []

- id: design
generates: design.md
description: Test plan defining what needs to pass
template: design.md
instruction: |
Define the test cases that will verify the fix or refactoring.

For bugs:
- Reproduction test (currently failing)
- Edge cases related to the bug
- Regression tests for related functionality

For refactoring:
- Existing behavior preservation tests
- Tests for improved cases (if applicable)
- Performance/maintainability verification (if relevant)

Format:
```
## Test Cases

### Category Name

- Test name - Description (unit/integration/e2e)
- **Given**: Setup/preconditions
- **When**: Action/trigger
- **Then**: Expected outcome
```

Write tests that will FAIL initially (for bugs) or verify existing behavior (for refactoring).
Tests define the contract - implementation must make them pass without breaking anything.
requires:
- proposal

- id: tasks
generates: tasks.md
description: Implementation task breakdown
template: tasks.md
instruction: |
Break down the implementation into trackable TDD tasks.

**IMPORTANT: Follow the template below exactly.** Use checkbox format: `- [ ] X.Y Description`

Group tasks by phase:

## 1. Test Setup
- [ ] 1.1 Write failing test for main issue
- [ ] 1.2 Add edge case tests

## 2. Implementation
- [ ] 2.1 Fix core issue (make main test pass)
- [ ] 2.2 Handle edge cases (make edge tests pass)

## 3. Refactoring
- [ ] 3.1 Clean up implementation while keeping tests green
- [ ] 3.2 Extract common logic/improve structure

## 4. Verification
- [ ] 4.1 All tests passing
- [ ] 4.2 No regressions (run full test suite)

Order tasks by TDD cycle: Red (failing test) → Green (make it pass) → Refactor (clean up).
Each task should be completable in one session.
requires:
- design

apply:
requires: [design, tasks]
tracks: tasks.md
instruction: |
Follow TDD workflow:
1. Review proposal.md - understand what's broken or needs refactoring
2. Review design.md - understand what tests need to pass
3. Work through tasks.md in order:
- Write failing tests first (Red)
- Implement minimal fix to pass tests (Green)
- Refactor while keeping tests green
4. Mark task checkboxes as you complete them

All tests must pass before marking complete. Pause if blocked or need clarification.
28 changes: 28 additions & 0 deletions openspec/schemas/tdd/templates/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Test Cases

<!-- For bugs: start with reproduction test. For refactoring: verify existing behavior preserved. -->

### Reproduction Tests

- Test name - Description (unit/integration/e2e)
- **Given**: Setup/preconditions
- **When**: Action/trigger
- **Then**: Expected outcome

### Edge Cases

- Test name - Description (unit/integration/e2e)
- **Given**: Setup/preconditions
- **When**: Action/trigger
- **Then**: Expected outcome

### Regression Tests

- Test name - Description (unit/integration/e2e)
- **Given**: Setup/preconditions
- **When**: Action/trigger
- **Then**: Expected outcome

## Notes

<!-- Track unexpected behaviors, additional edge cases found, test failures and resolutions. -->
15 changes: 15 additions & 0 deletions openspec/schemas/tdd/templates/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Why

<!-- For bugs: observed vs expected behavior. For refactoring: tech debt or maintainability issue. -->

## Root Cause

<!-- Technical reason for the bug or what makes current code problematic. -->

## What Changes

<!-- Which files/components affected? Mark breaking changes with **BREAKING**. -->

## Impact

<!-- Affected code, APIs, users. Breaking changes? Migration needed? -->
33 changes: 33 additions & 0 deletions openspec/schemas/tdd/templates/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## 1. Test Setup

<!-- RED: Write failing tests first -->

- [ ] 1.1 Write failing test for main issue
- [ ] 1.2 Add edge case tests
- [ ] 1.3 Add regression tests for related functionality

## 2. Implementation

<!-- GREEN: Make tests pass with minimal code -->

- [ ] 2.1 Fix core issue (make main test pass)
- [ ] 2.2 Handle edge cases (make edge tests pass)
- [ ] 2.3 Verify no regressions

## 3. Refactoring

<!-- REFACTOR: Clean up while keeping tests green -->

- [ ] 3.1 Clean up implementation
- [ ] 3.2 Extract common logic/improve structure
- [ ] 3.3 Remove duplication

## 4. Verification

- [ ] 4.1 All tests passing (including new tests)
- [ ] 4.2 Full test suite passes (no regressions)
- [ ] 4.3 Code review ready (clean, documented)

## Notes

<!-- Track test failures, refactoring decisions, blockers. -->
Loading