@hailstails/hone 0.0.0-stage → 0.1.0-pre.2

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 (186) hide show
  1. package/ADOPTING.md +314 -0
  2. package/LICENSE +17 -0
  3. package/MIGRATING.md +238 -0
  4. package/README.md +216 -2
  5. package/THIRD-PARTY-NOTICES.md +354 -0
  6. package/chunks/chunk-233U4FBA.js +42 -0
  7. package/chunks/chunk-7ZJZZBSS.js +14909 -0
  8. package/chunks/chunk-HBY4ZWSP.js +79 -0
  9. package/chunks/chunk-HJA4CX7C.js +24 -0
  10. package/chunks/chunk-NZLE2WMY.js +35 -0
  11. package/chunks/chunk-QWA6OVLC.js +11 -0
  12. package/chunks/chunk-TRCB27ET.js +202 -0
  13. package/core/check/tool-command.js +2305 -0
  14. package/docs/adding-a-discipline-or-mechanism.md +195 -0
  15. package/docs/why-chain-contract.md +78 -0
  16. package/mechanisms/audit/CD-1/any-cast.js +81 -0
  17. package/mechanisms/audit/CD-1/piece.json +13 -0
  18. package/mechanisms/audit/CD-10/piece.json +13 -0
  19. package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
  20. package/mechanisms/audit/CD-14/class-syntax.js +70 -0
  21. package/mechanisms/audit/CD-14/piece.json +13 -0
  22. package/mechanisms/audit/CD-15/loops.js +40 -0
  23. package/mechanisms/audit/CD-15/piece.json +13 -0
  24. package/mechanisms/audit/CD-17/clock-sources.js +29 -0
  25. package/mechanisms/audit/CD-17/piece.json +13 -0
  26. package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
  27. package/mechanisms/audit/CD-19/piece.json +13 -0
  28. package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
  29. package/mechanisms/audit/CD-2/piece.json +13 -0
  30. package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
  31. package/mechanisms/audit/CD-23/piece.json +13 -0
  32. package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
  33. package/mechanisms/audit/CD-25/piece.json +13 -0
  34. package/mechanisms/audit/CD-26/module-mocking.js +51 -0
  35. package/mechanisms/audit/CD-26/piece.json +13 -0
  36. package/mechanisms/audit/CD-27/piece.json +13 -0
  37. package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
  38. package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
  39. package/mechanisms/audit/CD-3/piece.json +49 -0
  40. package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
  41. package/mechanisms/audit/CD-43/piece.json +13 -0
  42. package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
  43. package/mechanisms/audit/CD-44/piece.json +13 -0
  44. package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
  45. package/mechanisms/audit/CD-47/piece.json +13 -0
  46. package/mechanisms/audit/CD-5/comments-directives.js +73 -0
  47. package/mechanisms/audit/CD-5/piece.json +13 -0
  48. package/mechanisms/audit/CD-6/identifier-names.js +132 -0
  49. package/mechanisms/audit/CD-6/piece.json +13 -0
  50. package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
  51. package/mechanisms/audit/CD-7/piece.json +13 -0
  52. package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
  53. package/mechanisms/audit/CD-7a/piece.json +13 -0
  54. package/mechanisms/audit/CD-8/piece.json +13 -0
  55. package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
  56. package/mechanisms/audit/runner/README.md +38 -0
  57. package/mechanisms/audit/runner/runner.js +546 -0
  58. package/mechanisms/eslint/CD-1/README.md +12 -0
  59. package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
  60. package/mechanisms/eslint/CD-1/piece.json +23 -0
  61. package/mechanisms/eslint/CD-10/README.md +9 -0
  62. package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
  63. package/mechanisms/eslint/CD-10/piece.json +15 -0
  64. package/mechanisms/eslint/CD-14/README.md +11 -0
  65. package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
  66. package/mechanisms/eslint/CD-14/piece.json +31 -0
  67. package/mechanisms/eslint/CD-27/README.md +12 -0
  68. package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
  69. package/mechanisms/eslint/CD-27/piece.json +23 -0
  70. package/mechanisms/eslint/CD-40/README.md +7 -0
  71. package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
  72. package/mechanisms/eslint/CD-40/piece.json +21 -0
  73. package/mechanisms/eslint/CD-41/README.md +12 -0
  74. package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
  75. package/mechanisms/eslint/CD-41/piece.json +23 -0
  76. package/mechanisms/eslint/CD-42/README.md +9 -0
  77. package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
  78. package/mechanisms/eslint/CD-42/piece.json +15 -0
  79. package/mechanisms/eslint/CD-44/README.md +7 -0
  80. package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
  81. package/mechanisms/eslint/CD-44/piece.json +20 -0
  82. package/mechanisms/eslint/CD-6/README.md +9 -0
  83. package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
  84. package/mechanisms/eslint/CD-6/piece.json +217 -0
  85. package/mechanisms/eslint/CD-7/README.md +9 -0
  86. package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
  87. package/mechanisms/eslint/CD-7/piece.json +15 -0
  88. package/mechanisms/eslint/runner/README.md +43 -0
  89. package/mechanisms/eslint/runner/runner.js +4248 -0
  90. package/methods/README.md +18 -0
  91. package/methods/lenses/clean-architecture.md +167 -0
  92. package/methods/lenses/decomposition.md +159 -0
  93. package/methods/lenses/defended-on-intent.md +178 -0
  94. package/methods/lenses/di-discipline.md +156 -0
  95. package/methods/lenses/errors-as-data.md +88 -0
  96. package/methods/lenses/function-first.md +193 -0
  97. package/methods/lenses/naming.md +127 -0
  98. package/methods/lenses/test-discipline.md +166 -0
  99. package/methods/lenses/type-soundness.md +135 -0
  100. package/methods/lenses/zod-boundary.md +158 -0
  101. package/package.json +65 -4
  102. package/rules/CD-1/README.md +43 -0
  103. package/rules/CD-1/discipline.json +185 -0
  104. package/rules/CD-10/README.md +55 -0
  105. package/rules/CD-10/discipline.json +133 -0
  106. package/rules/CD-11/README.md +19 -0
  107. package/rules/CD-11/discipline.json +12 -0
  108. package/rules/CD-12/README.md +19 -0
  109. package/rules/CD-12/discipline.json +12 -0
  110. package/rules/CD-13/README.md +19 -0
  111. package/rules/CD-13/discipline.json +12 -0
  112. package/rules/CD-14/README.md +54 -0
  113. package/rules/CD-14/discipline.json +173 -0
  114. package/rules/CD-15/README.md +48 -0
  115. package/rules/CD-15/discipline.json +73 -0
  116. package/rules/CD-16/README.md +17 -0
  117. package/rules/CD-17/README.md +42 -0
  118. package/rules/CD-17/discipline.json +51 -0
  119. package/rules/CD-18/README.md +19 -0
  120. package/rules/CD-18/discipline.json +12 -0
  121. package/rules/CD-19/README.md +45 -0
  122. package/rules/CD-19/discipline.json +65 -0
  123. package/rules/CD-2/README.md +43 -0
  124. package/rules/CD-2/discipline.json +65 -0
  125. package/rules/CD-20/README.md +17 -0
  126. package/rules/CD-21/README.md +19 -0
  127. package/rules/CD-21/discipline.json +12 -0
  128. package/rules/CD-22/README.md +19 -0
  129. package/rules/CD-22/discipline.json +12 -0
  130. package/rules/CD-23/README.md +41 -0
  131. package/rules/CD-23/discipline.json +57 -0
  132. package/rules/CD-24/README.md +17 -0
  133. package/rules/CD-25/README.md +43 -0
  134. package/rules/CD-25/discipline.json +57 -0
  135. package/rules/CD-26/README.md +42 -0
  136. package/rules/CD-26/discipline.json +57 -0
  137. package/rules/CD-27/README.md +51 -0
  138. package/rules/CD-27/discipline.json +233 -0
  139. package/rules/CD-28/README.md +19 -0
  140. package/rules/CD-28/discipline.json +12 -0
  141. package/rules/CD-29/README.md +19 -0
  142. package/rules/CD-29/discipline.json +12 -0
  143. package/rules/CD-3/README.md +48 -0
  144. package/rules/CD-3/discipline.json +363 -0
  145. package/rules/CD-30/README.md +19 -0
  146. package/rules/CD-30/discipline.json +12 -0
  147. package/rules/CD-31/README.md +19 -0
  148. package/rules/CD-31/discipline.json +12 -0
  149. package/rules/CD-32/README.md +19 -0
  150. package/rules/CD-32/discipline.json +12 -0
  151. package/rules/CD-33/README.md +19 -0
  152. package/rules/CD-33/discipline.json +12 -0
  153. package/rules/CD-34/README.md +19 -0
  154. package/rules/CD-34/discipline.json +12 -0
  155. package/rules/CD-39/README.md +19 -0
  156. package/rules/CD-39/discipline.json +12 -0
  157. package/rules/CD-4/README.md +19 -0
  158. package/rules/CD-4/discipline.json +12 -0
  159. package/rules/CD-40/README.md +45 -0
  160. package/rules/CD-40/discipline.json +58 -0
  161. package/rules/CD-41/README.md +60 -0
  162. package/rules/CD-41/discipline.json +124 -0
  163. package/rules/CD-42/README.md +53 -0
  164. package/rules/CD-42/discipline.json +61 -0
  165. package/rules/CD-43/README.md +43 -0
  166. package/rules/CD-43/discipline.json +65 -0
  167. package/rules/CD-44/README.md +54 -0
  168. package/rules/CD-44/discipline.json +111 -0
  169. package/rules/CD-45/README.md +19 -0
  170. package/rules/CD-45/discipline.json +12 -0
  171. package/rules/CD-46/README.md +13 -0
  172. package/rules/CD-47/README.md +47 -0
  173. package/rules/CD-47/discipline.json +57 -0
  174. package/rules/CD-5/README.md +46 -0
  175. package/rules/CD-5/discipline.json +65 -0
  176. package/rules/CD-6/README.md +57 -0
  177. package/rules/CD-6/discipline.json +165 -0
  178. package/rules/CD-7/README.md +52 -0
  179. package/rules/CD-7/discipline.json +142 -0
  180. package/rules/CD-7a/README.md +44 -0
  181. package/rules/CD-7a/discipline.json +57 -0
  182. package/rules/CD-8/README.md +48 -0
  183. package/rules/CD-8/discipline.json +57 -0
  184. package/rules/CD-9/README.md +19 -0
  185. package/rules/CD-9/discipline.json +12 -0
  186. package/rules/README.md +52 -0
