Overview
Agent Teams Lite v2.0 introduces full TDD (Test-Driven Development) support in thesdd-apply sub-agent. When enabled, the implementer follows a strict RED-GREEN-REFACTOR cycle for every task.
TDD mode ensures tests are written first, driving implementation from acceptance criteria defined in specs. This prevents untested code and validates that tests actually catch failures.
The RED-GREEN-REFACTOR Cycle
Every task follows this cycle when TDD is enabled:Enabling TDD Mode
Detection Priority
Thesdd-apply sub-agent detects TDD mode from (in priority order):
openspec/config.yaml→rules.apply.tdd(true/false — highest priority)- User’s installed skills — e.g.,
tdd/SKILL.mdexists - Existing test patterns — test files alongside source in codebase
- Default — standard mode (write code first, then verify)
Configuration
Method 1: OpenSpec Config (Recommended)
Method 2: Orchestrator Config
Pass TDD mode when launching the implementer:Test Command Detection
Iftest_command is not explicitly configured, the system detects it from:
The RED Phase: Writing Failing Tests
Purpose
Writing a failing test first ensures:- The test actually validates the behavior
- You understand the requirements before coding
- The test catches real failures (not false positives)
Example: RED Phase
Task: 1.1 Add CSV export endpoint Spec Scenario:The GREEN Phase: Minimal Implementation
Purpose
Write only the code needed to make the failing test pass. No extra features, no premature optimization.The goal is to get to passing tests as quickly as possible. You’ll improve the code in the REFACTOR phase.
Example: GREEN Phase
Implementation:The REFACTOR Phase: Clean Up
Purpose
Improve code quality without changing behavior. Tests must still pass after refactoring.Refactoring Opportunities
Refactoring Opportunities
- Extract helper functions
- Remove duplication
- Improve naming
- Match project patterns
- Add documentation
- Simplify logic
Example: REFACTOR Phase
Improvements:Implementation Progress Report
When TDD mode is active, the implementer returns a detailed test execution report:Test Pattern Detection
The implementer detects and follows project-specific test patterns:Detecting Test Frameworks
Framework Detection Logic
Framework Detection Logic
JavaScript/TypeScript:
package.json→jest,vitest,mocha,ava- Check for
*.test.js,*.spec.jsfiles - Look for test config files:
jest.config.js,vitest.config.ts
pyproject.toml,pytest.ini,setup.py→pytest,unittest- Check for
test_*.py,*_test.pyfiles - Look for
conftest.py(pytest)
- Check for
*_test.gofiles - Standard library
testingpackage
Gemfile→rspec,minitest- Check for
spec/ortest/directories
Following Project Patterns
The implementer reads existing test files to match:- File naming conventions
- Test structure and organization
- Assertion styles
- Mocking patterns
- Setup/teardown approaches
If user-installed skills exist (e.g.,
pytest/SKILL.md, vitest/SKILL.md), the implementer reads and follows those skill patterns for writing tests.Integration with Specs
TDD mode uses spec scenarios as acceptance criteria:Each Given/When/Then scenario typically becomes one test case. Complex scenarios may need multiple test cases.
Standard Mode vs TDD Mode
When to Use TDD Mode
Use TDD When:
✅ Building critical functionality ✅ Working with complex business logic ✅ Requirements are well-defined (specs exist) ✅ Test coverage is important ✅ Refactoring is expected ✅ Team values test-first developmentUse Standard Mode When:
⏩ Prototyping or exploring ⏩ Working with UI-heavy features (e.g., styling) ⏩ Requirements are vague ⏩ Quick iteration is priority ⏩ Tests are difficult to write (e.g., integration with external systems)Running Tests During TDD
Scoped Test Execution
Performance tip: During TDD, run ONLY the relevant test file/suite, not the entire test suite.
Test Output in Reports
The implementer captures test output for each phase:Best Practices
TDD Best Practices
TDD Best Practices
1. Write the Simplest Test First
Start with the happy path, add edge cases later.2. One Test at a Time
Don’t write multiple failing tests. One RED → GREEN → REFACTOR cycle per test.3. Test Behavior, Not Implementation
Test what the code does, not how it does it.4. Keep Tests Independent
Each test should run in isolation and not depend on other tests.5. Refactor Tests Too
Apply the same quality standards to test code as production code.6. Fast Feedback
Tests should run quickly. Slow tests discourage running them frequently.7. Use Descriptive Test Names
Test names should describe the scenario being tested.Verification Phase
After implementation, thesdd-verify sub-agent (v2.0) runs the full test suite:
Next Steps
Complete Workflow
Learn the full SDD workflow
Delta Specs
How specs become acceptance criteria
Implementer Sub-Agent
Deep dive into sdd-apply v2.0
Verifier Sub-Agent
Deep dive into sdd-verify v2.0