@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/ADOPTING.md +172 -38
  2. package/MIGRATING.md +58 -7
  3. package/README.md +117 -35
  4. package/THIRD-PARTY-NOTICES.md +1 -1
  5. package/api/audit.d.ts +3 -2
  6. package/api/rule-set.d.ts +2 -4
  7. package/chunks/chunk-3HFJHJDO.js +53 -0
  8. package/chunks/chunk-5LCLBXP7.js +76 -0
  9. package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
  10. package/chunks/chunk-LDQUT742.js +15 -0
  11. package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
  12. package/chunks/chunk-MVK5KFJI.js +421 -0
  13. package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
  14. package/chunks/chunk-WPRR2MPJ.js +22 -0
  15. package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
  16. package/core/check/tool-command.js +1130 -230
  17. package/core/mechanism-port/piece-failure-types.d.ts +14 -0
  18. package/core/mechanism-port/runner-module-types.d.ts +5 -0
  19. package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
  20. package/core/values/json-value.d.ts +3 -0
  21. package/docs/adding-a-discipline-or-mechanism.md +29 -13
  22. package/docs/extending.md +358 -0
  23. package/docs/output-contract.md +326 -0
  24. package/mechanisms/audit/CD-1/any-cast.js +9 -37
  25. package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
  26. package/mechanisms/audit/CD-19/piece.json +5 -0
  27. package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
  28. package/mechanisms/audit/CD-2/piece.json +6 -1
  29. package/mechanisms/audit/CD-5/comments-directives.js +121 -55
  30. package/mechanisms/audit/CD-5/piece.json +7 -0
  31. package/mechanisms/audit/runner/README.md +4 -2
  32. package/mechanisms/audit/runner/runner.js +102 -36
  33. package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
  34. package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
  35. package/mechanisms/eslint/CD-2/README.md +12 -0
  36. package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
  37. package/mechanisms/eslint/CD-2/piece.json +25 -0
  38. package/mechanisms/eslint/runner/README.md +12 -5
  39. package/mechanisms/eslint/runner/runner.js +940 -232
  40. package/methods/README.md +2 -0
  41. package/methods/assessment-template.md +35 -0
  42. package/methods/lenses/clean-architecture.md +2 -2
  43. package/methods/lenses/decomposition.md +2 -2
  44. package/methods/lenses/defended-on-intent.md +7 -7
  45. package/methods/lenses/di-discipline.md +38 -26
  46. package/methods/lenses/errors-as-data.md +2 -2
  47. package/methods/lenses/function-first.md +2 -2
  48. package/methods/lenses/naming.md +2 -2
  49. package/methods/lenses/test-discipline.md +15 -13
  50. package/methods/lenses/type-soundness.md +2 -2
  51. package/methods/lenses/zod-boundary.md +2 -2
  52. package/package.json +5 -4
  53. package/rules/CD-1/CHECKS.md +37 -0
  54. package/rules/CD-1/README.md +17 -32
  55. package/rules/CD-1/discipline.json +16 -6
  56. package/rules/CD-10/CHECKS.md +49 -0
  57. package/rules/CD-10/README.md +21 -49
  58. package/rules/CD-11/CHECKS.md +13 -0
  59. package/rules/CD-11/README.md +14 -8
  60. package/rules/CD-12/CHECKS.md +13 -0
  61. package/rules/CD-12/README.md +14 -8
  62. package/rules/CD-13/CHECKS.md +13 -0
  63. package/rules/CD-13/README.md +14 -8
  64. package/rules/CD-14/CHECKS.md +49 -0
  65. package/rules/CD-14/README.md +22 -48
  66. package/rules/CD-15/CHECKS.md +40 -0
  67. package/rules/CD-15/README.md +22 -40
  68. package/rules/CD-16/CHECKS.md +7 -0
  69. package/rules/CD-16/README.md +3 -5
  70. package/rules/CD-17/CHECKS.md +37 -0
  71. package/rules/CD-17/README.md +17 -31
  72. package/rules/CD-18/CHECKS.md +13 -0
  73. package/rules/CD-18/README.md +15 -9
  74. package/rules/CD-19/CHECKS.md +49 -0
  75. package/rules/CD-19/README.md +18 -34
  76. package/rules/CD-19/discipline.json +6 -8
  77. package/rules/CD-2/CHECKS.md +56 -0
  78. package/rules/CD-2/README.md +19 -32
  79. package/rules/CD-2/discipline.json +93 -7
  80. package/rules/CD-20/CHECKS.md +7 -0
  81. package/rules/CD-20/README.md +3 -5
  82. package/rules/CD-21/CHECKS.md +13 -0
  83. package/rules/CD-21/README.md +14 -9
  84. package/rules/CD-22/CHECKS.md +13 -0
  85. package/rules/CD-22/README.md +13 -8
  86. package/rules/CD-23/CHECKS.md +35 -0
  87. package/rules/CD-23/README.md +14 -29
  88. package/rules/CD-24/CHECKS.md +7 -0
  89. package/rules/CD-24/README.md +3 -5
  90. package/rules/CD-25/CHECKS.md +38 -0
  91. package/rules/CD-25/README.md +20 -32
  92. package/rules/CD-26/CHECKS.md +36 -0
  93. package/rules/CD-26/README.md +18 -31
  94. package/rules/CD-27/CHECKS.md +45 -0
  95. package/rules/CD-27/README.md +18 -40
  96. package/rules/CD-28/CHECKS.md +13 -0
  97. package/rules/CD-28/README.md +14 -8
  98. package/rules/CD-29/CHECKS.md +13 -0
  99. package/rules/CD-29/README.md +12 -8
  100. package/rules/CD-3/CHECKS.md +42 -0
  101. package/rules/CD-3/README.md +20 -42
  102. package/rules/CD-30/CHECKS.md +13 -0
  103. package/rules/CD-30/README.md +13 -8
  104. package/rules/CD-31/CHECKS.md +13 -0
  105. package/rules/CD-31/README.md +12 -8
  106. package/rules/CD-32/CHECKS.md +13 -0
  107. package/rules/CD-32/README.md +13 -8
  108. package/rules/CD-33/CHECKS.md +13 -0
  109. package/rules/CD-33/README.md +13 -8
  110. package/rules/CD-34/CHECKS.md +13 -0
  111. package/rules/CD-34/README.md +12 -8
  112. package/rules/CD-39/CHECKS.md +13 -0
  113. package/rules/CD-39/README.md +13 -8
  114. package/rules/CD-4/CHECKS.md +13 -0
  115. package/rules/CD-4/README.md +15 -8
  116. package/rules/CD-40/CHECKS.md +39 -0
  117. package/rules/CD-40/README.md +17 -33
  118. package/rules/CD-41/CHECKS.md +54 -0
  119. package/rules/CD-41/README.md +23 -54
  120. package/rules/CD-42/CHECKS.md +47 -0
  121. package/rules/CD-42/README.md +19 -47
  122. package/rules/CD-43/CHECKS.md +37 -0
  123. package/rules/CD-43/README.md +15 -31
  124. package/rules/CD-44/CHECKS.md +48 -0
  125. package/rules/CD-44/README.md +20 -48
  126. package/rules/CD-45/CHECKS.md +13 -0
  127. package/rules/CD-45/README.md +14 -8
  128. package/rules/CD-46/CHECKS.md +7 -0
  129. package/rules/CD-46/README.md +16 -4
  130. package/rules/CD-47/CHECKS.md +37 -0
  131. package/rules/CD-47/README.md +16 -32
  132. package/rules/CD-5/CHECKS.md +52 -0
  133. package/rules/CD-5/README.md +22 -40
  134. package/rules/CD-5/discipline.json +66 -0
  135. package/rules/CD-6/CHECKS.md +51 -0
  136. package/rules/CD-6/README.md +22 -51
  137. package/rules/CD-7/CHECKS.md +46 -0
  138. package/rules/CD-7/README.md +23 -46
  139. package/rules/CD-7a/CHECKS.md +38 -0
  140. package/rules/CD-7a/README.md +14 -32
  141. package/rules/CD-8/CHECKS.md +42 -0
  142. package/rules/CD-8/README.md +20 -42
  143. package/rules/CD-9/CHECKS.md +13 -0
  144. package/rules/CD-9/README.md +15 -8
  145. package/rules/README.md +5 -3
  146. package/rules/SPIRIT.md +50 -0
  147. package/core/mechanism-port/runner-failure-types.d.ts +0 -38
  148. package/core/rule-set-reader/rule-set-types.d.ts +0 -41
  149. /package/api/{audit.js → audit.mjs} +0 -0
  150. /package/api/{rule-set.js → rule-set.mjs} +0 -0
