@hailstails/hone 2.0.0-pre.3 → 2.0.0-pre.5

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 (282) hide show
  1. package/ADOPTING.md +9 -20
  2. package/CHANGELOG.md +104 -0
  3. package/MIGRATING.md +18 -9
  4. package/README.md +15 -17
  5. package/chunks/chunk-3CWFUD5B.js +38 -0
  6. package/chunks/chunk-4AJQHZ7I.js +191 -0
  7. package/chunks/chunk-5AKHEW6V.js +15 -0
  8. package/chunks/{chunk-L7BGRC6D.js → chunk-6LTJRJOE.js} +1 -1
  9. package/chunks/chunk-75XWZYNN.js +64 -0
  10. package/chunks/{chunk-ASUN4AVC.js → chunk-BISP2JOL.js} +73 -9
  11. package/chunks/chunk-COQMPHWZ.js +37 -0
  12. package/chunks/chunk-D6645WPB.js +6 -0
  13. package/chunks/chunk-DJMF6JIM.js +42 -0
  14. package/chunks/chunk-EBX57Z3V.js +8 -0
  15. package/chunks/chunk-EFUWHLZK.js +426 -0
  16. package/chunks/chunk-FHVNKG5Q.js +19 -0
  17. package/chunks/{chunk-NRIQD3PI.js → chunk-FRE5IA3C.js} +3 -5
  18. package/chunks/{chunk-OKLYWD2Z.js → chunk-GMLT3MHO.js} +262 -257
  19. package/chunks/{chunk-QP5TLOBY.js → chunk-HVZVKZPW.js} +12 -9
  20. package/chunks/chunk-LEFM7OPS.js +41 -0
  21. package/chunks/chunk-LNMDMRGQ.js +51 -0
  22. package/chunks/chunk-M4VSJ27S.js +139 -0
  23. package/chunks/{chunk-RGSHTPLA.js → chunk-MBEDAFVC.js} +3 -11
  24. package/chunks/chunk-ND3EOGDK.js +2350 -0
  25. package/chunks/chunk-ONDBACCR.js +14332 -0
  26. package/chunks/chunk-OO5KV7KN.js +17 -0
  27. package/chunks/chunk-SKDQ3QJD.js +75 -0
  28. package/chunks/chunk-U6W65ZOF.js +86 -0
  29. package/chunks/chunk-W5OIAUDW.js +18 -0
  30. package/chunks/{chunk-GNOMK7CR.js → chunk-WPEOCLTP.js} +495 -52
  31. package/chunks/chunk-X73RZUPO.js +63 -0
  32. package/chunks/chunk-XE2KKWYH.js +45 -0
  33. package/chunks/chunk-XNIXPQQ5.js +179 -0
  34. package/chunks/chunk-YONPKP3C.js +15 -0
  35. package/docs/adding-a-discipline-or-mechanism.md +1 -1
  36. package/docs/extending.md +7 -388
  37. package/methods/lenses/function-first.md +2 -2
  38. package/package.json +7 -6
  39. package/rules/README.md +7 -5
  40. package/rules/SPIRIT.md +1 -1
  41. package/rules/numbers.md +4 -4
  42. package/rules/principles/no-leak-across-a-boundary.md +1 -1
  43. package/rules/principles.md +1 -1
  44. package/rules/record-kinds/authorised-location.md +1 -1
  45. package/rules/records.md +11 -19
  46. package/rules/rules.md +5 -5
  47. package/rules/sources.md +6 -7
  48. package/rules/typescript/checks.md +280 -394
  49. package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
  50. package/rules/typescript/recipes/assert-to-narrow.md +114 -4
  51. package/rules/typescript/recipes/closure-factory.md +5 -5
  52. package/rules/typescript/recipes/companion-test-file.md +5 -3
  53. package/rules/typescript/recipes/composed-orchestrator.md +6 -4
  54. package/rules/typescript/recipes/composition-root.md +5 -3
  55. package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
  56. package/rules/typescript/recipes/copy-never-write-in.md +6 -4
  57. package/rules/typescript/recipes/declared-not-bundled.md +5 -3
  58. package/rules/typescript/recipes/dependency-record.md +5 -3
  59. package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
  60. package/rules/typescript/recipes/entity-module.md +8 -5
  61. package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
  62. package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
  63. package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
  64. package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
  65. package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
  66. package/rules/typescript/recipes/functional-iteration.md +8 -3
  67. package/rules/typescript/recipes/guard-clauses.md +5 -3
  68. package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
  69. package/rules/typescript/recipes/integration-test-suffix.md +5 -3
  70. package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
  71. package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
  72. package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
  73. package/rules/typescript/recipes/named-exported-type.md +5 -3
  74. package/rules/typescript/recipes/narrow-ports.md +5 -3
  75. package/rules/typescript/recipes/one-argument-object.md +8 -3
  76. package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
  77. package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
  78. package/rules/typescript/recipes/repo-scripts-only.md +5 -3
  79. package/rules/typescript/recipes/result-union.md +5 -5
  80. package/rules/typescript/recipes/screaming-folders.md +5 -5
  81. package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
  82. package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
  83. package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
  84. package/rules/typescript/recipes/whole-words.md +5 -3
  85. package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
  86. package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
  87. package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
  88. package/rules/typescript/recipes.md +567 -21
  89. package/rules/typescript/symptoms/ambient-randomness/random-call.md +10 -0
  90. package/rules/typescript/symptoms/ambient-randomness.md +1 -1
  91. package/rules/typescript/symptoms/answer-set-in-a-hook/hook-answer.md +10 -0
  92. package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
  93. package/rules/typescript/symptoms/assertion-outside-a-test-body/assertion-site.md +10 -0
  94. package/rules/typescript/symptoms/assertion-outside-a-test-body.md +25 -0
  95. package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
  96. package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
  97. package/rules/typescript/symptoms/built-unit-called-in-place/call-of-a-call.md +10 -0
  98. package/rules/typescript/symptoms/built-unit-called-in-place.md +25 -0
  99. package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
  100. package/rules/typescript/symptoms/code-or-prose-read-as-text-in-a-test/raw-read.md +10 -0
  101. package/rules/typescript/symptoms/code-or-prose-read-as-text-in-a-test.md +31 -0
  102. package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
  103. package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
  104. package/rules/typescript/symptoms/date-used-directly.md +1 -1
  105. package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
  106. package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +2 -19
  107. package/rules/typescript/symptoms/double-with-a-body/stub-implementation.md +2 -2
  108. package/rules/typescript/symptoms/double-with-a-body.md +1 -1
  109. package/rules/typescript/symptoms/export-from-a-test/test-file-export.md +10 -0
  110. package/rules/typescript/symptoms/export-from-a-test.md +33 -0
  111. package/rules/typescript/symptoms/failure-shaped-as-success/empty-catch.md +10 -0
  112. package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
  113. package/rules/typescript/symptoms/floating-version/version-selector.md +10 -0
  114. package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +2 -2
  115. package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
  116. package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
  117. package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
  118. package/rules/typescript/symptoms/many-spellings-of-one-concept/test-call-aliases.md +10 -0
  119. package/rules/typescript/symptoms/many-spellings-of-one-concept.md +3 -2
  120. package/rules/typescript/symptoms/module-or-global-patched/module-mock-call.md +4 -4
  121. package/rules/typescript/symptoms/no-lock-file/committed-lock-file.md +12 -0
  122. package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
  123. package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
  124. package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
  125. package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
  126. package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
  127. package/rules/typescript/symptoms/process-global-used-in-place/debugger-statement.md +10 -0
  128. package/rules/typescript/symptoms/process-global-used-in-place/direct-global-use.md +14 -0
  129. package/rules/typescript/symptoms/process-global-used-in-place.md +2 -2
  130. package/rules/typescript/symptoms/prose-in-code/comment-prose.md +12 -0
  131. package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
  132. package/rules/typescript/symptoms/rebinding.md +11 -1
  133. package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
  134. package/rules/typescript/symptoms/test-switched-off/skipped-tests.md +3 -6
  135. package/rules/typescript/symptoms/test-switched-off.md +1 -1
  136. package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
  137. package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
  138. package/rules/typescript/symptoms/throw-between-our-units/throw-statement.md +10 -0
  139. package/rules/typescript/symptoms/throw-or-catch-in-a-test/throw-statement.md +1 -1
  140. package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
  141. package/rules/typescript/symptoms/tool-fetched-at-run-time/fetch-command.md +10 -0
  142. package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +10 -0
  143. package/rules/typescript/symptoms/type-declared-in-a-test.md +33 -0
  144. package/rules/typescript/symptoms/unasserted-call.md +1 -1
  145. package/rules/typescript/symptoms/unit-without-a-running-test/companion-test-file.md +2 -2
  146. package/rules/typescript/symptoms/wide-input/unread-parameter.md +10 -0
  147. package/rules/typescript/symptoms/wide-input.md +3 -2
  148. package/rules/typescript/symptoms.md +210 -148
  149. package/src/application/conformance/conformance-testing-types.d.ts +13 -16
  150. package/src/domain/language-layer/authored-item-types.d.ts +66 -0
  151. package/src/domain/language-layer/catalogue-name.d.ts +5 -0
  152. package/src/domain/language-layer/check-address-text.d.ts +12 -0
  153. package/src/domain/rule-set/authored-rule-set-types.d.ts +31 -32
  154. package/src/domain/rule-set/clause-address-types.d.ts +4 -3
  155. package/src/domain/rule-set/rule-set-name-of.d.ts +10 -0
  156. package/src/domain/runner/check-binding.d.ts +18 -0
  157. package/src/domain/runner/check-observations.d.ts +39 -0
  158. package/src/domain/runner/conformance-types.d.ts +8 -2
  159. package/src/domain/runner/runner-result-types.d.ts +1 -2
  160. package/src/domain/settings/test-files.d.ts +7 -0
  161. package/src/eslint-plugin.js +45 -39
  162. package/src/hone.js +16 -13716
  163. package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
  164. package/src/infrastructure/engines/eslint/authored-class-or-this/static-members-only/piece.json +0 -6
  165. package/src/infrastructure/engines/eslint/long-function/function-length/piece.json +0 -6
  166. package/src/infrastructure/engines/eslint/runner/pieces/eslint-piece-settings-types.d.ts +2 -0
  167. package/src/infrastructure/engines/eslint/runner/runner.js +1001 -1234
  168. package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/README.md +0 -3
  169. package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/eslint-plugin.js +33 -21
  170. package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/piece.json +11 -4
  171. package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/skipped-tests.examples.json +28 -0
  172. package/src/infrastructure/engines/eslint/untyped-value/implicit-any-let/piece.json +0 -2
  173. package/src/infrastructure/engines/eslint/wide-input/unread-parameter/eslint-plugin.js +94 -0
  174. package/src/infrastructure/engines/eslint/wide-input/unread-parameter/piece.json +11 -0
  175. package/src/infrastructure/engines/eslint/wide-input/unread-parameter/unread-parameter.examples.json +48 -0
  176. package/src/infrastructure/engines/walker/ambient-randomness/random-call/ambient-randomness.js +109 -0
  177. package/src/infrastructure/engines/walker/ambient-randomness/random-call/piece.json +9 -0
  178. package/src/infrastructure/engines/walker/ambient-randomness/random-call/random-call.examples.json +48 -0
  179. package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/hook-answer.examples.json +42 -0
  180. package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/hook-answers.js +72 -0
  181. package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/piece.json +9 -0
  182. package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/assertion-site.examples.json +30 -0
  183. package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/assertion-site.js +123 -0
  184. package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/piece.json +9 -0
  185. package/src/infrastructure/engines/walker/authored-class-or-this/class-keyword/class-syntax.js +3 -3
  186. package/src/infrastructure/engines/walker/boolean-in-a-signature/boolean-annotation/boolean-signatures.js +7 -5
  187. package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +192 -147
  188. package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/call-of-a-call.examples.json +24 -0
  189. package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/call-of-a-call.js +34 -0
  190. package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/piece.json +9 -0
  191. package/src/infrastructure/engines/walker/claimed-type/cast-to-any/any-cast.js +6 -4
  192. package/src/infrastructure/engines/walker/claimed-type/unlisted-cast-site/cast-expressions.js +6 -4
  193. package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/piece.json +9 -0
  194. package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/raw-read.examples.json +30 -0
  195. package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/raw-read.js +166 -0
  196. package/src/infrastructure/engines/walker/computed-value-in-a-test/test-body/piece.json +0 -10
  197. package/src/infrastructure/engines/walker/date-used-directly/clock-sources/clock-sources.js +4 -4
  198. package/src/infrastructure/engines/walker/default-on-a-closed-union/default-arm/switch-defaults.js +8 -6
  199. package/src/infrastructure/engines/walker/double-with-a-body/logic-in-a-passed-function/piece.json +0 -10
  200. package/src/infrastructure/engines/walker/double-with-a-body/stub-implementation/dependency-isolation.js +9 -14
  201. package/src/infrastructure/engines/walker/drawer-path/drawer-names/categorical-paths.js +4 -4
  202. package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/piece.json +9 -0
  203. package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/test-file-export.examples.json +30 -0
  204. package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/test-file-export.js +31 -0
  205. package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/empty-catch.examples.json +18 -0
  206. package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/empty-catch.js +32 -0
  207. package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/piece.json +9 -0
  208. package/src/infrastructure/engines/walker/floating-version/version-selector/piece.json +9 -0
  209. package/src/infrastructure/engines/walker/floating-version/version-selector/version-selector.examples.json +54 -0
  210. package/src/infrastructure/engines/walker/floating-version/version-selector/version-selector.js +75 -0
  211. package/src/infrastructure/engines/walker/inherited-environment-in-a-subprocess/git-spawn-environment/hermetic-git-spawns.js +8 -17
  212. package/src/infrastructure/engines/walker/loop-keyword/loop-statement/loops.js +8 -6
  213. package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/piece.json +9 -0
  214. package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/test-call-aliases.examples.json +36 -0
  215. package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/test-call-aliases.js +67 -0
  216. package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/module-mock-call.examples.json +34 -0
  217. package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/module-mocking.js +64 -16
  218. package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/piece.json +5 -1
  219. package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/committed-lock-file.examples.json +24 -0
  220. package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/committed-lock-file.js +41 -0
  221. package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/piece.json +9 -0
  222. package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/import-boundaries.js +18 -16
  223. package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/piece.json +1 -1
  224. package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/debugger-statement.examples.json +18 -0
  225. package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/debugger-statement.js +17 -0
  226. package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/piece.json +9 -0
  227. package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/direct-global-use.examples.json +63 -0
  228. package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/piece.json +13 -0
  229. package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/process-global-used-in-place.js +126 -0
  230. package/src/infrastructure/engines/walker/prose-in-code/comment-prose/comment-prose.examples.json +42 -0
  231. package/src/infrastructure/engines/walker/prose-in-code/comment-prose/piece.json +16 -0
  232. package/src/infrastructure/engines/walker/prose-in-code/comment-prose/prose-in-code.js +90 -0
  233. package/src/infrastructure/engines/walker/rebinding/test-body/piece.json +0 -10
  234. package/src/infrastructure/engines/walker/runner/pieces/walker-piece.d.ts +7 -5
  235. package/src/infrastructure/engines/walker/runner/runner.js +268 -79
  236. package/src/infrastructure/engines/walker/runner/toolchain/typescript-parse.d.ts +3 -0
  237. package/src/infrastructure/engines/walker/shorthand-name/identifier-names/identifier-names.js +12 -7
  238. package/src/infrastructure/engines/walker/strictness-weakened/exact-optional-property-types/piece.json +0 -10
  239. package/src/infrastructure/engines/walker/strictness-weakened/no-fallthrough-cases-in-switch/piece.json +0 -10
  240. package/src/infrastructure/engines/walker/strictness-weakened/no-implicit-override/piece.json +0 -10
  241. package/src/infrastructure/engines/walker/strictness-weakened/no-property-access-from-index-signature/piece.json +0 -10
  242. package/src/infrastructure/engines/walker/strictness-weakened/no-unchecked-indexed-access/piece.json +0 -10
  243. package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +30 -52
  244. package/src/infrastructure/engines/walker/strictness-weakened/use-unknown-in-catch-variables/piece.json +0 -10
  245. package/src/infrastructure/engines/walker/text-past-its-reader/test-body/piece.json +0 -10
  246. package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/piece.json +9 -0
  247. package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/throw-statement.examples.json +36 -0
  248. package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/throws-in-production.js +12 -0
  249. package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/throw-statement.examples.json +6 -6
  250. package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/throws-in-tests.js +5 -44
  251. package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/try-block/piece.json +0 -10
  252. package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/fetch-command.examples.json +42 -0
  253. package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/fetch-command.js +152 -0
  254. package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/piece.json +9 -0
  255. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/piece.json +9 -0
  256. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +36 -0
  257. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +141 -0
  258. package/src/infrastructure/engines/walker/type-derived-from-code/factory-return-types/factory-return-types.js +8 -6
  259. package/src/infrastructure/engines/walker/unit-without-a-running-test/companion-test-file/export-test-sibling.js +16 -10
  260. package/src/infrastructure/engines/walker/untracked-escape/directive-pointers/comments-directives.js +18 -64
  261. package/src/infrastructure/engines/walker/write-into-a-parameter/parameter-mutation/parameter-mutation.js +7 -5
  262. package/src/measure-engines.process.js +80 -0
  263. package/src/rule-set.d.ts +2 -1
  264. package/src/testing.d.ts +2 -4
  265. package/src/testing.js +173 -314
  266. package/src/{audit.d.ts → walker.d.ts} +13 -8
  267. package/src/walker.js +28 -0
  268. package/chunks/chunk-5HRMJ4O2.js +0 -608
  269. package/chunks/chunk-IX2VZTBO.js +0 -887
  270. package/chunks/chunk-K2W3D3NB.js +0 -17
  271. package/chunks/chunk-M6SOGWT7.js +0 -82
  272. package/chunks/chunk-Q62Y25WS.js +0 -843
  273. package/chunks/chunk-R75QELTA.js +0 -481
  274. package/chunks/chunk-RANAKCTW.js +0 -31
  275. package/chunks/chunk-TNY2PASL.js +0 -38
  276. package/chunks/chunk-UJONWHA4.js +0 -22
  277. package/docs/output-contract.md +0 -1155
  278. package/rules/record-kinds/boundary-record.md +0 -9
  279. package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
  280. package/rules/typescript/recipes/stub-with-vifn.md +0 -20
  281. package/src/audit.js +0 -18
  282. package/src/domain/runner/runner-module-types.d.ts +0 -15
