test-first (the test-shaping technique)
The cycle — RED → GREEN → REFACTOR → COMMIT, its per-phase gates, the
characterize-first rule, the bug-fix and refactor variants, the
migration safety gate, and the recorded exceptions — lives in
docs/graph/protocols/test-first.md, the one home for the workflow. This skill
owns the craft of shaping each test the cycle asks for.
Test level selection
Pick the lowest level that exercises the behavior.
| Level |
Use when |
| Unit |
Pure logic, transformations, parsers, validators. |
| Integration |
Crossing an adapter (DB, file, network, SDK, model). |
| Contract |
API endpoints, structured outputs, message schemas. |
| End-to-end |
Critical flows — one or two per flow, no more. |
| Golden / snapshot |
Deterministic transforms, prompts, renderers. |
| Property-based |
Algorithms where the property is clearer than examples. |
| Evaluation |
LLM/VLM behavior, with rubrics and pass thresholds. |
Test shape
- The name names the contract. The spec §4 contract slug,
transformed for the language's convention
(
test_submit_valid_form_returns_2xx,
submitValidFormReturns2xx, …). The reviewer should be able to
read the test names and reconstruct the spec.
- The body is Given/When/Then. Set up Given, perform When,
assert Then.
- One outcome per test (or one assertion group about the same
outcome). Many small tests beat one giant one.
Reference files
docs/graph/protocols/test-first.md — the workflow this technique serves.
docs/graph/templates/spec.template.md — where contracts live (§4) and
test mapping is recorded (§10).
docs/graph/agents/04-tester.md — the agent that owns the cycle.
docs/graph/agents/02-implementer.md — the agent that writes GREEN.
1---2name: test-first3description: The test-SHAPING technique applied inside the test-first protocol — pick the lowest test level that exercises the behavior (unit, integration, contract, e2e, golden, property-based, evaluation), name the test after the spec contract, and assert one outcome per test. The workflow itself (entry conditions, RED-GREEN-REFACTOR-COMMIT gates, variants, exceptions) is the test-first protocol.4---56# test-first (the test-shaping technique)78The cycle — RED → GREEN → REFACTOR → COMMIT, its per-phase gates, the9characterize-first rule, the bug-fix and refactor variants, the10migration safety gate, and the recorded exceptions — lives in11`docs/graph/protocols/test-first.md`, the one home for the workflow. This skill12owns the craft of shaping each test the cycle asks for.1314## Test level selection1516Pick the lowest level that exercises the behavior.1718| Level | Use when |19|-------------------|---------------------------------------------------------|20| Unit | Pure logic, transformations, parsers, validators. |21| Integration | Crossing an adapter (DB, file, network, SDK, model). |22| Contract | API endpoints, structured outputs, message schemas. |23| End-to-end | Critical flows — one or two per flow, no more. |24| Golden / snapshot | Deterministic transforms, prompts, renderers. |25| Property-based | Algorithms where the property is clearer than examples. |26| Evaluation | LLM/VLM behavior, with rubrics and pass thresholds. |2728## Test shape2930- **The name names the contract.** The spec §4 contract slug,31 transformed for the language's convention32 (`test_submit_valid_form_returns_2xx`,33 `submitValidFormReturns2xx`, …). The reviewer should be able to34 read the test names and reconstruct the spec.35- **The body is Given/When/Then.** Set up Given, perform When,36 assert Then.37- **One outcome per test** (or one assertion group about the same38 outcome). Many small tests beat one giant one.3940## Reference files4142- `docs/graph/protocols/test-first.md` — the workflow this technique serves.43- `docs/graph/templates/spec.template.md` — where contracts live (§4) and44 test mapping is recorded (§10).45- `docs/graph/agents/04-tester.md` — the agent that owns the cycle.46- `docs/graph/agents/02-implementer.md` — the agent that writes GREEN.