main
md 37 lines 1.89 KB
Rendered Raw
1 ---
2 name: "test-discipline"
3 description: "Update tests when changing APIs no exceptions"
4 domain: "quality"
5 confidence: "high"
6 source: "earned (Fenster/Hockney incident, test assertion sync violations)"
7 ---
8
9 ## Context
10
11 When APIs or public interfaces change, tests must be updated in the same commit. When test assertions reference file counts or expected arrays, they must be kept in sync with disk reality. Stale tests block CI for other contributors.
12
13 ## Patterns
14
15 - **API changes → test updates (same commit):** If you change a function signature, public interface, or exported API, update the corresponding tests before committing
16 - **Test assertions → disk reality:** When test files contain expected counts (e.g., `EXPECTED_FEATURES`, `EXPECTED_SCENARIOS`), they must match the actual files on disk
17 - **Add files → update assertions:** When adding docs pages, features, or any counted resource, update the test assertion array in the same commit
18 - **CI failures → check assertions first:** Before debugging complex failures, verify test assertion arrays match filesystem state
19
20 ## Examples
21
22 **Correct:**
23 - Changed auth API signature → updated auth.test.ts in same commit
24 - Added `distributed-mesh.md` to features/ → added `'distributed-mesh'` to EXPECTED_FEATURES array
25 - Deleted two scenario files → removed entries from EXPECTED_SCENARIOS
26
27 **Incorrect:**
28 - Changed spawn parameters → committed without updating casting.test.ts (CI breaks for next person)
29 - Added `built-in-roles.md` → left EXPECTED_FEATURES at old count (PR blocked)
30 - Test says "expected 7 files" but disk has 25 (assertion staleness)
31
32 ## Anti-Patterns
33
34 - Committing API changes without test updates ("I'll fix tests later")
35 - Treating test assertion arrays as static (they evolve with content)
36 - Assuming CI passing means coverage is correct (stale assertions can pass while being wrong)
37 - Leaving gaps for other agents to discover