@@ -9,8 +9,8 @@
9
9
  - **Chosen because:** "I didn't want a json parse wrapper. I wanted a boundary on whoever made json"; "Json parse has no contract… Http fetch library for example has complexity to bind".
10
10
 
11
11
  - **Method:** An outside dependency or runtime module is imported only in the adapter file for the party it reaches. That adapter fulfils a port and returns our types. Nothing re-exports the outside dependency. `JSON.parse` is called inside the adapter for whoever produced the JSON.
12
- - **You can tell because:** Each package import sits in a file with a boundary record.
13
- - **Industry name:** Adapter; Gateway; anti-corruption layer; Hexagonal Architecture (Cockburn).
12
+ - **You can tell because:** Each package import sits in a file with an authorised location bound to that party.
13
+ - **Industry name:** Adapter; Gateway; anticorruption layer; Hexagonal Architecture (Cockburn).
14
14
 
15
15
  ### Ports declared inside
16
16
 
@@ -22,11 +22,11 @@
22
22
  - **You can tell because:** No other module calls an adapter's factory.
23
23
  - **Industry name:** Composition Root (Seemann).
24
24
 
25
- #### Port in the domain
25
+ #### Port in a module of its own
26
26
 
27
27
  - **Chosen because:** "In clean architecture the port is domain and to be kept separate to the concrete implementation or use."; "then host facts source should be declared separately to its concrete implementation to protiect dependency inversion".
