Consolidate Test Suites
Purpose: place each invariant in one owning test layer only.
Definitions:
- Invariant: the rule that must stay true.
- Owning layer: the lowest layer that truly owns and can prove that rule.
- Canonical suite: the normal existing suite for that owning layer.
- Probe: temporary test code, fixture, script, snapshot, diagnostic, assertion,
instrumentation, or helper created to investigate or reproduce one task.
Default: reuse an existing canonical suite. Do not create a new standalone regression test unless the exception rule below allows it.
Probes are useful working material, not permanent coverage by default. Before
finishing, classify every probe created for the current task as PROMOTE,
MERGE, or DROP.
Hard Rules
- You MUST identify the invariant before adding or moving any test.
- You MUST identify one primary owning layer: unit, integration, or end-to-end.
- You MUST first try to place coverage in an existing canonical suite for that layer.
- You MUST prefer editing an existing test file over creating a new test file.
- You MUST NOT add the same invariant in multiple layers unless each layer covers a different failure mode. If you keep more than one layer, name the distinct failure mode for each.
- You MUST NOT add tests that lock in implementation details unless that implementation unit itself owns the invariant.
- You MUST NOT create a standalone regression test because it is faster or easier.
- If you cannot name the invariant and the owning layer, STOP. Report that placement is not justified.
- You MUST remove current-task probes that are not promoted or merged, including
temporary code inserted into a permanent test or production file.
- You MUST preserve tests and dirty changes that predate the current task. Never
delete or rewrite them merely to reduce test count.
- If the request is review-only, report probe dispositions and cleanup
recommendations without modifying files.
Required Decision Order
Choose the first option that fits:
- Add to an existing test in an existing file in the owning layer.
- Add a new test to an existing canonical file in the owning layer.
- Create a new file inside the existing canonical suite in the owning layer.
- Create a standalone regression-style test only if the Exception Rule passes.
Owning Layer Rules
Choose unit when:
- one module owns the rule, and
- the bug reproduces without I/O, transport, persistence, retries, IPC, orchestration, or lifecycle coupling.
Choose integration when:
- the rule lives at a boundary between components, or
- the bug depends on serialization, persistence, ordering, replay, retries, IPC, process lifecycle, or multi-component coordination.
Choose end-to-end only when:
- the user-visible contract cannot be trusted from lower-layer tests alone.
Tie-breakers:
- If torn between unit and integration, choose integration.
- Never choose end-to-end to compensate for uncertainty.
- Never choose a higher layer just because it is easier to reproduce there.
Exception Rule for Standalone Regression Tests
A standalone regression-style test is allowed only if ALL are true:
- no existing canonical suite can express the case cleanly
- the reproduction is deterministic
- the case has durable incident or contract value
- adding it to the canonical suite would make that suite less clear
If any condition is false, fold the coverage into the canonical suite.
Probe Lifecycle
Use temporary probes when they materially help reproduce, diagnose, or falsify
a suspected bug. Keep their lifecycle lightweight:
- Before editing tests, inspect the existing test-related status and diff so
pre-existing work is distinguishable from task-created probes. Keep this
baseline in the working context; do not create tracking files for it.
- Once the behavior is accepted, compare each task-created probe with the
nearest canonical suite and choose exactly one disposition:
PROMOTE: keep the smallest version because it protects a unique durable
invariant at the stable owning boundary.
MERGE: move only its unique signal into an existing canonical test, then
remove the redundant probe.
DROP: remove it because it is diagnostic-only, redundant, speculative,
implementation-coupled, flaky, slow, or low-value.
- Parameterize or extend an existing behavior test when several examples prove
the same invariant. Test count and coverage percentage are not reasons to
keep another test.
- Remove every unpromoted task-created probe before final verification. If its
ownership is uncertain, preserve it and report the uncertainty instead of
guessing that it is safe to delete.
Promote a probe only when it is deterministic, protects an accepted observable
contract, would catch a meaningful regression, adds signal not already owned
elsewhere, and has maintenance cost proportional to its risk. When cheap and
safe, confirm that the proposed test fails against the faulty behavior and
passes against the fix; do not build extra infrastructure merely to produce
that proof.
Duplicate Cleanup
After placing coverage:
- Search for tests that assert the same invariant.
- Keep the strongest owned location.
- Merge any unique assertions into that location.
- Delete or simplify weaker duplicates.
- Rename tests by behavior and owner, not by ticket number or bug history.
Delete or rewrite pre-existing tests only when the task includes suite
consolidation and duplicate coverage has been demonstrated. Routine bug-fix work
may clean up only the probes it created.
Verification
Before finishing:
- Run the narrowest relevant test target first.
- Run required typecheck, build, or lint steps for touched code.
- Report exactly what was run and whether it passed.
Default Output Format
Use this format by default:
Invariant:
Owning layer: <unit | integration | end-to-end>
Target suite/file:
Action: <reuse existing test | add to existing suite | create file in canonical suite | keep standalone regression>
Why this layer owns it:
Duplicates to merge/delete: <list or "none">
Current-task probes: <PROMOTE / MERGE / DROP for each, or "none">
Probe cleanup completed: <removed paths or inline code, or "none">
Verification run:
Residual risk: <what is still not covered, if anything>
1---2name: consolidate-test-suites3description: Decide where durable test coverage belongs and clean up temporary test probes. Use while testing a bug fix or architectural change, or before finishing work that added tests, fixtures, snapshots, diagnostics, or temporary assertions. Select one owning layer, reuse canonical suites, merge unique signal, and remove task-created probe residue without disturbing pre-existing work.4---5
6# Consolidate Test Suites
7
8Purpose: place each invariant in one owning test layer only.
9
10Definitions:
11- Invariant: the rule that must stay true.
12- Owning layer: the lowest layer that truly owns and can prove that rule.
13- Canonical suite: the normal existing suite for that owning layer.
14- Probe: temporary test code, fixture, script, snapshot, diagnostic, assertion,
15 instrumentation, or helper created to investigate or reproduce one task.
16
17Default: reuse an existing canonical suite. Do not create a new standalone regression test unless the exception rule below allows it.
18
19Probes are useful working material, not permanent coverage by default. Before
20finishing, classify every probe created for the current task as `PROMOTE`,
21`MERGE`, or `DROP`.
22
23## Hard Rules
24
25- You MUST identify the invariant before adding or moving any test.
26- You MUST identify one primary owning layer: unit, integration, or end-to-end.
27- You MUST first try to place coverage in an existing canonical suite for that layer.
28- You MUST prefer editing an existing test file over creating a new test file.
29- You MUST NOT add the same invariant in multiple layers unless each layer covers a different failure mode. If you keep more than one layer, name the distinct failure mode for each.
30- You MUST NOT add tests that lock in implementation details unless that implementation unit itself owns the invariant.
31- You MUST NOT create a standalone regression test because it is faster or easier.
32- If you cannot name the invariant and the owning layer, STOP. Report that placement is not justified.
33- You MUST remove current-task probes that are not promoted or merged, including
34 temporary code inserted into a permanent test or production file.
35- You MUST preserve tests and dirty changes that predate the current task. Never
36 delete or rewrite them merely to reduce test count.
37- If the request is review-only, report probe dispositions and cleanup
38 recommendations without modifying files.
39
40## Required Decision Order
41
42Choose the first option that fits:
43
441. Add to an existing test in an existing file in the owning layer.
452. Add a new test to an existing canonical file in the owning layer.
463. Create a new file inside the existing canonical suite in the owning layer.
474. Create a standalone regression-style test only if the Exception Rule passes.
48
49## Owning Layer Rules
50
51Choose unit when:
52- one module owns the rule, and
53- the bug reproduces without I/O, transport, persistence, retries, IPC, orchestration, or lifecycle coupling.
54
55Choose integration when:
56- the rule lives at a boundary between components, or
57- the bug depends on serialization, persistence, ordering, replay, retries, IPC, process lifecycle, or multi-component coordination.
58
59Choose end-to-end only when:
60- the user-visible contract cannot be trusted from lower-layer tests alone.
61
62Tie-breakers:
63- If torn between unit and integration, choose integration.
64- Never choose end-to-end to compensate for uncertainty.
65- Never choose a higher layer just because it is easier to reproduce there.
66
67## Exception Rule for Standalone Regression Tests
68
69A standalone regression-style test is allowed only if ALL are true:
70
71- no existing canonical suite can express the case cleanly
72- the reproduction is deterministic
73- the case has durable incident or contract value
74- adding it to the canonical suite would make that suite less clear
75
76If any condition is false, fold the coverage into the canonical suite.
77
78## Probe Lifecycle
79
80Use temporary probes when they materially help reproduce, diagnose, or falsify
81a suspected bug. Keep their lifecycle lightweight:
82
831. Before editing tests, inspect the existing test-related status and diff so
84 pre-existing work is distinguishable from task-created probes. Keep this
85 baseline in the working context; do not create tracking files for it.
862. Once the behavior is accepted, compare each task-created probe with the
87 nearest canonical suite and choose exactly one disposition:
88 - `PROMOTE`: keep the smallest version because it protects a unique durable
89 invariant at the stable owning boundary.
90 - `MERGE`: move only its unique signal into an existing canonical test, then
91 remove the redundant probe.
92 - `DROP`: remove it because it is diagnostic-only, redundant, speculative,
93 implementation-coupled, flaky, slow, or low-value.
943. Parameterize or extend an existing behavior test when several examples prove
95 the same invariant. Test count and coverage percentage are not reasons to
96 keep another test.
974. Remove every unpromoted task-created probe before final verification. If its
98 ownership is uncertain, preserve it and report the uncertainty instead of
99 guessing that it is safe to delete.
100
101Promote a probe only when it is deterministic, protects an accepted observable
102contract, would catch a meaningful regression, adds signal not already owned
103elsewhere, and has maintenance cost proportional to its risk. When cheap and
104safe, confirm that the proposed test fails against the faulty behavior and
105passes against the fix; do not build extra infrastructure merely to produce
106that proof.
107
108## Duplicate Cleanup
109
110After placing coverage:
111
1121. Search for tests that assert the same invariant.
1132. Keep the strongest owned location.
1143. Merge any unique assertions into that location.
1154. Delete or simplify weaker duplicates.
1165. Rename tests by behavior and owner, not by ticket number or bug history.
117
118Delete or rewrite pre-existing tests only when the task includes suite
119consolidation and duplicate coverage has been demonstrated. Routine bug-fix work
120may clean up only the probes it created.
121
122## Verification
123
124Before finishing:
125
1261. Run the narrowest relevant test target first.
1272. Run required typecheck, build, or lint steps for touched code.
1283. Report exactly what was run and whether it passed.
129
130## Default Output Format
131
132Use this format by default:
133
134Invariant: <rule that failed>
135
136Owning layer: <unit | integration | end-to-end>
137
138Target suite/file: <path or suite name>
139
140Action: <reuse existing test | add to existing suite | create file in canonical suite | keep standalone regression>
141
142Why this layer owns it: <one short paragraph>
143
144Duplicates to merge/delete: <list or "none">
145
146Current-task probes: <PROMOTE / MERGE / DROP for each, or "none">
147
148Probe cleanup completed: <removed paths or inline code, or "none">
149
150Verification run: <commands and result>
151
152Residual risk: <what is still not covered, if anything>