Skip to main content

Overview

Agent Teams Lite v2.0 introduces full TDD (Test-Driven Development) support in the sdd-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

The sdd-apply sub-agent detects TDD mode from (in priority order):
  1. openspec/config.yamlrules.apply.tdd (true/false — highest priority)
  2. User’s installed skills — e.g., tdd/SKILL.md exists
  3. Existing test patterns — test files alongside source in codebase
  4. Default — standard mode (write code first, then verify)

Configuration

Method 2: Orchestrator Config

Pass TDD mode when launching the implementer:

Test Command Detection

If test_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)
Critical: If the test passes immediately, either the behavior already exists or the test is wrong. Investigate before proceeding.

Example: RED Phase

Task: 1.1 Add CSV export endpoint Spec Scenario:
Test (RED — should fail):
Run test (should FAIL):
Test fails as expected. Proceed to GREEN.

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:
Register blueprint:
Run test (should PASS):
Test passes. Proceed to REFACTOR.

The REFACTOR Phase: Clean Up

Purpose

Improve code quality without changing behavior. Tests must still pass after refactoring.
  • Extract helper functions
  • Remove duplication
  • Improve naming
  • Match project patterns
  • Add documentation
  • Simplify logic

Example: REFACTOR Phase

Improvements:
Run tests again (should STILL PASS):
Tests still pass. Refactoring successful. Mark task complete:

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

JavaScript/TypeScript:
  • package.jsonjest, vitest, mocha, ava
  • Check for *.test.js, *.spec.js files
  • Look for test config files: jest.config.js, vitest.config.ts
Python:
  • pyproject.toml, pytest.ini, setup.pypytest, unittest
  • Check for test_*.py, *_test.py files
  • Look for conftest.py (pytest)
Go:
  • Check for *_test.go files
  • Standard library testing package
Ruby:
  • Gemfilerspec, minitest
  • Check for spec/ or test/ 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:
Maps to tests:
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 development

Use 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)
TDD adds time to each task (write test, run test, refactor). Ensure the project benefits justify the investment.

Running Tests During TDD

Scoped Test Execution

Performance tip: During TDD, run ONLY the relevant test file/suite, not the entire test suite.
Examples:

Test Output in Reports

The implementer captures test output for each phase:
$ pytest tests/test_export.py::test_csv_export_with_data FAILED tests/test_export.py::test_csv_export_with_data - AssertionError: 404 != 200
$ pytest tests/test_export.py::test_csv_export_with_data PASSED tests/test_export.py::test_csv_export_with_data
$ pytest tests/test_export.py::test_csv_export_with_data PASSED tests/test_export.py::test_csv_export_with_data

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, the sdd-verify sub-agent (v2.0) runs the full test suite:
See sdd-verify documentation for details.

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