28
28
 
29
- - **Method:** The port's interface is declared in the domain, in a module of its own, named for the capability. It sits apart from the adapter that fulfils it and from the unit that uses it; both import it from there. Storage is such a port, named for what the domain asks.
29
+ - **Method:** The port's interface is declared on the inside, in a module of its own, named for the capability. It sits apart from the adapter that fulfils it and from the unit that uses it; both import it from there. Storage is such a port, named for what the domain asks.
30
30
  - **You can tell because:** No port is declared in an adapter's module or in its consumer's. No business-logic file imports an adapter. No query or driver type in business logic.
31
31
  - **Industry name:** dependency inversion (Martin); Clean Architecture.
32
32
  - **Review:** storage sits behind a repository port and domain code never imports a storage driver
@@ -49,18 +49,32 @@
49
49
  - **You can tell because:** No `class` keyword in our code. No unit reads `this`.
50
50
  - **Industry name:** Private Members (Crockford).
51
51
 
52
- [Functional iteration](recipes/functional-iteration.md) also serves this principle.
53
-
54
52
  ### Copy, never write in
55
53
 
56
54
  - **Chosen because:** "this is giving mutation of input args vibes, not okay"; "pure functions are required".
57
55
 
58
56
  - **Method:** A changed value is a new one: `{ ...order, total }` or `[...items].sort()`. Nothing writes to, deletes from, or rebinds a parameter.
59
57
  - **You can tell because:** No assignment to a parameter or its fields.
60
- - **Industry name:** immutability; Value Object (Fowler); functional core.
58
+ - **Industry name:** immutability; Value Object (Fowler).
59
+
60
+ ### Functional iteration
61
+
62
+ - **Chosen because:** "For of mutates by its nature. It doesn't return. It's state holding required or side effect based."
63
+
64
+ - **Method:** Work over several values uses `map`, `filter`, `flatMap` or `reduce`, returning new values. No `for`, `for…of` or `while`. A stream is drained with `for await` only in its source's adapter, at an authorised location.
65
+ - **You can tell because:** No loop keyword outside a recorded drain. Nothing is pushed into an outer binding.
66
+ - **Industry name:** Collection Pipeline; Replace Loop with Pipeline (Fowler).
61
67
 
