@whaaaley/crush 0.0.0-stage → 0.2.7

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 +14 -0
  170. package/dist/judge/task-meta.js +1 -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,402 @@
1
+ // oxlint-disable typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { snapshotterOf, uncloned } from '../capture/capture.operations.js';
4
+ import { CrushError } from '../utils/errors.js';
5
+ import { safe } from '../utils/safe.js';
6
+ // What every instrumented file shares through this one module: the sides the current case takes, the point or site forced now, and the step limit.
7
+ // A point in `forced` returns its forced value, and a non-empty `current` names the case whose sides are being recorded.
8
+ // The id code running while a test file's modules load records under, before any test runs.
9
+ export const loadId = 'crush:load';
10
+ export const stateOf = () => ({
11
+ // A point forced to `once` is a loop let through for one pass only, the removal of its repeat side.
12
+ forced: new Map(),
13
+ site: -1,
14
+ // Code that runs while a test file loads its modules records under `loadId`, which judging credits to every passing test of that file.
15
+ current: loadId,
16
+ steps: 0,
17
+ ticks: 0,
18
+ limit: 0,
19
+ // Whether a run passed its limit, which a hook runner that returns only its first error can hide.
20
+ isLimitHit: false,
21
+ // The latest test at each fork side or site, cleared when its recorded observations are cleared or replaced.
22
+ lastHit: [],
23
+ lastReach: [],
24
+ // A fork side is keyed by its point doubled, plus one for the true side.
25
+ hits: new Map(),
26
+ // How many times the baseline runs passed through each fork side, by the same key.
27
+ passes: new Map(),
28
+ reach: new Map(),
29
+ // The tests that ran a loop a second time in one entry, or got an item from an iterator, the only ones a loop let through once can tell apart.
30
+ repeats: new Map(),
31
+ // The sources a test file's run loaded, which every verdict from that file rests on.
32
+ loaded: new Set(),
33
+ // The project files a test file's run loaded that crush leaves uninstrumented, where no step counts.
34
+ outside: new Set(),
35
+ // The units a test file's run entered, in the order first entered, which its verdicts rest on.
36
+ entered: new Set(),
37
+ // The tests that entered each unit, by the test running when it was entered, which show a function called though it returned before any site in it.
38
+ entries: new Map(),
39
+ weighed: new Set(),
40
+ infected: new Map(),
41
+ // Whether exports wrap themselves to keep their calls, which the runner turns on for its judging passes before any module loads; only a recording baseline keeps one.
42
+ isCapturing: false,
43
+ // Every call the baselines kept, in the order they began.
44
+ calls: [],
45
+ // How many calls each test kept of each export, by test and export key.
46
+ counts: new Map(),
47
+ // How many kept calls are still running, so a side taken while none is skips the async context lookup.
48
+ open: 0,
49
+ // The number of the last step any kept call took, shared by every call of the file so steps order across calls.
50
+ sequence: 0,
51
+ // Which file's capture is current, so a call an earlier file left running settles without touching this one's count.
52
+ epoch: 0,
53
+ // The kept calls each side's async context runs under, outermost first.
54
+ frames: new AsyncLocalStorage(),
55
+ // The tests and suite hooks running when a field of a literal justification was read, whose verdicts then rest on its text.
56
+ metadataReaders: new Set(),
57
+ });
58
+ // The prototypes every generator and async generator function shares, which tell a generator apart from a plain function.
59
+ const generatorPrototypes = new Set([Object.getPrototypeOf(function* () { }), Object.getPrototypeOf(async function* () { })]);
60
+ // Matches the source of a class, which starts with the `class` keyword.
61
+ export const classSourcePattern = /^class\b/;
62
+ // The most calls one test keeps of one export, so a test calling it in a hot loop keeps a sample while every other test keeps its own.
63
+ export const callLimit = 64;
64
+ // The most steps one call's path keeps, so a call looping over changing sides keeps a bounded prefix.
65
+ export const pathLimit = 1024;
66
+ // What a throw leaves of itself: an Error's name and message, or any other value as it was.
67
+ // Reading an error can run a getter that throws, which leaves it uncloned rather than replacing the throw the call made.
68
+ const thrownOf = (thrown, snapshotOf) => {
69
+ if (!(thrown instanceof Error))
70
+ return snapshotOf(thrown);
71
+ const { data, error } = safe(() => ({ name: String(thrown.name), message: String(thrown.message) }));
72
+ return error ? uncloned : data;
73
+ };
74
+ const stackOf = (thrown) => {
75
+ if (!Error.isError(thrown))
76
+ return '';
77
+ const { data, error } = safe(() => String(thrown.stack ?? ''));
78
+ return error ? '' : data;
79
+ };
80
+ // Whether a function is one a proxy must not stand in for: a class, which reads its private members through `this`, which a proxy would be.
81
+ // A callable exposing its own identity is left alone, as is one whose descriptors cannot be read.
82
+ const isUnproxied = (fn) => {
83
+ const { data, error } = safe(() => classSourcePattern.test(Function.prototype.toString.call(fn)) || Reflect.ownKeys(fn).some((key) => Reflect.getOwnPropertyDescriptor(fn, key)?.value === fn));
84
+ return Boolean(error) || Boolean(data);
85
+ };
86
+ // Whether a function is a generator, whose call returns before its body runs.
87
+ const isGenerator = (fn) => generatorPrototypes.has(Object.getPrototypeOf(fn));
88
+ // A side taken again with no step of any call between counts as one more pass of the step before.
89
+ const stepped = (state, call, key) => {
90
+ const last = call.path.at(-1);
91
+ if (last && last[1] === key && last[0] === state.sequence)
92
+ last[2] += 1;
93
+ else if (call.path.length < pathLimit)
94
+ call.path.push([++state.sequence, key, 1]);
95
+ else
96
+ call.isPathCut = true;
97
+ };
98
+ // The innermost kept call still running in a side's async context, which the side belongs to.
99
+ const innermostOf = (lives) => lives.findLast(({ isSettled }) => !isSettled);
100
+ export const stepLimitFactor = 10;
101
+ export const stepLimitFloor = 1000;
102
+ // A rerun may make ten times its baseline's steps, plus a floor for a baseline of few, before it counts as stuck.
103
+ export const stepLimitOf = (ticks) => ticks * stepLimitFactor + stepLimitFloor;
104
+ // Runs a call held to `limit` ticks from now, 0 for none, putting back the limit it found before its throw reaches any caller.
105
+ // This module loads uninstrumented, so nothing here ticks; a caller's instrumented catch would tick against the passed limit and throw again.
106
+ export const limitedRun = (state, limit, call) => {
107
+ const held = state.limit;
108
+ state.limit = limit ? state.ticks + limit : 0;
109
+ try {
110
+ return call();
111
+ }
112
+ finally {
113
+ state.limit = held;
114
+ }
115
+ };
116
+ // Starts the next test file's capture from nothing, its calls, counts, step numbers and running calls, leaving any call the last file left running to settle unseen.
117
+ export const clearedCalls = (state) => {
118
+ state.calls = [];
119
+ state.counts.clear();
120
+ state.sequence = 0;
121
+ state.open = 0;
122
+ state.epoch += 1;
123
+ };
124
+ // Installs an empty set of observations for the next file, or the observations credited to its tests.
125
+ export const setObservations = (state, hits = new Map(), reach = new Map()) => {
126
+ state.hits = hits;
127
+ state.reach = reach;
128
+ state.lastHit.length = 0;
129
+ state.lastReach.length = 0;
130
+ };
131
+ // What a case gives its switch when it misses, which no discriminant equals.
132
+ const caseMiss = Symbol('crush:case-miss');
133
+ // How many keys a `for...in` would walk, inherited ones included, counted no further than two.
134
+ const keyCountOf = (value) => {
135
+ let count = 0;
136
+ for (const _key in Object(value))
137
+ if (++count > 1)
138
+ break;
139
+ return count;
140
+ };
141
+ const hitLimitMessage = 'crush hit limit exceeded';
142
+ // The counters instrumented code calls, recording onto the state they are given.
143
+ export const countersOf = (state) => {
144
+ const { snapshotOf, snapshotsOf } = snapshotterOf(new WeakSet());
145
+ // A mutant that loops forever still passes a counter every iteration, so ticks stop it.
146
+ const tick = () => {
147
+ state.ticks++;
148
+ if (!state.limit || state.ticks <= state.limit)
149
+ return;
150
+ state.isLimitHit = true;
151
+ throw new CrushError(hitLimitMessage);
152
+ };
153
+ const isRecording = () => state.current !== '' && state.site === -1 && state.forced.size === 0;
154
+ // Once a site has a set, recording another witness only updates that set.
155
+ const note = (recorded, key) => {
156
+ const witnesses = recorded.get(key);
157
+ if (witnesses)
158
+ witnesses.add(state.current);
159
+ else
160
+ recorded.set(key, new Set().add(state.current));
161
+ };
162
+ const __t = (index, value) => {
163
+ state.steps++;
164
+ tick();
165
+ const forced = state.forced.get(index);
166
+ if (typeof forced === 'boolean')
167
+ return forced;
168
+ if (!state.current)
169
+ return value;
170
+ const key = index * 2 + (value ? 1 : 0);
171
+ if (isRecording())
172
+ state.passes.set(key, (state.passes.get(key) ?? 0) + 1);
173
+ const owner = state.open ? innermostOf(state.frames.getStore() ?? []) : undefined;
174
+ if (owner)
175
+ stepped(state, owner.call, key);
176
+ if (state.lastHit[key] !== state.current) {
177
+ state.lastHit[key] = state.current;
178
+ note(state.hits, key);
179
+ }
180
+ return value;
181
+ };
182
+ // A plain test forced to a value is never read, as the removal that forces it leaves no test to read, and still counts a step so a loop forced on is stopped.
183
+ const __n = (index) => {
184
+ const forced = state.forced.get(index);
185
+ if (typeof forced !== 'boolean')
186
+ return undefined;
187
+ state.steps++;
188
+ tick();
189
+ return forced;
190
+ };
191
+ // Notes that the current test ran a loop a second time in one entry.
192
+ const __r = (index, entered) => {
193
+ if (entered === 2 && isRecording())
194
+ state.repeats.set(index, (state.repeats.get(index) ?? new Set()).add(state.current));
195
+ return true;
196
+ };
197
+ // A loop forced to one pass stops before the test of any later pass of the same entry, whose passes its own counter holds.
198
+ const __l = (index, pass) => pass === 0 || state.forced.get(index) !== 'once';
199
+ const __s = (index) => {
200
+ tick();
201
+ if (state.current && state.lastReach[index] !== state.current) {
202
+ state.lastReach[index] = state.current;
203
+ note(state.reach, index);
204
+ }
205
+ return index === state.site;
206
+ };
207
+ // A replacement is weighed only while a baseline case records, noting each case where it gives another value, so a mutant only those cases tell apart reruns only them.
208
+ const __w = (indices, replacements, value) => {
209
+ if (!isRecording())
210
+ return value;
211
+ // A replacement already noted for this test can note nothing more, so once every one is, weighing is skipped, which hot code pays for on every pass.
212
+ if (indices.every((index) => state.infected.get(index)?.has(state.current)))
213
+ return value;
214
+ const { data: given, error } = safe(replacements);
215
+ for (const [place, index] of indices.entries()) {
216
+ state.weighed.add(index);
217
+ if (!error && Object.is(given[place], value))
218
+ continue;
219
+ state.infected.set(index, (state.infected.get(index) ?? new Set()).add(state.current));
220
+ }
221
+ return value;
222
+ };
223
+ const __c = (index, discriminant, test) => (__t(index, discriminant === test) ? discriminant : caseMiss);
224
+ // A `default` written last is reached only once every case before it missed, so reaching it is its true side.
225
+ const __d = (index, discriminant) => (__t(index, true) ? discriminant : caseMiss);
226
+ // A `for...of` takes its true side at its first item and its false side when there is none; forcing the true side off stops it before its first pass.
227
+ // Let through once, it closes its iterator after the first item as a `break` would, never asking for a second, which any test that got an item can tell.
228
+ const passed = function* (index, iterable) {
229
+ let isEmpty = true;
230
+ for (const item of iterable) {
231
+ if (isEmpty && !__t(index, true))
232
+ return;
233
+ isEmpty = false;
234
+ yield item;
235
+ if (state.forced.get(index) === 'once')
236
+ return;
237
+ }
238
+ if (isEmpty)
239
+ __t(index, false);
240
+ };
241
+ const __o = (index, iterable) => {
242
+ if (!Array.isArray(iterable) || state.forced.get(index) === 'once')
243
+ return passed(index, iterable);
244
+ if (!__t(index, iterable.length > 0))
245
+ return [];
246
+ return iterable;
247
+ };
248
+ // A `for...in` takes its true side when its object has a key, and forcing it off walks an empty object instead.
249
+ const __i = (index, object) => {
250
+ const count = keyCountOf(object);
251
+ const isFilled = count > 0;
252
+ if (!__t(index, isFilled) && isFilled)
253
+ return {};
254
+ if (state.forced.get(index) !== 'once')
255
+ return object;
256
+ for (const key in Object(object))
257
+ return { __proto__: null, [key]: 0 };
258
+ return { __proto__: null };
259
+ };
260
+ // A default runs only on a missing value, and forcing that side off leaves it missing.
261
+ const __v = (index, value) => (__t(index, true) ? value : undefined);
262
+ // An optional chain's true side is its object missing; forcing it off reads the object as a plain `.` would.
263
+ const __q = (index, object) => {
264
+ if (__t(index, object == null))
265
+ return undefined;
266
+ if (object == null)
267
+ throw new TypeError(`Cannot read properties of ${String(object)}`);
268
+ return object;
269
+ };
270
+ // A deciding callback with a braced body decides by what it returns, and forced to an answer never runs, as the removal that forces it leaves no body to run.
271
+ const __f = (index, callback) => {
272
+ return function (...args) {
273
+ return __n(index) ?? __t(index, Reflect.apply(callback, this, args));
274
+ };
275
+ };
276
+ // Marks a project file loaded that crush leaves uninstrumented, as each such module does when it first runs.
277
+ const __u = (path) => {
278
+ state.outside.add(path);
279
+ };
280
+ // Marks a source loaded, as each instrumented module does when it first runs.
281
+ const __m = (path) => {
282
+ state.loaded.add(path);
283
+ };
284
+ // Marks a unit entered, as each function of a planned source or test file does whenever it is called.
285
+ const __e = (index) => {
286
+ state.entered.add(index);
287
+ if (state.current)
288
+ state.entries.set(index, (state.entries.get(index) ?? new Set()).add(state.current));
289
+ };
290
+ // Starts keeping one baseline call of an export, or null where none is kept: outside a recording baseline, or once its test kept its limit of that export.
291
+ // A rerun is no recording baseline, so its call pays only that check before it runs, its arguments never copied.
292
+ const begun = (key, args) => {
293
+ if (!isRecording())
294
+ return null;
295
+ const counted = `${state.current}\0${key}`;
296
+ const count = state.counts.get(counted) ?? 0;
297
+ if (count >= callLimit)
298
+ return null;
299
+ state.counts.set(counted, count + 1);
300
+ const under = (state.frames.getStore() ?? []).filter(({ isSettled }) => !isSettled);
301
+ const enclosing = innermostOf(under);
302
+ const parent = enclosing ? enclosing.call.id : null;
303
+ const snapshots = snapshotsOf(args);
304
+ const call = { id: state.calls.length, exportKey: key, test: state.current, parent, depth: under.length, args: snapshots, outcome: 'promised', result: uncloned, stack: '', path: [], isPathCut: false };
305
+ state.calls.push(call);
306
+ state.open += 1;
307
+ return { live: { call, isSettled: false, epoch: state.epoch }, under };
308
+ };
309
+ // A call the last file left running counts against no file once its file's capture is cleared.
310
+ const settle = (live, outcome, result, stack) => {
311
+ Object.assign(live.call, { outcome, result, stack });
312
+ live.isSettled = true;
313
+ if (live.epoch === state.epoch)
314
+ state.open -= 1;
315
+ };
316
+ const threw = (live, thrown) => settle(live, 'threw', thrownOf(thrown, snapshotOf), stackOf(thrown));
317
+ // Runs the call with every side its async context takes stepping its path, a throw passing on as the value it was, which `safe` would wrap into an Error.
318
+ const ranUnder = ({ live, under }, run) => {
319
+ try {
320
+ return state.frames.run([...under, live], run);
321
+ }
322
+ catch (thrown) {
323
+ threw(live, thrown);
324
+ throw thrown;
325
+ }
326
+ };
327
+ // A promise a call returned, read on a side branch, so the caller gets the very promise back with all it carries.
328
+ // The branch's handlers mark the promise handled, so in a baseline a rejection the test leaves unhandled no longer reports as one; no handler-free way to read a settled value exists.
329
+ // The branch runs before any handler the caller attaches later, so the result is snapshotted before the caller can change it.
330
+ const settledLater = (live, promise) => {
331
+ void promise.then((value) => settle(live, 'returned', snapshotOf(value), ''), (thrown) => threw(live, thrown));
332
+ };
333
+ // Runs one call of an export, keeping it while a baseline records: a declared function's body, which the instrumenter moved into `run` so the declaration stays the very function it was, or a wrapped value's call.
334
+ const __b = (key, args, run) => {
335
+ const kept = state.isCapturing ? begun(key, args) : null;
336
+ if (!kept)
337
+ return run();
338
+ const result = ranUnder(kept, run);
339
+ if (result instanceof Promise)
340
+ settledLater(kept.live, result);
341
+ else
342
+ settle(kept.live, 'returned', snapshotOf(result), '');
343
+ return result;
344
+ };
345
+ // Keeps a generator's call by its arguments alone: its body runs as the caller iterates, after the call returns, so no side it takes is its own and its path is cut, which keeps it out of the path checks while explore still seeds from it.
346
+ // The generator is called as it is, so its body, its `finally` and its `arguments` stay as they were.
347
+ const __g = (key, args, run) => {
348
+ const kept = state.isCapturing ? begun(key, args) : null;
349
+ if (!kept)
350
+ return run();
351
+ kept.live.call.isPathCut = true;
352
+ const result = ranUnder(kept, run);
353
+ settle(kept.live, 'returned', uncloned, '');
354
+ return result;
355
+ };
356
+ // Wraps an exported function as its module loads, as `export const f = __x('a.ts#f', (...) => ...)`, through a proxy, so its name, length, prototype, `this` and `new` stay as they were.
357
+ // Outside a capturing pass, or for a value that is no function, it hands back the value itself.
358
+ const __x = (key, value) => {
359
+ if (!state.isCapturing || typeof value !== 'function' || isUnproxied(value))
360
+ return value;
361
+ // A function whose prototype cannot be read is handed back as it is, rather than failing as its module loads.
362
+ const { data: generator, error } = safe(() => isGenerator(value));
363
+ if (error)
364
+ return value;
365
+ const call = generator ? __g : __b;
366
+ return new Proxy(value, {
367
+ apply: (target, thisArg, args) => call(key, args, () => Reflect.apply(target, thisArg, args)),
368
+ construct: (target, args, newTarget) => {
369
+ const kept = begun(key, args);
370
+ if (!kept)
371
+ return Reflect.construct(target, args, newTarget);
372
+ const made = ranUnder(kept, () => Reflect.construct(target, args, newTarget));
373
+ settle(kept.live, 'returned', snapshotOf(made), '');
374
+ return made;
375
+ },
376
+ });
377
+ };
378
+ return { __t, __n, __l, __r, __s, __w, __c, __d, __o, __i, __v, __q, __f, __u, __m, __e, __x, __b };
379
+ };
380
+ // The one state every instrumented file and the runner share, which only crush's runner writes.
381
+ export const state = stateOf();
382
+ const literalJustifications = new WeakSet();
383
+ // Each entry's fields become getters naming the test or hook that reads them, so only a verdict resting on a reader rests on the justification's text.
384
+ // Getters survive the structured clone Vitest sends task metadata through, where a proxy cannot be cloned; a clone's own reads only add a reader, which judges its verdicts again.
385
+ const isEntry = (value) => typeof value === 'object' && value !== null;
386
+ export const __j = (entries) => {
387
+ literalJustifications.add(entries);
388
+ for (const entry of entries) {
389
+ if (!isEntry(entry))
390
+ continue;
391
+ for (const [key, value] of Object.entries(entry)) {
392
+ const read = () => {
393
+ state.metadataReaders.add(state.current);
394
+ return value;
395
+ };
396
+ Object.defineProperty(entry, key, { get: read, enumerable: true, configurable: true });
397
+ }
398
+ }
399
+ return entries;
400
+ };
401
+ export const isLiteralJustification = (entries) => literalJustifications.has(entries);
402
+ export const { __t, __n, __l, __r, __s, __w, __c, __d, __o, __i, __v, __q, __f, __u, __m, __e, __x, __b } = countersOf(state);
@@ -0,0 +1,14 @@
1
+ import type { ExportCallOutput } from '../../capture/capture.schema.ts';
2
+ import { type Finding } from '../../explore/edges/explore.db.ts';
3
+ import type { CrushError } from '../../utils/errors.ts';
4
+ import { type Safe } from '../../utils/safe.ts';
5
+ export { countedOn } from '../../explore/edges/explore.ts';
6
+ export { stateOf } from '../counters.ts';
7
+ export type { ExportCallOutput, Finding };
8
+ export declare const capturedCallsOf: (root: string) => Safe<ExportCallOutput[], CrushError>;
9
+ type SaveFindingsInput = {
10
+ root: string;
11
+ targets: readonly string[];
12
+ findings: Finding[];
13
+ };
14
+ export declare const saveFindings: ({ root, targets, findings }: SaveFindingsInput) => Error | null;
@@ -0,0 +1,80 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ import { setFindings } from '../../explore/edges/explore.db.js';
54
+ import { getExportCalls } from '../../record/edges/calls.db.js';
55
+ import { openCurrentRecord, readCurrentRecord } from '../../record/edges/record.db.js';
56
+ import { safe } from '../../utils/safe.js';
57
+ import { recordPathOf } from './vitest.js';
58
+ // What another plugin reads and writes of a project's record, as a fuzzer outside crush needs: the captured calls to seed from, the counters to run a call on, and the findings `vp run questions` asks about.
59
+ export { countedOn } from '../../explore/edges/explore.js';
60
+ export { stateOf } from '../counters.js';
61
+ // Every call the record's baseline captured to an exported function, with its arguments and how it ended.
62
+ export const capturedCallsOf = (root) => readCurrentRecord(recordPathOf(root), getExportCalls);
63
+ // Replaces the findings of the named targets with these, which the next questions run asks about as explore's own.
64
+ export const saveFindings = ({ root, targets, findings }) => {
65
+ const env_1 = { stack: [], error: void 0, hasError: false };
66
+ try {
67
+ const { data: opened, error } = openCurrentRecord(recordPathOf(root));
68
+ if (error)
69
+ return error;
70
+ const record = __addDisposableResource(env_1, opened, false);
71
+ return safe(() => setFindings(record, { targets, findings })).error;
72
+ }
73
+ catch (e_1) {
74
+ env_1.error = e_1;
75
+ env_1.hasError = true;
76
+ }
77
+ finally {
78
+ __disposeResources(env_1);
79
+ }
80
+ };
@@ -0,0 +1,9 @@
1
+ import { MinimalReporter, type TestModule, type TestRunEndReason, type Vitest } from 'vite-plus/test/node';
2
+ export default class CompletionReporter extends MinimalReporter {
3
+ readonly isTimed: boolean;
4
+ constructor(options?: unknown);
5
+ onInit(ctx: Vitest): void;
6
+ onTestModuleEnd(): void;
7
+ onTestRunEnd(modules: ReadonlyArray<TestModule>, errors: Parameters<MinimalReporter['onTestRunEnd']>[1], reason: TestRunEndReason): void;
8
+ private timingLineOf;
9
+ }
@@ -0,0 +1,51 @@
1
+ import { z } from 'zod';
2
+ import { MinimalReporter } from 'vite-plus/test/node';
3
+ import { runHintsOf } from './hints.reporter.js';
4
+ import { baselineMsOf, judgeSpeedsOf, planSpeedKey } from './speed.js';
5
+ const seconds = (ms) => `${(ms / 1000).toFixed(3)} s`;
6
+ const passLine = ({ ms, reruns, sites }) => `${seconds(ms)}, ${reruns} reruns, ${sites ? (reruns / sites).toFixed(2) : '0.00'} reruns/site`;
7
+ // The reporter's options, as `['crush/reporter', { timings: true }]` passes them: the timing line, crush's own speed readout, prints only when asked for.
8
+ const optionsInput = z.object({ timings: z.boolean().default(false) });
9
+ // Preserve Vitest's final diagnostics without printing a banner, progress or per-file results.
10
+ export default class CompletionReporter extends MinimalReporter {
11
+ isTimed;
12
+ constructor(options = {}) {
13
+ super();
14
+ this.isTimed = optionsInput.parse(options).timings;
15
+ }
16
+ onInit(ctx) {
17
+ this.ctx = ctx;
18
+ this.silent = true;
19
+ }
20
+ onTestModuleEnd() { }
21
+ onTestRunEnd(modules, errors, reason) {
22
+ super.onTestRunEnd(modules, errors, reason);
23
+ const project = this.ctx.projects.find(({ name }) => name === 'record' || name === 'judge');
24
+ if (!project)
25
+ return;
26
+ if (this.isTimed)
27
+ this.log(this.timingLineOf(project, modules, reason));
28
+ for (const line of runHintsOf({ ctx: this.ctx, modules, reason }))
29
+ this.log(line);
30
+ }
31
+ // The phase's status, wall time and where its time went, a speed readout for working on crush itself.
32
+ timingLineOf(project, modules, reason) {
33
+ const plan = project.getProvidedContext()[planSpeedKey];
34
+ const files = modules.flatMap((module) => module.meta().crushBaselineSpeed ?? []);
35
+ const judge = judgeSpeedsOf(modules.flatMap((module) => module.meta().crushJudgeSpeed ?? []));
36
+ const parts = [
37
+ `${project.name} ${reason === 'passed' ? 'done' : 'failed'}`,
38
+ `wall ${seconds(performance.now())}`,
39
+ `plan ${seconds(plan?.plan ?? 0)}, ${plan?.built ?? 0} built`,
40
+ `cached plan ${seconds(plan?.cachedPlan ?? 0)}, ${plan?.cached ?? 0} reused`,
41
+ ];
42
+ if (project.name === 'record')
43
+ parts.push(`baseline ${seconds(baselineMsOf(files))}`);
44
+ else {
45
+ parts.push(`judge ${passLine(judge.judge)}`, `merge ${seconds(judge.merge)}`, `verify ${seconds(judge.verify.ms)}, ${judge.verify.reruns} reruns`);
46
+ }
47
+ const writes = (plan?.writes ?? 0) + judge.writes + files.reduce((total, file) => total + file.writes, 0);
48
+ parts.push(`record.db writes ${seconds(writes)}`, `verdicts reused ${judge.reused}, judged ${judge.judge.sites}`);
49
+ return parts.join(' | ');
50
+ }
51
+ }
@@ -0,0 +1,13 @@
1
+ import type { Reporter, TestModule, TestRunEndReason, Vitest } from 'vite-plus/test/node';
2
+ type RunHintsInput = {
3
+ ctx: Vitest;
4
+ modules: ReadonlyArray<TestModule>;
5
+ reason: TestRunEndReason;
6
+ };
7
+ export declare const runHintsOf: ({ ctx, modules, reason }: RunHintsInput) => string[];
8
+ export default class HintsReporter implements Reporter {
9
+ ctx: Vitest | undefined;
10
+ onInit(ctx: Vitest): void;
11
+ onTestRunEnd(modules: ReadonlyArray<TestModule>, _errors: unknown, reason: TestRunEndReason): void;
12
+ }
13
+ export {};
@@ -0,0 +1,29 @@
1
+ import { relative } from 'node:path';
2
+ import { hintLinesOf } from '../hints.js';
3
+ const commands = new Set(['record', 'judge', 'questions', 'explore']);
4
+ const isHintCommand = (name) => commands.has(name);
5
+ // The hint lines for the crush command this run is, or none for a run of another project.
6
+ export const runHintsOf = ({ ctx, modules, reason }) => {
7
+ const project = ctx.projects.find(({ name }) => isHintCommand(name));
8
+ if (!project || !isHintCommand(project.name))
9
+ return [];
10
+ // A judge run adds crush's own runner files to the related list, and those sit outside the project, so only the paths inside it are the user's.
11
+ const related = (ctx.config.related ?? []).map((path) => relative(ctx.config.root, path)).filter((path) => !path.startsWith('..'));
12
+ const metas = modules.flatMap((module) => [...module.children.allTests()].map((test) => test.meta()));
13
+ const open = metas.reduce((total, { crushOpen }) => total + (crushOpen ?? 0), 0);
14
+ const [firstFile = null] = metas.flatMap(({ crushOpenIn }) => (crushOpenIn ? [crushOpenIn] : []));
15
+ return hintLinesOf({ command: project.name, isPassed: reason === 'passed', related, open, firstFile });
16
+ };
17
+ // Ends a questions or explore run with the hint, skill and next-step lines, after Vitest's own report.
18
+ export default class HintsReporter {
19
+ ctx;
20
+ onInit(ctx) {
21
+ this.ctx = ctx;
22
+ }
23
+ onTestRunEnd(modules, _errors, reason) {
24
+ if (!this.ctx)
25
+ return;
26
+ for (const line of runHintsOf({ ctx: this.ctx, modules, reason }))
27
+ this.ctx.logger.log(line);
28
+ }
29
+ }
@@ -0,0 +1,52 @@
1
+ import type { ExportCallOutput } from '../../capture/capture.schema.ts';
2
+ import type { ReachEdgeOutput, ReachNodeOutput } from '../../graph/symbols/symbols.schema.ts';
3
+ import type { PlanInput } from '../../instrument/instrument.schema.ts';
4
+ import { type CapturedPart, type PartStamp } from '../../record/edges/parts.db.ts';
5
+ import { type PassEndInput, type PassWaitInput } from '../../record/edges/passes.db.ts';
6
+ import { type SiteVerdict } from '../../record/edges/site-verdicts.db.ts';
7
+ import { type MeasureWrite } from '../../record/edges/record.db.ts';
8
+ import type { CrushError } from '../../utils/errors.ts';
9
+ import type { Safe } from '../../utils/safe.ts';
10
+ import type { Candidate, Hold, Judged, Verified } from '../judge.schema.ts';
11
+ import { type Finding } from '../../explore/edges/explore.db.ts';
12
+ export type JudgeEdges = {
13
+ getPlan: (input?: {
14
+ withRewrites?: boolean;
15
+ }) => PlanInput;
16
+ getJudged: (input: {
17
+ withHits: boolean;
18
+ }) => Judged[];
19
+ getPartStampNullable: (path: string) => PartStamp | null;
20
+ getPartIsAllReusedNullable: (path: string) => boolean | null;
21
+ getNextGeneration: (path: string) => number;
22
+ getSiteVerdicts: (keys: readonly string[]) => Map<string, SiteVerdict>;
23
+ setSiteVerdicts: (verdicts: readonly SiteVerdict[]) => void;
24
+ getRecordedStateNullable: () => string | null;
25
+ setJudgedState: (hash: string) => void;
26
+ clearRecordedState: () => void;
27
+ setPassEnded: (input: PassEndInput) => void;
28
+ passEnded: (input: PassWaitInput) => Promise<Error | null>;
29
+ setJudged: (judged: Judged, captured?: CapturedPart) => void;
30
+ clearJudged: (path: string) => void;
31
+ clearFileFailure: (path: string, ranTests: boolean) => void;
32
+ setFileFailure: (path: string, failure: string) => void;
33
+ getVerified: () => Verified[];
34
+ getCheckedCandidatesNullable: (path: string) => string | null;
35
+ setVerified: (verified: Verified) => CrushError | null;
36
+ clearVerified: (path: string) => void;
37
+ getCandidates: () => Candidate[];
38
+ setCandidates: (list: Candidate[], basis: string) => void;
39
+ getMergeBasis: () => Safe<string, CrushError>;
40
+ getHolds: () => Hold[];
41
+ setHolds: (held: Hold[]) => void;
42
+ getReachNodes: () => ReachNodeOutput[];
43
+ getReachEdges: () => ReachEdgeOutput[];
44
+ getExportCalls: () => ExportCallOutput[];
45
+ getFindings: () => Finding[];
46
+ getSeeds: () => Map<string, unknown[][]>;
47
+ marked: (name: string, work: () => Promise<Error | null>) => Promise<Error | null>;
48
+ settled: () => Promise<Error | null>;
49
+ [Symbol.dispose]: () => void;
50
+ };
51
+ export declare const readJudgeEdges: (path: string) => Safe<JudgeEdges, CrushError>;
52
+ export declare const openCurrentJudgeEdges: (path: string, write?: MeasureWrite) => Safe<JudgeEdges, CrushError>;