@whaaaley/crush 0.0.0-stage → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +185 -2
  3. package/SKILL.md +187 -0
  4. package/THIRD_PARTY_NOTICES.md +277 -0
  5. package/dist/capture/capture.operations.d.ts +23 -0
  6. package/dist/capture/capture.operations.js +231 -0
  7. package/dist/capture/capture.schema.d.ts +73 -0
  8. package/dist/capture/capture.schema.js +28 -0
  9. package/dist/collapse/collapse.operations.d.ts +2 -0
  10. package/dist/collapse/collapse.operations.js +82 -0
  11. package/dist/collapse/collapse.schema.d.ts +40 -0
  12. package/dist/collapse/collapse.schema.js +35 -0
  13. package/dist/crush.tables.d.ts +3583 -0
  14. package/dist/crush.tables.js +456 -0
  15. package/dist/crushes/callback.crush.d.ts +2 -0
  16. package/dist/crushes/callback.crush.js +19 -0
  17. package/dist/crushes/crush.d.ts +36 -0
  18. package/dist/crushes/crush.js +12 -0
  19. package/dist/crushes/crush.names.d.ts +1 -0
  20. package/dist/crushes/crush.names.js +2 -0
  21. package/dist/crushes/crushes.d.ts +2 -0
  22. package/dist/crushes/crushes.js +9 -0
  23. package/dist/crushes/default-value.crush.d.ts +2 -0
  24. package/dist/crushes/default-value.crush.js +29 -0
  25. package/dist/crushes/drop-operand.crush.d.ts +2 -0
  26. package/dist/crushes/drop-operand.crush.js +37 -0
  27. package/dist/crushes/fold.d.ts +64 -0
  28. package/dist/crushes/fold.js +366 -0
  29. package/dist/crushes/force-fork.crush.d.ts +2 -0
  30. package/dist/crushes/force-fork.crush.js +79 -0
  31. package/dist/crushes/loop-once.crush.d.ts +2 -0
  32. package/dist/crushes/loop-once.crush.js +71 -0
  33. package/dist/crushes/optional-chain.crush.d.ts +2 -0
  34. package/dist/crushes/optional-chain.crush.js +30 -0
  35. package/dist/crushes/switch-case.crush.d.ts +2 -0
  36. package/dist/crushes/switch-case.crush.js +19 -0
  37. package/dist/decisions/decide.d.ts +61 -0
  38. package/dist/decisions/decide.js +161 -0
  39. package/dist/decisions/decisions.d.ts +24 -0
  40. package/dist/decisions/decisions.js +62 -0
  41. package/dist/decisions/forks.decision.d.ts +4 -0
  42. package/dist/decisions/forks.decision.js +32 -0
  43. package/dist/decisions/kinds.d.ts +101 -0
  44. package/dist/decisions/kinds.js +38 -0
  45. package/dist/decisions/loops.decision.d.ts +4 -0
  46. package/dist/decisions/loops.decision.js +39 -0
  47. package/dist/decisions/shorts.decision.d.ts +3 -0
  48. package/dist/decisions/shorts.decision.js +66 -0
  49. package/dist/decisions/switches.decision.d.ts +3 -0
  50. package/dist/decisions/switches.decision.js +20 -0
  51. package/dist/decisions/throws.decision.d.ts +3 -0
  52. package/dist/decisions/throws.decision.js +35 -0
  53. package/dist/decisions/values.decision.d.ts +3 -0
  54. package/dist/decisions/values.decision.js +67 -0
  55. package/dist/explore/edges/explore.d.ts +60 -0
  56. package/dist/explore/edges/explore.db.d.ts +22 -0
  57. package/dist/explore/edges/explore.db.js +55 -0
  58. package/dist/explore/edges/explore.js +305 -0
  59. package/dist/explore/edges/random.d.ts +2 -0
  60. package/dist/explore/edges/random.js +32 -0
  61. package/dist/explore/explore.operations.d.ts +30 -0
  62. package/dist/explore/explore.operations.js +117 -0
  63. package/dist/explore/limits.operations.d.ts +14 -0
  64. package/dist/explore/limits.operations.js +20 -0
  65. package/dist/explore/targets.operations.d.ts +36 -0
  66. package/dist/explore/targets.operations.js +32 -0
  67. package/dist/explore/utils/draws.d.ts +6 -0
  68. package/dist/explore/utils/draws.js +2 -0
  69. package/dist/explore/utils/edits.d.ts +15 -0
  70. package/dist/explore/utils/edits.js +151 -0
  71. package/dist/explore/utils/guide.d.ts +23 -0
  72. package/dist/explore/utils/guide.js +35 -0
  73. package/dist/explore/utils/keep.d.ts +10 -0
  74. package/dist/explore/utils/keep.js +61 -0
  75. package/dist/explore/utils/pools.d.ts +17 -0
  76. package/dist/explore/utils/pools.js +121 -0
  77. package/dist/explore/utils/reads.d.ts +19 -0
  78. package/dist/explore/utils/reads.js +118 -0
  79. package/dist/explore/utils/twin.d.ts +21 -0
  80. package/dist/explore/utils/twin.js +55 -0
  81. package/dist/forks/forks.operations.d.ts +32 -0
  82. package/dist/forks/forks.operations.js +134 -0
  83. package/dist/forks/forks.schema.d.ts +20 -0
  84. package/dist/forks/forks.schema.js +14 -0
  85. package/dist/graph/cfg/cfg.d.ts +28 -0
  86. package/dist/graph/cfg/cfg.js +31 -0
  87. package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
  88. package/dist/graph/cfg/code-paths/analyzer.js +358 -0
  89. package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
  90. package/dist/graph/cfg/code-paths/segments.js +105 -0
  91. package/dist/graph/cfg/code-paths/state.d.ts +121 -0
  92. package/dist/graph/cfg/code-paths/state.js +611 -0
  93. package/dist/graph/cfg/entries.d.ts +13 -0
  94. package/dist/graph/cfg/entries.js +120 -0
  95. package/dist/graph/cfg/functions.d.ts +6 -0
  96. package/dist/graph/cfg/functions.js +47 -0
  97. package/dist/graph/cfg/paths.d.ts +27 -0
  98. package/dist/graph/cfg/paths.js +91 -0
  99. package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
  100. package/dist/graph/cfg/scopes/scopes.js +375 -0
  101. package/dist/graph/symbols/file.d.ts +90 -0
  102. package/dist/graph/symbols/file.js +427 -0
  103. package/dist/graph/symbols/keys.d.ts +13 -0
  104. package/dist/graph/symbols/keys.js +22 -0
  105. package/dist/graph/symbols/resolve.operations.d.ts +4 -0
  106. package/dist/graph/symbols/resolve.operations.js +33 -0
  107. package/dist/graph/symbols/symbols.d.ts +12 -0
  108. package/dist/graph/symbols/symbols.js +155 -0
  109. package/dist/graph/symbols/symbols.schema.d.ts +32 -0
  110. package/dist/graph/symbols/symbols.schema.js +19 -0
  111. package/dist/graph/unused/tests.d.ts +7 -0
  112. package/dist/graph/unused/tests.js +95 -0
  113. package/dist/graph/unused/unused.d.ts +53 -0
  114. package/dist/graph/unused/unused.js +319 -0
  115. package/dist/graph/walk/walk.d.ts +7 -0
  116. package/dist/graph/walk/walk.js +39 -0
  117. package/dist/instrument/instrument.operations.d.ts +72 -0
  118. package/dist/instrument/instrument.operations.js +786 -0
  119. package/dist/instrument/instrument.schema.d.ts +257 -0
  120. package/dist/instrument/instrument.schema.js +100 -0
  121. package/dist/judge/counters.d.ts +86 -0
  122. package/dist/judge/counters.js +402 -0
  123. package/dist/judge/edges/api.d.ts +14 -0
  124. package/dist/judge/edges/api.js +80 -0
  125. package/dist/judge/edges/completion.reporter.d.ts +9 -0
  126. package/dist/judge/edges/completion.reporter.js +51 -0
  127. package/dist/judge/edges/hints.reporter.d.ts +13 -0
  128. package/dist/judge/edges/hints.reporter.js +29 -0
  129. package/dist/judge/edges/judge.edges.d.ts +52 -0
  130. package/dist/judge/edges/judge.edges.js +59 -0
  131. package/dist/judge/edges/judge.fs.d.ts +8 -0
  132. package/dist/judge/edges/judge.fs.js +45 -0
  133. package/dist/judge/edges/merge.d.ts +11 -0
  134. package/dist/judge/edges/merge.js +60 -0
  135. package/dist/judge/edges/plugin.d.ts +132 -0
  136. package/dist/judge/edges/plugin.js +441 -0
  137. package/dist/judge/edges/reach.d.ts +68 -0
  138. package/dist/judge/edges/reach.js +132 -0
  139. package/dist/judge/edges/speed.d.ts +32 -0
  140. package/dist/judge/edges/speed.js +34 -0
  141. package/dist/judge/edges/strays.d.ts +1 -0
  142. package/dist/judge/edges/strays.js +14 -0
  143. package/dist/judge/edges/vitest.d.ts +20 -0
  144. package/dist/judge/edges/vitest.js +36 -0
  145. package/dist/judge/edges/vitest.schema.d.ts +14 -0
  146. package/dist/judge/edges/vitest.schema.js +16 -0
  147. package/dist/judge/explore.test.d.ts +1 -0
  148. package/dist/judge/explore.test.js +101 -0
  149. package/dist/judge/hints.d.ts +11 -0
  150. package/dist/judge/hints.js +44 -0
  151. package/dist/judge/judge.operations.d.ts +218 -0
  152. package/dist/judge/judge.operations.js +464 -0
  153. package/dist/judge/judge.schema.d.ts +135 -0
  154. package/dist/judge/judge.schema.js +129 -0
  155. package/dist/judge/judge.shard-1.test.d.ts +1 -0
  156. package/dist/judge/judge.shard-1.test.js +3 -0
  157. package/dist/judge/judge.shard-2.test.d.ts +1 -0
  158. package/dist/judge/judge.shard-2.test.js +3 -0
  159. package/dist/judge/judge.test.d.ts +1 -0
  160. package/dist/judge/judge.test.js +3 -0
  161. package/dist/judge/refusals.d.ts +14 -0
  162. package/dist/judge/refusals.js +10 -0
  163. package/dist/judge/report.test.d.ts +1 -0
  164. package/dist/judge/report.test.js +432 -0
  165. package/dist/judge/runner.d.ts +3 -0
  166. package/dist/judge/runner.js +1602 -0
  167. package/dist/judge/stresses.test.d.ts +1 -0
  168. package/dist/judge/stresses.test.js +12 -0
  169. package/dist/judge/task-meta.d.ts +51 -0
  170. package/dist/judge/task-meta.js +3 -0
  171. package/dist/justify/edges/load.d.ts +7 -0
  172. package/dist/justify/edges/load.js +40 -0
  173. package/dist/justify/edges/refresh.fs.d.ts +8 -0
  174. package/dist/justify/edges/refresh.fs.js +15 -0
  175. package/dist/justify/justify.operations.d.ts +46 -0
  176. package/dist/justify/justify.operations.js +80 -0
  177. package/dist/justify/justify.schema.d.ts +21 -0
  178. package/dist/justify/justify.schema.js +11 -0
  179. package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
  180. package/dist/mutators/arithmetic-operator.mutator.js +22 -0
  181. package/dist/mutators/array-declaration.mutator.d.ts +2 -0
  182. package/dist/mutators/array-declaration.mutator.js +12 -0
  183. package/dist/mutators/arrow-function.mutator.d.ts +2 -0
  184. package/dist/mutators/arrow-function.mutator.js +10 -0
  185. package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
  186. package/dist/mutators/assignment-operator.mutator.js +29 -0
  187. package/dist/mutators/await-expression.mutator.d.ts +2 -0
  188. package/dist/mutators/await-expression.mutator.js +7 -0
  189. package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
  190. package/dist/mutators/bitwise-operator.mutator.js +19 -0
  191. package/dist/mutators/block-statement.mutator.d.ts +2 -0
  192. package/dist/mutators/block-statement.mutator.js +30 -0
  193. package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
  194. package/dist/mutators/boolean-literal.mutator.js +5 -0
  195. package/dist/mutators/coercion.mutator.d.ts +2 -0
  196. package/dist/mutators/coercion.mutator.js +28 -0
  197. package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
  198. package/dist/mutators/conditional-expression.mutator.js +36 -0
  199. package/dist/mutators/disposal.mutator.d.ts +2 -0
  200. package/dist/mutators/disposal.mutator.js +13 -0
  201. package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
  202. package/dist/mutators/empty-destructuring.mutator.js +35 -0
  203. package/dist/mutators/empty-return.mutator.d.ts +2 -0
  204. package/dist/mutators/empty-return.mutator.js +35 -0
  205. package/dist/mutators/equality-operator.mutator.d.ts +2 -0
  206. package/dist/mutators/equality-operator.mutator.js +16 -0
  207. package/dist/mutators/loop-exit.mutator.d.ts +2 -0
  208. package/dist/mutators/loop-exit.mutator.js +5 -0
  209. package/dist/mutators/method-expression.mutator.d.ts +2 -0
  210. package/dist/mutators/method-expression.mutator.js +59 -0
  211. package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
  212. package/dist/mutators/missing-lookup.mutator.js +25 -0
  213. package/dist/mutators/mutator.d.ts +40 -0
  214. package/dist/mutators/mutator.js +49 -0
  215. package/dist/mutators/mutator.names.d.ts +3 -0
  216. package/dist/mutators/mutator.names.js +43 -0
  217. package/dist/mutators/mutators.d.ts +8 -0
  218. package/dist/mutators/mutators.js +84 -0
  219. package/dist/mutators/nested-condition.mutator.d.ts +2 -0
  220. package/dist/mutators/nested-condition.mutator.js +16 -0
  221. package/dist/mutators/number-literal.mutator.d.ts +3 -0
  222. package/dist/mutators/number-literal.mutator.js +13 -0
  223. package/dist/mutators/object-literal.mutator.d.ts +2 -0
  224. package/dist/mutators/object-literal.mutator.js +6 -0
  225. package/dist/mutators/odd-number.mutator.d.ts +2 -0
  226. package/dist/mutators/odd-number.mutator.js +15 -0
  227. package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
  228. package/dist/mutators/operand-deletion.mutator.js +9 -0
  229. package/dist/mutators/outcome.mutator.d.ts +3 -0
  230. package/dist/mutators/outcome.mutator.js +45 -0
  231. package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
  232. package/dist/mutators/plain-assignment.mutator.js +7 -0
  233. package/dist/mutators/power-operator.mutator.d.ts +2 -0
  234. package/dist/mutators/power-operator.mutator.js +13 -0
  235. package/dist/mutators/private-brand.mutator.d.ts +2 -0
  236. package/dist/mutators/private-brand.mutator.js +7 -0
  237. package/dist/mutators/regex.mutator.d.ts +2 -0
  238. package/dist/mutators/regex.mutator.js +29 -0
  239. package/dist/mutators/short-iteration.mutator.d.ts +2 -0
  240. package/dist/mutators/short-iteration.mutator.js +8 -0
  241. package/dist/mutators/string-literal.mutator.d.ts +3 -0
  242. package/dist/mutators/string-literal.mutator.js +149 -0
  243. package/dist/mutators/switch-default.mutator.d.ts +2 -0
  244. package/dist/mutators/switch-default.mutator.js +13 -0
  245. package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
  246. package/dist/mutators/sync-iteration.mutator.js +9 -0
  247. package/dist/mutators/thrown-call.mutator.d.ts +2 -0
  248. package/dist/mutators/thrown-call.mutator.js +7 -0
  249. package/dist/mutators/unary-operator.mutator.d.ts +2 -0
  250. package/dist/mutators/unary-operator.mutator.js +18 -0
  251. package/dist/mutators/unbound-call.mutator.d.ts +2 -0
  252. package/dist/mutators/unbound-call.mutator.js +14 -0
  253. package/dist/mutators/update-operator.mutator.d.ts +2 -0
  254. package/dist/mutators/update-operator.mutator.js +15 -0
  255. package/dist/mutators/yield-value.mutator.d.ts +2 -0
  256. package/dist/mutators/yield-value.mutator.js +7 -0
  257. package/dist/parity/compare.d.ts +27 -0
  258. package/dist/parity/compare.js +26 -0
  259. package/dist/parity/corpus.parity.d.ts +1 -0
  260. package/dist/parity/corpus.parity.js +97 -0
  261. package/dist/parity/edges/corpus.fs.d.ts +3 -0
  262. package/dist/parity/edges/corpus.fs.js +30 -0
  263. package/dist/parity/edges/ports.d.ts +2 -0
  264. package/dist/parity/edges/ports.js +21 -0
  265. package/dist/parity/edges/vitest.d.ts +2 -0
  266. package/dist/parity/edges/vitest.js +3 -0
  267. package/dist/parity/parity.operations.d.ts +33 -0
  268. package/dist/parity/parity.operations.js +60 -0
  269. package/dist/parity/parity.schema.d.ts +5 -0
  270. package/dist/parity/parity.schema.js +6 -0
  271. package/dist/parity/stryker/compare.d.ts +14 -0
  272. package/dist/parity/stryker/compare.js +52 -0
  273. package/dist/parity/stryker/edges/ports.d.ts +12 -0
  274. package/dist/parity/stryker/edges/ports.js +28 -0
  275. package/dist/parity/stryker/equivalence.d.ts +1 -0
  276. package/dist/parity/stryker/equivalence.js +42 -0
  277. package/dist/parity/stryker/intended.d.ts +29 -0
  278. package/dist/parity/stryker/intended.js +152 -0
  279. package/dist/parity/stryker/normalize.d.ts +27 -0
  280. package/dist/parity/stryker/normalize.js +181 -0
  281. package/dist/parity/stryker/rules.d.ts +6 -0
  282. package/dist/parity/stryker/rules.js +116 -0
  283. package/dist/parity/stryker/sides.d.ts +46 -0
  284. package/dist/parity/stryker/sides.js +199 -0
  285. package/dist/parity/stryker/stryker.parity.d.ts +1 -0
  286. package/dist/parity/stryker/stryker.parity.js +147 -0
  287. package/dist/parity/stryker/stryker.schema.d.ts +6 -0
  288. package/dist/parity/stryker/stryker.schema.js +7 -0
  289. package/dist/parity/views.d.ts +21 -0
  290. package/dist/parity/views.js +119 -0
  291. package/dist/questions/questions.operations.d.ts +110 -0
  292. package/dist/questions/questions.operations.js +446 -0
  293. package/dist/questions/questions.schema.d.ts +57 -0
  294. package/dist/questions/questions.schema.js +28 -0
  295. package/dist/record/edges/calls.db.d.ts +10 -0
  296. package/dist/record/edges/calls.db.js +91 -0
  297. package/dist/record/edges/hits.db.d.ts +3 -0
  298. package/dist/record/edges/hits.db.js +5 -0
  299. package/dist/record/edges/holds.db.d.ts +4 -0
  300. package/dist/record/edges/holds.db.js +31 -0
  301. package/dist/record/edges/judged-state.db.d.ts +5 -0
  302. package/dist/record/edges/judged-state.db.js +25 -0
  303. package/dist/record/edges/markers.db.d.ts +11 -0
  304. package/dist/record/edges/markers.db.js +55 -0
  305. package/dist/record/edges/merge.db.d.ts +7 -0
  306. package/dist/record/edges/merge.db.js +46 -0
  307. package/dist/record/edges/parts.db.d.ts +42 -0
  308. package/dist/record/edges/parts.db.js +389 -0
  309. package/dist/record/edges/parts.edges.d.ts +2 -0
  310. package/dist/record/edges/parts.edges.js +7 -0
  311. package/dist/record/edges/parts.fs.d.ts +1 -0
  312. package/dist/record/edges/parts.fs.js +11 -0
  313. package/dist/record/edges/parts.writer.d.ts +1 -0
  314. package/dist/record/edges/parts.writer.js +85 -0
  315. package/dist/record/edges/passes.db.d.ts +19 -0
  316. package/dist/record/edges/passes.db.js +31 -0
  317. package/dist/record/edges/plan.db.d.ts +21 -0
  318. package/dist/record/edges/plan.db.js +174 -0
  319. package/dist/record/edges/reach.db.d.ts +6 -0
  320. package/dist/record/edges/reach.db.js +62 -0
  321. package/dist/record/edges/record.db.d.ts +22 -0
  322. package/dist/record/edges/record.db.js +176 -0
  323. package/dist/record/edges/record.fs.d.ts +3 -0
  324. package/dist/record/edges/record.fs.js +7 -0
  325. package/dist/record/edges/site-verdicts.db.d.ts +11 -0
  326. package/dist/record/edges/site-verdicts.db.js +66 -0
  327. package/dist/record/edges/verified.db.d.ts +7 -0
  328. package/dist/record/edges/verified.db.js +71 -0
  329. package/dist/record/parts.operations.d.ts +26 -0
  330. package/dist/record/parts.operations.js +31 -0
  331. package/dist/record/path-checks.operations.d.ts +15 -0
  332. package/dist/record/path-checks.operations.js +84 -0
  333. package/dist/record/record.operations.d.ts +36 -0
  334. package/dist/record/record.operations.js +11 -0
  335. package/dist/stresses/edges/stresses.record.d.ts +4 -0
  336. package/dist/stresses/edges/stresses.record.js +37 -0
  337. package/dist/stresses/stresses.operations.d.ts +28 -0
  338. package/dist/stresses/stresses.operations.js +22 -0
  339. package/dist/utils/ast.d.ts +55 -0
  340. package/dist/utils/ast.js +181 -0
  341. package/dist/utils/errors.d.ts +8 -0
  342. package/dist/utils/errors.js +12 -0
  343. package/dist/utils/faults.d.ts +6 -0
  344. package/dist/utils/faults.js +10 -0
  345. package/dist/utils/lookup.d.ts +4 -0
  346. package/dist/utils/lookup.js +27 -0
  347. package/dist/utils/order.d.ts +2 -0
  348. package/dist/utils/order.js +17 -0
  349. package/dist/utils/retry.d.ts +14 -0
  350. package/dist/utils/retry.js +15 -0
  351. package/dist/utils/safe.d.ts +11 -0
  352. package/dist/utils/safe.js +31 -0
  353. package/migrations/main/20261129123324_initial/migration.sql +418 -0
  354. package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
  355. package/package.json +89 -4
  356. package/references/consumer-setup.md +92 -0
  357. package/src/graph/cfg/code-paths/LICENSE +21 -0
  358. package/src/graph/cfg/scopes/LICENSE +24 -0