62
68
  ## No leak across a boundary
63
69
 
70
+ ### Adapter per outside party
71
+
72
+ - **Chosen because:** "I didn't want a json parse wrapper. I wanted a boundary on whoever made json"; "Json parse has no contract… Http fetch library for example has complexity to bind".
73
+
74
+ - **Method:** An outside dependency or runtime module is imported only in the adapter file for the party it reaches. That adapter fulfils a port and returns our types. Nothing re-exports the outside dependency. `JSON.parse` is called inside the adapter for whoever produced the JSON.
75
+ - **You can tell because:** Each package import sits in a file with an authorised location bound to that party.
76
+ - **Industry name:** Adapter; Gateway; anticorruption layer; Hexagonal Architecture (Cockburn).
77
+
64
78
  ### Failure mapping at the adapter
65
79
 
66
80
  - **Chosen because (proposed):** "They are about speaking the language of the caller at the boundary."
@@ -69,16 +83,34 @@
69
83
  - **You can tell because:** No `throw` except at an adapter whose caller expects one.
70
84
  - **Industry name:** anticorruption layer (Evans), applied to failures.
71
85
 
72
- Failure mapping at the adapter also serves Failures are values.
73
-
74
86
  ### Map out at the adapter
75
87
 
76
88
  - **Chosen because:** "As we should be runtime objects not json as soon as we leave a boundary".
