@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 @@
1
+ export declare const isPartPathMissing: (root: string, path: string) => boolean;
@@ -0,0 +1,11 @@
1
+ import { accessSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { safe } from '../../utils/safe.js';
4
+ const isMissing = (error) => {
5
+ if (!error)
6
+ return false;
7
+ if ('code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
8
+ return true;
9
+ throw error;
10
+ };
11
+ export const isPartPathMissing = (root, path) => isMissing(safe(() => accessSync(join(root, path))).error);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,85 @@
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 { pointKeyOf } from '../../judge/judge.operations.js';
54
+ import { setJudged } from './parts.db.js';
55
+ import { openCurrentRecord } from './record.db.js';
56
+ // One process standing in for a test file's worker: it writes its own judged part, over and over, to a record another process made and planned.
57
+ const [path, file] = process.argv.slice(2);
58
+ if (!path || !file) {
59
+ console.error('usage: parts.writer.ts <record> <file>');
60
+ process.exit(1);
61
+ }
62
+ const { data: opened, error } = openCurrentRecord(path);
63
+ if (error) {
64
+ console.error(error.message);
65
+ process.exit(1);
66
+ }
67
+ var record, tests, siteKey, hits, verdicts, part;
68
+ const env_1 = { stack: [], error: void 0, hasError: false };
69
+ try {
70
+ record = __addDisposableResource(env_1, opened, false);
71
+ tests = Array.from({ length: 200 }, (_, at) => ({ key: `${file}::t${at}`, passed: true, failure: null, steps: at, ticks: at, ns: at, answers: [], keeps: null, statedSteps: null, stepsReason: null, isSteady: true }));
72
+ siteKey = pointKeyOf('a.ts', 'd');
73
+ hits = tests.map(({ key }) => ({ siteKey, side: 'true', testKey: key }));
74
+ verdicts = [{ key: 's', status: 'caught', catcher: `${file}::t0`, backup: null, reruns: 1, basis: 'b', reads: { generation: 1, count: 0 }, isReused: false, deferred: null, answered: [] }];
75
+ part = { file, tests, hits, entered: [], verdicts, reads: [], rerunFailing: [], passes: [], outside: [], changed: [], assignees: [], sequence: { generation: 1, units: [] }, failure: null, properties: [] };
76
+ for (let round = 0; round < 20; round += 1)
77
+ setJudged(record, { ...part, hash: String(round), reused: round });
78
+ }
79
+ catch (e_1) {
80
+ env_1.error = e_1;
81
+ env_1.hasError = true;
82
+ }
83
+ finally {
84
+ __disposeResources(env_1);
85
+ }
@@ -0,0 +1,19 @@
1
+ import { type judgePasses } from '../../crush.tables.ts';
2
+ import { CrushError } from '../../utils/errors.ts';
3
+ import { type Clock } from '../../utils/retry.ts';
4
+ import type { Record } from './record.db.ts';
5
+ export type JudgePass = (typeof judgePasses)[number];
6
+ export declare const clearPasses: (db: Record) => void;
7
+ export type PassEndInput = {
8
+ pass: JudgePass;
9
+ shard: number;
10
+ failure: string | null;
11
+ };
12
+ export declare const setPassEnded: (db: Record, { pass, shard, failure }: PassEndInput) => void;
13
+ export declare class PassRunning extends CrushError {
14
+ }
15
+ export type PassWaitInput = {
16
+ pass: JudgePass;
17
+ shards: number;
18
+ };
19
+ export declare const passEnded: (db: Record, { pass, shards }: PassWaitInput, clock?: Clock) => Promise<Error | null>;
@@ -0,0 +1,31 @@
1
+ import { eq } from 'drizzle-orm';
2
+ import { passesEnded } from '../../crush.tables.js';
3
+ import { CrushError } from '../../utils/errors.js';
4
+ import { retried, systemClock } from '../../utils/retry.js';
5
+ import { safe } from '../../utils/safe.js';
6
+ // A pass can run as long as the slowest shard judges, so a shard waits for the others well past any one pass, and a shard killed outright stops the others only once this runs out.
7
+ const waitMs = 24 * 60 * 60 * 1000;
8
+ // How long a shard waits between looks at the passes the others ended.
9
+ const pollMs = 100;
10
+ // The passes a killed run's shards ended would let this run's shards go on before the others, so a run starts by clearing them.
11
+ export const clearPasses = (db) => {
12
+ db.delete(passesEnded).run();
13
+ };
14
+ export const setPassEnded = (db, { pass, shard, failure }) => {
15
+ db.insert(passesEnded).values({ pass, shard, failure }).onConflictDoNothing().run();
16
+ };
17
+ export class PassRunning extends CrushError {
18
+ }
19
+ // Waits until every shard has ended the pass, answering the first shard's failure, so no shard starts the next pass on a part another left unwritten.
20
+ export const passEnded = async (db, { pass, shards }, clock = systemClock) => {
21
+ const run = () => {
22
+ const { data: ended, error } = safe(() => db.select().from(passesEnded).where(eq(passesEnded.pass, pass)).all());
23
+ if (error)
24
+ return error;
25
+ const failed = ended.find(({ failure }) => failure !== null);
26
+ if (failed)
27
+ return new CrushError(`shard ${failed.shard} failed its ${pass} pass: ${failed.failure}`);
28
+ return ended.length < shards ? new PassRunning(`${shards - ended.length} of ${shards} shards still in the ${pass} pass after ${waitMs} ms`) : null;
29
+ };
30
+ return await retried({ run, isRetried: (error) => error instanceof PassRunning, waitMs, intervalMs: pollMs, clock });
31
+ };
@@ -0,0 +1,21 @@
1
+ import { forcings } from '../../crush.tables.ts';
2
+ import type { PlanFileInput, PlanInput, PlanTestInput } from '../../instrument/instrument.schema.ts';
3
+ import { type Reader, type Record } from './record.db.ts';
4
+ type Forcing = (typeof forcings)[number];
5
+ export declare const forcedOf: (forced: boolean | 'once') => Forcing;
6
+ export declare const forcingOf: (forced: Forcing) => boolean | 'once';
7
+ export declare const siteIdsOf: (db: Reader) => Map<string, number>;
8
+ export declare const siteIdsFor: (db: Reader, keys: readonly string[]) => Map<string, number>;
9
+ export declare const siteKeysOf: (db: Reader, ids?: ReadonlySet<number>) => Map<number, string>;
10
+ export declare const setPlan: (db: Record, planned: PlanFileInput[], tests: PlanTestInput[]) => void;
11
+ export type PlanCode = {
12
+ path: string;
13
+ hash: string;
14
+ code: string;
15
+ };
16
+ export declare const setPlanCodes: (db: Record, planKey: string, codes: readonly PlanCode[]) => void;
17
+ export declare const getPlanCodesNullable: (db: Record, planKey: string) => PlanCode[] | null;
18
+ export declare const getPlan: (db: Record, { withRewrites }?: {
19
+ withRewrites?: boolean;
20
+ }) => PlanInput;
21
+ export {};
@@ -0,0 +1,174 @@
1
+ import { and, asc, inArray, notInArray, sql } from 'drizzle-orm';
2
+ import { forcings, planCodes, planCrushDedents, planCrushEdits, planCrushes, planPoints, planSwitches, planTests, planUnits, sites, sources } from '../../crush.tables.js';
3
+ import { pointKeyOf } from '../../judge/judge.operations.js';
4
+ import { entryAt } from '../../utils/lookup.js';
5
+ import { clearHitsFor } from './hits.db.js';
6
+ import { chunksOf } from './record.db.js';
7
+ export const forcedOf = (forced) => (forced === 'once' ? 'once' : forced ? 'true' : 'false');
8
+ export const forcingOf = (forced) => (forced === 'once' ? 'once' : forced === 'true');
9
+ // Every site's id by its key.
10
+ export const siteIdsOf = (db) => {
11
+ return new Map(db
12
+ .select({ id: sites.id, siteKey: sites.siteKey })
13
+ .from(sites)
14
+ .all()
15
+ .map(({ id, siteKey }) => [siteKey, id]));
16
+ };
17
+ // The ids of the sites named by key, a key no site holds left out.
18
+ export const siteIdsFor = (db, keys) => {
19
+ return new Map(chunksOf(keys.map((siteKey) => ({ siteKey }))).flatMap((chunk) => {
20
+ return db
21
+ .select({ id: sites.id, siteKey: sites.siteKey })
22
+ .from(sites)
23
+ .where(inArray(sites.siteKey, chunk.map(({ siteKey }) => siteKey)))
24
+ .all()
25
+ .map(({ id, siteKey }) => [siteKey, id]);
26
+ }));
27
+ };
28
+ // Site keys by their IDs, optionally restricted to the sites the caller reads.
29
+ export const siteKeysOf = (db, ids) => {
30
+ const query = db.select({ id: sites.id, siteKey: sites.siteKey }).from(sites);
31
+ const rows = ids
32
+ ? chunksOf([...ids].map((id) => ({ id }))).flatMap((chunk) => {
33
+ return query
34
+ .where(inArray(sites.id, chunk.map(({ id }) => id)))
35
+ .all();
36
+ })
37
+ : query.all();
38
+ return new Map(rows.map(({ id, siteKey }) => [id, siteKey]));
39
+ };
40
+ // Every planned source's rows by table, each source and crush numbered in planned order.
41
+ const planRowsOf = (planned, siteOf) => {
42
+ const rows = { sources: [], points: [], switches: [], crushes: [], edits: [], dedents: [] };
43
+ let crushId = 0;
44
+ for (const [position, { path, hash, points, switches, crushes, left }] of planned.entries()) {
45
+ const source = position + 1;
46
+ rows.sources.push({ id: source, path, hash, ...left });
47
+ for (const { index, decision, kind } of points)
48
+ rows.points.push({ source, site: entryAt(siteOf, pointKeyOf(path, decision), 'a planned point'), counter: index, decision, kind });
49
+ for (const { index, key, mutator, owner, code, replacement, start, line } of switches) {
50
+ rows.switches.push({ source, site: entryAt(siteOf, key, 'a planned switch'), counter: index, mutator, owner, code, replacement, startAt: start, line });
51
+ }
52
+ for (const crush of crushes) {
53
+ crushId += 1;
54
+ const { key, side, start, end, forced, edits, dedents, ...rest } = crush;
55
+ // A planned side is any text, which the side check constraint refuses outside its list, so it binds as a plain parameter.
56
+ rows.crushes.push({ id: crushId, source, site: entryAt(siteOf, key, 'a planned crush'), ...rest, side: sql `${side}`, startAt: start, endAt: end, forced: forcedOf(forced) });
57
+ for (const edit of edits)
58
+ rows.edits.push({ crush: crushId, startAt: edit.start, endAt: edit.end, replacement: edit.text });
59
+ for (const dedent of dedents)
60
+ rows.dedents.push({ crush: crushId, startAt: dedent.start, endAt: dedent.end, width: dedent.by });
61
+ }
62
+ }
63
+ return rows;
64
+ };
65
+ // The whole plan in one transaction, replacing the last; a site the plan no longer names goes, and every row about it with it.
66
+ export const setPlan = (db, planned, tests) => {
67
+ const units = [...planned, ...tests].flatMap(({ path, units: each }) => each.map(({ index, name, hash }) => ({ counter: index, path, name, hash })));
68
+ const keys = planned.flatMap(({ path, points, switches, crushes }) => [...points.map(({ decision }) => pointKeyOf(path, decision)), ...switches.map(({ key }) => key), ...crushes.map(({ key }) => key)]);
69
+ const siteKeys = keys.map((siteKey) => ({ siteKey }));
70
+ db.transaction((tx) => {
71
+ tx.delete(planUnits).run();
72
+ tx.delete(planTests).run();
73
+ for (const chunk of chunksOf(units))
74
+ tx.insert(planUnits).values(chunk).run();
75
+ for (const chunk of chunksOf(tests.map(({ path, hash, metadataHash }) => ({ path, hash, metadataHash: metadataHash ?? null }))))
76
+ tx.insert(planTests).values(chunk).run();
77
+ for (const chunk of chunksOf(siteKeys))
78
+ tx.insert(sites).values(chunk).onConflictDoNothing().run();
79
+ const rows = planRowsOf(planned, siteIdsOf(tx));
80
+ tx.delete(sources).run();
81
+ for (const chunk of chunksOf(rows.sources))
82
+ tx.insert(sources).values(chunk).run();
83
+ for (const chunk of chunksOf(rows.points))
84
+ tx.insert(planPoints).values(chunk).run();
85
+ for (const chunk of chunksOf(rows.switches))
86
+ tx.insert(planSwitches).values(chunk).run();
87
+ for (const chunk of chunksOf(rows.crushes))
88
+ tx.insert(planCrushes).values(chunk).run();
89
+ for (const chunk of chunksOf(rows.edits))
90
+ tx.insert(planCrushEdits).values(chunk).run();
91
+ for (const chunk of chunksOf(rows.dedents))
92
+ tx.insert(planCrushDedents).values(chunk).run();
93
+ const isUnplanned = and(notInArray(sites.id, tx.select({ site: planPoints.site }).from(planPoints)), notInArray(sites.id, tx.select({ site: planSwitches.site }).from(planSwitches)), notInArray(sites.id, tx.select({ site: planCrushes.site }).from(planCrushes)));
94
+ // Hits hold no foreign key to their site, so a dropped site's hits go first, before the site they would outlive.
95
+ clearHitsFor(tx, tx.select({ id: sites.id }).from(sites).where(isUnplanned));
96
+ tx.delete(sites).where(isUnplanned).run();
97
+ }, { behavior: 'immediate' });
98
+ };
99
+ // Keeps every planned file's instrumented code under the key of the plan it came from, replacing the last plan's.
100
+ export const setPlanCodes = (db, planKey, codes) => {
101
+ const rows = codes.map(({ path, hash, code }) => ({ path, planKey, hash, code }));
102
+ db.transaction((tx) => {
103
+ tx.delete(planCodes).run();
104
+ for (const chunk of chunksOf(rows))
105
+ tx.insert(planCodes).values(chunk).run();
106
+ }, { behavior: 'immediate' });
107
+ };
108
+ // The instrumented code kept under a plan key, in path order, or null when the last plan kept was another.
109
+ export const getPlanCodesNullable = (db, planKey) => {
110
+ const rows = db.select().from(planCodes).orderBy(asc(planCodes.path)).all();
111
+ if (!rows.length || rows.some((row) => row.planKey !== planKey))
112
+ return null;
113
+ return rows.map(({ path, hash, code }) => ({ path, hash, code }));
114
+ };
115
+ // The plan as the plugin last wrote it, every list in the order it was planned in.
116
+ export const getPlan = (db, { withRewrites = true } = {}) => {
117
+ return db.transaction((tx) => {
118
+ const keyOf = siteKeysOf(tx);
119
+ const points = Map.groupBy(tx.select().from(planPoints).orderBy(asc(planPoints.id)).all(), ({ source }) => source);
120
+ const switches = Map.groupBy(tx.select().from(planSwitches).orderBy(asc(planSwitches.id)).all(), ({ source }) => source);
121
+ const edits = withRewrites ? Map.groupBy(tx.select().from(planCrushEdits).orderBy(asc(planCrushEdits.id)).all(), ({ crush }) => crush) : undefined;
122
+ const dedents = withRewrites ? Map.groupBy(tx.select().from(planCrushDedents).orderBy(asc(planCrushDedents.id)).all(), ({ crush }) => crush) : undefined;
123
+ const crushes = Map.groupBy(tx.select().from(planCrushes).orderBy(asc(planCrushes.id)).all(), ({ source }) => source);
124
+ const units = Map.groupBy(tx.select().from(planUnits).orderBy(asc(planUnits.counter)).all(), ({ path }) => path);
125
+ const unitsOf = (path) => (units.get(path) ?? []).map(({ counter, name, hash }) => ({ index: counter, name, hash }));
126
+ return {
127
+ tests: tx
128
+ .select()
129
+ .from(planTests)
130
+ .orderBy(asc(planTests.path))
131
+ .all()
132
+ .map(({ path, hash, metadataHash }) => ({ path, hash, metadataHash: metadataHash ?? undefined, units: unitsOf(path) })),
133
+ files: tx
134
+ .select()
135
+ .from(sources)
136
+ .orderBy(asc(sources.id))
137
+ .all()
138
+ .map(({ id, path, hash, excluded, overlap }) => ({
139
+ path,
140
+ hash,
141
+ left: { excluded, overlap },
142
+ points: (points.get(id) ?? []).map(({ counter, decision, kind }) => ({ index: counter, decision, kind })),
143
+ switches: (switches.get(id) ?? []).map(({ site, counter, mutator, owner, code, replacement, startAt, line }) => ({
144
+ index: counter,
145
+ key: entryAt(keyOf, site, 'a planned switch'),
146
+ mutator,
147
+ owner,
148
+ code,
149
+ replacement,
150
+ start: startAt,
151
+ line,
152
+ })),
153
+ crushes: (crushes.get(id) ?? []).map(({ id: crush, site, crush: name, decision, side, point, startAt, endAt, forced, skips, forcedEffect, owner, code, line }) => ({
154
+ key: entryAt(keyOf, site, 'a planned crush'),
155
+ crush: name,
156
+ decision,
157
+ side,
158
+ point,
159
+ start: startAt,
160
+ end: endAt,
161
+ forced: forcingOf(forced),
162
+ skips,
163
+ forcedEffect: forcedEffect ?? undefined,
164
+ owner,
165
+ code,
166
+ edits: (edits?.get(crush) ?? []).map(({ startAt: from, endAt: to, replacement }) => ({ start: from, end: to, text: replacement })),
167
+ dedents: (dedents?.get(crush) ?? []).map(({ startAt: from, endAt: to, width }) => ({ start: from, end: to, by: width })),
168
+ line,
169
+ })),
170
+ units: unitsOf(path),
171
+ })),
172
+ };
173
+ });
174
+ };
@@ -0,0 +1,6 @@
1
+ import type { ReachChanges } from '../../graph/unused/unused.ts';
2
+ import { type ReachEdgeOutput, type ReachNodeOutput } from '../../graph/symbols/symbols.schema.ts';
3
+ import { type Reader, type Record } from './record.db.ts';
4
+ export declare const setReachChanges: (db: Record, { removedNodes, savedNodes, removedEdges, addedEdges }: ReachChanges) => void;
5
+ export declare const getReachNodes: (db: Reader) => ReachNodeOutput[];
6
+ export declare const getReachEdges: (db: Reader) => ReachEdgeOutput[];
@@ -0,0 +1,62 @@
1
+ import { inArray, sql } from 'drizzle-orm';
2
+ import { reachEdges, reachNodes } from '../../crush.tables.js';
3
+ import { reachKeyOutput, reachNodeOutput } from '../../graph/symbols/symbols.schema.js';
4
+ import { chunksOf } from './record.db.js';
5
+ // The plan step's changes to the whole-project graph in one transaction: removed edges and nodes go first, a removed node's edges with it by cascade, then changed nodes are saved and new edges added.
6
+ export const setReachChanges = (db, { removedNodes, savedNodes, removedEdges, addedEdges }) => {
7
+ const saved = {
8
+ file: sql `excluded.file`,
9
+ kind: sql `excluded.kind`,
10
+ name: sql `excluded.name`,
11
+ line: sql `excluded.line`,
12
+ parsed: sql `excluded.parsed`,
13
+ ask: sql `excluded.ask`,
14
+ alongside: sql `excluded.alongside`,
15
+ onlyTests: sql `excluded.only_tests`,
16
+ sharedTests: sql `excluded.shared_tests`,
17
+ unnamedTests: sql `excluded.unnamed_tests`,
18
+ patternTests: sql `excluded.pattern_tests`,
19
+ };
20
+ db.transaction((tx) => {
21
+ // Drizzle has no typed row-value comparison, so an edge's two keys match as one pair in SQL.
22
+ for (const chunk of chunksOf(removedEdges)) {
23
+ const pairs = sql.join(chunk.map(({ fromKey, toKey }) => sql `(${fromKey}, ${toKey})`), sql `, `);
24
+ tx.delete(reachEdges)
25
+ .where(sql `(${reachEdges.fromKey}, ${reachEdges.toKey}) in (values ${pairs})`)
26
+ .run();
27
+ }
28
+ for (const chunk of chunksOf(removedNodes.map((key) => ({ key })))) {
29
+ tx.delete(reachNodes)
30
+ .where(inArray(reachNodes.nodeKey, chunk.map(({ key }) => key)))
31
+ .run();
32
+ }
33
+ for (const chunk of chunksOf(savedNodes)) {
34
+ const rows = chunk.map(({ key, ...node }) => Object.assign(node, { nodeKey: key }));
35
+ tx.insert(reachNodes).values(rows).onConflictDoUpdate({ target: reachNodes.nodeKey, set: saved }).run();
36
+ }
37
+ for (const chunk of chunksOf(addedEdges))
38
+ tx.insert(reachEdges).values(chunk).run();
39
+ }, { behavior: 'immediate' });
40
+ };
41
+ export const getReachNodes = (db) => {
42
+ return db
43
+ .select()
44
+ .from(reachNodes)
45
+ .all()
46
+ .map(({ nodeKey, ...node }) => reachNodeOutput.parse({ key: nodeKey, ...node }));
47
+ };
48
+ export const getReachEdges = (db) => {
49
+ const rows = db.select().from(reachEdges).all();
50
+ const checked = new Set();
51
+ const check = (key) => {
52
+ if (checked.has(key))
53
+ return;
54
+ reachKeyOutput.parse(key);
55
+ checked.add(key);
56
+ };
57
+ for (const { fromKey, toKey } of rows) {
58
+ check(fromKey);
59
+ check(toKey);
60
+ }
61
+ return rows;
62
+ };
@@ -0,0 +1,22 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ import { type NodeSQLiteDatabase } from 'drizzle-orm/node-sqlite';
3
+ import { CrushError } from '../../utils/errors.ts';
4
+ import { type Safe } from '../../utils/safe.ts';
5
+ export declare const recordVersion = "57";
6
+ export declare const memoryPath = ":memory:";
7
+ export type Record = NodeSQLiteDatabase & {
8
+ $client: DatabaseSync;
9
+ [Symbol.dispose]: () => void;
10
+ };
11
+ export type WriteTransaction = Parameters<Parameters<Record['transaction']>[0]>[0];
12
+ export type Reader = Pick<Record, 'select'>;
13
+ export type MeasureWrite = <T>(write: () => T) => T;
14
+ export declare const measureWritesOf: (speed: {
15
+ writes: number;
16
+ }) => MeasureWrite;
17
+ export declare const writeDirectly: MeasureWrite;
18
+ export declare const openRecord: (path: string) => Record;
19
+ export declare const openCurrentRecord: (path: string) => Safe<Record, CrushError>;
20
+ export declare const openReadOnlyRecord: (path: string) => Safe<Record, CrushError>;
21
+ export declare const readCurrentRecord: <T>(path: string, read: (record: Record) => T) => Safe<T, CrushError>;
22
+ export declare const chunksOf: <T extends object>(rows: readonly T[]) => T[][];
@@ -0,0 +1,176 @@
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 { join } from 'node:path';
54
+ import { DatabaseSync } from 'node:sqlite';
55
+ import { drizzle } from 'drizzle-orm/node-sqlite';
56
+ import { migrate } from 'drizzle-orm/node-sqlite/migrator';
57
+ import { meta } from '../../crush.tables.js';
58
+ import { CrushError, failed } from '../../utils/errors.js';
59
+ import { safe } from '../../utils/safe.js';
60
+ import { ensureRecordFolder, recordFileExists, removeRecordFile } from './record.fs.js';
61
+ import { unreadableRecordOf } from '../../judge/refusals.js';
62
+ // The record's shape; a record of any other version is deleted and rebuilt, since every row can be recorded again.
63
+ export const recordVersion = '57';
64
+ // How long a connection waits on the record while another holds its write lock, as every test file's worker writes its own part at once.
65
+ const busyMs = 30_000;
66
+ const migrationsFolder = join(import.meta.dirname, '../../../migrations/main');
67
+ // SQLite binds at most this many parameters in one statement, so a list write splits its rows at it.
68
+ const parameterLimit = 32_766;
69
+ const versionOf = (path) => {
70
+ const env_1 = { stack: [], error: void 0, hasError: false };
71
+ try {
72
+ if (!recordFileExists(path))
73
+ return null;
74
+ const database = __addDisposableResource(env_1, new DatabaseSync(path, { readOnly: true, timeout: busyMs }), false);
75
+ const found = database.prepare("select name from sqlite_master where type = 'table' and name = 'meta'").get();
76
+ const row = found ? database.prepare('select version from meta').get() : undefined;
77
+ return typeof row?.version === 'string' ? row.version : null;
78
+ }
79
+ catch (e_1) {
80
+ env_1.error = e_1;
81
+ env_1.hasError = true;
82
+ }
83
+ finally {
84
+ __disposeResources(env_1);
85
+ }
86
+ };
87
+ // A connection with write-ahead logging, so readers never block the writer, and its foreign keys enforced, so a part's rows go with it.
88
+ // The path that opens a record in memory alone, as crush's own tests do, so a test touches no disk.
89
+ export const memoryPath = ':memory:';
90
+ export const measureWritesOf = (speed) => {
91
+ return (write) => {
92
+ const started = performance.now();
93
+ try {
94
+ return write();
95
+ }
96
+ finally {
97
+ speed.writes += performance.now() - started;
98
+ }
99
+ };
100
+ };
101
+ export const writeDirectly = (write) => write();
102
+ // A record commits through the write-ahead log, syncing at its checkpoints rather than on every commit, since crush rebuilds a record it loses from the project's files.
103
+ const connect = (path) => {
104
+ const client = new DatabaseSync(path, { timeout: busyMs });
105
+ client.exec('pragma journal_mode = wal');
106
+ client.exec('pragma synchronous = normal');
107
+ client.exec('pragma foreign_keys = on');
108
+ return Object.assign(drizzle({ client }), { [Symbol.dispose]: () => client.close() });
109
+ };
110
+ // Opens the record at `path`, rebuilding it first when it holds another version, and migrates it; only one process may do this at a time.
111
+ export const openRecord = (path) => {
112
+ // A record in memory starts empty, so only a file is checked for its version and given a folder.
113
+ if (path !== memoryPath) {
114
+ if (versionOf(path) !== recordVersion)
115
+ removeRecordFile(path);
116
+ ensureRecordFolder(path);
117
+ }
118
+ const db = connect(path);
119
+ migrate(db, { migrationsFolder });
120
+ db.insert(meta)
121
+ .values({ version: recordVersion, createdAt: new Date(Temporal.Now.instant().epochMilliseconds) })
122
+ .onConflictDoNothing()
123
+ .run();
124
+ return db;
125
+ };
126
+ // Opens a record another process already opened and migrated, as a test file's worker does, refusing one of another version or none at all.
127
+ export const openCurrentRecord = (path) => {
128
+ const version = versionOf(path);
129
+ if (version !== recordVersion)
130
+ return failed(staleOf(path, version));
131
+ return { data: connect(path), error: null };
132
+ };
133
+ const staleOf = (path, version) => `the record at ${path} is ${version ? `version ${version}` : 'missing'}, not version ${recordVersion}; \`vp run record\` rebuilds it`;
134
+ // The read-only connection sets no pragma, as reporting must leave the record as it was.
135
+ export const openReadOnlyRecord = (path) => {
136
+ const { data: version, error: versionError } = safe(() => versionOf(path));
137
+ if (versionError)
138
+ return failed(unreadableRecordOf({ path, message: versionError.message }));
139
+ if (version !== recordVersion)
140
+ return failed(staleOf(path, version));
141
+ const open = () => {
142
+ const client = new DatabaseSync(path, { readOnly: true, timeout: busyMs });
143
+ return Object.assign(drizzle({ client }), { [Symbol.dispose]: () => client.close() });
144
+ };
145
+ const { data, error } = safe(open);
146
+ return error ? failed(unreadableRecordOf({ path, message: error.message })) : { data, error: null };
147
+ };
148
+ export const readCurrentRecord = (path, read) => {
149
+ const env_2 = { stack: [], error: void 0, hasError: false };
150
+ try {
151
+ const { data: opened, error: openError } = openReadOnlyRecord(path);
152
+ if (openError)
153
+ return { data: null, error: openError };
154
+ const record = __addDisposableResource(env_2, opened, false);
155
+ const readOnce = () => read(record);
156
+ const { data, error } = safe(readOnce);
157
+ if (error)
158
+ return failed(unreadableRecordOf({ path, message: error.message }));
159
+ return { data, error: null };
160
+ }
161
+ catch (e_2) {
162
+ env_2.error = e_2;
163
+ env_2.hasError = true;
164
+ }
165
+ finally {
166
+ __disposeResources(env_2);
167
+ }
168
+ };
169
+ // A list's rows in the fewest inserts SQLite binds, each row's fields counted as its parameters.
170
+ export const chunksOf = (rows) => {
171
+ const [first] = rows;
172
+ if (!first)
173
+ return [];
174
+ const size = Math.floor(parameterLimit / Object.keys(first).length);
175
+ return Array.from({ length: Math.ceil(rows.length / size) }, (_, at) => rows.slice(at * size, (at + 1) * size));
176
+ };
@@ -0,0 +1,3 @@
1
+ export declare const recordFileExists: (path: string) => boolean;
2
+ export declare const removeRecordFile: (path: string) => void;
3
+ export declare const ensureRecordFolder: (path: string) => void;
@@ -0,0 +1,7 @@
1
+ import { existsSync, mkdirSync, rmSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ export const recordFileExists = (path) => existsSync(path);
4
+ export const removeRecordFile = (path) => rmSync(path, { force: true });
5
+ export const ensureRecordFolder = (path) => {
6
+ mkdirSync(dirname(path), { recursive: true });
7
+ };
@@ -0,0 +1,11 @@
1
+ import type { Judged } from '../../judge/judge.schema.ts';
2
+ import { type Reader, type Record } from './record.db.ts';
3
+ export type SiteVerdict = Pick<Judged['verdicts'][number], 'key' | 'status' | 'catcher' | 'backup' | 'reruns' | 'basis'> & {
4
+ owner: string | null;
5
+ readUnits: string[];
6
+ readsHash: string;
7
+ isReused: boolean;
8
+ isBackupSearched: boolean;
9
+ };
10
+ export declare const getSiteVerdicts: (db: Reader, keys: readonly string[]) => Map<string, SiteVerdict>;
11
+ export declare const setSiteVerdicts: (db: Record, verdicts: readonly SiteVerdict[]) => void;