@@ -0,0 +1,464 @@
1
+ import { z } from 'zod';
2
+ import { outcomeMutatorName } from '../mutators/mutator.names.js';
3
+ import { reachingKinds, siteQuestionsOf, testTitleOf } from '../questions/questions.operations.js';
4
+ import { hashOf, unitKeyOf } from '../record/record.operations.js';
5
+ import { failed } from '../utils/errors.js';
6
+ import { entryAt, itemAt } from '../utils/lookup.js';
7
+ import { safeAsync } from '../utils/safe.js';
8
+ // The tests that reran against a site, cheapest first by baseline ticks, then by key, so two runs of one project rerun them in one order and name one catcher.
9
+ export const ridersOf = (reached, tests) => {
10
+ return [...new Set(reached)]
11
+ .flatMap((key) => {
12
+ const rider = tests.get(key);
13
+ return rider ? [rider] : [];
14
+ })
15
+ .toSorted((left, right) => left.ticks - right.ticks || left.key.localeCompare(right.key));
16
+ };
17
+ // Every test under each suite of a tree, the file's own top level included, outermost suite first.
18
+ export const testsUnderOf = (root) => {
19
+ const under = new Map();
20
+ const walk = (task) => {
21
+ if (task.type !== 'suite')
22
+ return [task.id];
23
+ const own = [];
24
+ under.set(task.id, own);
25
+ for (const child of task.tasks)
26
+ own.push(...walk(child));
27
+ return own;
28
+ };
29
+ walk(root);
30
+ return under;
31
+ };
32
+ // What a suite's hooks reached, as `beforeAll` building an app, credited to every test under that suite, since each test runs on that work.
33
+ export const creditedOf = (reached, testsUnder) => {
34
+ return new Map([...reached].map(([index, ids]) => [index, new Set([...ids].flatMap((id) => testsUnder.get(id) ?? [id]))]));
35
+ };
36
+ // A project's own function run as a hooked body, its throw read as its failure, as Vitest reads a test function's.
37
+ export const caughtOf = (fn) => {
38
+ return async () => (await safeAsync(async () => await fn())).error;
39
+ };
40
+ // Runs every hook in order, one after another, where a throw stops the rest of the kind.
41
+ const inOrderOf = async (groups, results) => {
42
+ for (const hook of groups.flat()) {
43
+ // oxlint-disable-next-line no-await-in-loop -- each hook may set up what the next reads, and a throw stops the rest
44
+ const { data, error } = await safeAsync(async () => await hook());
45
+ if (error)
46
+ return error;
47
+ results.push(data);
48
+ }
49
+ return null;
50
+ };
51
+ // Runs each group's hooks all at once, group after group, answering a group's errors once it settles.
52
+ const inParallelOf = async (groups, results) => {
53
+ for (const group of groups) {
54
+ // oxlint-disable-next-line no-await-in-loop -- each group is one suite's, which finishes before the next suite's starts
55
+ const settled = await Promise.all(group.map(async (hook) => await safeAsync(async () => await hook())));
56
+ for (const { data, error } of settled)
57
+ if (!error)
58
+ results.push(data);
59
+ const errors = [...new Set(settled.flatMap(({ error }) => (error ? [error] : [])))];
60
+ if (errors.length > 1)
61
+ return new AggregateError(errors, 'Multiple hooks failed.');
62
+ const [error] = errors;
63
+ if (error)
64
+ return error;
65
+ }
66
+ return null;
67
+ };
68
+ // Runs one kind of hooks, group by group, as Vitest's callSuiteHook does: in order, where a throw stops the rest of the kind, or each group all at once, where the group's errors are answered once it settles.
69
+ // Adds what each hook returned to `results` in run order as it returns, so a throw keeps what ran before it, as callSuiteHook's cleanups do (vitest run.ts:228).
70
+ const kindOf = async (sequence, groups, results) => (sequence === 'parallel' ? await inParallelOf(groups, results) : await inOrderOf(groups, results));
71
+ // The message Vitest fails a run with when an around hook returns without running what it wraps (vitest run.ts:401).
72
+ const unwrappedMessages = {
73
+ test: 'The `runTest()` callback was not called in the `aroundEach` hook. Make sure to call `runTest()` to run the test.',
74
+ suite: 'The `runSuite()` callback was not called in the `aroundAll` hook. Make sure to call `runSuite()` to run the suite.',
75
+ };
76
+ // A body run as Vitest runs it: inside each around hook, the before groups, then the body, then the after groups, then the cleanups the before hooks returned.
77
+ // A throwing before hook skips the body and the rest of its kind but not the after hooks or the cleanups of the hooks before it (vitest run.ts:689-696 and 938-946), and a throwing after hook skips the rest of its kind and the cleanups.
78
+ // Under `stack`, each after group and the cleanups run last-registered first, so a rerun leaves nothing, such as fake timers, for the next one, and the first error is the rerun's.
79
+ export const hookedOf = ({ sequence, wraps, hooks, body }) => {
80
+ return async () => {
81
+ const errors = [];
82
+ const ordered = (group) => (sequence === 'stack' ? group.toReversed() : [...group]);
83
+ const inner = async () => {
84
+ const returned = [];
85
+ const setUpError = await kindOf(sequence, hooks.before, returned);
86
+ if (setUpError)
87
+ errors.push(setUpError);
88
+ else {
89
+ const error = await body();
90
+ if (error)
91
+ errors.push(error);
92
+ }
93
+ const tearDownError = await kindOf(sequence, hooks.after.map(ordered), []);
94
+ if (tearDownError) {
95
+ errors.push(tearDownError);
96
+ return;
97
+ }
98
+ const cleanups = returned.flatMap((result) => (typeof result === 'function' ? [() => Reflect.apply(result, undefined, [])] : []));
99
+ const cleanupError = await kindOf(sequence, [ordered(cleanups)], []);
100
+ if (cleanupError)
101
+ errors.push(cleanupError);
102
+ };
103
+ const wrappedIn = (use, around) => {
104
+ return async () => {
105
+ let isUsed = false;
106
+ const used = async () => {
107
+ isUsed = true;
108
+ await use();
109
+ };
110
+ const { error } = await safeAsync(async () => await around(used));
111
+ if (error)
112
+ errors.push(error);
113
+ else if (!isUsed)
114
+ errors.push(new Error(unwrappedMessages[wraps]));
115
+ };
116
+ };
117
+ const wrapped = hooks.around.toReversed().reduce(wrappedIn, inner);
118
+ await wrapped();
119
+ const [first] = errors;
120
+ return first ?? null;
121
+ };
122
+ };
123
+ // A body inside each suite's `beforeAll`, `afterAll` and `aroundAll`, outermost suite first, each suite closing with its afterAll and its own cleanups before the suite around it.
124
+ export const suitedOf = ({ sequence, suites, body }) => {
125
+ let run = body;
126
+ for (const hooks of suites.toReversed())
127
+ run = hookedOf({ sequence, wraps: 'suite', hooks, body: run });
128
+ return run;
129
+ };
130
+ // The group a test's backup must come from outside of: its outermost describe, or its file for a test under none, so a backup comes only from another function's tests.
131
+ export const groupOf = (file, groups) => JSON.stringify([file, ...groups.slice(0, 1)]);
132
+ // The sites each question a catch answers asks about, by its id, built over every planned site as the report builds them, so an id names its one site, the occurrence of its code included.
133
+ // A question a reach answers is left out, since a test's hits show it.
134
+ export const answerSitesOf = (files) => {
135
+ const { all } = siteQuestionsOf(judgedSitesOf(files, new Map()));
136
+ return new Map(all.filter(({ kind }) => !reachingKinds.has(kind)).map(({ id, sites }) => [id, new Set(sites)]));
137
+ };
138
+ // Whether an answer names a question a catch of this very site answers.
139
+ const answersSiteOf = (answer, { key, answerSites }) => Boolean(answerSites.get(answer)?.has(key));
140
+ // After a catch, only a test of another group can be the backup, so a site never counts its catcher's neighbours as a second catcher.
141
+ // A test answering a question about this site is tried first and one answering another question next, since an answer counts only where its test catches.
142
+ export const backupRidersOf = ({ riders, catcher, site }) => {
143
+ const others = riders.filter((rider) => rider.group !== catcher.group);
144
+ const rankOf = ({ answers }) => {
145
+ if (!answers.length)
146
+ return 2;
147
+ return answers.some((id) => answersSiteOf(id, site)) ? 0 : 1;
148
+ };
149
+ return others.toSorted((left, right) => rankOf(left) - rankOf(right));
150
+ };
151
+ // The other groups' tests answering a question about this site, the only second catchers a judge that finds no redundant tests still looks for, since an answer counts only where its test catches.
152
+ export const answeringRidersOf = ({ riders, catcher, site }) => riders.filter(({ group, answers }) => group !== catcher.group && answers.some((id) => answersSiteOf(id, site)));
153
+ // The sides of a crush's decision a test must have taken for the crush to change what it sees: the side the forced value takes away, and for a loop let through once, a second pass.
154
+ // A forced test that did work no longer does it, which a test on the kept side sees too, so such a crush rides both sides.
155
+ export const ridingSidesOf = ({ forced, skips }) => {
156
+ if (forced === 'once')
157
+ return ['repeat'];
158
+ const removed = forced ? 'false' : 'true';
159
+ return skips ? [removed, forced ? 'true' : 'false'] : [removed];
160
+ };
161
+ // The fork side a crush's question asks a test to take: the first it rides, as a dropped operand rides the side opposite the value it is dropped to.
162
+ export const askedSideOf = (crush) => itemAt(ridingSidesOf(crush), 0);
163
+ // The plan's named functions by unit key, and the tests whose baseline entered each, which every run kept only for a test that judges sites.
164
+ // The fork points are read from the hits of the tests whose baseline and unforced rerun passed, as entries are kept only for those.
165
+ export const functionsOf = (files, runs) => {
166
+ const enteredBy = new Map();
167
+ for (const { unit, testKey } of runs.flatMap(({ entered }) => entered))
168
+ enteredBy.set(unit, (enteredBy.get(unit) ?? new Set()).add(testKey));
169
+ const counting = new Set(runs.flatMap(({ tests, rerunFailing }) => {
170
+ const isRerunFailing = new Set(rerunFailing);
171
+ return tests.filter(({ key, passed }) => passed && !isRerunFailing.has(key)).map(({ key }) => key);
172
+ }));
173
+ const taken = new Set(runs.flatMap(({ hits }) => hits.filter(({ side, testKey }) => (side === 'true' || side === 'false') && counting.has(testKey)).map(({ siteKey }) => siteKey)));
174
+ return { named: new Set(files.flatMap(({ path, units }) => units.flatMap(({ name }) => (name ? [unitKeyOf(path, name)] : [])))), enteredBy, taken };
175
+ };
176
+ // Every planned site as questions read it, a site no verdict names left unreached.
177
+ export const judgedSitesOf = (files, merged) => {
178
+ return files.flatMap((file) => [
179
+ ...file.switches.map((site) => ({
180
+ key: site.key,
181
+ kind: 'tell',
182
+ mutator: site.mutator,
183
+ file: file.path,
184
+ owner: site.owner,
185
+ code: site.code,
186
+ replacement: site.replacement,
187
+ side: '',
188
+ start: site.start,
189
+ line: site.line,
190
+ status: merged.get(site.key)?.status ?? 'unreached',
191
+ point: '',
192
+ crush: '',
193
+ })),
194
+ ...file.crushes.map((site) => ({
195
+ key: site.key,
196
+ kind: 'crush',
197
+ mutator: '',
198
+ file: file.path,
199
+ owner: site.owner,
200
+ code: site.code,
201
+ replacement: '',
202
+ side: askedSideOf(site),
203
+ start: site.start,
204
+ line: site.line,
205
+ status: merged.get(site.key)?.status ?? 'unreached',
206
+ point: pointKeyOf(file.path, site.decision),
207
+ crush: site.crush,
208
+ forcedEffect: site.forcedEffect,
209
+ edits: site.edits,
210
+ })),
211
+ ]);
212
+ };
213
+ // Only verdicts that read code contribute evidence to a site's justification basis.
214
+ export const verdictBasesOf = (runs) => {
215
+ const bases = new Map();
216
+ for (const { verdicts } of runs) {
217
+ for (const { key, readHash } of verdicts) {
218
+ if (readHash !== undefined)
219
+ bases.set(key, (bases.get(key) ?? new Set()).add(readHash));
220
+ }
221
+ }
222
+ return bases;
223
+ };
224
+ // One verdict per site across every test file's run: caught by the first file whose tests caught it, survived when some file's tests reached it and none caught it, and unreached when none reached it.
225
+ // A backup comes from the catching file, or else from the next file that also caught it.
226
+ export const mergedOf = (runs) => {
227
+ const merged = new Map();
228
+ for (const run of runs) {
229
+ for (const verdict of run) {
230
+ const kept = merged.get(verdict.key);
231
+ // A part's verdict carries how this file judged it, such as its basis and reads, which the merged verdict leaves behind.
232
+ if (!kept || rankOf(verdict.status) > rankOf(kept.status)) {
233
+ const { key, status, catcher, backup } = verdict;
234
+ merged.set(key, { key, status, catcher, backup });
235
+ continue;
236
+ }
237
+ // A verdict reaching here ranks no higher than the kept one, so it names a catcher only when both caught, and a backup is taken only from one that did.
238
+ if (!kept.backup)
239
+ kept.backup = verdict.catcher;
240
+ }
241
+ }
242
+ return merged;
243
+ };
244
+ // A catch outranks a survival, which outranks a site no test reached.
245
+ const ranks = { unreached: 0, unjudged: 1, survived: 2, caught: 3 };
246
+ const rankOf = (status) => ranks[status];
247
+ // A fork point's key in the record: its source's path with its decision's id, since a decision's id names its function and code but not its file.
248
+ export const pointKeyOf = (path, decision) => JSON.stringify([path, decision]);
249
+ export const sideKeyOf = (point, side) => JSON.stringify([point, side]);
250
+ // The fork kinds whose false side no removal forces, a loop's body never running or a default never applying, so cov counts only their true side.
251
+ const oneSidedKinds = new Set(['forOf', 'forIn', 'switchDefault', 'valueDefault']);
252
+ // A figure with nothing to measure reads none, so no empty file shows 100%.
253
+ const figureOf = (part, whole, of) => (whole ? `${Math.floor((part * 100) / whole)}%: ${part} of ${whole} ${of}` : 'none');
254
+ // cov, the score and behavior cov: a justified site and its fork's sides counted nowhere, outcome mutants apart from the score as behavior cov, and a one-sided fork's true side alone.
255
+ export const figuresOf = ({ points, taken, sites, justified }) => {
256
+ const counted = sites.filter(({ key }) => !justified.has(key));
257
+ const justifiedPoints = new Set(sites.filter(({ key, point }) => point && justified.has(key)).map(({ point }) => point));
258
+ const sides = points.filter(({ key }) => !justifiedPoints.has(key)).flatMap(({ key, kind }) => (oneSidedKinds.has(kind) ? [sideKeyOf(key, 'true')] : [sideKeyOf(key, 'true'), sideKeyOf(key, 'false')]));
259
+ const scored = counted.filter(({ mutator }) => mutator !== outcomeMutatorName);
260
+ const outcomes = counted.filter(({ mutator }) => mutator === outcomeMutatorName);
261
+ const caughtOf = (list) => list.filter(({ status }) => status === 'caught').length;
262
+ const lines = [`cov ${figureOf(sides.filter((side) => taken.has(side)).length, sides.length, 'fork sides')}`, `score ${figureOf(caughtOf(scored), scored.length, 'sites caught')}`];
263
+ if (outcomes.length)
264
+ lines.push(`behavior cov ${figureOf(caughtOf(outcomes), outcomes.length, 'outcomes checked')}`);
265
+ return lines.join(' · ');
266
+ };
267
+ // How much source a crush's edits reach over, from its first edit's start to its last edit's end.
268
+ export const widthOf = ({ edits }) => Math.max(...edits.map(({ end }) => end)) - Math.min(...edits.map(({ start }) => start));
269
+ // The crushes collapse may apply together: each one no test file caught or left unreached, none held back by an earlier run, widest first as collapse applies them.
270
+ // Two sides of one decision can never fall together, so a point keeps only its widest crush.
271
+ export const candidatesOf = (crushes, statusOf, held) => {
272
+ const seen = new Set();
273
+ return crushes
274
+ .filter(({ key }) => statusOf.get(key) === 'survived' && !held.has(key))
275
+ .toSorted((left, right) => widthOf(right) - widthOf(left) || left.start - right.start || left.key.localeCompare(right.key))
276
+ .filter(({ point }) => {
277
+ if (seen.has(point))
278
+ return false;
279
+ seen.add(point);
280
+ return true;
281
+ });
282
+ };
283
+ // The candidate set a joint check ran, named by its hash, so the report counts only the files that checked the set merge last named.
284
+ export const candidatesHashOf = (list) => hashOf(JSON.stringify(list));
285
+ // What every hold rests on: a partner crush may sit in any source and a pillar in any test, so the text of each of them.
286
+ export const holdBasisOf = ({ sources, tests }) => hashOf(JSON.stringify([sources.map(({ path, hash }) => [path, hash]), tests.map(({ file, hash }) => [file, hash])]));
287
+ // The holds after a run: each kept while what it rests on is unchanged and its crush still falls alone, and each crush a test file dropped this run held on the basis it has now.
288
+ // A crush held again keeps every test that held it, since each is a pillar a removal must keep.
289
+ export const heldAfter = (held, dropped, statusOf, basisOf) => {
290
+ const kept = new Map(held.filter(({ key, basis }) => statusOf.get(key) === 'survived' && basisOf(key) === basis).map((hold) => [hold.key, { ...hold }]));
291
+ for (const { key, tests } of dropped) {
292
+ const hold = kept.get(key);
293
+ if (hold)
294
+ hold.tests = [...new Set([...hold.tests, ...tests])];
295
+ else
296
+ kept.set(key, { key, basis: basisOf(key), tests: [...new Set(tests)] });
297
+ }
298
+ return [...kept.values()].toSorted((left, right) => left.key.localeCompare(right.key));
299
+ };
300
+ // Whether a removal question could ask to remove a test: never one kept by its own reason, and under `answers` only one written to answer a question.
301
+ export const isRemovableOf = ({ answers, keeps }, removableTests) => !keeps && (removableTests === 'all' || answers.length > 0);
302
+ // The test files one shard of the judge command takes: every count-th from its own index, so the shards split the files evenly and none takes a file twice.
303
+ export const shareOf = (files, { index, count }) => files.filter((_, at) => at % count === index);
304
+ export const stalePartsOf = ({ parts, testFiles, hashOf: currentHashOf }) => {
305
+ const byFile = new Map(parts.map((part) => [part.file, part]));
306
+ const changesFor = (file) => {
307
+ const part = byFile.get(file);
308
+ if (!part)
309
+ return [{ file, changes: [{ path: file, reason: 'unrecorded' }] }];
310
+ const changes = [{ path: file, hash: part.hash }, ...part.reads].flatMap(({ path, hash }) => {
311
+ const current = currentHashOf(path);
312
+ if (current === hash)
313
+ return [];
314
+ return [{ path, reason: current === null ? 'missing' : 'changed' }];
315
+ });
316
+ return changes.length ? [{ file, changes }] : [];
317
+ };
318
+ return testFiles.toSorted().flatMap(changesFor);
319
+ };
320
+ const nextOccurrenceOf = (base, seen) => {
321
+ const count = seen.get(base) ?? 0;
322
+ seen.set(base, count + 1);
323
+ return count;
324
+ };
325
+ // The registration ordinal also counts skipped tests, so a rerun can use the same key without having run them.
326
+ export const testKeyOf = (file, name, seen) => {
327
+ const fields = [file, name.groups, name.title];
328
+ const occurrence = nextOccurrenceOf(JSON.stringify(fields), seen);
329
+ return JSON.stringify([...fields, occurrence]);
330
+ };
331
+ // A test's key as `testKeyOf` builds it: its file, its groups, its title and its occurrence.
332
+ const testKeyInput = z.tuple([z.string(), z.array(z.string()), z.string(), z.number()]);
333
+ // The test file a test's key names, which every test key begins with.
334
+ export const testFileOfKey = (key) => testKeyInput.parse(JSON.parse(key))[0];
335
+ const testLabelBaseOf = ({ file, groups, title }) => `${file}::${[...groups, title].join(' > ')}`;
336
+ export const testDisplayNameOf = (file, name, seen) => {
337
+ const occurrence = nextOccurrenceOf(testLabelBaseOf({ file, ...name }), seen);
338
+ return occurrence ? { ...name, occurrence } : name;
339
+ };
340
+ export const testLabelOf = ({ file, groups, title, occurrence }, seen) => {
341
+ const label = testLabelBaseOf({ file, groups, title });
342
+ return testTitleOf({ groups, title: label, occurrence: seen ? nextOccurrenceOf(label, seen) : occurrence });
343
+ };
344
+ export const runKeyOf = ({ file, titles }) => JSON.stringify([file, titles]);
345
+ // The passing tests that hold nothing up, so removing every one together leaves each caught site caught, each reached site reached, and each hold standing.
346
+ // A test is kept as a hold's pillar, as a catcher with no backup, as a catcher whose backup is not kept, as the cheapest reacher of a site no kept test reaches, or by its own reason.
347
+ export const removableOf = ({ tests, reach, verdicts, holds, removableTests, liveQuestions, catchingTests }) => {
348
+ const passing = new Map(tests.filter(({ passed }) => passed).map((test) => [test.key, test]));
349
+ const isKeptByItself = (test) => !isRemovableOf(test, removableTests) || (test.answers.some((id) => liveQuestions.has(id)) && catchingTests.has(test.key));
350
+ const kept = new Set([...holds.flatMap((hold) => hold.tests), ...[...passing.values()].filter(isKeptByItself).map(({ key }) => key)]);
351
+ // Only a caught site names a catcher, and a failing catcher or backup is never among the tests reaching a site, so neither needs a check of its own.
352
+ const caught = [...verdicts.values()].flatMap(({ catcher, backup }) => (catcher ? [{ catcher, backup }] : []));
353
+ for (const { catcher, backup } of caught)
354
+ if (!backup)
355
+ kept.add(catcher);
356
+ // Keeping a catcher only ever covers more sites, so one pass leaves every caught site with a kept catcher or backup.
357
+ for (const { catcher, backup } of caught)
358
+ if (!(backup && kept.has(backup)))
359
+ kept.add(catcher);
360
+ for (const reachers of reach.values()) {
361
+ const live = [...reachers].flatMap((key) => passing.get(key) ?? []);
362
+ const isCovered = live.some(({ key }) => kept.has(key));
363
+ const [cheapest] = live.toSorted((left, right) => left.ticks - right.ticks || left.key.localeCompare(right.key));
364
+ if (!isCovered && cheapest)
365
+ kept.add(cheapest.key);
366
+ }
367
+ // A passing test that reaches no site is offered too, since it holds nothing up.
368
+ return [...passing.keys()]
369
+ .filter((key) => !kept.has(key))
370
+ .toSorted()
371
+ .map((key) => {
372
+ const mine = caught.filter(({ catcher }) => catcher === key);
373
+ const counts = Map.groupBy(mine, ({ backup }) => backup ?? '');
374
+ const backups = [...counts].map(([backup, each]) => ({ key: backup, count: each.length })).toSorted((left, right) => right.count - left.count || left.key.localeCompare(right.key));
375
+ return { key, firsts: mine.length, backups };
376
+ });
377
+ };
378
+ // Whether every test file dropped the same crushes, each file then having passed its tests with exactly the set collapse applies.
379
+ export const dropsAgree = (checks) => {
380
+ const sets = checks.map(({ dropped }) => {
381
+ return dropped
382
+ .map(({ key }) => key)
383
+ .toSorted()
384
+ .join('\n');
385
+ });
386
+ const [first] = sets;
387
+ return sets.every((set) => set === first);
388
+ };
389
+ // The tests an open question in a source they reach unsettles, which may not be asked to go, so a test reaching no source at all may be.
390
+ // A crush that is survived and unheld always asks its own question, so a test that once held it is never asked while it stays that way.
391
+ export const unsettledTestsOf = ({ reach, fileOfSite, openFiles }) => {
392
+ const unsettled = new Set();
393
+ for (const [site, tests] of reach) {
394
+ if (!openFiles.has(entryAt(fileOfSite, site, `the source of ${site}`)))
395
+ continue;
396
+ for (const test of tests)
397
+ unsettled.add(test);
398
+ }
399
+ return unsettled;
400
+ };
401
+ // The count and reason a test states in `{ meta: { steps, stepsReason } }`, refused where a value would ask a question no answer could close.
402
+ const stepsMetaOf = (meta) => {
403
+ const steps = Reflect.get(meta, 'steps');
404
+ const reason = Reflect.get(meta, 'stepsReason');
405
+ const isCount = typeof steps === 'number' && Number.isInteger(steps) && steps >= 0;
406
+ if (steps !== undefined && !isCount)
407
+ return failed(`meta.steps must be a whole number of 0 or more, not ${JSON.stringify(steps)}`);
408
+ if (reason !== undefined && typeof reason !== 'string')
409
+ return failed(`meta.stepsReason must be text, not ${JSON.stringify(reason)}`);
410
+ if (reason !== undefined && steps === undefined)
411
+ return failed('meta.stepsReason needs meta.steps, the count it explains, beside it');
412
+ return { data: { statedSteps: isCount ? steps : null, stepsReason: typeof reason === 'string' ? reason : null }, error: null };
413
+ };
414
+ // The reason a test is kept, from `{ meta: { keeps } }`, refused where it is not text.
415
+ const keepsMetaOf = (meta) => {
416
+ const value = Reflect.get(meta, 'keeps');
417
+ if (value !== undefined && typeof value !== 'string')
418
+ return failed(`meta.keeps must be text, not ${JSON.stringify(value)}`);
419
+ return { data: value ?? null, error: null };
420
+ };
421
+ // The questions a test answers, from `{ meta: { answers } }` as one id or a list of them, refused where it is neither.
422
+ const answersMetaOf = (meta) => {
423
+ const value = Reflect.get(meta, 'answers');
424
+ if (value === undefined)
425
+ return { data: [], error: null };
426
+ if (typeof value === 'string')
427
+ return { data: [value], error: null };
428
+ const isList = Array.isArray(value) && value.every((id) => typeof id === 'string');
429
+ if (!isList)
430
+ return failed(`meta.answers must be a question id or a list of them, not ${JSON.stringify(value)}`);
431
+ return { data: value, error: null };
432
+ };
433
+ // A test's meta as the runner reads it: its stated steps, the question it answers and why it stays, refused at the first value a run cannot read.
434
+ export const metaOf = (meta) => {
435
+ const { data: steps, error: stepsError } = stepsMetaOf(meta);
436
+ if (stepsError)
437
+ return { data: null, error: stepsError };
438
+ const { data: answers, error: answersError } = answersMetaOf(meta);
439
+ if (answersError)
440
+ return { data: null, error: answersError };
441
+ const { data: keeps, error: keepsError } = keepsMetaOf(meta);
442
+ if (keepsError)
443
+ return { data: null, error: keepsError };
444
+ return { data: { ...steps, answers, keeps }, error: null };
445
+ };
446
+ // Matches the error Vitest fails a test or a hook with when it runs past its timeout.
447
+ export const timedOutPattern = /^(?:Test|Hook) timed out in \d+ms/;
448
+ // Every error a suite or any suite nested in it was left with, as a throwing suite hook leaves one, never a test's own.
449
+ const suiteErrorsOf = (node) => (node.type === 'test' ? [] : [...(node.result?.errors ?? []), ...(node.tasks ?? []).flatMap(suiteErrorsOf)]);
450
+ // Why a test file failed outside its tests, from the errors every suite in it was left with, or null when they left none.
451
+ // An error with no message still fails the file, so it is named rather than left as empty text a reader would take for none.
452
+ export const fileFailureOf = (file) => {
453
+ const errors = suiteErrorsOf(file);
454
+ if (!errors.length)
455
+ return null;
456
+ return errors.map(({ message }) => message || 'a suite hook threw with no message').join('\n');
457
+ };
458
+ // Every test in a file or suite that failed, by name.
459
+ const failedTestsOf = (node) => (node.type === 'test' ? (node.result?.state === 'fail' ? [node.name] : []) : (node.tasks ?? []).flatMap(failedTestsOf));
460
+ // Why a phase's run of a test file failed: a suite's error, or a test failing there, as one failing only in the verify rerun does, or null when the run passed.
461
+ export const runFailureOf = (file) => {
462
+ const failed = failedTestsOf(file);
463
+ return fileFailureOf(file) ?? (failed.length ? `failed: ${failed.join(', ')}` : null);
464
+ };
@@ -0,0 +1,135 @@
1
+ import { z } from 'zod';
2
+ export declare const candidateInput: z.ZodObject<{
3
+ key: z.ZodString;
4
+ point: z.ZodNumber;
5
+ forced: z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"once">]>;
6
+ start: z.ZodNumber;
7
+ edits: z.ZodArray<z.ZodObject<{
8
+ start: z.ZodNumber;
9
+ end: z.ZodNumber;
10
+ }, z.core.$strip>>;
11
+ }, z.core.$strip>;
12
+ export type Candidate = z.infer<typeof candidateInput>;
13
+ export declare const phaseRootInput: z.ZodString;
14
+ export declare const removableTestsInput: z.ZodEnum<{
15
+ all: "all";
16
+ answers: "answers";
17
+ }>;
18
+ export type RemovableTests = z.infer<typeof removableTestsInput>;
19
+ export declare const stepsSettingInput: z.ZodBoolean;
20
+ export declare const holdInput: z.ZodObject<{
21
+ key: z.ZodString;
22
+ basis: z.ZodString;
23
+ tests: z.ZodArray<z.ZodString>;
24
+ }, z.core.$strip>;
25
+ export type Hold = z.infer<typeof holdInput>;
26
+ declare const testNameInput: z.ZodObject<{
27
+ groups: z.ZodArray<z.ZodString>;
28
+ title: z.ZodString;
29
+ occurrence: z.ZodOptional<z.ZodNumber>;
30
+ }, z.core.$strip>;
31
+ export type TestName = z.infer<typeof testNameInput>;
32
+ export declare const judgedInput: z.ZodObject<{
33
+ file: z.ZodString;
34
+ hash: z.ZodString;
35
+ tests: z.ZodArray<z.ZodObject<{
36
+ key: z.ZodString;
37
+ name: z.ZodOptional<z.ZodObject<{
38
+ groups: z.ZodArray<z.ZodString>;
39
+ title: z.ZodString;
40
+ occurrence: z.ZodOptional<z.ZodNumber>;
41
+ }, z.core.$strip>>;
42
+ passed: z.ZodBoolean;
43
+ failure: z.ZodNullable<z.ZodString>;
44
+ steps: z.ZodNumber;
45
+ ticks: z.ZodNumber;
46
+ ns: z.ZodNumber;
47
+ answers: z.ZodArray<z.ZodString>;
48
+ keeps: z.ZodNullable<z.ZodString>;
49
+ statedSteps: z.ZodNullable<z.ZodNumber>;
50
+ stepsReason: z.ZodNullable<z.ZodString>;
51
+ isSteady: z.ZodBoolean;
52
+ }, z.core.$strip>>;
53
+ justifications: z.ZodOptional<z.ZodArray<z.ZodObject<{
54
+ id: z.ZodString;
55
+ basis: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"refresh">]>;
56
+ reason: z.ZodString;
57
+ path: z.ZodString;
58
+ position: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>>;
60
+ hits: z.ZodArray<z.ZodObject<{
61
+ siteKey: z.ZodString;
62
+ side: z.ZodEnum<{
63
+ absent: "absent";
64
+ case: "case";
65
+ default: "default";
66
+ false: "false";
67
+ present: "present";
68
+ reached: "reached";
69
+ repeat: "repeat";
70
+ true: "true";
71
+ }>;
72
+ testKey: z.ZodString;
73
+ }, z.core.$strip>>;
74
+ entered: z.ZodArray<z.ZodObject<{
75
+ unit: z.ZodString;
76
+ testKey: z.ZodString;
77
+ }, z.core.$strip>>;
78
+ verdicts: z.ZodArray<z.ZodObject<{
79
+ key: z.ZodString;
80
+ status: z.ZodEnum<{
81
+ caught: "caught";
82
+ survived: "survived";
83
+ unjudged: "unjudged";
84
+ unreached: "unreached";
85
+ }>;
86
+ catcher: z.ZodNullable<z.ZodString>;
87
+ backup: z.ZodNullable<z.ZodString>;
88
+ reruns: z.ZodNumber;
89
+ basis: z.ZodString;
90
+ reads: z.ZodObject<{
91
+ generation: z.ZodNumber;
92
+ count: z.ZodNumber;
93
+ }, z.core.$strip>;
94
+ readHash: z.ZodOptional<z.ZodString>;
95
+ isReused: z.ZodBoolean;
96
+ deferred: z.ZodNullable<z.ZodString>;
97
+ }, z.core.$strip>>;
98
+ reads: z.ZodArray<z.ZodObject<{
99
+ path: z.ZodString;
100
+ hash: z.ZodString;
101
+ }, z.core.$strip>>;
102
+ reused: z.ZodNumber;
103
+ rerunFailing: z.ZodArray<z.ZodString>;
104
+ passes: z.ZodArray<z.ZodObject<{
105
+ siteKey: z.ZodString;
106
+ side: z.ZodEnum<{
107
+ false: "false";
108
+ true: "true";
109
+ }>;
110
+ passes: z.ZodNumber;
111
+ }, z.core.$strip>>;
112
+ outside: z.ZodArray<z.ZodString>;
113
+ changed: z.ZodArray<z.ZodString>;
114
+ properties: z.ZodArray<z.ZodString>;
115
+ failure: z.ZodNullable<z.ZodString>;
116
+ assignees: z.ZodArray<z.ZodObject<{
117
+ source: z.ZodString;
118
+ assignee: z.ZodString;
119
+ }, z.core.$strip>>;
120
+ sequence: z.ZodObject<{
121
+ generation: z.ZodNumber;
122
+ units: z.ZodArray<z.ZodString>;
123
+ }, z.core.$strip>;
124
+ }, z.core.$strip>;
125
+ export type Judged = z.infer<typeof judgedInput>;
126
+ export declare const verifiedInput: z.ZodObject<{
127
+ file: z.ZodString;
128
+ candidates: z.ZodString;
129
+ dropped: z.ZodArray<z.ZodObject<{
130
+ key: z.ZodString;
131
+ tests: z.ZodArray<z.ZodString>;
132
+ }, z.core.$strip>>;
133
+ }, z.core.$strip>;
134
+ export type Verified = z.infer<typeof verifiedInput>;
135
+ export {};