tdd-cycle
Use this skill when implementing any new feature, function, class, or module. Triggers include: "implement", "let's build", "add a feature", "write a function", "create a class", "add a method", "let'
Files1
View on GitHubSKILL.md.claude/skills/tdd-cycle/SKILL.md
GitHubTDD Cycle (Red → Green → Refactor)
Strict test-first discipline. ≥90% coverage on the deterministic core emerges as a side effect.
HW5 note: the pure Tier-1 modules (
metrics,economics,roofline,harnessagainst themockrunner) are fully TDD-able keyless. The realrunners(torch/airllm/llama.cpp) are thin and hardware-bound — exercised by the Tier-2 committed runs, marked@pytest.mark.hardware, excluded from CI. Put the logic in pure modules so it's testable; keep the runners as thin adapters.
The cycle (one concern at a time)
RED — write the failing test first
- Create/open the matching
tests/unit/test_<module>/test_<thing>.py. - Write a test describing behavior, with a descriptive name
(
test_breakeven_is_monotonic_in_volume, nottest_econ). - Run it — it MUST fail meaningfully (missing attr, wrong value), not an unrelated import error:
uv run pytest tests/unit/test_economics/test_breakeven.py::test_breakeven_is_monotonic_in_volume -xvs - Commit RED:
git commit -m "test(economics): failing test for monotonic break-even"
GREEN — minimal code to pass
- Write only enough to pass — nothing the tests don't demand.
- Re-run the test (
1 passed), then the suite (uv run pytest -x). - Commit GREEN:
git commit -m "feat(economics): break-even curve from cost components"
REFACTOR — improve without changing behavior
Extract helpers, improve names, add docstrings, keep files < 150 lines. Tests stay green. Optional.
Rules
- One concern per cycle — don't implement two functions off one test.
- No skipping RED. Code-first → delete, write the test, re-implement.
- Verify each phase by reading pytest output, not by trusting it.
- No
pytest.skipto defer work — write it now or remove it. - Coverage is a side effect, not the goal.
Unit vs integration vs hardware
tests/unit/— one pure module in isolation (metrics, economics, roofline, sampler-with-fake-clock).tests/integration/— composition (harness driving themockrunner end-to-end →RunResult→ metrics).@pytest.mark.hardware— needs the GPU box; excluded from CI, run manually for Tier-2.
Verify before signaling success
make test and make lint both green. If either fails, the cycle isn't complete.