spec-kit
spec-kit copied to clipboard
Add TDD Extension: Strict REDβGREENβREFACTOR Vertical Slicing
Summary
Add a built-in TDD extension that enhances the existing --tdd flag with strict REDβGREENβREFACTOR vertical slicing methodology.
References:
- AI Hero - TDD Skill for Claude Code by Matt Pocock
- mfranzon/tdd - TDD skill implementation (126 stars)
Problem
Current --tdd flag provides "tests before code" but NOT in strict vertical slices:
Current --tdd |
Desired Behavior |
|---|---|
| Tests before code (bulk) | ONE test β ONE impl β repeat |
| Horizontal (all tests β all code) | Vertical slices |
| Generic test tasks | Increment-based from patterns |
| No quality gate | Review validates test patterns |
Solution
Create extensions/tdd/ with four commands that integrate with existing spec.* workflow:
| Command | Purpose | Called By |
|---|---|---|
spec.tdd.setup |
Detect language/test framework | /spec.specify --tdd (auto) |
spec.tdd.plan |
Decompose feature into increments | /spec.tasks (TDD mode) |
spec.tdd.workflow |
Execute REDβGREENβREFACTOR cycle | /spec.implement (TDD mode) |
spec.tdd.review |
Validate test quality | Hook after /spec.implement |
Extension Structure
extensions/tdd/
βββ extension.yml
βββ README.md
βββ CHANGELOG.md
βββ LICENSE
βββ commands/
β βββ setup.md # spec.tdd.setup
β βββ plan.md # spec.tdd.plan
β βββ workflow.md # spec.tdd.workflow
β βββ review.md # spec.tdd.review
βββ scripts/bash/
β βββ detect-language.sh
β βββ decompose-feature.sh
β βββ validate-test-quality.sh
βββ references/
βββ language-configs.md
βββ increments.md
βββ test-quality.md
Integration Flow
/spec.specify --tdd "Add JWT auth"
β
βΌ
βββββββββββββββββ
β spec.tdd.setupβ β Auto-detect Python/pytest
βββββββββ¬ββββββββ
β
βΌ
/spec.tasks
β
βΌ
βββββββββββββββββ
β spec.tdd.plan β β Generate increment-based tasks
βββββββββ¬ββββββββ
β
βΌ
/spec.implement
β
βΌ
ββββββββββββββββββββββ
β spec.tdd.workflow β β For each increment:
β RED β GREEN β β 1. Write ONE failing test
β REFACTOR β 2. Pause for review
ββββββββββ¬ββββββββββββ 3. Minimal code to pass
β 4. Refactor
βΌ 5. Repeat
ββββββββββββββββββ
βspec.tdd.review β β Optional hook
ββββββββββββββββββ
Key Features
Language Detection (spec.tdd.setup)
- Auto-detect from:
pyproject.toml,package.json,go.mod,Cargo.toml - Supported: Python/pytest, TypeScript/vitest, Go/testing
- Output stored in feature config
Increment Decomposition (spec.tdd.plan)
Strategy: Degenerate β Happy path β Variations β Edge cases β Errors
Patterns:
- CRUD: Create valid β Create invalid β Read exists β Read not-found β Update β Delete
- Data Transform: Empty β Single β Multiple β Quoted β Missing β Malformed
- State Machine: Initial state β Valid transition β Invalid transition β Terminal state
- Calculation: Zero/base β Single input β Known example β Boundary β Overflow
- Integration: Success β Connection error β Timeout β Non-200 β Malformed response
TDD Workflow (spec.tdd.workflow)
- RED: Write ONE failing test to real test file, run, confirm failure, pause for review
- GREEN: Write minimal code to pass, run full suite, continue if green
- REFACTOR: Apply improvements, run full suite, continue if green
- Writes directly to real files (git for undo)
Test Quality Review (spec.tdd.review)
| Good Tests | Bad Tests |
|---|---|
| Exercise real code through public interfaces | Mock internal collaborators |
| Describe WHAT the system does | Test HOW it's implemented |
| Survive internal refactors unchanged | Break on refactoring |
| Read like specifications | Test data structure shapes |
Implementation Tasks
Phase 1: Extension Structure
- [ ] Create
extensions/tdd/directory - [ ] Create
extension.ymlmanifest - [ ] Create
README.md,CHANGELOG.md,LICENSE
Phase 2: Commands
- [ ] Create
commands/setup.md - [ ] Create
commands/plan.md - [ ] Create
commands/workflow.md - [ ] Create
commands/review.md
Phase 3: Scripts (following generate-risk-tests.sh pattern)
- [ ] Create
scripts/bash/detect-language.sh - [ ] Create
scripts/bash/decompose-feature.sh - [ ] Create
scripts/bash/validate-test-quality.sh
Phase 4: References
- [ ] Create
references/language-configs.md - [ ] Create
references/increments.md - [ ] Create
references/test-quality.md
Phase 5: Integration
- [ ] Update
catalog.jsonwith TDD extension entry - [ ] Update
/spec.specifyto auto-callspec.tdd.setupwhen--tdd - [ ] Update
/spec.tasksto usespec.tdd.planwhen TDD enabled - [ ] Update
/spec.implementto usespec.tdd.workflowwhen TDD enabled
Decisions
| Decision | Answer |
|---|---|
| Command prefix | spec.tdd.* (aligns with core commands) |
| Catalog entry | Yes, add to built-in catalog.json |
| Auto-enable | Yes, spec.tdd.setup runs automatically on --tdd |
| Scope | Per-feature (set via /spec.specify --tdd) |
Labels
enhancement, extension, testing
@kanfil Can you please make sure you or your automation do not open issues in the wrong repository? Thanks!
Sure, sorry about that