@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,3 @@
1
+ import { type SQLWrapper } from 'drizzle-orm';
2
+ import type { Record } from './record.db.ts';
3
+ export declare const clearHitsFor: (db: Pick<Record, 'delete'>, sites: SQLWrapper) => void;
@@ -0,0 +1,5 @@
1
+ import { inArray } from 'drizzle-orm';
2
+ import { hits } from '../../crush.tables.js';
3
+ export const clearHitsFor = (db, sites) => {
4
+ db.delete(hits).where(inArray(hits.site, sites)).run();
5
+ };
@@ -0,0 +1,4 @@
1
+ import type { Hold } from '../../judge/judge.schema.ts';
2
+ import { type Record } from './record.db.ts';
3
+ export declare const setHolds: (db: Record, held: Hold[]) => void;
4
+ export declare const getHolds: (db: Record) => Hold[];
@@ -0,0 +1,31 @@
1
+ import { asc } from 'drizzle-orm';
2
+ import { holds, holdTests } from '../../crush.tables.js';
3
+ import { entryAt } from '../../utils/lookup.js';
4
+ import { siteIdsOf, siteKeysOf } from './plan.db.js';
5
+ import { chunksOf } from './record.db.js';
6
+ // Every hold in one transaction, replacing the last.
7
+ export const setHolds = (db, held) => {
8
+ db.transaction((tx) => {
9
+ tx.delete(holds).run();
10
+ const siteOf = siteIdsOf(tx);
11
+ const holdRows = held.map(({ key, basis }) => ({ site: entryAt(siteOf, key, 'a held crush'), basisHash: basis }));
12
+ const testRows = held.flatMap(({ key, tests }) => tests.map((testKey) => ({ site: entryAt(siteOf, key, 'a held crush'), testKey })));
13
+ for (const chunk of chunksOf(holdRows))
14
+ tx.insert(holds).values(chunk).run();
15
+ for (const chunk of chunksOf(testRows))
16
+ tx.insert(holdTests).values(chunk).run();
17
+ }, { behavior: 'immediate' });
18
+ };
19
+ // Every hold, in key order as the report wrote them.
20
+ export const getHolds = (db) => {
21
+ return db.transaction((tx) => {
22
+ const keyOf = siteKeysOf(tx);
23
+ const tests = Map.groupBy(tx.select().from(holdTests).orderBy(asc(holdTests.id)).all(), ({ site }) => site);
24
+ return tx
25
+ .select()
26
+ .from(holds)
27
+ .all()
28
+ .map(({ site, basisHash }) => ({ key: entryAt(keyOf, site, 'a held crush'), basis: basisHash, tests: (tests.get(site) ?? []).map(({ testKey }) => testKey) }))
29
+ .toSorted((left, right) => left.key.localeCompare(right.key));
30
+ });
31
+ };
@@ -0,0 +1,5 @@
1
+ import type { Reader, Record } from './record.db.ts';
2
+ export declare const getRecordedStateNullable: (db: Reader) => string | null;
3
+ export declare const setJudgedState: (db: Record, hash: string) => void;
4
+ export declare const clearRecordedState: (db: Record) => void;
5
+ export declare const setRecordedState: (db: Record, ran: ReadonlySet<string>) => void;
@@ -0,0 +1,25 @@
1
+ import { eq } from 'drizzle-orm';
2
+ import { judgedState, testFiles } from '../../crush.tables.js';
3
+ // The state the last clean judge judged, once a whole record since kept every part as it was, or null otherwise.
4
+ export const getRecordedStateNullable = (db) => {
5
+ const [row] = db.select().from(judgedState).where(eq(judgedState.isRecorded, true)).limit(1).all();
6
+ return row?.hash ?? null;
7
+ };
8
+ // Saves the state a judge finished cleanly on, waiting for a record to confirm it, and replaces the last.
9
+ export const setJudgedState = (db, hash) => {
10
+ db.transaction((tx) => {
11
+ tx.delete(judgedState).run();
12
+ tx.insert(judgedState).values({ hash, isRecorded: false }).run();
13
+ }, { behavior: 'immediate' });
14
+ };
15
+ // A judge that skipped consumes the record's confirmation, so a later judge with no record between judges again.
16
+ export const clearRecordedState = (db) => {
17
+ db.update(judgedState).set({ isRecorded: false }).run();
18
+ };
19
+ // Confirms the judged state once a record ran every test file the record holds and wrote no part, which would have cleared the state.
20
+ export const setRecordedState = (db, ran) => {
21
+ const held = db.select({ path: testFiles.path }).from(testFiles).all();
22
+ if (!held.length || !held.every(({ path }) => ran.has(path)))
23
+ return;
24
+ db.update(judgedState).set({ isRecorded: true }).run();
25
+ };
@@ -0,0 +1,11 @@
1
+ import { CrushError } from '../../utils/errors.ts';
2
+ import { type Clock } from '../../utils/retry.ts';
3
+ import { type MeasureWrite, type Record } from './record.db.ts';
4
+ export declare const clearWorking: (db: Record) => void;
5
+ export declare const getWorking: (db: Record) => string[];
6
+ export declare class StillWorking extends CrushError {
7
+ }
8
+ export declare const settled: (db: Record, clock?: Clock) => Promise<Error | null>;
9
+ export declare const markWorking: (db: Record, name: string) => void;
10
+ export declare const unmarkWorking: (db: Record, name: string, write: MeasureWrite) => Promise<Error | null>;
11
+ export declare const marked: (db: Record, name: string, work: () => Promise<Error | null>, clock?: Clock, write?: MeasureWrite) => Promise<Error | null>;
@@ -0,0 +1,55 @@
1
+ import { eq } from 'drizzle-orm';
2
+ import { working } from '../../crush.tables.js';
3
+ import { CrushError } from '../../utils/errors.js';
4
+ import { retried, systemClock } from '../../utils/retry.js';
5
+ import { safe, safeAsync } from '../../utils/safe.js';
6
+ import { writeDirectly } from './record.db.js';
7
+ import { stillWorkingOf } from '../../judge/refusals.js';
8
+ // How long a phase waits for test files still working before it fails rather than read a partial run.
9
+ const waitMs = 120_000;
10
+ // How long a phase waits between looks at the working markers, and a removal between tries past a busy record.
11
+ const pollMs = 50;
12
+ // SQLite's code for a record another connection holds locked, which Drizzle carries on the cause of the error it throws.
13
+ const busyCode = 5;
14
+ // A marker a killed run left standing would hold up this run's phases, so a run starts by clearing them.
15
+ export const clearWorking = (db) => {
16
+ db.delete(working).run();
17
+ };
18
+ // The test files whose runner still holds a marker, by name.
19
+ export const getWorking = (db) => {
20
+ return db
21
+ .select({ name: working.name })
22
+ .from(working)
23
+ .all()
24
+ .map(({ name }) => name);
25
+ };
26
+ export class StillWorking extends CrushError {
27
+ }
28
+ // Waits until no test file's runner still holds a marker, so a phase never reads the parts before every file has written its own.
29
+ export const settled = async (db, clock = systemClock) => {
30
+ const run = () => {
31
+ const { data: names, error } = safe(() => getWorking(db));
32
+ if (error)
33
+ return error;
34
+ return names.length ? new StillWorking(stillWorkingOf(names, waitMs)) : null;
35
+ };
36
+ return await retried({ run, isRetried: (error) => error instanceof StillWorking, waitMs, intervalMs: pollMs, clock });
37
+ };
38
+ const isBusy = (error) => error instanceof Error && (('errcode' in error && error.errcode === busyCode) || isBusy(error.cause));
39
+ // A marker left standing holds up every later phase, so its removal outwaits any writer holding the record past the busy timeout.
40
+ const unmark = async (db, name, clock, write) => {
41
+ const run = () => safe(() => write(() => db.delete(working).where(eq(working.name, name)).run())).error;
42
+ return await retried({ run, isRetried: isBusy, waitMs, intervalMs: pollMs, clock });
43
+ };
44
+ export const markWorking = (db, name) => {
45
+ db.insert(working).values({ name }).onConflictDoNothing().run();
46
+ };
47
+ export const unmarkWorking = (db, name, write) => unmark(db, name, systemClock, write);
48
+ // Runs one test file's work under a marker that goes whether the work fails, passes, or throws on a broken invariant, answering the first failure.
49
+ export const marked = async (db, name, work, clock = systemClock, write = writeDirectly) => {
50
+ write(() => markWorking(db, name));
51
+ // A broken invariant still throws out of the work, and a marker left standing holds up every later phase, so the work runs inside safeAsync.
52
+ const { data: failure, error: thrown } = await safeAsync(work);
53
+ const unmarkError = await unmark(db, name, clock, write);
54
+ return thrown ?? failure ?? unmarkError;
55
+ };
@@ -0,0 +1,7 @@
1
+ import type { Candidate } from '../../judge/judge.schema.ts';
2
+ import { type CrushError } from '../../utils/errors.ts';
3
+ import type { Safe } from '../../utils/safe.ts';
4
+ import { type Reader, type Record } from './record.db.ts';
5
+ export declare const setCandidates: (db: Record, list: Candidate[], basis: string) => void;
6
+ export declare const getCandidates: (db: Record) => Candidate[];
7
+ export declare const getMergeBasis: (db: Reader) => Safe<string, CrushError>;
@@ -0,0 +1,46 @@
1
+ import { asc } from 'drizzle-orm';
2
+ import { candidateEdits, candidates, mergeBasis } from '../../crush.tables.js';
3
+ import { entryAt } from '../../utils/lookup.js';
4
+ import { failed } from '../../utils/errors.js';
5
+ import { forcedOf, forcingOf, siteIdsOf, siteKeysOf } from './plan.db.js';
6
+ import { chunksOf } from './record.db.js';
7
+ // The merge's candidates and the basis it chose them under, in one transaction, replacing the last.
8
+ export const setCandidates = (db, list, basis) => {
9
+ db.transaction((tx) => {
10
+ tx.delete(candidates).run();
11
+ tx.delete(mergeBasis).run();
12
+ const siteOf = siteIdsOf(tx);
13
+ const candidateRows = list.map(({ key, point, forced, start }, position) => ({ id: position + 1, site: entryAt(siteOf, key, 'a candidate crush'), point, forced: forcedOf(forced), startAt: start }));
14
+ const editRows = list.flatMap(({ edits }, position) => edits.map((edit) => ({ candidate: position + 1, startAt: edit.start, endAt: edit.end })));
15
+ for (const chunk of chunksOf(candidateRows))
16
+ tx.insert(candidates).values(chunk).run();
17
+ for (const chunk of chunksOf(editRows))
18
+ tx.insert(candidateEdits).values(chunk).run();
19
+ tx.insert(mergeBasis).values({ hash: basis }).run();
20
+ }, { behavior: 'immediate' });
21
+ };
22
+ export const getCandidates = (db) => {
23
+ return db.transaction((tx) => {
24
+ const keyOf = siteKeysOf(tx);
25
+ const edits = Map.groupBy(tx.select().from(candidateEdits).orderBy(asc(candidateEdits.id)).all(), ({ candidate }) => candidate);
26
+ return tx
27
+ .select()
28
+ .from(candidates)
29
+ .orderBy(asc(candidates.id))
30
+ .all()
31
+ .map(({ id, site, point, forced, startAt }) => ({
32
+ key: entryAt(keyOf, site, 'a candidate crush'),
33
+ point,
34
+ forced: forcingOf(forced),
35
+ start: startAt,
36
+ edits: (edits.get(id) ?? []).map((edit) => ({ start: edit.startAt, end: edit.endAt })),
37
+ }));
38
+ });
39
+ };
40
+ // The basis the last merge chose its candidates under.
41
+ export const getMergeBasis = (db) => {
42
+ const [row] = db.select().from(mergeBasis).limit(1).all();
43
+ if (!row)
44
+ return failed('the record holds no merge basis, so judge has not merged its verdicts');
45
+ return { data: row.hash, error: null };
46
+ };
@@ -0,0 +1,42 @@
1
+ import type { ExportCallInput } from '../../capture/capture.schema.ts';
2
+ import type { Judged } from '../../judge/judge.schema.ts';
3
+ import { type Reader, type Record } from './record.db.ts';
4
+ export declare const getReadSequences: (db: Reader, path: string) => Map<number, string[]>;
5
+ export declare const getNextGeneration: (db: Record, path: string) => number;
6
+ export declare const getHottestSides: (db: Record, limit: number) => {
7
+ siteKey: string;
8
+ side: string;
9
+ passes: number;
10
+ }[];
11
+ export declare const getSlowestTests: (db: Record, limit: number) => {
12
+ testKey: string;
13
+ ns: number;
14
+ }[];
15
+ export type CapturedPart = {
16
+ calls: ExportCallInput[];
17
+ clearVerification: boolean;
18
+ clearFailure?: boolean;
19
+ };
20
+ export declare const setJudged: (db: Record, { file, hash, reused, tests, justifications, failure, properties, hits: taken, entered, verdicts: judged, reads, rerunFailing, passes, outside, changed, assignees, sequence }: Judged, captured?: CapturedPart) => void;
21
+ export declare const clearJudged: (db: Record, path: string) => void;
22
+ export declare const clearFileFailure: (db: Record, path: string, ranTests: boolean) => void;
23
+ export declare const setFileFailure: (db: Record, path: string, failure: string) => void;
24
+ export declare const clearTestFiles: (db: Record, isMissing: (path: string) => boolean) => void;
25
+ export declare const getPartIsAllReusedNullable: (db: Record, path: string) => boolean | null;
26
+ export declare const getJudged: (db: Record, { withHits }: {
27
+ withHits: boolean;
28
+ }) => Judged[];
29
+ export type PartStamp = {
30
+ hash: string;
31
+ failure: string | null;
32
+ tests: {
33
+ key: string;
34
+ passed: boolean;
35
+ }[];
36
+ reads: {
37
+ path: string;
38
+ hash: string;
39
+ }[];
40
+ };
41
+ export declare const getPartStampNullable: (db: Record, path: string) => PartStamp | null;
42
+ export declare const getJudgedNullable: (db: Record, path: string) => Judged | undefined;
@@ -0,0 +1,389 @@
1
+ import { z } from 'zod';
2
+ import { and, asc, desc, eq, inArray, isNull, notInArray, sql, sum } from 'drizzle-orm';
3
+ import { entries, hits, judgedState, partAssignees, readSequences, sidePasses, sites, testFileChanged, testFileOutside, testFileProperties, testFileReads, testFiles, testRuns, verdicts, verifiedFiles } from '../../crush.tables.js';
4
+ import { byPath, hitTextOf, partFrom, partTextOf } from '../parts.operations.js';
5
+ import { entryAt, itemAt } from '../../utils/lookup.js';
6
+ import { prepareExportCalls, writeExportCalls } from './calls.db.js';
7
+ import { siteIdsFor, siteKeysOf } from './plan.db.js';
8
+ import { chunksOf } from './record.db.js';
9
+ const answersInput = z.array(z.string());
10
+ // A test's answers are kept as one JSON list, null for a test that answers nothing.
11
+ const storedAnswersOf = (answers) => (answers.length ? JSON.stringify(answers) : null);
12
+ // Every read sequence the record holds for one test file, by generation, its units in the order first entered.
13
+ export const getReadSequences = (db, path) => {
14
+ const rows = db.select().from(readSequences).where(eq(readSequences.testFile, path)).orderBy(asc(readSequences.generation), asc(readSequences.position)).all();
15
+ return new Map([...Map.groupBy(rows, ({ generation }) => generation)].map(([generation, each]) => [generation, each.map(({ unit }) => unit)]));
16
+ };
17
+ // The generation a test file's next run reads under, past every one the record holds for it.
18
+ export const getNextGeneration = (db, path) => {
19
+ const [row] = db
20
+ .select({ generation: sql `max(${readSequences.generation})` })
21
+ .from(readSequences)
22
+ .where(eq(readSequences.testFile, path))
23
+ .all();
24
+ return (row?.generation ?? 0) + 1;
25
+ };
26
+ // One test file's read sequence of a generation from a position on, its units in the order first entered, rows already saved kept.
27
+ const setSequence = (tx, path, { generation, units }, from) => {
28
+ const rows = units.slice(from).map((unit, at) => ({ testFile: path, generation, position: from + at, unit }));
29
+ for (const chunk of chunksOf(rows))
30
+ tx.insert(readSequences).values(chunk).onConflictDoNothing().run();
31
+ };
32
+ // The fork sides the tests passed through most often, the hottest first, naming the same sides on every record of the same tests.
33
+ export const getHottestSides = (db, limit) => {
34
+ const passes = sql `cast(${sum(sidePasses.passes)} as integer)`;
35
+ return db
36
+ .select({ siteKey: sites.siteKey, side: sidePasses.side, passes })
37
+ .from(sidePasses)
38
+ .innerJoin(sites, eq(sidePasses.site, sites.id))
39
+ .groupBy(sites.siteKey, sidePasses.side)
40
+ .orderBy(desc(passes), asc(sites.siteKey), asc(sidePasses.side))
41
+ .limit(limit)
42
+ .all();
43
+ };
44
+ export const getSlowestTests = (db, limit) => db.select({ testKey: testRuns.testKey, ns: testRuns.ns }).from(testRuns).orderBy(desc(testRuns.ns), asc(testRuns.testKey)).limit(limit).all();
45
+ // The part a test file's last run left, its tests named by key rather than row, as `partFrom` names them.
46
+ // Its verdicts are left out, since a judge rewrites them on a part whose every other row stands.
47
+ const partOf = (db, testFile) => {
48
+ const runs = db.select().from(testRuns).where(eq(testRuns.testFile, testFile)).all();
49
+ const keyOf = new Map(runs.map(({ id, testKey }) => [id, testKey]));
50
+ return partTextOf({
51
+ runs: runs.map(({ id: _id, testFile: _testFile, ns: _ns, ...run }) => run),
52
+ taken: db
53
+ .select({ site: hits.site, side: hits.side, test: hits.test })
54
+ .from(hits)
55
+ .innerJoin(testRuns, eq(hits.test, testRuns.id))
56
+ .where(eq(testRuns.testFile, testFile))
57
+ .all()
58
+ .map(({ site, side, test }) => hitTextOf(site, side, keyOf.get(test))),
59
+ entered: db
60
+ .select({ unit: entries.unit, test: entries.test })
61
+ .from(entries)
62
+ .innerJoin(testRuns, eq(entries.test, testRuns.id))
63
+ .where(eq(testRuns.testFile, testFile))
64
+ .all()
65
+ .map(({ unit, test }) => ({ unit, testKey: keyOf.get(test) })),
66
+ passes: db.select({ site: sidePasses.site, side: sidePasses.side, passes: sidePasses.passes }).from(sidePasses).where(eq(sidePasses.testFile, testFile)).all(),
67
+ reads: db.select({ path: testFileReads.path, hash: testFileReads.hash }).from(testFileReads).where(eq(testFileReads.testFile, testFile)).all(),
68
+ outside: db.select({ path: testFileOutside.path }).from(testFileOutside).where(eq(testFileOutside.testFile, testFile)).all(),
69
+ changed: db.select({ path: testFileChanged.path }).from(testFileChanged).where(eq(testFileChanged.testFile, testFile)).all(),
70
+ properties: db.select({ name: testFileProperties.name }).from(testFileProperties).where(eq(testFileProperties.testFile, testFile)).all(),
71
+ });
72
+ };
73
+ export const setJudged = (db, { file, hash, reused, tests, justifications, failure, properties, hits: taken, entered, verdicts: judged, reads, rerunFailing, passes, outside, changed, assignees, sequence }, captured) => {
74
+ const calls = captured && prepareExportCalls(captured.calls);
75
+ const isRerunFailing = new Set(rerunFailing);
76
+ const runs = tests.map(({ key, name, passed, isSteady, answers, ...test }) => ({
77
+ testKey: key,
78
+ name: name ?? null,
79
+ passed: passed ? 1 : 0,
80
+ isSteady: isSteady ? 1 : 0,
81
+ rerunFailed: isRerunFailing.has(key) ? 1 : 0,
82
+ answers: storedAnswersOf(answers),
83
+ ...test,
84
+ }));
85
+ const siteKeys = new Set(judged.map(({ key }) => key));
86
+ for (const { siteKey } of taken)
87
+ siteKeys.add(siteKey);
88
+ for (const { siteKey } of passes)
89
+ siteKeys.add(siteKey);
90
+ if (calls)
91
+ for (const { steps } of calls)
92
+ for (const { siteKey } of steps)
93
+ siteKeys.add(siteKey);
94
+ db.transaction((tx) => {
95
+ const [before] = tx.select({ hash: testFiles.hash }).from(testFiles).where(eq(testFiles.path, file)).limit(1).all();
96
+ const part = { hash, reused, justifications: justifications?.length ? justifications : null };
97
+ // A failure an earlier phase of this record stored stands, so a later phase's rewrite adds to it and never clears it.
98
+ const updated = { ...part, failure: captured?.clearFailure ? failure : sql `coalesce(${testFiles.failure}, excluded.failure)` };
99
+ const upserted = tx
100
+ .insert(testFiles)
101
+ .values({ path: file, ...part, failure })
102
+ .onConflictDoUpdate({ target: testFiles.path, set: updated })
103
+ .returning({ id: testFiles.id })
104
+ .all();
105
+ const { id: testFile } = itemAt(upserted, 0);
106
+ // A part written since the last clean judge leaves its state behind, so the next judge judges again.
107
+ tx.delete(judgedState).run();
108
+ if (captured?.clearVerification)
109
+ tx.delete(verifiedFiles).where(eq(verifiedFiles.testFile, testFile)).run();
110
+ const siteOf = siteIdsFor(tx, [...siteKeys]);
111
+ // The assignment the part was judged under replaces the one before, even where the rest of the part is left as it was.
112
+ tx.delete(partAssignees).where(eq(partAssignees.testFile, testFile)).run();
113
+ for (const chunk of chunksOf(assignees.map(({ source, assignee }) => ({ testFile, source, assignee }))))
114
+ tx.insert(partAssignees).values(chunk).run();
115
+ // A rerun of an unchanged test file that left every row of its part as it was rewrites only its tests' timings, since rewriting a file's every hit is most of a warm record's writes.
116
+ const testRows = tests.map(({ key, answers, ...test }) => ({ testFile, testKey: key, ...test, answers: storedAnswersOf(answers), rerunFailed: isRerunFailing.has(key) }));
117
+ // A part's verdicts are written apart from its other rows, so a judge adding verdicts to the part a record just wrote rewrites only those.
118
+ const writeVerdicts = (testOf) => {
119
+ const verdictRows = judged.flatMap(({ key, status, catcher, backup, reruns, basis, readHash, reads: at, isReused, deferred }) => {
120
+ const site = siteOf.get(key);
121
+ const caught = { catcher: catcher ? entryAt(testOf, catcher, 'a catching test') : null, backup: backup ? entryAt(testOf, backup, 'a backup test') : null };
122
+ return site ? [{ testFile, site, status, ...caught, reruns, basisHash: basis, readHash: readHash ?? null, readGeneration: at.generation, readCount: at.count, isReused, deferredTo: deferred }] : [];
123
+ });
124
+ for (const chunk of chunksOf(verdictRows))
125
+ tx.insert(verdicts).values(chunk).run();
126
+ setSequence(tx, file, sequence, 0);
127
+ const kept = [...new Set([sequence.generation, ...judged.map(({ reads: at }) => at.generation)])];
128
+ tx.delete(readSequences)
129
+ .where(and(eq(readSequences.testFile, file), notInArray(readSequences.generation, kept)))
130
+ .run();
131
+ };
132
+ if (before?.hash === hash && partOf(tx, testFile) === partFrom({ runs, taken, entered, reads, passes, outside, changed, properties, siteOf })) {
133
+ // Every test key is already this file's, so the upsert only moves each test's timing.
134
+ for (const chunk of chunksOf(testRows)) {
135
+ tx.insert(testRuns)
136
+ .values(chunk)
137
+ .onConflictDoUpdate({ target: testRuns.testKey, set: { ns: sql `excluded.ns` } })
138
+ .run();
139
+ }
140
+ tx.delete(verdicts).where(eq(verdicts.testFile, testFile)).run();
141
+ const held = tx.select({ id: testRuns.id, testKey: testRuns.testKey }).from(testRuns).where(eq(testRuns.testFile, testFile)).all();
142
+ writeVerdicts(new Map(held.map(({ id, testKey }) => [testKey, id])));
143
+ if (calls)
144
+ writeExportCalls(tx, testFile, calls, siteOf);
145
+ return;
146
+ }
147
+ tx.delete(verdicts).where(eq(verdicts.testFile, testFile)).run();
148
+ tx.delete(testRuns).where(eq(testRuns.testFile, testFile)).run();
149
+ tx.delete(sidePasses).where(eq(sidePasses.testFile, testFile)).run();
150
+ tx.delete(testFileOutside).where(eq(testFileOutside.testFile, testFile)).run();
151
+ for (const chunk of chunksOf(outside.map((path) => ({ testFile, path }))))
152
+ tx.insert(testFileOutside).values(chunk).run();
153
+ tx.delete(testFileProperties).where(eq(testFileProperties.testFile, testFile)).run();
154
+ // Two tests may declare one property, which the file holds once.
155
+ for (const chunk of chunksOf([...new Set(properties)].map((name) => ({ testFile, name }))))
156
+ tx.insert(testFileProperties).values(chunk).run();
157
+ tx.delete(testFileChanged).where(eq(testFileChanged.testFile, testFile)).run();
158
+ for (const chunk of chunksOf(changed.map((path) => ({ testFile, path }))))
159
+ tx.insert(testFileChanged).values(chunk).run();
160
+ tx.delete(testFileReads).where(eq(testFileReads.testFile, testFile)).run();
161
+ for (const chunk of chunksOf(reads.map(({ path, hash: readHash }) => ({ testFile, path, hash: readHash }))))
162
+ tx.insert(testFileReads).values(chunk).run();
163
+ const insertTests = (chunk) => tx.insert(testRuns).values(chunk).returning({ id: testRuns.id, testKey: testRuns.testKey }).all();
164
+ const inserted = chunksOf(testRows).flatMap(insertTests);
165
+ const testOf = new Map(inserted.map(({ id, testKey }) => [testKey, id]));
166
+ const hitRows = taken.flatMap(({ siteKey, side, testKey }) => {
167
+ const site = siteOf.get(siteKey);
168
+ const test = testOf.get(testKey);
169
+ return site && test ? [{ site, side, test }] : [];
170
+ });
171
+ for (const chunk of chunksOf(hitRows))
172
+ tx.insert(hits).values(chunk).run();
173
+ const entryRows = entered.flatMap(({ unit, testKey }) => {
174
+ const test = testOf.get(testKey);
175
+ return test ? [{ test, unit }] : [];
176
+ });
177
+ for (const chunk of chunksOf(entryRows))
178
+ tx.insert(entries).values(chunk).run();
179
+ const passRows = passes.flatMap(({ siteKey, side, passes: count }) => {
180
+ const site = siteOf.get(siteKey);
181
+ return site ? [{ testFile, site, side, passes: count }] : [];
182
+ });
183
+ for (const chunk of chunksOf(passRows))
184
+ tx.insert(sidePasses).values(chunk).run();
185
+ writeVerdicts(testOf);
186
+ if (calls)
187
+ writeExportCalls(tx, testFile, calls, siteOf);
188
+ }, { behavior: 'immediate' });
189
+ };
190
+ // Removes one test file's judged part, with its joint-check part, so a run that could not judge it leaves no earlier verdicts standing for it.
191
+ export const clearJudged = (db, path) => {
192
+ db.delete(judgedState).run();
193
+ db.delete(testFiles).where(eq(testFiles.path, path)).run();
194
+ db.delete(readSequences).where(eq(readSequences.testFile, path)).run();
195
+ };
196
+ // Clears a test file's failure as a record's judging reruns it, so only what this record finds of it stands, and a file no phase reruns keeps the last.
197
+ export const clearFileFailure = (db, path, ranTests) => {
198
+ if (!ranTests)
199
+ return;
200
+ db.update(testFiles).set({ failure: null }).where(eq(testFiles.path, path)).run();
201
+ };
202
+ // Notes why a test file failed outside its tests in a phase after its part was written, as a verify rerun's suite hook, keeping the first reason its part already holds.
203
+ export const setFileFailure = (db, path, failure) => {
204
+ db.update(testFiles)
205
+ .set({ failure })
206
+ .where(and(eq(testFiles.path, path), isNull(testFiles.failure)))
207
+ .run();
208
+ };
209
+ const getPartPaths = (db) => {
210
+ const judged = db.select({ path: testFiles.path }).from(testFiles).all();
211
+ const reads = db.selectDistinct({ path: readSequences.testFile }).from(readSequences).all();
212
+ return [...new Set([...judged, ...reads].map(({ path }) => path))];
213
+ };
214
+ export const clearTestFiles = (db, isMissing) => {
215
+ db.transaction((tx) => {
216
+ // Hold the write lock from checking each path through deleting its parts and checkpoints.
217
+ const missing = getPartPaths(tx).filter(isMissing);
218
+ for (const rows of chunksOf(missing.map((path) => ({ path })))) {
219
+ const gone = rows.map(({ path }) => path);
220
+ tx.delete(testFiles).where(inArray(testFiles.path, gone)).run();
221
+ tx.delete(readSequences).where(inArray(readSequences.testFile, gone)).run();
222
+ }
223
+ }, { behavior: 'immediate' });
224
+ };
225
+ // Whether a test file's every verdict was reused, or null when it has no part, as the joint pass asks of one file.
226
+ export const getPartIsAllReusedNullable = (db, path) => {
227
+ const [row] = db
228
+ .select({ judged: sql `coalesce(sum(${verdicts.isReused} = 0), 0)` })
229
+ .from(testFiles)
230
+ .leftJoin(verdicts, eq(verdicts.testFile, testFiles.id))
231
+ .where(eq(testFiles.path, path))
232
+ .groupBy(testFiles.id)
233
+ .all();
234
+ if (!row)
235
+ return null;
236
+ return row.judged === 0;
237
+ };
238
+ const partsIn = (db, { withHits, path: only }) => {
239
+ return db.transaction((tx) => {
240
+ const [chosen] = only === null ? [] : tx.select({ id: testFiles.id }).from(testFiles).where(eq(testFiles.path, only)).limit(1).all();
241
+ if (only !== null && !chosen)
242
+ return [];
243
+ const fileId = chosen?.id ?? null;
244
+ const runs = tx
245
+ .select()
246
+ .from(testRuns)
247
+ .where(fileId === null ? undefined : eq(testRuns.testFile, fileId))
248
+ .orderBy(asc(testRuns.id))
249
+ .all();
250
+ const testKeyOf = new Map(runs.map(({ id, testKey }) => [id, testKey]));
251
+ const fileOfTest = new Map(runs.map(({ id, testFile }) => [id, testFile]));
252
+ const tests = Map.groupBy(runs, ({ testFile }) => testFile);
253
+ const judged = Map.groupBy(tx
254
+ .select()
255
+ .from(verdicts)
256
+ .where(fileId === null ? undefined : eq(verdicts.testFile, fileId))
257
+ .orderBy(sql `rowid`)
258
+ .all(), ({ testFile }) => testFile);
259
+ const counted = Map.groupBy(tx
260
+ .select()
261
+ .from(sidePasses)
262
+ .where(fileId === null ? undefined : eq(sidePasses.testFile, fileId))
263
+ .orderBy(asc(sidePasses.site), asc(sidePasses.side))
264
+ .all(), ({ testFile }) => testFile);
265
+ // One part without hits only needs the sites its verdicts and pass counts name.
266
+ const needed = fileId === null || withHits ? undefined : new Set([...(judged.get(fileId) ?? []), ...(counted.get(fileId) ?? [])].map(({ site }) => site));
267
+ const keyOf = siteKeysOf(tx, needed);
268
+ const loadedOutside = Map.groupBy(tx
269
+ .select()
270
+ .from(testFileOutside)
271
+ .where(fileId === null ? undefined : eq(testFileOutside.testFile, fileId))
272
+ .orderBy(asc(testFileOutside.path))
273
+ .all(), ({ testFile }) => testFile);
274
+ const declared = Map.groupBy(tx
275
+ .select()
276
+ .from(testFileProperties)
277
+ .where(fileId === null ? undefined : eq(testFileProperties.testFile, fileId))
278
+ .orderBy(asc(testFileProperties.name))
279
+ .all(), ({ testFile }) => testFile);
280
+ const changedDuring = Map.groupBy(tx
281
+ .select()
282
+ .from(testFileChanged)
283
+ .where(fileId === null ? undefined : eq(testFileChanged.testFile, fileId))
284
+ .orderBy(asc(testFileChanged.path))
285
+ .all(), ({ testFile }) => testFile);
286
+ const read = Map.groupBy(tx
287
+ .select()
288
+ .from(testFileReads)
289
+ .where(fileId === null ? undefined : eq(testFileReads.testFile, fileId))
290
+ .orderBy(asc(testFileReads.path))
291
+ .all(), ({ testFile }) => testFile);
292
+ const enteredBy = Map.groupBy(tx
293
+ .select()
294
+ .from(entries)
295
+ .where(fileId === null ? undefined : inArray(entries.test, tx.select({ id: testRuns.id }).from(testRuns).where(eq(testRuns.testFile, fileId))))
296
+ .orderBy(asc(entries.test), asc(entries.unit))
297
+ .all(), ({ test }) => entryAt(fileOfTest, test, 'an entering test'));
298
+ const taken = withHits
299
+ ? Map.groupBy(tx
300
+ .select()
301
+ .from(hits)
302
+ .orderBy(sql `rowid`)
303
+ .all(), ({ test }) => entryAt(fileOfTest, test, 'a hit test'))
304
+ : new Map();
305
+ const sequences = Map.groupBy(tx
306
+ .select()
307
+ .from(readSequences)
308
+ .where(only === null ? undefined : eq(readSequences.testFile, only))
309
+ .orderBy(asc(readSequences.generation), asc(readSequences.position))
310
+ .all(), ({ testFile }) => testFile);
311
+ // A file's latest read sequence, the one its last run's new verdicts read.
312
+ const sequenceOf = (path) => {
313
+ const rows = sequences.get(path) ?? [];
314
+ const generation = Math.max(0, ...rows.map((row) => row.generation));
315
+ return { generation, units: rows.filter((row) => row.generation === generation).map(({ unit }) => unit) };
316
+ };
317
+ const judgedUnder = Map.groupBy(tx
318
+ .select()
319
+ .from(partAssignees)
320
+ .where(fileId === null ? undefined : eq(partAssignees.testFile, fileId))
321
+ .orderBy(asc(partAssignees.source))
322
+ .all(), ({ testFile }) => testFile);
323
+ const parts = tx
324
+ .select()
325
+ .from(testFiles)
326
+ .where(fileId === null ? undefined : eq(testFiles.id, fileId))
327
+ .all()
328
+ .map(({ id, path, hash, reused, justifications, failure }) => ({
329
+ justifications: justifications ?? undefined,
330
+ file: path,
331
+ hash,
332
+ failure,
333
+ tests: (tests.get(id) ?? []).map(({ testKey, name, passed, failure, steps, statedSteps, stepsReason, isSteady, ticks, ns, answers, keeps }) => ({
334
+ key: testKey,
335
+ name: name ?? undefined,
336
+ passed,
337
+ failure,
338
+ steps,
339
+ ticks,
340
+ ns,
341
+ answers: answers ? answersInput.parse(JSON.parse(answers)) : [],
342
+ keeps,
343
+ statedSteps,
344
+ stepsReason,
345
+ isSteady,
346
+ })),
347
+ hits: (taken.get(id) ?? []).map(({ site, side, test }) => ({ siteKey: entryAt(keyOf, site, 'a hit site'), side, testKey: entryAt(testKeyOf, test, 'a hit test') })),
348
+ entered: (enteredBy.get(id) ?? []).map(({ unit, test }) => ({ unit, testKey: entryAt(testKeyOf, test, 'an entering test') })),
349
+ verdicts: (judged.get(id) ?? []).map(({ site, status, catcher, backup, reruns, basisHash, readHash, readGeneration, readCount, isReused, deferredTo }) => ({
350
+ readHash: readHash ?? undefined,
351
+ key: entryAt(keyOf, site, 'a judged site'),
352
+ status,
353
+ catcher: catcher ? entryAt(testKeyOf, catcher, 'a catching test') : null,
354
+ backup: backup ? entryAt(testKeyOf, backup, 'a backup test') : null,
355
+ reruns,
356
+ basis: basisHash,
357
+ reads: { generation: readGeneration, count: readCount },
358
+ isReused,
359
+ deferred: deferredTo,
360
+ })),
361
+ sequence: sequenceOf(path),
362
+ reads: (read.get(id) ?? []).map(({ path: readPath, hash: readHash }) => ({ path: readPath, hash: readHash })),
363
+ reused,
364
+ rerunFailing: (tests.get(id) ?? []).filter(({ rerunFailed }) => rerunFailed).map(({ testKey }) => testKey),
365
+ passes: (counted.get(id) ?? []).map(({ site, side, passes: count }) => ({ siteKey: entryAt(keyOf, site, 'a passed site'), side, passes: count })),
366
+ outside: (loadedOutside.get(id) ?? []).map(({ path: loaded }) => loaded),
367
+ changed: (changedDuring.get(id) ?? []).map(({ path: source }) => source),
368
+ properties: (declared.get(id) ?? []).map(({ name }) => name),
369
+ assignees: (judgedUnder.get(id) ?? []).map(({ source, assignee }) => ({ source, assignee })),
370
+ }));
371
+ return byPath(parts);
372
+ });
373
+ };
374
+ // Every test file's judged part, in path order, with the sides its tests took only when the caller reads them, since they are most of the record.
375
+ export const getJudged = (db, { withHits }) => partsIn(db, { withHits, path: null });
376
+ export const getPartStampNullable = (db, path) => {
377
+ return db.transaction((tx) => {
378
+ const [file] = tx.select({ id: testFiles.id, hash: testFiles.hash, failure: testFiles.failure }).from(testFiles).where(eq(testFiles.path, path)).limit(1).all();
379
+ if (!file)
380
+ return null;
381
+ const tests = tx.select({ key: testRuns.testKey, passed: testRuns.passed }).from(testRuns).where(eq(testRuns.testFile, file.id)).all();
382
+ const reads = tx.select({ path: testFileReads.path, hash: testFileReads.hash }).from(testFileReads).where(eq(testFileReads.testFile, file.id)).all();
383
+ return { hash: file.hash, failure: file.failure, tests, reads };
384
+ });
385
+ };
386
+ export const getJudgedNullable = (db, path) => {
387
+ const [part] = partsIn(db, { withHits: false, path });
388
+ return part;
389
+ };
@@ -0,0 +1,2 @@
1
+ import { type MeasureWrite, type Record } from './record.db.ts';
2
+ export declare const clearGoneTestFiles: (record: Record, root: string, write?: MeasureWrite) => void;
@@ -0,0 +1,7 @@
1
+ import { clearTestFiles } from './parts.db.js';
2
+ import { isPartPathMissing } from './parts.fs.js';
3
+ import { writeDirectly } from './record.db.js';
4
+ // A part and its checkpoints stand only while their test file does.
5
+ export const clearGoneTestFiles = (record, root, write = writeDirectly) => {
6
+ write(() => clearTestFiles(record, (path) => isPartPathMissing(root, path)));
7
+ };