@@ -4,16 +4,21 @@
4
4
 
5
5
  Middleware carries the context it consumes through a constrained generic that each layer widens, not an open property bag — so a capability the middleware reads from context (time, logging, correlation) is guaranteed present by the type rather than defensively re-checked or defaulted. A middleware that reads a context field but leaves its context generic unbounded is the violation.
6
6
 
7
- The sections below describe how the rule is checked.
7
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-22#middleware-context` | review | middleware reads its context through a constrained generic, not an open property bag |
11
+ **What the friction is for.** Middleware that reads from an open property bag has to check whether what it needs is there. The friction makes the type guarantee it, so capabilities are present by construction.
14
12
 
15
- Review lens: [di-discipline](../../methods/lenses/di-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *Context read defensively.* Middleware checks or defaults a field like the clock or logger. Constrain its context type so the field must exist.
15
+ - *Layers that add capabilities untyped.* Earlier layers add fields the type never records. Widen the generic at each layer.
16
16
 
17
- ## How it is checked
17
+ **Where to go.** Each middleware declares the context it needs through a constrained generic. A missing capability is a compile error.
18
18
 
19
- Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies the rule above with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
19
+ **Reactions to distrust.**
20
+ - "A default is safer." A default hides wiring mistakes until they matter.
21
+
22
+ **Principles behind it.**
23
+ - *Make illegal states unrepresentable* (Yaron Minsky). A context type that requires the field cannot be built without it.
24
+ - *Explicit dependencies.* A unit states what it needs in its signature, not by reaching into a shared bag.
@@ -0,0 +1,35 @@
1
+ # CD-23 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-23#export-test-sibling` | audit | a production file with a runtime export and no `.test` sibling |
10
+
11
+ ## What the check flags
12
+ - Production `.ts` and `.tsx` files. Skipped: `*.test.ts(x)`, `.d.ts` and anything under `__tests__`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder or file can be left out with `exclude` in disciplines.json.
13
+ - A file with a runtime export (`export const`, `function`, `class`, `enum`, `export default`, or `export { name }`) and no `<name>.test.ts` beside it (`<name>.test.tsx` for `.tsx`). The sibling must be in the repository's file list.
14
+ - Allowed: files with only `export type`, `export interface`, `export declare`, type-only named exports or `export * from`, and files with no exports.
15
+ - The source rule asks for a test beside every source file; files without runtime exports are left to review.
16
+
17
+ ## Example violation
18
+ ```ts
19
+ export const price = 1;
20
+ ```
21
+ This is `src/price.ts` with no `src/price.test.ts` beside it.
22
+
23
+ ## How to fix
24
+ Add `src/price.test.ts` next to the file, with at least one test of its behaviour.
25
+
26
+ ## Exceptions
27
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file only wires exports together and has no behaviour of its own to test. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
28
+
29
+ ```json
30
+ { "version": 1, "exceptions": [
31
+ { "kind": "authorised-location", "clause": "CD-23#export-test-sibling", "file": "src/index.ts", "reason": "..." }
32
+ ] }
33
+ ```
34
+
35
+ Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -4,38 +4,23 @@
4
4
 
5
5
  Every source file ships a test sibling that sits beside it, sharing its name — there are no source files without a test, and no tests in a separate parallel tree. This is the real coverage floor: not a percentage, but the guarantee that every unit has at least one co-located test stating what it is for. Co-location makes the test the unit's visible contract and keeps the two changing together, where a parallel test tree lets them drift apart.
6
6
 
7
- The sections below describe what the audit check covers.
7
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-23#export-test-sibling` | audit | a production file with a runtime export and no `.test` sibling |
11
+ **What the friction is for.** A unit nobody can test alone is a unit nobody understands alone. The friction makes "write the test beside it" part of writing the unit, so every unit has a stated purpose and the two change together.
14
12
 
15
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the files against these causes.
14
+ - *A unit too tangled to test.* The test was skipped because the unit reaches its dependencies directly. Inject them, and the unit can be tested alone.
15
+ - *A file that is not a unit.* It holds loose pieces with no single purpose. Split it into units that each have one.
16
+ - *Tests in a parallel tree.* The tests exist but live elsewhere and drift. Move each beside its unit.
17
+ - *Tested only through something bigger.* The unit is covered only by an integration test. Give it its own.
16
18
 
17
- ## What the check flags
18
- - Production `.ts` and `.tsx` files. Skipped: `*.test.ts(x)`, `.d.ts` and anything under `__tests__`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder or file can be left out with `exclude` in disciplines.json.
19
- - A file with a runtime export (`export const`, `function`, `class`, `enum`, `export default`, or `export { name }`) and no `<name>.test.ts` beside it (`<name>.test.tsx` for `.tsx`). The sibling must be in the repository's file list.
20
- - Allowed: files with only `export type`, `export interface`, `export declare`, type-only named exports or `export * from`, and files with no exports.
21
- - The source rule asks for a test beside every source file; files without runtime exports are left to review.
19
+ **Where to go.** Every unit has a sibling test that states what it is for, and the two are edited together.
22
20
 
23
- ## Example violation
24
- ```ts
25
- export const price = 1;
26
- ```
27
- This is `src/price.ts` with no `src/price.test.ts` beside it.
21
+ **Reactions to distrust.**
22
+ - "It's covered by the integration tests." Covered is not specified. A failure there does not say which unit broke.
23
+ - "It's too simple to test." Then the test is short. It still states the purpose.
28
24
 
29
- ## How to fix
30
- Add `src/price.test.ts` next to the file, with at least one test of its behaviour.
31
-
32
- ## Exceptions
33
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file only wires exports together and has no behaviour of its own to test. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
34
-
35
- ```json
36
- { "version": 1, "exceptions": [
37
- { "kind": "authorised-location", "clause": "CD-23#export-test-sibling", "file": "src/index.ts", "reason": "..." }
38
- ] }
39
- ```
40
-
41
- Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
25
+ **Principles behind it.**
26
+ - *Listen to the tests* (Steve Freeman and Nat Pryce, *Growing Object-Oriented Software, Guided by Tests*). Difficulty testing a unit is feedback about its design.
@@ -0,0 +1,7 @@
1
+ # CD-24 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## How it is checked
6
+
7
+ This discipline has no clauses of its own. Its rule is carried by [CD-23](../CD-23/README.md); select that discipline's clauses instead.
@@ -8,10 +8,8 @@ sibling. The enforcing walker already computes them as a single check. CD-23 now
8
8
  carries both. This id is retained as a redirect so existing citations resolve; it
9
9
  is not independently enforced.
10
10
 
11
- The sections below describe how the rule is checked.
11
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
12
12
 
13
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ ## Spirit
14
14
 
15
- ## How it is checked
16
-
17
- This discipline has no clauses of its own. Its rule is carried by [CD-23](../CD-23/README.md); select that discipline's clauses instead.
15
+ See [CD-23's Spirit section](../CD-23/README.md#spirit). "Every file is unit-tested" and "tests are co-located" are one signal: a unit without its own stated purpose.
@@ -0,0 +1,38 @@
1
+ # CD-25 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-25#dependency-isolation` | audit | `vi.fn(<implementation>)` and `.mockImplementation(...)` |
10
+
11
+ ## What the check flags
12
+ - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
13
+ - A `vi.fn(...)` call with any argument, and any call to a method named `mockImplementation` (on any receiver, with or without arguments).
14
+ - Allowed: `vi.fn()`, `.mockReturnValue(...)`, `.mockResolvedValue(...)`, `.mockReturnValueOnce(...)` and `.mockImplementationOnce(...)`.
15
+ - `.mockImplementationOnce(...)` is not flagged even though it takes an implementation; whether that implementation gives the double behaviour is left to review.
16
+ - The source rule is wider (no real I/O, no real collaborators). Whether a unit is isolated is left to review.
17
+
18
+ ## Example violation
19
+ ```ts
20
+ const clock = { now: vi.fn(() => 1) };
21
+ ```
22
+
23
+ ## How to fix
24
+ ```ts
25
+ const clock = { now: vi.fn().mockReturnValue(1) };
26
+ ```
27
+ Return a canned value: that double is a stub. If the double needs logic, the seam is probably too wide, or the double is a fake that belongs in a shared in-memory implementation of the port with its own tests.
28
+
29
+ ## Exceptions
30
+ A double that legitimately needs behaviour is a fake: write it once as an in-memory implementation of the port, in its own module with its own tests, and pass it in. That is the home for the behaviour, not an exception for a test file. For debt in one file, add a `file-carve-out` entry to `discipline-exceptions.json` at the repository root: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
31
+
32
+ ```json
33
+ { "version": 1, "exceptions": [
34
+ { "kind": "file-carve-out", "clause": "CD-25#dependency-isolation", "file": "src/legacy/billing.test.ts", "reason": "..." }
35
+ ] }
36
+ ```
37
+
38
+ Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -1,43 +1,31 @@
1
- # CD-25: Unit tests fake everything outside the unit
1
+ # CD-25: Unit tests replace everything outside the unit with test doubles
2
2
 
3
3
  ## Rule
4
4
 
5
- A unit test fakes everything outside the unit under test, injected through the unit's own seam — no real I/O, no real collaborators. The test exercises exactly one unit's logic, with every dependency a controlled fake, so a failure points at that unit and nowhere else.
5
+ A unit test replaces everything outside the unit under test with a test double, injected through the unit's own seam — no real I/O, no real collaborators. The test exercises exactly one unit's logic, with every dependency a controlled double, so a failure points at that unit and nowhere else.
6
6
 
7
- The sections below describe what the audit check covers.
7
+ **Test doubles.** These rules use Gerard Meszaros's names from *xUnit Test Patterns*, and only in these senses. A *dummy* is passed but never used. A *stub* returns canned answers. A *spy* is a stub that also records how it was called, for the test to assert afterwards. A *mock* is set up with expectations and verifies them itself. A *fake* is a working, lightweight implementation, such as an in-memory repository. The doubles a unit test builds itself are dummies, stubs and spies. A double that needs behaviour is a fake: it is written once as an in-memory implementation of the port, with its own tests, and passed in like any other double (a fake clock that the test advances is one), not built inline in a test.
8
8
 
9
- ## Clauses
9
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md), [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-25#dependency-isolation` | audit | `vi.fn(<implementation>)` and `.mockImplementation(...)` |
11
+ ## Spirit
14
12
 
15
- Review lens: [di-discipline](../../methods/lenses/di-discipline.md), [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What the friction is for.** A unit test should fail for one reason: this unit is wrong. The friction makes a stub with a canned answer the easiest double to write, so a failure points at one place and the unit's seams stay narrow.
16
14
 
17
- ## What the check flags
18
- - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
19
- - A `vi.fn(...)` call with any argument, and any call to a method named `mockImplementation` (on any receiver, with or without arguments).
20
- - Allowed: `vi.fn()`, `.mockReturnValue(...)`, `.mockResolvedValue(...)`, `.mockReturnValueOnce(...)` and `.mockImplementationOnce(...)`.
21
- - The source rule is wider (no real I/O, no real collaborators). Whether a unit is isolated is left to review.
15
+ **What a finding points at.** Match the sites against these causes.
16
+ - *A seam wider than its use.* The double needs logic because the port does many things or takes rich input. Narrow the port, and its inputs, to what this unit uses; a stub then answers its one question.
17
+ - *Behaviour hiding in a collaborator.* The double re-implements logic the unit relies on. That logic is a unit of its own with its own tests; a stub returns its result.
18
+ - *Real I/O in a unit test.* Files, on-disk fixtures, network, the clock. A dependency was reached for, not injected. Inject a port and give the test a stub, or the port's shared in-memory fake.
19
+ - *An integration test with a unit suffix.* It wires several units over real backings. Move it to the integration layer, and keep that layer thin.
22
20
 
23
- ## Example violation
24
- ```ts
25
- const clock = { now: vi.fn(() => 1) };
26
- ```
21
+ **Where to go.** Unit tests give every collaborator a stub or spy with canned answers, or the port's shared in-memory fake. On-disk fixtures are integration test tools: used at a bare minimum, only where the composition under test demands a real backing.
27
22
 
28
- ## How to fix
29
- ```ts
30
- const clock = { now: vi.fn().mockReturnValue(1) };
31
- ```
32
- Return a fixed value. If the fake needs logic, the seam is probably too wide.
23
+ **Reactions to distrust.**
24
+ - "It's just tests." The test is the unit's first consumer. A collaborator that is hard to replace with a double is a design finding.
25
+ - "The double must be realistic." Realism belongs in the few integration tests. A unit case needs one fixed answer.
26
+ - "A fixture file is easier." Easier once. Each one ties the test to real I/O and to data the reader cannot see in the test.
33
27
 
34
- ## Exceptions
35
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs a fake with an implementation. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
36
-
37
- ```json
38
- { "version": 1, "exceptions": [
39
- { "kind": "authorised-location", "clause": "CD-25#dependency-isolation", "file": "src/testing/fake-port.test.ts", "reason": "..." }
40
- ] }
41
- ```
42
-
43
- Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
28
+ **Principles behind it.**
29
+ - *Test doubles* (Gerard Meszaros, *xUnit Test Patterns*). Doubles come in kinds; the stub is the simplest double that answers, and a canned answer keeps the test about the unit rather than about the double.
30
+ - *Interface Segregation Principle* (Robert C. Martin, SOLID). A port shaped to one consumer's needs is trivial to stub; a stub that needs logic is reporting a port that serves too many needs.
31
+ - *The test pyramid* (Mike Cohn). Many fast isolated unit tests, few integration tests. Real backings and fixtures belong to the thin upper layer.
@@ -0,0 +1,36 @@
1
+ # CD-26 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-26#module-mocking` | audit | calls to `vi.mock` |
10
+
11
+ ## What the check flags
12
+ - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
13
+ - Every call spelled `vi.mock(...)`, with or without arguments.
14
+ - Not detected: `vi.doMock`, `jest.mock`, `vitest.mock` and `vi["mock"]`. Those are left to review.
15
+
16
+ ## Example violation
17
+ ```ts
18
+ vi.mock("./store.ts");
19
+ ```
20
+
21
+ ## How to fix
22
+ ```ts
23
+ const subject = createSubject({ store: storeStub });
24
+ ```
25
+ Pass the collaborator in as a dependency and hand the test a stub.
26
+
27
+ ## Exceptions
28
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs to intercept a module. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
29
+
30
+ ```json
31
+ { "version": 1, "exceptions": [
32
+ { "kind": "authorised-location", "clause": "CD-26#module-mocking", "file": "src/legacy/payments.test.ts", "reason": "..." }
33
+ ] }
34
+ ```
35
+
36
+ Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -2,41 +2,28 @@
2
2
 
3
3
  ## Rule
4
4
 
5
- Faking happens through the unit's own injected dependencies, never by intercepting the module system. A module-mock is a signal that the dependency injection is wrong: if a unit reaches for a collaborator the test cannot substitute through the signature, the collaborator should have been a port. Fix the seam, don't mock the module.
5
+ Test doubles are supplied through the unit's own injected dependencies, never by intercepting the module system. A module-mock, the test runner's name for replacing a module through the module system and not a mock in [the test-double sense](../CD-25/README.md#rule), is a signal that the dependency injection is wrong: if a unit reaches for a collaborator the test cannot substitute through the signature, the collaborator should have been a port. Fix the seam, don't mock the module.
6
6
 
7
- The sections below describe what the audit check covers.
7
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md), [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-26#module-mocking` | audit | calls to `vi.mock` |
11
+ **What the friction is for.** If a test can only control a dependency by intercepting imports, production cannot swap it either. The friction makes passing the collaborator in the easy route, so the unit is the same code under test and in production.
14
12
 
15
- Review lens: [di-discipline](../../methods/lenses/di-discipline.md), [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *A collaborator imported, not received.* The unit reaches its dependency through an import. Make it a port the unit receives in its argument.
15
+ - *No place that wires.* Nothing builds the real dependencies and passes them in, so imports are the only wiring there is. Create one composition root.
16
+ - *A port too big to stub.* Replacing the whole module is easier than writing doubles for a wide port. Narrow the port to what this unit uses.
17
+ - *Ambient capabilities.* Time, randomness, environment or the filesystem read directly. Same cause; see CD-17 and CD-19.
16
18
 
17
- ## What the check flags
18
- - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
19
- - Every call spelled `vi.mock(...)`, with or without arguments.
20
- - Not detected: `vi.doMock`, `jest.mock`, `vitest.mock` and `vi["mock"]`. Those are left to review.
19
+ **Where to go.** Every collaborator arrives through the unit's own signature. Tests hand in test doubles exactly the way production hands in the real thing. Start with the module mocked most often; one port at a time.
21
20
 
22
- ## Example violation
23
- ```ts
24
- vi.mock("./store.ts");
25
- ```
21
+ **Reactions to distrust.**
22
+ - "It's just tests." The module-mock is the test reporting the design. The fix is in the unit.
23
+ - "The framework's docs mock modules." A framework idiom does not make the seam right. Wrap the framework behind a port.
24
+ - "Rewiring is too big." It is one port at a time, and each one removes a module-mock for good.
26
25
 
27
- ## How to fix
28
- ```ts
29
- const subject = createSubject({ store: fakeStore });
30
- ```
31
- Pass the collaborator in as a dependency and hand the test a fake.
32
-
33
- ## Exceptions
34
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs to intercept a module. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
35
-
36
- ```json
37
- { "version": 1, "exceptions": [
38
- { "kind": "authorised-location", "clause": "CD-26#module-mocking", "file": "src/legacy/payments.test.ts", "reason": "..." }
39
- ] }
40
- ```
41
-
42
- Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
26
+ **Principles behind it.**
27
+ - *Dependency Inversion Principle* (Robert C. Martin, SOLID). The unit depends on an abstraction it is given, not on a concrete module it imports.
28
+ - *Dependency injection and the composition root.* Dependencies are built in one place and passed in, so any of them can be replaced without touching the unit.
29
+ - *Ports and adapters* (Alistair Cockburn, hexagonal architecture). A test is one more adapter plugged into the same port.
@@ -0,0 +1,45 @@
1
+ # CD-27 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-27#test-body-logic` | audit | branching, `let`, and computing methods in a test file |
10
+ | `CD-27#focused-tests` | eslint | `.only` on a test or suite, or `fdescribe`, `fit`, `ftest`, `fsuite` |
11
+ | `CD-27#skipped-tests` | eslint | `.skip` or `.fixme` on a test or suite, or `xdescribe`, `xit`, `xtest`, `xsuite` |
12
+
13
+ ## What the check flags
14
+ - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
15
+ - `if` statements, `try` statements, ternary expressions and `let` declarations.
16
+ - Any method call with a computing or mutating name, on any receiver: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
17
+ - Loops are not flagged here; CD-15 covers them. `throw` is CD-10.
18
+
19
+ ## What the ESLint check flags
20
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-27/README.md).
21
+ - `hone-cd27/focused-tests` flags `.only` on a `describe`, `it`, `test` or `suite` chain, including `.only.each` and `test.describe.only`, and the bare names `fdescribe`, `fit`, `ftest` and `fsuite`. It reports at the `only` token.
22
+ - `hone-cd27/skipped-tests` flags `.skip` and `.fixme` on those chains, and the bare names `xdescribe`, `xit`, `xtest` and `xsuite`.
23
+ - Not flagged: `.todo`, `.concurrent` and `.each`.
24
+
25
+ ## Example violation
26
+ ```ts
27
+ const expected = rows.map((row) => row.id);
28
+ ```
29
+
30
+ ## How to fix
31
+ ```ts
32
+ expect(ids).toEqual(["a1", "b2"]);
33
+ ```
34
+ Write the expected value out. A method call in the act step is flagged too, so move such logic into the unit under test.
35
+
36
+ ## Exceptions
37
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs logic. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
38
+
39
+ ```json
40
+ { "version": 1, "exceptions": [
41
+ { "kind": "authorised-location", "clause": "CD-27#test-body-logic", "file": "src/legacy/report.test.ts", "reason": "..." }
42
+ ] }
43
+ ```
44
+
45
+ Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -2,50 +2,28 @@
2
2
 
3
3
  ## Rule
4
4
 
5
- Test bodies are zero-logic straight lines: no branching, no loops, no try, no ternary, no computed expectations — just arrange, act, assert against hardcoded values. Logic in a test is untested code testing code; variability is faked and pinned, never accommodated with a conditional.
5
+ Test bodies are zero-logic straight lines: no branching, no loops, no try, no ternary, no computed expectations — just arrange, act, assert against hardcoded values. Logic in a test is untested code testing code; variability is supplied by a stub or a fake clock and pinned, never accommodated with a conditional.
6
6
 
7
- The sections below describe what the audit and ESLint checks cover.
7
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-27#test-body-logic` | audit | branching, `let`, and computing methods in a test file |
14
- | `CD-27#focused-tests` | eslint | `.only` on a test or suite, or `fdescribe`, `fit`, `ftest`, `fsuite` |
15
- | `CD-27#skipped-tests` | eslint | `.skip` or `.fixme` on a test or suite, or `xdescribe`, `xit`, `xtest`, `xsuite` |
11
+ **What the friction is for.** A test is the unit's specification, and it is read when it fails. Logic in a test is code with no test of its own. The friction makes a straight line with written-out expectations the easy test, so a failure can be trusted and read in one pass.
16
12
 
17
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *Output that is hard to predict.* Expectations are computed because the result varies with time, randomness or ordering. Inject the source of variation and pin it with a stub.
15
+ - *Several cases in one test.* A branch or a conditional picks between cases. Write one test per case, or one parameterised test over a table of rows.
16
+ - *The unit's logic repeated in the test.* The test derives the answer the way the unit does. Write the answer out. If that is hard, the unit returns too much for one case or does too much.
17
+ - *Failures caught to inspect them.* A try in a test means the unit throws where it could return its failure as data. Assert on the returned result.
18
+ - *Tests switched off or focused.* A skip or an only hides a failing, slow or flaky case. Fix it or delete it.
18
19
 
19
- ## What the check flags
20
- - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
21
- - `if` statements, `try` statements, ternary expressions and `let` declarations.
22
- - Any method call with a computing or mutating name, on any receiver: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
23
- - Loops are not flagged here; CD-15 covers them. `throw` is CD-10.
20
+ **Where to go.** Every test is arrange, act, assert, against literal values. Variation comes from injected stubs. N cases are N tests or one table.
24
21
 
25
- ## What the ESLint check flags
26
- Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-27/README.md).
27
- - `hone-cd27/focused-tests` flags `.only` on a `describe`, `it`, `test` or `suite` chain, including `.only.each` and `test.describe.only`, and the bare names `fdescribe`, `fit`, `ftest` and `fsuite`. It reports at the `only` token.
28
- - `hone-cd27/skipped-tests` flags `.skip` and `.fixme` on those chains, and the bare names `xdescribe`, `xit`, `xtest` and `xsuite`.
29
- - Not flagged: `.todo`, `.concurrent` and `.each`.
22
+ **Reactions to distrust.**
23
+ - "It's just a helper in the test." A helper with logic is untested code deciding whether other code passes.
24
+ - "Written-out values are brittle." They break when behaviour changes. That is their job.
25
+ - "The expected value is too big to write." Then the test asserts more than the unit's own responsibility, or the unit does too much.
30
26
 
31
- ## Example violation
32
- ```ts
33
- const expected = rows.map((row) => row.id);
34
- ```
35
-
36
- ## How to fix
37
- ```ts
38
- expect(ids).toEqual(["a1", "b2"]);
39
- ```
40
- Write the expected value out. A method call in the act step is flagged too, so move such logic into the unit under test.
41
-
42
- ## Exceptions
43
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs logic. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
44
-
45
- ```json
46
- { "version": 1, "exceptions": [
47
- { "kind": "authorised-location", "clause": "CD-27#test-body-logic", "file": "src/legacy/report.test.ts", "reason": "..." }
48
- ] }
49
- ```
50
-
51
- Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
27
+ **Principles behind it.**
28
+ - *Conditional Test Logic* (a test smell in Gerard Meszaros, *xUnit Test Patterns*). A test with branches can pass without checking what it claims to check.
29
+ - *Arrange, act, assert.* One setup, one action, one check: the shape that makes a test a readable specification.
@@ -0,0 +1,13 @@
1
+ # CD-28 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-28#unit-responsibility` | review | a test asserts the unit's output and its direct collaborator calls only |
10
+
11
+ ## How it is checked
12
+
13
+ Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
@@ -4,16 +4,22 @@
4
4
 
5
5
  A test asserts the unit's own direct responsibility — its returned output and the calls it makes to its collaborators — not the transitive internals of those collaborators. Asserting through a dependency couples the test to code the unit does not own and makes it fail for the wrong reasons.
6
6
 
7
- The sections below describe how the rule is checked.
7
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-28#unit-responsibility` | review | a test asserts the unit's output and its direct collaborator calls only |
11
+ **What the friction is for.** A test that checks what a collaborator does breaks when that collaborator changes, even if this unit did not. The friction keeps each test on its own unit, so a failure means this unit broke.
14
12
 
15
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the tests against these causes.
14
+ - *Assertions reaching through stubs.* The test checks what a stub returned, not what the unit did with it. Assert the unit's output and the calls it made.
15
+ - *A real collaborator in the test.* The test asserts results produced by code it does not own. Replace it with a stub.
16
+ - *A unit that passes values through.* The only thing to check is a delegate's output. The unit may have no responsibility of its own; question it.
16
17
 
17
- ## How it is checked
18
+ **Where to go.** Each test asserts the unit's own output and the exact calls it makes. Collaborators have their own tests.
18
19
 
19
- Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies the rule above with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
20
+ **Reactions to distrust.**
21
+ - "Testing through gives more confidence." It gives confidence about the collaborator, and blame in the wrong place when it fails.
22
+
23
+ **Principles behind it.**
24
+ - *Defect localisation.* A test that can fail only when its own unit is wrong points straight at the fault.
25
+ - *Fragile Test* (a test smell in Gerard Meszaros, *xUnit Test Patterns*). Tests that depend on more than the unit break for reasons unrelated to it.
@@ -0,0 +1,13 @@
1
+ # CD-29 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-29#test-pyramid` | review | unit tests form the bulk and component or integration tests stay few |
10
+
11
+ ## How it is checked
12
+
13
+ Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
@@ -4,16 +4,20 @@
4
4
 
5
5
  Integration tests are the thin layer of the pyramid, not its bulk: many unit tests at the base, few component tests in the middle, a thin smoke layer on top. Inverting the pyramid — leaning on slow, broad integration tests to catch what unit tests should — is forbidden.
6
6
 
7
- The sections below describe how the rule is checked.
7
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-29#test-pyramid` | review | unit tests form the bulk and component or integration tests stay few |
11
+ **What the friction is for.** Broad tests are slow and say little about where a fault is. The friction keeps most tests small and fast, so the suite runs often and failures point at one unit.
14
12
 
15
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the suite against these causes.
14
+ - *Units that cannot be tested alone.* Integration tests carry the load because units take no injected dependencies. Inject them; unit tests follow.
15
+ - *Logic tested through the system.* Business rules are checked end to end. Move each rule's cases to the unit that owns it.
16
16
 
17
- ## How it is checked
17
+ **Where to go.** Many unit tests, few component tests, a thin smoke layer.
18
18
 
19
- Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies the rule above with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
19
+ **Reactions to distrust.**
20
+ - "Integration tests catch real bugs." They catch wiring bugs. Logic bugs belong to unit tests that run in milliseconds.
21
+
22
+ **Principles behind it.**
23
+ - *The test pyramid* (Mike Cohn). Many fast unit tests at the base, fewer broader tests above.