Skip to content

Commit 73e1218

Browse files
committed
docs: add TDD and branch coverage requirements to AGENTS.md
Document that tests are first-class planning requirements, not afterthoughts. 100% branch coverage is mandatory (enforced by CI), coverage must be verified before committing, and pytest fixtures should be used instead of hardcoded paths.
1 parent 8ce602d commit 73e1218

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ async def test_something(self, sm_runner):
160160

161161
Do **not** manually add async no-op listeners or duplicate test classes — prefer `sm_runner`.
162162

163+
### TDD and coverage requirements
164+
165+
Follow a **test-driven development** approach: tests are not an afterthought — they are a
166+
first-class requirement that must be part of every implementation plan.
167+
168+
- **Planning phase:** every plan must include test tasks as explicit steps, not a final
169+
"add tests" bullet. Identify what needs to be tested (new branches, edge cases, error
170+
paths) while designing the implementation.
171+
- **100% branch coverage is mandatory.** The pre-commit hook enforces `--cov-fail-under=100`
172+
with branch coverage enabled. Code that drops coverage will not pass CI.
173+
- **Verify coverage before committing:** after writing tests, run coverage on the affected
174+
modules and check for missing lines/branches:
175+
```bash
176+
timeout 120 uv run pytest tests/<test_file>.py --cov=statemachine.<module> --cov-report=term-missing --cov-branch
177+
```
178+
- **Use pytest fixtures** (`tmp_path`, `monkeypatch`, etc.) — never hardcode paths or
179+
use mutable global state when a fixture exists.
180+
- **Unreachable defensive branches** (e.g., `if` guards that can never be True given the
181+
type system) may be marked with `pragma: no cover`, but prefer writing a test first.
182+
163183
## Linting and formatting
164184

165185
```bash

0 commit comments

Comments
 (0)