@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,319 @@
1
+ import { reachedFrom } from '../symbols/symbols.js';
2
+ import { fileKey, namespaceKey } from '../symbols/keys.js';
3
+ // Matches a path inside a fixtures folder, whose files a test reads as data rather than runs.
4
+ export const fixturePattern = /(^|\/)fixtures\//;
5
+ // The node every key the graph names stands for; a key it never made is a bug, which reads as a node of no file.
6
+ const noNode = { kind: 'file', key: '', file: '', name: '', line: 0, parsed: false };
7
+ // What the entries and tests leave unused, each question holding applied alone.
8
+ export const unusedOf = ({ symbols, roots, runners: declared }) => {
9
+ const { nodes, edges } = symbols;
10
+ const nodeAt = (key) => nodes.get(key) ?? noNode;
11
+ const startsOf = (root) => [...roots].filter(([, kind]) => kind === root).map(([path]) => fileKey(path));
12
+ const fromTests = reachedFrom(edges, startsOf('test'));
13
+ const fromEntries = reachedFrom(edges, startsOf('entry'));
14
+ const reached = new Set([...fromEntries, ...fromTests]);
15
+ const bindingAt = (key) => {
16
+ const node = nodeAt(key);
17
+ return node.kind === 'binding' ? node : null;
18
+ };
19
+ const isParsed = (file) => {
20
+ const node = nodeAt(fileKey(file));
21
+ return node.kind === 'file' && node.parsed;
22
+ };
23
+ const isInTests = (key) => roots.get(nodeAt(key).file) === 'test';
24
+ // Who names each node, reached or not, apart from a namespace listing its own file's exports.
25
+ const namedBy = new Map();
26
+ for (const [from, out] of edges) {
27
+ const namer = nodeAt(from);
28
+ if (namer.kind === 'namespace')
29
+ continue;
30
+ for (const to of out) {
31
+ const namers = namedBy.get(to);
32
+ if (namers)
33
+ namers.push(namer);
34
+ else
35
+ namedBy.set(to, [namer]);
36
+ }
37
+ }
38
+ // An export a star passes on is no namer of its own, so it names its source only while something reads that name through it, by member or through the barrel's whole namespace.
39
+ // The walk keeps its own stack, so a chain of barrels longer than the call stack is walked whole, and past the first star any namer holds the name.
40
+ const isNamedFrom = (key, isElsewhere) => {
41
+ const seen = new Set();
42
+ const pending = [];
43
+ for (const from of namedBy.get(key) ?? []) {
44
+ if (!isElsewhere(from))
45
+ continue;
46
+ if (from.kind !== 'export' || from.isOwn)
47
+ return true;
48
+ pending.push(from.key);
49
+ }
50
+ for (let passed = pending.pop(); passed !== undefined; passed = pending.pop()) {
51
+ if (seen.has(passed))
52
+ continue;
53
+ seen.add(passed);
54
+ const node = nodeAt(passed);
55
+ for (const from of [...(namedBy.get(passed) ?? []), ...(namedBy.get(namespaceKey(node.file)) ?? [])]) {
56
+ if (from.kind !== 'export' || from.isOwn)
57
+ return true;
58
+ pending.push(from.key);
59
+ }
60
+ }
61
+ return false;
62
+ };
63
+ // A question must hold applied alone, so nothing is asked of a node something still names, even unreached code, which is asked about first.
64
+ const askOf = (node) => {
65
+ // A test's own code is the check, and a fixture is the data it reads, so neither is asked to go, and a file that did not parse is recorded but never asked about.
66
+ if (roots.get(node.file) === 'test' || fixturePattern.test(node.file) || !isParsed(node.file))
67
+ return 'none';
68
+ const isOtherFile = (from) => from.file !== node.file;
69
+ // Code only tests reach goes with those tests, so only a namer outside the tests holds it.
70
+ const isOutsideTests = (from) => isOtherFile(from) && roots.get(from.file) !== 'test';
71
+ const isTestOnly = !fromEntries.has(node.key) && fromTests.has(node.key);
72
+ if (node.kind === 'file' && isTestOnly)
73
+ return isNamedFrom(node.key, isOutsideTests) ? 'none' : 'tests';
74
+ // An entry is reached from itself, and a test returned above.
75
+ if (node.kind === 'file')
76
+ return reached.has(node.key) || isNamedFrom(node.key, isOtherFile) ? 'none' : 'remove';
77
+ if (!reached.has(fileKey(node.file)))
78
+ return 'none';
79
+ // An export leads only to a binding of its own file, so any export naming a binding is that binding's own.
80
+ const isNotExport = (from) => from.kind !== 'export';
81
+ // Anything naming a binding holds it, its own export, each of several merged declarations' export, or a reader, and none of these is an export a star passes on.
82
+ if (node.kind === 'binding')
83
+ return !reached.has(node.owner) || namedBy.has(node.key) ? 'none' : 'remove';
84
+ if (node.kind !== 'export' || !node.isOwn)
85
+ return 'none';
86
+ // A name merged from several declarations is used while any one of them is.
87
+ const { bindings } = node;
88
+ const isReached = bindings.some((binding) => reached.has(binding));
89
+ const isNamedOutside = (isElsewhere) => bindings.some((binding) => isNamedFrom(binding, isElsewhere));
90
+ // An export of a file only tests reach is asked with its file, and one whose code the entries run, as a pattern exported to be tested, is no test-only code.
91
+ if (isTestOnly) {
92
+ // Whatever the entries run that reaches the binding names it, which the hold below sees.
93
+ if (!fromEntries.has(fileKey(node.file)))
94
+ return 'none';
95
+ const isHeld = isNamedFrom(node.key, isOutsideTests) || isNamedFrom(namespaceKey(node.file), isOutsideTests) || isNamedOutside(isNotExport);
96
+ return isHeld ? 'none' : 'tests';
97
+ }
98
+ // A file's namespace read whole from elsewhere may read any of its exports.
99
+ if (isNamedFrom(node.key, isOtherFile) || isNamedFrom(namespaceKey(node.file), isOtherFile))
100
+ return 'none';
101
+ // A pattern is exported to be tested directly, so one no test reads asks for its test.
102
+ // A test reading the pattern imports it, so another file names it and the check above already holds it.
103
+ if (bindings.some((binding) => bindingAt(binding)?.isPattern && reached.has(binding)))
104
+ return 'test';
105
+ if (reached.has(node.key))
106
+ return 'none';
107
+ if (isReached)
108
+ return 'unexport';
109
+ return isNamedOutside(isNotExport) ? 'none' : 'remove';
110
+ };
111
+ const runners = [];
112
+ const insideOf = new Map();
113
+ for (const [file, { tests, hooks, inside }] of declared) {
114
+ for (const [test, fn] of tests)
115
+ runners.push({ test, file, fn, isTest: true });
116
+ for (const [test, fn] of hooks)
117
+ runners.push({ test, file, fn, isTest: false });
118
+ for (const [group, inner] of inside) {
119
+ const inners = insideOf.get(group);
120
+ if (inners)
121
+ inners.push(inner);
122
+ else
123
+ insideOf.set(group, [inner]);
124
+ }
125
+ }
126
+ const runnerBodies = new Set(runners.map(({ fn }) => fn));
127
+ const runnersByBody = Map.groupBy(runners, ({ fn }) => fn);
128
+ const runnerOrder = new Map(runners.map((runner, index) => [runner, index]));
129
+ // Who names each node, read backward from a key to the runners whose walks reach it.
130
+ let namersKept = null;
131
+ const namersOf = () => {
132
+ if (namersKept)
133
+ return namersKept;
134
+ namersKept = new Map();
135
+ for (const [from, out] of edges) {
136
+ for (const to of out) {
137
+ const namers = namersKept.get(to);
138
+ if (namers)
139
+ namers.push(from);
140
+ else
141
+ namersKept.set(to, [from]);
142
+ }
143
+ }
144
+ return namersKept;
145
+ };
146
+ // A test reading an exported pattern is the evidence its untested question closes on, so a removal keeps one such test for each pattern.
147
+ // A reader crush cannot name as one test, a hook or a test with a computed title, is named by its file, whose every test then reads the pattern.
148
+ // A runner's walk never passes into another runner's body, so the walk back from a key stops at the first body it meets, which is a reader, and goes no further.
149
+ // The tests' own code has no readers, since a runner's reach leaves out every key in the tests.
150
+ const readersKept = new Map();
151
+ const readersOf = (key) => {
152
+ const kept = readersKept.get(key);
153
+ if (kept)
154
+ return kept;
155
+ const readers = [];
156
+ if (!isInTests(key)) {
157
+ const seen = new Set([key]);
158
+ const pending = [key];
159
+ for (let at = pending.pop(); at !== undefined; at = pending.pop()) {
160
+ for (const from of namersOf().get(at) ?? []) {
161
+ if (seen.has(from))
162
+ continue;
163
+ seen.add(from);
164
+ const bodies = runnersByBody.get(from);
165
+ if (bodies)
166
+ readers.push(...bodies);
167
+ else
168
+ pending.push(from);
169
+ }
170
+ }
171
+ readers.sort((left, right) => (runnerOrder.get(left) ?? 0) - (runnerOrder.get(right) ?? 0));
172
+ }
173
+ readersKept.set(key, readers);
174
+ return readers;
175
+ };
176
+ const patternTestsOf = (binding) => {
177
+ const readers = readersOf(binding);
178
+ return [...new Set(readers.map(({ test, file, isTest }) => (isTest && test ? test : file)))];
179
+ };
180
+ // The tests reaching code only tests reach, split into those reaching nothing else outside the tests, which go with it, and those also reaching live code, which only drop it.
181
+ // Each file's nodes, grouped once, since a question of a file reads its own nodes alone.
182
+ let nodesByFile = null;
183
+ // A test file whose own top level reads the code, as a table of cases, drops it there rather than in any one test, so the holders at a test file's top level are listed once with what they name.
184
+ let testTopLevel = null;
185
+ const testTopLevelOf = () => {
186
+ if (testTopLevel)
187
+ return testTopLevel;
188
+ testTopLevel = [];
189
+ for (const [from, out] of edges) {
190
+ const holder = nodeAt(from);
191
+ const isModuleLevel = holder.kind === 'file' || (holder.kind === 'binding' && holder.owner === fileKey(holder.file));
192
+ if (isInTests(from) && isModuleLevel)
193
+ testTopLevel.push([holder, out]);
194
+ }
195
+ return testTopLevel;
196
+ };
197
+ const testsOf = (node) => {
198
+ nodesByFile ??= Map.groupBy(nodes.values(), ({ file }) => file);
199
+ // A file's code is everything it declares, an export's what the export leads to, less what the entries still run.
200
+ const led = node.kind === 'file' ? (nodesByFile.get(node.file) ?? []).map(({ key }) => key) : [...reachedFrom(edges, [node.key])];
201
+ // The tests' own code is never asked to go, so it is no dead code, and no runner body, each in a test file, is ever dead.
202
+ const dead = new Set(led.filter((key) => !fromEntries.has(key) && !isInTests(key)));
203
+ // The runners reaching any dead key, found from the keys rather than by scanning every runner's walk, kept in runner order.
204
+ const reachingSet = new Set([...dead].flatMap(readersOf));
205
+ const reachingAny = runners.filter((runner) => reachingSet.has(runner));
206
+ const reaching = reachingAny.filter(({ test }) => test);
207
+ // A test crush cannot name is told by its file, so the question never reads as having no tests.
208
+ const unnamedTests = [...new Set(reachingAny.filter(({ test }) => !test).map(({ file }) => file))];
209
+ // A test reaches only the dead code when, kept out of it, the test reaches nothing outside the tests, what the dead code calls not counting.
210
+ const isAround = (key) => !dead.has(key) && !runnerBodies.has(key);
211
+ const reachingFns = new Set(reaching.map(({ fn }) => fn));
212
+ // A runner's body is in the tests, so the walk stops once it meets a key outside them, and each runner is walked once, though a group asks again of the tests inside it.
213
+ const ownOnly = new Map();
214
+ const isOwnOnly = (fn) => {
215
+ const kept = ownOnly.get(fn);
216
+ if (kept !== undefined)
217
+ return kept;
218
+ let isOnlyTests = true;
219
+ const seen = new Set([fn]);
220
+ const pending = [fn];
221
+ for (let at = pending.pop(); isOnlyTests && at !== undefined; at = pending.pop()) {
222
+ for (const next of edges.get(at) ?? []) {
223
+ if (seen.has(next) || !isAround(next))
224
+ continue;
225
+ if (!isInTests(next))
226
+ isOnlyTests = false;
227
+ seen.add(next);
228
+ pending.push(next);
229
+ }
230
+ }
231
+ ownOnly.set(fn, isOnlyTests);
232
+ return isOnlyTests;
233
+ };
234
+ // A group goes whole, so it is under remove only when every test and hook inside it is too.
235
+ const isOnly = ({ fn }) => isOwnOnly(fn) && (insideOf.get(fn) ?? []).every((inner) => reachingFns.has(inner) && isOwnOnly(inner));
236
+ const readingFiles = new Set();
237
+ for (const [holder, out] of testTopLevelOf()) {
238
+ if ([...out].some((to) => dead.has(to) && nodeAt(to).kind !== 'file'))
239
+ readingFiles.add(holder.file);
240
+ }
241
+ const byOwnership = Map.groupBy(reaching, isOnly);
242
+ const titles = (each = []) => each.map(({ test }) => test);
243
+ return { onlyTests: titles(byOwnership.get(true)), sharedTests: [...titles(byOwnership.get(false)), ...readingFiles], unnamedTests };
244
+ };
245
+ const unused = [];
246
+ const patternTests = new Map();
247
+ for (const node of nodes.values()) {
248
+ const patterns = node.kind === 'export' ? node.bindings.flatMap((binding) => bindingAt(binding) ?? []).filter(({ isPattern }) => isPattern) : [];
249
+ const readers = [...new Set(patterns.flatMap((pattern) => patternTestsOf(pattern.key)))];
250
+ if (readers.length)
251
+ patternTests.set(node.key, readers);
252
+ const ask = askOf(node);
253
+ if (ask === 'none')
254
+ continue;
255
+ // A removal names the imports only its bindings read, every merged declaration's among them, so removing them together leaves nothing unread.
256
+ const removed = (node.kind === 'export' ? node.bindings : [node.key]).flatMap((key) => bindingAt(key) ?? []);
257
+ const tests = ask === 'tests' ? testsOf(node) : { onlyTests: [], sharedTests: [], unnamedTests: [] };
258
+ unused.push({ key: node.key, ask, alongside: ask === 'remove' ? [...new Set(removed.flatMap(({ alongside }) => alongside))] : [], ...tests });
259
+ }
260
+ return { unused, patternTests };
261
+ };
262
+ // The graph and its questions as the record's rows, each list joined by `, ` for imports and by lines for tests.
263
+ export const reachOf = (symbols, { unused, patternTests }) => {
264
+ const asked = new Map(unused.map((each) => [each.key, each]));
265
+ const parsedOf = (file) => {
266
+ const node = symbols.nodes.get(fileKey(file));
267
+ return node?.kind === 'file' && node.parsed;
268
+ };
269
+ return {
270
+ nodes: [...symbols.nodes.values()].map((node) => {
271
+ const question = asked.get(node.key);
272
+ return {
273
+ key: node.key,
274
+ file: node.file,
275
+ kind: node.kind === 'namespace' ? 'export' : node.kind,
276
+ name: node.name,
277
+ line: node.line,
278
+ parsed: parsedOf(node.file),
279
+ ask: question?.ask ?? 'none',
280
+ alongside: (question?.alongside ?? []).join(', '),
281
+ onlyTests: (question?.onlyTests ?? []).join('\n'),
282
+ sharedTests: (question?.sharedTests ?? []).join('\n'),
283
+ unnamedTests: (question?.unnamedTests ?? []).join('\n'),
284
+ patternTests: (patternTests.get(node.key) ?? []).join('\n'),
285
+ };
286
+ }),
287
+ edges: [...symbols.edges].flatMap(([fromKey, out]) => [...out].map((toKey) => ({ fromKey, toKey }))),
288
+ };
289
+ };
290
+ const edgeId = ({ fromKey, toKey }) => JSON.stringify([fromKey, toKey]);
291
+ // Each node is compared field by field, so a replan that changes one file rewrites only that file's rows and whatever its change moved.
292
+ export const reachChangesOf = (before, after) => {
293
+ const oldNodes = new Map(before.nodes.map((node) => [node.key, node]));
294
+ const newKeys = new Set(after.nodes.map(({ key }) => key));
295
+ const isSame = (node) => {
296
+ const old = oldNodes.get(node.key);
297
+ if (!old)
298
+ return false;
299
+ return (old.file === node.file &&
300
+ old.kind === node.kind &&
301
+ old.name === node.name &&
302
+ old.line === node.line &&
303
+ old.parsed === node.parsed &&
304
+ old.ask === node.ask &&
305
+ old.alongside === node.alongside &&
306
+ old.onlyTests === node.onlyTests &&
307
+ old.sharedTests === node.sharedTests &&
308
+ old.unnamedTests === node.unnamedTests &&
309
+ old.patternTests === node.patternTests);
310
+ };
311
+ const oldEdges = new Set(before.edges.map(edgeId));
312
+ const newEdges = new Set(after.edges.map(edgeId));
313
+ return {
314
+ removedNodes: before.nodes.filter(({ key }) => !newKeys.has(key)).map(({ key }) => key),
315
+ savedNodes: after.nodes.filter((node) => !isSame(node)),
316
+ removedEdges: before.edges.filter((edge) => !newEdges.has(edgeId(edge))),
317
+ addedEdges: after.edges.filter((edge) => !oldEdges.has(edgeId(edge))),
318
+ };
319
+ };
@@ -0,0 +1,7 @@
1
+ import { type Node } from '../../utils/ast.ts';
2
+ import { type Faults } from '../../utils/faults.ts';
3
+ export type Listener = {
4
+ enter: (node: Node, parent: Node, key: string, isRuntime: boolean) => void;
5
+ exit: (node: Node, parent: Node, key: string, isRuntime: boolean) => void;
6
+ };
7
+ export declare const walkFile: (program: Node, faults: Faults, listeners: readonly Listener[]) => void;
@@ -0,0 +1,39 @@
1
+ import { visitorKeys } from 'oxc-parser';
2
+ import { holdsRuntime } from '../../utils/ast.js';
3
+ import { heldOr } from '../../utils/faults.js';
4
+ const noKeys = [];
5
+ // visitorKeys name only child slots, and each holds a node, an array of nodes, or nothing.
6
+ const isNode = (value) => Boolean(value);
7
+ // One walk tells every listener of every node by oxc's child keys, type-only ones included, as ESLint walked them, the root being its own parent.
8
+ // Listeners are told in order on entering and in reverse on leaving, so each sees its own nodes nest.
9
+ // It keeps its own stack, so a tree deeper than the call stack is walked whole.
10
+ export const walkFile = (program, faults, listeners) => {
11
+ const leaving = listeners.toReversed();
12
+ const open = [];
13
+ const enter = (node, parent, key, isRuntime) => {
14
+ for (const listener of listeners)
15
+ listener.enter(node, parent, key, isRuntime);
16
+ return { node, parent, key, isRuntime, keys: heldOr(faults, visitorKeys[node.type], noKeys, 'child keys of a node'), slot: 0, item: 0 };
17
+ };
18
+ let step = enter(program, program, program.type, true);
19
+ while (step) {
20
+ const childKey = step.keys[step.slot];
21
+ if (childKey === undefined) {
22
+ for (const listener of leaving)
23
+ listener.exit(step.node, step.parent, step.key, step.isRuntime);
24
+ step = open.pop();
25
+ continue;
26
+ }
27
+ const value = Reflect.get(step.node, childKey);
28
+ const child = Array.isArray(value) ? value[step.item] : value;
29
+ step.item += 1;
30
+ if (!Array.isArray(value) || step.item >= value.length) {
31
+ step.slot += 1;
32
+ step.item = 0;
33
+ }
34
+ if (isNode(child)) {
35
+ open.push(step);
36
+ step = enter(child, step.node, childKey, step.isRuntime && holdsRuntime(child));
37
+ }
38
+ }
39
+ };
@@ -0,0 +1,72 @@
1
+ import { type Fork } from '../decisions/decisions.ts';
2
+ import { type Cfg } from '../graph/cfg/cfg.ts';
3
+ import { type Forks } from '../forks/forks.operations.ts';
4
+ import { type Paths } from '../graph/cfg/paths.ts';
5
+ import type { Listener } from '../graph/walk/walk.ts';
6
+ import type { MutationSettings, PlanFileInput, PlanTestInput, UnitInput } from './instrument.schema.ts';
7
+ import { type Mutation, type Project } from '../mutators/mutator.ts';
8
+ import { type Parsed } from '../utils/ast.ts';
9
+ import type { CrushError } from '../utils/errors.ts';
10
+ import type { Safe } from '../utils/safe.ts';
11
+ export type Entry = {
12
+ index: number;
13
+ open: number;
14
+ close: number | null;
15
+ };
16
+ type InstrumentInput = {
17
+ path: string;
18
+ source: string;
19
+ parsed: Parsed;
20
+ forks: Fork[];
21
+ sites: Mutation[];
22
+ entries: Entry[];
23
+ pointBase: number;
24
+ siteBase: number;
25
+ counters: string;
26
+ };
27
+ export declare const preludeOf: (counters: string, repeat?: string) => string;
28
+ export declare const instrumented: (input: InstrumentInput) => string;
29
+ type OutlineEdit = {
30
+ start: number;
31
+ end: number;
32
+ text: string;
33
+ };
34
+ export declare const unitsOf: (source: string, parsed: Parsed, paths: Paths, unitBase: number, edits?: OutlineEdit[]) => {
35
+ units: UnitInput[];
36
+ entries: Entry[];
37
+ };
38
+ type PlanTestOfInput = {
39
+ path: string;
40
+ hash: string;
41
+ source: string;
42
+ parsed: Parsed;
43
+ unitBase: number;
44
+ counters: string;
45
+ listeners?: readonly Listener[];
46
+ };
47
+ export declare const planTestOf: ({ path, hash, source, parsed, unitBase, counters, listeners }: PlanTestOfInput) => Safe<{
48
+ code: string;
49
+ plan: PlanTestInput;
50
+ paths: Paths;
51
+ }, CrushError>;
52
+ export declare const regexSpecialPattern: RegExp;
53
+ type PlanFileOfInput = {
54
+ path: string;
55
+ hash: string;
56
+ source: string;
57
+ parsed: Parsed;
58
+ project: Project;
59
+ forkPlugins: Forks;
60
+ mutation: MutationSettings;
61
+ pointBase: number;
62
+ siteBase: number;
63
+ unitBase: number;
64
+ counters: string;
65
+ listeners?: readonly Listener[];
66
+ };
67
+ export declare const planFileOf: (input: PlanFileOfInput) => Safe<{
68
+ code: string;
69
+ plan: PlanFileInput;
70
+ cfg: Cfg;
71
+ }, CrushError>;
72
+ export {};