@@ -0,0 +1,17 @@
1
+ # CD-20: Runtime stdlib imports arrive through injected ports
2
+
3
+ ## Rule
4
+
5
+ Collapsed into [CD-19](../CD-19/README.md) — confining the
6
+ runtime's own standard library behind a wrapping port is the same intent as
7
+ confining a third-party dependency (CD-20 was originally split out of CD-19). CD-19
8
+ now covers both third-party and stdlib dependencies. This id is retained as a
9
+ redirect so existing citations resolve; it is not independently enforced.
10
+
11
+ The sections below describe how the rule is checked.
12
+
13
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md). The lens reviews the whole rule, including what no check flags.
14
+
15
+ ## How it is checked
16
+
17
+ This discipline has no clauses of its own. Its rule is carried by [CD-19](../CD-19/README.md); select that discipline's clauses instead.
@@ -0,0 +1,19 @@
1
+ # CD-21: Every injected port ships a default production factory
2
+
3
+ ## Rule
4
+
5
+ A port is not just an interface — it ships its own default production implementation, co-located in the same module. Wiring is then trivial and there is exactly one canonical construction site per capability; production wires the default, tests supply their own fakes. A port with no default factory is an incomplete capability.
6
+
7
+ The sections below describe how the rule is checked.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-21#default-factories` | review | each injected port ships one default production factory |
14
+
15
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md). The lens reviews the whole rule, including what no check flags.
16
+
17
+ ## How it is checked
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-21",
4
+ "clauses": [
5
+ {
6
+ "kind": "judgement",
7
+ "id": "default-factories",
8
+ "summary": "each injected port ships one default production factory",
9
+ "enforcedBy": "review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,19 @@
1
+ # CD-22: Middleware generic context constraint
2
+
3
+ ## Rule
4
+
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
+
7
+ The sections below describe how the rule is checked.
8
+
9
+ ## Clauses
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 |
14
+
15
+ Review lens: [di-discipline](../../methods/lenses/di-discipline.md). The lens reviews the whole rule, including what no check flags.
16
+
17
+ ## How it is checked
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-22",
4
+ "clauses": [
5
+ {
6
+ "kind": "judgement",
7
+ "id": "middleware-context",
8
+ "summary": "middleware reads its context through a constrained generic, not an open property bag",
9
+ "enforcedBy": "review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,41 @@
1
+ # CD-23: Every unit has a co-located test sibling
2
+
3
+ ## Rule
4
+
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
+
7
+ The sections below describe what the audit check covers.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-23#export-test-sibling` | audit | a production file with a runtime export and no `.test` sibling |
14
+
15
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
16
+
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.
22
+
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.
28
+
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.
@@ -0,0 +1,57 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-23",
4
+ "clauses": [
5
+ {
6
+ "kind": "mechanical",
7
+ "id": "export-test-sibling",
8
+ "summary": "Every unit has a co-located test sibling",
9
+ "mechanisms": [
10
+ "audit"
11
+ ],
12
+ "anchor": {
13
+ "kind": "file"
14
+ },
15
+ "cases": {
16
+ "flag": [
17
+ {
18
+ "name": "runtime const export without sibling",
19
+ "fileName": "src/price.ts",
20
+ "source": "export const price = 1;\n",
21
+ "expectedLines": [
22
+ 1
23
+ ]
24
+ },
25
+ {
26
+ "name": "function export without sibling",
27
+ "fileName": "src/format.ts",
28
+ "source": "export function format(): string {\n return \"\";\n}\n",
29
+ "expectedLines": [
30
+ 1
31
+ ]
32
+ }
33
+ ],
34
+ "allow": [
35
+ {
36
+ "name": "type-only exports",
37
+ "fileName": "src/types-only.ts",
38
+ "source": "export interface Account { readonly id: string }\nexport type Id = string;\n",
39
+ "expectedLines": []
40
+ },
41
+ {
42
+ "name": "no exports",
43
+ "fileName": "src/internal.ts",
44
+ "source": "const hidden = 1;\n",
45
+ "expectedLines": []
46
+ },
47
+ {
48
+ "name": "test file is not a production file",
49
+ "fileName": "src/price.test.ts",
50
+ "source": "export const price = 1;\n",
51
+ "expectedLines": []
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ]
57
+ }
@@ -0,0 +1,17 @@
1
+ # CD-24: Every file is unit-tested
2
+
3
+ ## Rule
4
+
5
+ Collapsed into [CD-23](../CD-23/README.md) — "every file is unit-tested"
6
+ and "tests are co-located" are one intent: every unit has a co-located test
7
+ sibling. The enforcing walker already computes them as a single check. CD-23 now
8
+ carries both. This id is retained as a redirect so existing citations resolve; it
9
+ is not independently enforced.
10
+
11
+ The sections below describe how the rule is checked.
12
+
13
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
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.
@@ -0,0 +1,43 @@
1
+ # CD-25: Unit tests fake everything outside the unit
2
+
3
+ ## Rule
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.
6
+
7
+ The sections below describe what the audit check covers.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-25#dependency-isolation` | audit | `vi.fn(<implementation>)` and `.mockImplementation(...)` |
14
+
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.
16
+
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.
22
+
23
+ ## Example violation
24
+ ```ts
25
+ const clock = { now: vi.fn(() => 1) };
26
+ ```
27
+
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.
33
+
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.
@@ -0,0 +1,57 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-25",
4
+ "clauses": [
5
+ {
6
+ "kind": "mechanical",
7
+ "id": "dependency-isolation",
8
+ "summary": "Unit tests fake everything outside the unit",
9
+ "mechanisms": [
10
+ "audit"
11
+ ],
12
+ "anchor": {
13
+ "kind": "file"
14
+ },
15
+ "cases": {
16
+ "flag": [
17
+ {
18
+ "name": "vi.fn with an implementation",
19
+ "fileName": "clock.test.ts",
20
+ "source": "const clock = { now: vi.fn(() => 1) };\n",
21
+ "expectedLines": [
22
+ 1
23
+ ]
24
+ },
25
+ {
26
+ "name": "mockImplementation call",
27
+ "fileName": "port.test.ts",
28
+ "source": "const port = vi.fn();\nport.mockImplementation(() => 2);\n",
29
+ "expectedLines": [
30
+ 2
31
+ ]
32
+ }
33
+ ],
34
+ "allow": [
35
+ {
36
+ "name": "vi.fn with a fixed return value",
37
+ "fileName": "value.test.ts",
38
+ "source": "const port = vi.fn().mockReturnValue(1);\n",
39
+ "expectedLines": []
40
+ },
41
+ {
42
+ "name": "mockResolvedValue",
43
+ "fileName": "resolved.test.ts",
44
+ "source": "const port = vi.fn().mockResolvedValue(1);\n",
45
+ "expectedLines": []
46
+ },
47
+ {
48
+ "name": "vi.fn with an implementation outside a test file",
49
+ "fileName": "helper.ts",
50
+ "source": "export const port = vi.fn(() => 1);\n",
51
+ "expectedLines": []
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ]
57
+ }
@@ -0,0 +1,42 @@
1
+ # CD-26: No module-mocking — module-mock means DI is wrong
2
+
3
+ ## Rule
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.
6
+
7
+ The sections below describe what the audit check covers.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-26#module-mocking` | audit | calls to `vi.mock` |
14
+
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.
16
+
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.
21
+
22
+ ## Example violation
23
+ ```ts
24
+ vi.mock("./store.ts");
25
+ ```
26
+
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.
@@ -0,0 +1,57 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-26",
4
+ "clauses": [
5
+ {
6
+ "kind": "mechanical",
7
+ "id": "module-mocking",
8
+ "summary": "No module-mocking — module-mock means DI is wrong",
9
+ "mechanisms": [
10
+ "audit"
11
+ ],
12
+ "anchor": {
13
+ "kind": "file"
14
+ },
15
+ "cases": {
16
+ "flag": [
17
+ {
18
+ "name": "vi.mock of a module",
19
+ "fileName": "store.test.ts",
20
+ "source": "vi.mock(\"./store.ts\");\n",
21
+ "expectedLines": [
22
+ 1
23
+ ]
24
+ },
25
+ {
26
+ "name": "vi.mock in a tsx test",
27
+ "fileName": "view.test.tsx",
28
+ "source": "import { vi } from \"vitest\";\nvi.mock(\"module\");\n",
29
+ "expectedLines": [
30
+ 2
31
+ ]
32
+ }
33
+ ],
34
+ "allow": [
35
+ {
36
+ "name": "injected fake port",
37
+ "fileName": "port.test.ts",
38
+ "source": "const port = vi.fn();\nconst other = { mock: vi.fn() };\n",
39
+ "expectedLines": []
40
+ },
41
+ {
42
+ "name": "vi.mock outside a test file",
43
+ "fileName": "helper.ts",
44
+ "source": "vi.mock(\"module\");\n",
45
+ "expectedLines": []
46
+ },
47
+ {
48
+ "name": "bracket access is not detected",
49
+ "fileName": "bracket.test.ts",
50
+ "source": "vi[\"mock\"](\"module\");\n",
51
+ "expectedLines": []
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ]
57
+ }
@@ -0,0 +1,51 @@
1
+ # CD-27: Tests are zero-everything — zero logic, zero branches, zero unpredictability
2
+
3
+ ## Rule
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.
6
+
7
+ The sections below describe what the audit and ESLint checks cover.
8
+
9
+ ## Clauses
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` |
16
+
17
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
18
+
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.
24
+
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`.
30
+
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.