spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

Add TDD Extension: Strict RED→GREEN→REFACTOR Vertical Slicing

Open kanfil opened this issue 9 months ago β€’ 2 comments

Summary

Add a built-in TDD extension that enhances the existing --tdd flag with strict RED→GREEN→REFACTOR vertical slicing methodology.

References:

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.yml manifest
  • [ ] 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.json with TDD extension entry
  • [ ] Update /spec.specify to auto-call spec.tdd.setup when --tdd
  • [ ] Update /spec.tasks to use spec.tdd.plan when TDD enabled
  • [ ] Update /spec.implement to use spec.tdd.workflow when 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 avatar Feb 27 '26 14:02 kanfil

@kanfil Can you please make sure you or your automation do not open issues in the wrong repository? Thanks!

mnriem avatar Feb 27 '26 15:02 mnriem

Sure, sorry about that

kanfil avatar Feb 28 '26 11:02 kanfil