# Tdd

> Cargo TDD with HITL: failing test for the right reason, user approves, green, refactor, fmt/clippy. Trigger: tdd, red-green-refactor, test first, cargo test.

- Skill: `igmarin/tdd-3` (Agent Skill)
- Install (CLI): `npx get-skill add igmarin/tdd-3`
- Raw SKILL.md: https://api.skillmd.com/api/skills/igmarin/tdd-3/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: igmarin (https://skillmd.com/u/igmarin)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/igmarin/tdd-3

---


# TDD playbook

## HARD-GATE

- No implementation until a test exists, was run, and failed because behaviour is missing (not because of compile noise you have not fixed in the test).
- Implementation waits for **explicit user approval**.
- Quality gate before you call it done — same commands as `docs/skill-authoring.md`: `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test`.

## When to use

New or changed behaviour in a Rust crate. Prefer unit tests next to the module; `tests/` only for public-API contracts.

## Loads

| Skill | Role |
|-------|------|
| `load-context` | existing crates |
| `rust-essentials` | apply `docs/fcis-rust.md` |

## Phases

1. **Context + RED** — `load-context` if the crate exists. Write the smallest failing test. Run `cargo test <test_name> -- --exact`.
2. **HITL + GREEN** — show the test + failure. Wait. Implement only what was approved. Re-run until green.
3. **Refactor** — behaviour unchanged; re-run after each step.
4. **Quality** — fmt, clippy `-D warnings`, `cargo test` for the crate.

## Validation

- RED: failure is missing behaviour
- User said to implement
- GREEN on the target test
- fmt/clippy/test exit 0

## Error recovery

| Problem | Action |
|---------|--------|
| Test does not compile | fix the test; stay in RED |
| Still red after impl | smallest fix; re-approve if the approach changed |
| Refactor red | revert last step |
| Clippy red | fix; do not `#[allow]` to skip the gate |

## Output

```text
## TDD Report
**Behaviour:** …
**Test:** `path` / `test_name`
**RED:** command + reason
**Approval:** yes/no
**GREEN:** command
**Quality:** fmt / clippy / test
**Skipped (ponytail):** …
```

## Integration

Atomics during GREEN: `type-driven-design`, `error-handling`, `ownership-borrowing` as needed. Do not skip `rust-essentials`.