89
+ - **Examples:** [serialising-or-parsing-json](recipes/map-out-at-the-adapter.md#serialising-or-parsing-json) answers [text-past-its-reader#test-body serialising-or-parsing-json](symptoms/text-past-its-reader/test-body.md#serialising-or-parsing-json).
77
90
 
78
91
  - **Method:** Business logic hands the adapter our own value. Only the adapter turns it into the receiver's form (`JSON.stringify`, a status, a header).
79
92
  - **You can tell because:** No outside form is built in business logic.
80
93
  - **Industry name:** anticorruption layer (Evans).
81
94
 
95
+ #### Examples
96
+
97
+ ##### Serialising or parsing JSON
98
+ ```ts
99
+ declare const publish: (request: { readonly id: string; readonly send: (text: string) => void }) => void;
100
+ const send = vi.fn<(text: string) => void>();
101
+ publish({ id: "a", send });
102
+ expect(send).toHaveBeenCalledWith(JSON.stringify({ id: "a" }));
103
+ ```
104
+
105
+ Hand the adapter our own value, and leave the text to it:
106
+
107
+ ```ts
108
+ declare const publish: (request: { readonly id: string; readonly send: (task: { readonly id: string }) => void }) => void;
109
+ const send = vi.fn<(task: { readonly id: string }) => void>();
110
+ publish({ id: "a", send });
111
+ expect(send).toHaveBeenCalledWith({ id: "a" });
112
+ ```
113
+
82
114
  ### Zod at the producer's adapter
83
115
 
84
116
  - **Chosen because:** "my insistence on not writing complex logic to parse"; "Hand rolled is potentially a messy and lossy option?"; "Zod is the wire."
@@ -98,7 +130,7 @@ Failure mapping at the adapter also serves Failures are values.
98
130
 
99
131
  - **Method:** An orchestrator's body is a sequence of named calls to our units. Each failed result returns at once, unchanged. Any computing or branching between calls moves into a named doer.
100
132
  - **You can tell because:** The orchestrator holds calls, early returns of failures, and a final return.
101
- - **Industry name:** the Integration Operation Segregation Principle (Westphal); Composed Method (Beck).
133
+ - **Industry name:** the Integration Operation Segregation Principle (Westphal).
102
134
 
103
135
  #### Functional iteration
104
136
 
@@ -128,8 +160,6 @@ Failure mapping at the adapter also serves Failures are values.
128
160
  - **You can tell because:** No file holds only types, except port declarations.
129
161
  - **Industry name:** DDD entity (Evans).
130
162
 
131
- Entity module also serves One reason per module.
132
-
133
163
  #### Narrow ports
134
164
 
135
165
  - **Chosen because:** "Rather than writing 6 different concrete things 1 for each."; "narrowed ports that still help us find the seams where the dependencies link up".
@@ -149,6 +179,14 @@ Entity module also serves One reason per module.
149
179
 
150
180
  ### One reason per module
151
181
 
182
+ #### Entity module
183
+
184
+ - **Chosen because:** "The anaemic concern there is that by writing types with no logic you are failing coupling/cohesion and single responsibility principles."
185
+
186
+ - **Method:** An entity's type and its logic share one module. Its functions take the entity.
187
+ - **You can tell because:** No file holds only types, except port declarations.
188
+ - **Industry name:** DDD entity (Evans).
189
+
152
190
  #### Screaming folders
153
191
 
154
192
  - **Chosen because:** "all types have a purpose. that purpose is its reason to exist and its reason to change"; screaming architecture "making those boundaries easier to see when broken".
@@ -157,8 +195,6 @@ Entity module also serves One reason per module.
157
195
  - **You can tell because:** Each path names a domain concept.
158
196
  - **Industry name:** Screaming Architecture (Martin); package by feature.
159
197
 
160
- [Entity module](recipes/entity-module.md) also serves this rule.
161
-
162
198
  ## Our code reads in the common language
163
199
 
164
200
  ### One word everywhere
@@ -179,10 +215,17 @@ Entity module also serves One reason per module.
179
215
  - **You can tell because:** No comment or JSDoc in our code.
180
216
  - **Industry name:** none; ours. It is stricter than Martin's *Clean Code*, which keeps a section on good comments.
181
217
 
182
- [One argument object](recipes/one-argument-object.md) also serves this rule.
183
-
184
218
  Casing is a check that runs the adopter's own lint. It is not a recipe. Basic logic in the language's own constructs is a case under the principle; its recipe is the native array and object methods, chosen because an outside dependency's language for them is "language obscuring standard operations".
185
219
 
220
+ #### One argument object
221
+
222
+ - **Chosen because:** "Shows up in tests where to avoid writing a large object for 2 fields that impact th test they double cast. It shows the minimum interface principle."; "Functions with no outside influence should take 1. 2 is debatable. But for agents the goal is always 1."; "nope, you will not use tupple like arrays for data".
223
+
224
+ - **Method:** A function whose signature is ours to choose takes one argument: an object with named fields, whose declared type lists only the fields the unit reads. A function whose shape an outside API fixes (a callback to `map` or `reduce`) takes what that API passes. No tuple carries data.
225
+ - **You can tell because:** No function of ours has two or more parameters unless an outside API fixes its shape. No test casts to build an input.
226
+ - **Industry name:** Introduce Parameter Object (Fowler), always one object.
227
+ - **Review:** the single argument is an object with named fields, not a positional scalar
228
+
186
229
  #### Whole words
187
230
 
188
231
  - **Chosen because:** "dont care if its a lambda function or not, meaningful names always"; "no, the problem is the lack of a whole word".
@@ -251,35 +294,378 @@ Proposed, not accepted: the case An adopter is not handed our risk, under Outsid
251
294
  #### Assert to narrow
252
295
 
253
296
  - **Chosen because:** "use vi assert to validate it's existence first to narrow the type to exclude the need for optional chain".
297
+ - **Examples:** [a-short-circuit](recipes/assert-to-narrow.md#a-short-circuit) answers [branch-in-a-test#test-body a-short-circuit](symptoms/branch-in-a-test/test-body.md#a-short-circuit); [an-optional-chain-after-an-index](recipes/assert-to-narrow.md#an-optional-chain-after-an-index) answers [branch-in-a-test#test-body an-optional-chain-after-an-index](symptoms/branch-in-a-test/test-body.md#an-optional-chain-after-an-index); [an-optional-chain-on-a-property](recipes/assert-to-narrow.md#an-optional-chain-on-a-property) answers [branch-in-a-test#test-body an-optional-chain-on-a-property](symptoms/branch-in-a-test/test-body.md#an-optional-chain-on-a-property); [an-optional-call](recipes/assert-to-narrow.md#an-optional-call) answers [branch-in-a-test#test-body an-optional-call](symptoms/branch-in-a-test/test-body.md#an-optional-call).
254
298
 
255
299
  - **Method:** A value that may be absent or one of several outcomes is narrowed with the framework's `assert` first. After that, plain `expect` reads it.
256
300
  - **You can tell because:** No `?.`, `&&`, `if` or ternary in the test.
257
301
  - **Industry name:** Guard Assertion (Meszaros).
258
302
 
303
+ The framework's assertion is not a claim of ours.
304
+
305
+ ##### Examples
306
+
307
+ ###### A short-circuit
308
+ ```ts
309
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
310
+ const found = lookup("a");
311
+ expect(found !== undefined && found.name === "Ada").toBe(true);
312
+ ```
313
+
314
+ Assert the value is defined, then read it:
315
+
316
+ ```ts
317
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
318
+ const found = lookup("a");
319
+ assert.isDefined(found);
320
+ expect(found.name).toBe("Ada");
321
+ ```
322
+
323
+ ###### An optional chain after an index
324
+ ```ts
325
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
326
+ expect(listTasks()[0]?.id).toBe("a");
327
+ ```
328
+
329
+ Destructure the element and assert it is defined, then read it:
330
+
331
+ ```ts
332
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
333
+ const [first] = listTasks();
334
+ assert.isDefined(first);
335
+ expect(first.id).toBe("a");
336
+ ```
337
+
338
+ ###### An optional chain on a property
339
+ ```ts
340
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
341
+ expect(findUser("a")?.name).toBe("Ada");
342
+ ```
343
+
344
+ Assert the value is defined, then read it:
345
+
346
+ ```ts
347
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
348
+ const user = findUser("a");
349
+ assert.isDefined(user);
350
+ expect(user.name).toBe("Ada");
351
+ ```
352
+
353
+ ###### An optional call
354
+ ```ts
355
+ declare const observers: { readonly enter?: (node: string) => string };
356
+ expect(observers.enter?.("a")).toBe("entered a");
357
+ ```
358
+
359
+ Destructure the function and assert it is defined, then call it:
360
+
361
+ ```ts
362
+ declare const observers: { readonly enter?: (node: string) => string };
363
+ const { enter } = observers;
364
+ assert.isDefined(enter);
365
+ expect(enter("a")).toBe("entered a");
366
+ ```
367
+
368
+ A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there.
369
+
259
370
  #### Failure asserted as a value
260
371
 
261
372
  - **Chosen because (proposed):** "more error throwing, not allowed". A `try` or `catch` in a test is a branch that decides whether the test passes.
373
+ - **Examples:** [a-try-block](recipes/failure-asserted-as-a-value.md#a-try-block) answers [throw-or-catch-in-a-test#try-block a-try-block](symptoms/throw-or-catch-in-a-test/try-block.md#a-try-block).
262
374
 
263
375
  - **Method:** A failure is checked as the returned variant: `expect(result).toEqual({ outcome: "failure", ... })`. An adapter whose caller's contract is a throw is checked with `expect(call).toThrow(...)`.
264
376
  - **You can tell because:** No `try`, `catch` or `throw` in any test.
265
377
  - **Industry name:** none; it follows from Failures are values.
266
378
 
379
+ ##### Examples
380
+
381
+ ###### A try block
382
+ ```ts
383
+ declare const load: (path: string) => string;
384
+ try {
385
+ load("missing.json");
386
+ } catch (error) {
387
+ expect(error).toBeInstanceOf(Error);
388
+ }
389
+ ```
390
+
391
+ Assert the returned variant:
392
+
393
+ ```ts
394
+ declare const load: (path: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failure"; readonly kind: "missing" };
395
+ expect(load("missing.json")).toEqual({ outcome: "failure", kind: "missing" });
396
+ ```
397
+
398
+ For an adapter whose caller's contract is a throw, assert the throw:
399
+
400
+ ```ts
401
+ declare const load: (path: string) => string;
402
+ const call = () => load("missing.json");
403
+ expect(call).toThrow(Error);
404
+ ```
405
+
267
406
  #### it.each over typed rows
268
407
 
269
408
  - **Chosen because:** "It's just boilerplate for cases being tested."
409
+ - **Examples:** [branching-with-if](recipes/it-each-over-typed-rows.md#branching-with-if) answers [branch-in-a-test#test-body branching-with-if](symptoms/branch-in-a-test/test-body.md#branching-with-if); [a-ternary](recipes/it-each-over-typed-rows.md#a-ternary) answers [branch-in-a-test#test-body a-ternary](symptoms/branch-in-a-test/test-body.md#a-ternary); [a-switch](recipes/it-each-over-typed-rows.md#a-switch) answers [branch-in-a-test#test-body a-switch](symptoms/branch-in-a-test/test-body.md#a-switch).
270
410
 
271
- - **Method:** Several cases of one behaviour are one `it.each<Row>([...])`. `Row` is a declared type. Each row writes out its input and its expected output.
411
+ - **Method:** Several cases of one behaviour are one `it.each<Row>([...])`. `Row` is a declared type whose members are primitives, types imported from non-test modules, or readonly lists of imported types. Each row writes out its input and its expected output.
272
412
  - **You can tell because:** Every row is a literal. No row is built, mapped or picked.
273
413
  - **Industry name:** Parameterized Test (Meszaros), with rows typed and written out.
274
414
 
415
+ ##### Examples
416
+
417
+ ###### Branching with if
418
+ ```ts
419
+ declare const gradeFor: (score: number) => string;
420
+ const score = 60;
421
+ const grade = gradeFor(score);
422
+ if (score >= 50) {
423
+ expect(grade).toBe("pass");
424
+ }
425
+ ```
426
+
427
+ Write one typed row per case:
428
+
429
+ ```ts
430
+ declare const gradeFor: (score: number) => string;
431
+ type Row = { readonly score: number; readonly expected: string };
432
+ it.each<Row>([
433
+ { score: 60, expected: "pass" },
434
+ { score: 40, expected: "fail" },
435
+ ])("grades $score as $expected", ({ score, expected }) => {
436
+ expect(gradeFor(score)).toBe(expected);
437
+ });
438
+ ```
439
+
440
+ ###### A ternary
441
+ ```ts
442
+ declare const discountFor: (order: { readonly quantity: number }) => number;
443
+ const quantity = 10;
444
+ expect(discountFor({ quantity })).toBe(quantity >= 10 ? 5 : 0);
445
+ ```
446
+
447
+ Write one typed row per case:
448
+
449
+ ```ts
450
+ declare const discountFor: (order: { readonly quantity: number }) => number;
451
+ type Row = { readonly quantity: number; readonly expected: number };
452
+ it.each<Row>([
453
+ { quantity: 10, expected: 5 },
454
+ { quantity: 9, expected: 0 },
455
+ ])("gives $expected off an order of $quantity", ({ quantity, expected }) => {
456
+ expect(discountFor({ quantity })).toBe(expected);
457
+ });
458
+ ```
459
+
460
+ ###### A switch
461
+ ```ts
462
+ declare const labelFor: (basket: { readonly count: number }) => string;
463
+ const basket = { count: 1 } as const;
464
+ switch (basket.count) {
465
+ case 1:
466
+ expect(labelFor(basket)).toBe("1 item");
467
+ }
468
+ ```
469
+
470
+ Write one typed row per case:
471
+
472
+ ```ts
473
+ declare const labelFor: (basket: { readonly count: number }) => string;
474
+ type Row = { readonly count: number; readonly expected: string };
475
+ it.each<Row>([
476
+ { count: 1, expected: "1 item" },
477
+ { count: 2, expected: "2 items" },
478
+ ])("labels a basket of $count", ({ count, expected }) => {
479
+ expect(labelFor({ count })).toBe(expected);
480
+ });
481
+ ```
482
+
275
483
  #### Whole written-out expectation
276
484
 
277
485
  - **Chosen because:** "no find, use bare access in tests for determinstic insistence on behaviours".
486
+ - **Examples:** [branching-with-if](recipes/whole-written-out-expectation.md#branching-with-if) answers [branch-in-a-test#test-body branching-with-if](symptoms/branch-in-a-test/test-body.md#branching-with-if); [a-short-circuit](recipes/whole-written-out-expectation.md#a-short-circuit) answers [branch-in-a-test#test-body a-short-circuit](symptoms/branch-in-a-test/test-body.md#a-short-circuit); [an-optional-chain-after-an-index](recipes/whole-written-out-expectation.md#an-optional-chain-after-an-index) answers [branch-in-a-test#test-body an-optional-chain-after-an-index](symptoms/branch-in-a-test/test-body.md#an-optional-chain-after-an-index); [a-method-that-picks-or-tests-an-element](recipes/whole-written-out-expectation.md#a-method-that-picks-or-tests-an-element) answers [computed-value-in-a-test#test-body a-method-that-picks-or-tests-an-element](symptoms/computed-value-in-a-test/test-body.md#a-method-that-picks-or-tests-an-element); [a-method-that-computes-a-value](recipes/whole-written-out-expectation.md#a-method-that-computes-a-value) answers [computed-value-in-a-test#test-body a-method-that-computes-a-value](symptoms/computed-value-in-a-test/test-body.md#a-method-that-computes-a-value); [a-method-that-mutates](recipes/whole-written-out-expectation.md#a-method-that-mutates) answers [computed-value-in-a-test#test-body a-method-that-mutates](symptoms/computed-value-in-a-test/test-body.md#a-method-that-mutates); [merging-objects](recipes/whole-written-out-expectation.md#merging-objects) answers [computed-value-in-a-test#test-body merging-objects](symptoms/computed-value-in-a-test/test-body.md#merging-objects); [building-an-object-from-entries](recipes/whole-written-out-expectation.md#building-an-object-from-entries) answers [computed-value-in-a-test#test-body building-an-object-from-entries](symptoms/computed-value-in-a-test/test-body.md#building-an-object-from-entries); [building-an-array-from-a-length](recipes/whole-written-out-expectation.md#building-an-array-from-a-length) answers [computed-value-in-a-test#test-body building-an-array-from-a-length](symptoms/computed-value-in-a-test/test-body.md#building-an-array-from-a-length); [a-math-call](recipes/whole-written-out-expectation.md#a-math-call) answers [computed-value-in-a-test#test-body a-math-call](symptoms/computed-value-in-a-test/test-body.md#a-math-call); [serialising-or-parsing-json](recipes/whole-written-out-expectation.md#serialising-or-parsing-json) answers [text-past-its-reader#test-body serialising-or-parsing-json](symptoms/text-past-its-reader/test-body.md#serialising-or-parsing-json).
278
487
 
279
488
  - **Method:** Assert the whole returned value with `toEqual` against a written-out literal. Read list items by bare index after an assert, never with `find`.
280
489
  - **You can tell because:** The expected value is a literal in the test.
281
490
  - **Industry name:** Literal Value (Meszaros).
282
491
 
492
+ ##### Examples
493
+
494
+ ###### Branching with if
495
+ ```ts
496
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
497
+ const parsed = parse("a");
498
+ if (parsed.outcome === "ok") {
499
+ expect(parsed.value).toBe("a");
500
+ }
501
+ ```
502
+
503
+ Compare the whole result:
504
+
505
+ ```ts
506
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
507
+ expect(parse("a")).toEqual({ outcome: "ok", value: "a" });
508
+ ```
509
+
510
+ ###### A short-circuit
511
+ ```ts
512
+ declare const assign: (task: { readonly id: string; readonly owner?: string }) => { readonly id: string; readonly owner: string };
513
+ const task: { readonly id: string; readonly owner?: string } = { id: "a" };
514
+ expect(assign(task)).toEqual({ id: "a", owner: task.owner ?? "none" });
515
+ ```
516
+
517
+ Write the expected value out:
518
+
519
+ ```ts
520
+ declare const assign: (task: { readonly id: string; readonly owner?: string }) => { readonly id: string; readonly owner: string };
521
+ expect(assign({ id: "a" })).toEqual({ id: "a", owner: "none" });
522
+ ```
523
+
524
+ ###### An optional chain after an index
525
+ ```ts
526
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
527
+ expect(listTasks()[0]?.id).toBe("a");
528
+ ```
529
+
530
+ Assert the whole array:
531
+
532
+ ```ts
533
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
534
+ expect(listTasks()).toEqual([
535
+ { id: "a", status: "open" },
536
+ { id: "b", status: "done" },
537
+ ]);
538
+ ```
539
+
540
+ Or read the element by bare index after an assert:
541
+
542
+ ```ts
543
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
544
+ const tasks = listTasks();
545
+ assert.isDefined(tasks[0]);
546
+ expect(tasks[0]).toEqual({ id: "a", status: "open" });
547
+ ```
548
+
549
+ ###### A method that picks or tests an element
550
+ ```ts
551
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
552
+ expect(listTasks().find((task) => task.id === "a")).toEqual({ id: "a", status: "open" });
553
+ ```
554
+
555
+ Assert the whole array:
556
+
557
+ ```ts
558
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
559
+ expect(listTasks()).toEqual([
560
+ { id: "a", status: "open" },
561
+ { id: "b", status: "done" },
562
+ ]);
563
+ ```
564
+
565
+ Or read the element by bare index after an assert:
566
+
567
+ ```ts
568
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
569
+ const tasks = listTasks();
570
+ assert.isDefined(tasks[0]);
571
+ expect(tasks[0]).toEqual({ id: "a", status: "open" });
572
+ ```
573
+
574
+ ###### A method that computes a value
575
+ ```ts
576
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
577
+ const rows = [{ id: "a1" }, { id: "b2" }];
578
+ expect(idsOf(rows)).toEqual(rows.map((row) => row.id));
579
+ ```
580
+
581
+ Write the expected value out:
582
+
583
+ ```ts
584
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
585
+ expect(idsOf([{ id: "a1" }, { id: "b2" }])).toEqual(["a1", "b2"]);
586
+ ```
587
+
588
+ ###### A method that mutates
589
+ ```ts
590
+ declare const namesOf: (team: string) => readonly string[];
591
+ const expected = ["Ada"];
592
+ expected.push("Grace");
593
+ expect(namesOf("core")).toEqual(expected);
594
+ ```
595
+
596
+ Write the finished array out:
597
+
598
+ ```ts
599
+ declare const namesOf: (team: string) => readonly string[];
600
+ expect(namesOf("core")).toEqual(["Ada", "Grace"]);
601
+ ```
602
+
603
+ ###### Merging objects
604
+ ```ts
605
+ declare const requestFor: (task: { readonly body: string }) => { readonly method: "POST"; readonly path: string; readonly body: string };
606
+ const base = { method: "POST", path: "/tasks" } as const;
607
+ expect(requestFor({ body: "a" })).toEqual(Object.assign({}, base, { body: "a" }));
608
+ ```
609
+
610
+ Write the whole object out:
611
+
612
+ ```ts
613
+ declare const requestFor: (task: { readonly body: string }) => { readonly method: "POST"; readonly path: string; readonly body: string };
614
+ expect(requestFor({ body: "a" })).toEqual({ method: "POST", path: "/tasks", body: "a" });
615
+ ```
616
+
617
+ ###### Building an object from entries
618
+ ```ts
619
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
620
+ expect(countsOf(["a"])).toEqual(Object.fromEntries([["a", 1]]));
621
+ ```
622
+
623
+ Write the object out:
624
+
625
+ ```ts
626
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
627
+ expect(countsOf(["a"])).toEqual({ a: 1 });
628
+ ```
629
+
630
+ ###### Building an array from a length
631
+ ```ts
632
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
633
+ expect(pageOf(Array.from({ length: 3 }, (_, index) => ({ id: index })))).toHaveLength(3);
634
+ ```
635
+
636
+ Write the array out, and assert the whole array that comes back:
637
+
638
+ ```ts
639
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
640
+ expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toEqual([{ id: 0 }, { id: 1 }, { id: 2 }]);
641
+ ```
642
+
643
+ ###### A Math call
644
+ ```ts
645
+ declare const roundedOf: (amount: number) => number;
646
+ expect(roundedOf(2.5)).toBe(Math.round(2.5));
647
+ ```
648
+
649
+ Write the number out:
650
+
651
+ ```ts
652
+ declare const roundedOf: (amount: number) => number;
653
+ expect(roundedOf(2.5)).toEqual(3);
654
+ ```
655
+
656
+ ###### Serialising or parsing JSON
657
+ ```ts
658
+ declare const render: (row: { readonly id: string }) => string;
659
+ expect(JSON.parse(render({ id: "a" }))).toEqual({ id: "a" });
660
+ ```
661
+
662
+ Assert the object the unit gives back, written out:
663
+
664
+ ```ts
665
+ declare const rowOf: (row: { readonly id: string }) => { readonly id: string };
666
+ expect(rowOf({ id: "a" })).toEqual({ id: "a" });
667
+ ```
668
+
283
669
  ### Tested where it's owned
284
670
 
285
671
  #### Companion test file
@@ -319,6 +705,7 @@ Proposed, not accepted: the case An adopter is not handed our risk, under Outsid
319
705
  #### Stub with vi.fn
320
706
 
321
707
  - **Chosen because:** "these should be vi.fn, with mockResolvedValue, not custom async functions"; "Agents take fake to mean whatever they want it to mean right now." The framework's double has no body of ours to hold logic.
708
+ - **Examples:** [an-optional-chain-on-a-mock-call](recipes/stub-with-vi-fn.md#an-optional-chain-on-a-mock-call) answers [branch-in-a-test#test-body an-optional-chain-on-a-mock-call](symptoms/branch-in-a-test/test-body.md#an-optional-chain-on-a-mock-call); [an-optional-chain-on-a-mock-result](recipes/stub-with-vi-fn.md#an-optional-chain-on-a-mock-result) answers [branch-in-a-test#test-body an-optional-chain-on-a-mock-result](symptoms/branch-in-a-test/test-body.md#an-optional-chain-on-a-mock-result); [logic-inside-a-function-the-test-passes-on](recipes/stub-with-vi-fn.md#logic-inside-a-function-the-test-passes-on) answers [double-with-a-body#logic-in-a-passed-function logic-inside-a-function-the-test-passes-on](symptoms/double-with-a-body/logic-in-a-passed-function.md#logic-inside-a-function-the-test-passes-on); [a-let](recipes/stub-with-vi-fn.md#a-let) answers [rebinding#test-body a-let](symptoms/rebinding/test-body.md#a-let).
322
709
 
323
710
  - **Method:** Each collaborator is a `vi.fn()` declared as a const inside the test that uses it. Shared boilerplate or a mock builder is allowed where it hides none of three things: a wide interface, an assumption a test rests on, or coupling between tests. A shared double is therefore a symptom, suspect by default, not a breach. Its answer is `mockReturnValue` or `mockResolvedValue` with a written-out value. Each call is checked with `toHaveBeenCalledWith` and a written-out argument.
324
711
  - **You can tell because:** No double has a body, a branch or a table. Every call the unit makes is asserted.
@@ -326,11 +713,157 @@ Proposed, not accepted: the case An adopter is not handed our risk, under Outsid
326
713
 
327
714
  A fake is not a recipe. It is a [deviation record](../record-kinds/deviation.md), and the bar it must meet is: "Moving a fake is only allowed if the test cannot be done with deterministic stubs or hardcoded things."
328
715
 
716
+ ##### Examples
717
+
718
+ ###### An optional chain on a mock call
719
+ ```ts
720
+ declare const start: (run: (task: { readonly id: string }) => void) => void;
721
+ const run = vi.fn<(task: { readonly id: string }) => void>();
722
+ start(run);
723
+ expect(run.mock.calls[0]?.[0].id).toBe("a");
724
+ ```
725
+
726
+ Check the call, its argument written out:
727
+
728
+ ```ts
729
+ declare const start: (run: (task: { readonly id: string }) => void) => void;
730
+ const run = vi.fn<(task: { readonly id: string }) => void>();
731
+ start(run);
732
+ expect(run).toHaveBeenCalledWith({ id: "a" });
733
+ ```
734
+
735
+ ###### An optional chain on a mock result
736
+ ```ts
737
+ declare const pricing: { readonly priceOf: (amount: number) => number };
738
+ declare const settle: (order: { readonly amount: number; readonly priceOf: (amount: number) => number }) => number;
739
+ const priceOf = vi.spyOn(pricing, "priceOf");
740
+ settle({ amount: 2, priceOf: pricing.priceOf });
741
+ expect(priceOf.mock.results[0]?.value).toBe(4);
742
+ ```
743
+
744
+ Write out what the collaborator gives back, then check what the unit returns and the call it makes:
745
+
746
+ ```ts
747
+ declare const settle: (order: { readonly amount: number; readonly priceOf: (amount: number) => number }) => number;
748
+ const priceOf = vi.fn<(amount: number) => number>().mockReturnValue(4);
749
+ expect(settle({ amount: 2, priceOf })).toBe(4);
750
+ expect(priceOf).toHaveBeenCalledWith(2);
751
+ ```
752
+
753
+ ###### Logic inside a function the test passes on
754
+ ```ts
755
+ declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
756
+ const installedFiles = ["bin/hone.js"];
757
+ expect(isInstalled({ kindOf: (path) => (installedFiles.includes(path) ? "file" : "missing") })).toBe("installed");
758
+ ```
759
+
760
+ Make it a `vi.fn` with a written-out return, and check the call:
761
+
762
+ ```ts
763
+ declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
764
+ const kindOf = vi.fn<(path: string) => "file" | "missing">().mockReturnValue("file");
765
+ expect(isInstalled({ kindOf })).toBe("installed");
766
+ expect(kindOf).toHaveBeenCalledExactlyOnceWith("bin/hone.js");
767
+ ```
768
+
769
+ ###### A let
770
+ ```ts
771
+ declare const record: (store: { readonly save: (text: string) => void }) => void;
772
+ let saved = "";
773
+ record({ save: (text) => { saved = text; } });
774
+ expect(saved).toBe("a");
775
+ ```
776
+
777
+ Pass in a `vi.fn`, and check the call:
778
+
779
+ ```ts
780
+ declare const record: (store: { readonly save: (text: string) => void }) => void;
781
+ const save = vi.fn<(text: string) => void>();
782
+ record({ save });
783
+ expect(save).toHaveBeenCalledWith("a");
784
+ ```
785
+
329
786
  ## The type checker proves it
330
787
 
331
788
  ### Declared, not asserted
332
789
 
333
- #### Bounded context generic
790
+ #### Assert to narrow
791
+
792
+ - **Chosen because:** "use vi assert to validate it's existence first to narrow the type to exclude the need for optional chain".
793
+ - **Examples:** [a-short-circuit](recipes/assert-to-narrow.md#a-short-circuit) answers [branch-in-a-test#test-body a-short-circuit](symptoms/branch-in-a-test/test-body.md#a-short-circuit); [an-optional-chain-after-an-index](recipes/assert-to-narrow.md#an-optional-chain-after-an-index) answers [branch-in-a-test#test-body an-optional-chain-after-an-index](symptoms/branch-in-a-test/test-body.md#an-optional-chain-after-an-index); [an-optional-chain-on-a-property](recipes/assert-to-narrow.md#an-optional-chain-on-a-property) answers [branch-in-a-test#test-body an-optional-chain-on-a-property](symptoms/branch-in-a-test/test-body.md#an-optional-chain-on-a-property); [an-optional-call](recipes/assert-to-narrow.md#an-optional-call) answers [branch-in-a-test#test-body an-optional-call](symptoms/branch-in-a-test/test-body.md#an-optional-call).
794
+
795
+ - **Method:** A value that may be absent or one of several outcomes is narrowed with the framework's `assert` first. After that, plain `expect` reads it.
796
+ - **You can tell because:** No `?.`, `&&`, `if` or ternary in the test.
797
+ - **Industry name:** Guard Assertion (Meszaros).
798
+
799
+ The framework's assertion is not a claim of ours.
800
+
801
+ ##### Examples
802
+
803
+ ###### A short-circuit
804
+ ```ts
805
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
806
+ const found = lookup("a");
807
+ expect(found !== undefined && found.name === "Ada").toBe(true);
808
+ ```
809
+
810
+ Assert the value is defined, then read it:
811
+
812
+ ```ts
813
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
814
+ const found = lookup("a");
815
+ assert.isDefined(found);
816
+ expect(found.name).toBe("Ada");
817
+ ```
818
+
819
+ ###### An optional chain after an index
820
+ ```ts
821
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
822
+ expect(listTasks()[0]?.id).toBe("a");
823
+ ```
824
+
825
+ Destructure the element and assert it is defined, then read it:
826
+
827
+ ```ts
828
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
829
+ const [first] = listTasks();
830
+ assert.isDefined(first);
831
+ expect(first.id).toBe("a");
832
+ ```
833
+
834
+ ###### An optional chain on a property
835
+ ```ts
836
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
837
+ expect(findUser("a")?.name).toBe("Ada");
838
+ ```
839
+
840
+ Assert the value is defined, then read it:
841
+
842
+ ```ts
843
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
844
+ const user = findUser("a");
845
+ assert.isDefined(user);
846
+ expect(user.name).toBe("Ada");
847
+ ```
848
+
849
+ ###### An optional call
850
+ ```ts
851
+ declare const observers: { readonly enter?: (node: string) => string };
852
+ expect(observers.enter?.("a")).toBe("entered a");
853
+ ```
854
+
855
+ Destructure the function and assert it is defined, then call it:
856
+
857
+ ```ts
858
+ declare const observers: { readonly enter?: (node: string) => string };
859
+ const { enter } = observers;
860
+ assert.isDefined(enter);
861
+ expect(enter("a")).toBe("entered a");
862
+ ```
863
+
864
+ A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there.
865
+
866
+ #### Constrained context generic
334
867
 
335
868
  - **Chosen because (proposed):** A field read from an open context is either cast or defaulted. Both hide a missing capability until run time.
336
869
 
@@ -363,10 +896,25 @@ A fake is not a recipe. It is a [deviation record](../record-kinds/deviation.md)
363
896
  - **You can tell because:** The resolved config of every project has every flag on.
364
897
  - **Industry name:** none; ours.
365
898
 
366
- [Zod at the producer's adapter](recipes/zod-at-the-producers-adapter.md) and [Assert to narrow](recipes/assert-to-narrow.md) also serve this rule. The framework's assertion is not a claim of ours.
899
+ #### Zod at the producer's adapter
900
+
901
+ - **Chosen because:** "my insistence on not writing complex logic to parse"; "Hand rolled is potentially a messy and lossy option?"; "Zod is the wire."
902
+
903
+ - **Method:** The adapter for whoever produced the data parses it once with a Zod schema. The `z.infer` type is the wire type and stays in the adapter. The adapter maps it to a domain type of ours. A missing required value, environment included, is a failure, never a default.
904
+ - **You can tell because:** No schema, `z.infer` type or text past the adapter. Each crossing is parsed once.
905
+ - **Industry name:** parse, don't validate (King).
906
+ - **Review:** every crossing from the untyped outside world is schema-validated at the seam
367
907
 
368
908
  ### Failures are values
369
909
 
910
+ #### Failure mapping at the adapter
911
+
912
+ - **Chosen because (proposed):** "They are about speaking the language of the caller at the boundary."
913
+
914
+ - **Method:** The adapter turns a library's throw into a failure variant of ours. At the program's edge, it turns our failure into the caller's form: an exit code, a status, or a throw where that caller's contract is exceptions.
915
+ - **You can tell because:** No `throw` except at an adapter whose caller expects one.
916
+ - **Industry name:** anticorruption layer (Evans), applied to failures.
917
+
370
918
  #### Result union
371
919
 
372
920
  - **Chosen because:** "it makes the output clear to type system instead of hidden in throws".
@@ -375,8 +923,6 @@ A fake is not a recipe. It is a [deviation record](../record-kinds/deviation.md)
375
923
  - **You can tell because:** No `throw` between units of ours. No failure is returned as `null`, `false`, `[]` or a default.
376
924
  - **Industry name:** Result type (Wlaschin).
377
925
 
378
- [Failure mapping at the adapter](recipes/failure-mapping-at-the-adapter.md) also serves this rule.
379
-
380
926
  - **Review:** operational errors are tagged data built by a factory and dispatched on their tag
381
927
 
382
928
  ### Kinds are named