@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,46 @@
1
+ import { resolverOf } from '../../graph/symbols/resolve.operations.ts';
2
+ import { type Context } from '../../mutators/mutator.ts';
3
+ import { type Node, type Visit } from '../../utils/ast.ts';
4
+ import type { CrushError } from '../../utils/errors.ts';
5
+ import type { Safe } from '../../utils/safe.ts';
6
+ import type { Ports } from './edges/ports.ts';
7
+ import type { Side, Site } from './intended.ts';
8
+ import type { Edit, Mutant } from './normalize.ts';
9
+ export declare const portNames: ReadonlySet<string>;
10
+ type SourceInput = {
11
+ source: string;
12
+ path: string;
13
+ };
14
+ export declare const strykerMutants: ({ source, path }: SourceInput) => Promise<Mutant[]>;
15
+ type Span = {
16
+ start: number;
17
+ end: number;
18
+ };
19
+ export type Scan = {
20
+ ports: Ports;
21
+ program: Node;
22
+ around: Omit<Context, keyof Visit>;
23
+ spans: Map<string, boolean>;
24
+ functions: Span[];
25
+ reprinted: Map<string, Node>;
26
+ arrows: Map<string, string>;
27
+ chains: Set<string>;
28
+ };
29
+ export declare const spanKey: ({ start, end }: Span) => string;
30
+ type ResolveImport = ReturnType<typeof resolverOf>;
31
+ export declare const corpusImportResolverOf: (root: string, files: readonly string[]) => ResolveImport;
32
+ type ScanInput = SourceInput & {
33
+ ports: Ports;
34
+ resolveImport: ResolveImport;
35
+ };
36
+ export declare const scanOf: ({ source, path, ports, resolveImport }: ScanInput) => Safe<Scan, CrushError>;
37
+ export declare const narrowed: ({ reprinted }: Scan, source: string, mutant: Mutant) => Mutant;
38
+ export declare const crushMutants: ({ ports, program, around }: Scan) => Mutant[];
39
+ export declare const spanFits: ({ chains }: Scan, stryker: Span, crush: Span) => boolean;
40
+ export type Unmatched = {
41
+ edit: Edit;
42
+ side: Side;
43
+ };
44
+ export declare const sitesOf: (scan: Scan, unmatched: readonly Unmatched[]) => Site[];
45
+ export declare const insideFunction: ({ spans, functions }: Scan, span: Span) => boolean;
46
+ export {};
@@ -0,0 +1,199 @@
1
+ import { readCorpusSource } from '../edges/corpus.fs.js';
2
+ import { join, relative } from 'node:path';
3
+ import { resolverOf } from '../../graph/symbols/resolve.operations.js';
4
+ import { Instrumenter } from '@stryker-mutator/instrumenter';
5
+ import { mutationsOf } from '../../mutators/mutator.js';
6
+ import { entryAt } from '../../utils/ast.js';
7
+ // StrykerJS's mutators crush ports, each port named exactly as its StrykerJS mutator, so a name maps to itself; StrykerJS's CallExpression has no port.
8
+ export const portNames = new Set([
9
+ 'ArithmeticOperator',
10
+ 'ArrayDeclaration',
11
+ 'ArrowFunction',
12
+ 'AssignmentOperator',
13
+ 'BlockStatement',
14
+ 'BooleanLiteral',
15
+ 'ConditionalExpression',
16
+ 'EqualityOperator',
17
+ 'LogicalOperator',
18
+ 'MethodExpression',
19
+ 'ObjectLiteral',
20
+ 'OptionalChaining',
21
+ 'Regex',
22
+ 'StringLiteral',
23
+ 'UnaryOperator',
24
+ 'UpdateOperator',
25
+ ]);
26
+ const quiet = () => { };
27
+ const off = () => false;
28
+ const logger = {
29
+ isTraceEnabled: off,
30
+ isDebugEnabled: off,
31
+ isInfoEnabled: off,
32
+ isWarnEnabled: off,
33
+ isErrorEnabled: off,
34
+ isFatalEnabled: off,
35
+ trace: quiet,
36
+ debug: quiet,
37
+ info: quiet,
38
+ warn: quiet,
39
+ error: quiet,
40
+ fatal: quiet,
41
+ };
42
+ const instrumenter = new Instrumenter(logger);
43
+ const options = { plugins: null, excludedMutations: [], ignorers: [], noHeader: true };
44
+ // The offset of each line's first character, which a 0-based line and column resolve against.
45
+ const lineStartsOf = (source) => {
46
+ const starts = [0];
47
+ for (let at = source.indexOf('\n'); at !== -1; at = source.indexOf('\n', at + 1))
48
+ starts.push(at + 1);
49
+ return starts;
50
+ };
51
+ // StrykerJS's mutants of a file from its instrumenter alone, which collects every mutant without running a test, kept to the ported mutators.
52
+ export const strykerMutants = async ({ source, path }) => {
53
+ const { mutants } = await instrumenter.instrument([{ name: path, content: source, mutate: true }], options);
54
+ const starts = lineStartsOf(source);
55
+ const offsetOf = ({ line, column }) => (starts[line] ?? source.length) + column;
56
+ return mutants.filter((mutant) => portNames.has(mutant.mutatorName)).map((mutant) => ({ mutator: mutant.mutatorName, start: offsetOf(mutant.location.start), end: offsetOf(mutant.location.end), replacement: mutant.replacement }));
57
+ };
58
+ const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
59
+ export const spanKey = ({ start, end }) => `${start}:${end}`;
60
+ // Programs parsed for import closures, kept for the files a folder's walk is near, as siblings import one another.
61
+ // A program is kept by the text it was read from, so a file rewritten at the same path is parsed again.
62
+ // A resolved file that disappears before its read is kept by path alone, so its other importers do not retry it.
63
+ const parsedFiles = new Map();
64
+ const parsedLimit = 256;
65
+ const keep = (key, program) => {
66
+ if (parsedFiles.size >= parsedLimit)
67
+ parsedFiles.clear();
68
+ parsedFiles.set(key, program);
69
+ return program;
70
+ };
71
+ const programAt = ({ parse }, path) => {
72
+ if (parsedFiles.has(path))
73
+ return null;
74
+ const { data: text, error: readError } = readCorpusSource(path);
75
+ if (readError)
76
+ return keep(path, null);
77
+ const key = `${path}\n${text}`;
78
+ const kept = parsedFiles.get(key);
79
+ if (kept !== undefined)
80
+ return kept;
81
+ return keep(key, parse(text, path).data?.program ?? null);
82
+ };
83
+ // Resolves relative imports against the files selected for the Stryker corpus.
84
+ export const corpusImportResolverOf = (root, files) => {
85
+ const fromRoot = (path) => relative(root, path).split('\\').join('/');
86
+ const resolve = resolverOf(new Set(files.map(fromRoot)));
87
+ return (from, specifier) => {
88
+ const path = resolve(fromRoot(from), specifier);
89
+ return path === null ? null : join(root, path);
90
+ };
91
+ };
92
+ // The file and every file it reaches through imports and re-exports, the programs crush's string port follows a callee into.
93
+ const projectOf = (ports, path, program, resolveImport) => {
94
+ const project = new Map([[path, program]]);
95
+ const waiting = [path];
96
+ for (let from = waiting.pop(); from !== undefined; from = waiting.pop()) {
97
+ for (const item of entryAt(project, from, 'a project file').body) {
98
+ const target = item.type === 'ImportDeclaration' || item.type === 'ExportNamedDeclaration' || item.type === 'ExportAllDeclaration' ? item.source?.value : undefined;
99
+ if (!target)
100
+ continue;
101
+ const resolved = resolveImport(from, target);
102
+ if (resolved === null || project.has(resolved))
103
+ continue;
104
+ const found = programAt(ports, resolved);
105
+ if (!found)
106
+ continue;
107
+ project.set(resolved, found);
108
+ waiting.push(resolved);
109
+ }
110
+ }
111
+ return project;
112
+ };
113
+ export const scanOf = ({ source, path, ports, resolveImport }) => {
114
+ const { data: parsed, error } = ports.parse(source, path);
115
+ if (error)
116
+ return { data: null, error };
117
+ const { program } = parsed;
118
+ const { data: paths, error: broken } = ports.pathsOf(parsed);
119
+ if (broken)
120
+ return { data: null, error: broken };
121
+ const around = { source, comments: parsed.comments, path, project: projectOf(ports, path, program, resolveImport), bindings: ports.bindingsOf(paths) };
122
+ const spans = new Map();
123
+ const functions = [];
124
+ const reprinted = new Map();
125
+ const arrows = new Map();
126
+ const chains = new Set();
127
+ ports.walk(program, ({ node, inFunction }) => {
128
+ const key = spanKey(node);
129
+ spans.set(key, (spans.get(key) ?? false) || inFunction);
130
+ if (functionTypes.has(node.type))
131
+ functions.push({ start: node.start, end: node.end });
132
+ if (node.type === 'ForStatement' || node.type === 'SwitchCase')
133
+ reprinted.set(key, node);
134
+ if (node.type === 'ArrowFunctionExpression' && node.expression)
135
+ arrows.set(key, spanKey(node.body));
136
+ if (node.type === 'ChainExpression')
137
+ chains.add(key);
138
+ });
139
+ return { data: { ports, program, around, spans, functions, reprinted, arrows, chains }, error: null };
140
+ };
141
+ // StrykerJS writes a testless `for` or an emptied case as the whole statement reprinted by Babel, whose printing of the body can differ from the source.
142
+ // Its mutant is narrowed to the one change it makes, `false` inserted as the test or the case's statements removed, so only that change is compared.
143
+ export const narrowed = ({ reprinted }, source, mutant) => {
144
+ const node = reprinted.get(spanKey(mutant));
145
+ if (mutant.mutator !== 'ConditionalExpression' || !node)
146
+ return mutant;
147
+ if (node.type === 'ForStatement' && !node.test) {
148
+ const at = source.indexOf(';', node.init ? node.init.end : node.start) + 1;
149
+ return { ...mutant, start: at, end: at, replacement: 'false' };
150
+ }
151
+ if (node.type !== 'SwitchCase')
152
+ return mutant;
153
+ const last = node.consequent.at(-1);
154
+ if (!last)
155
+ return mutant;
156
+ const start = source.indexOf(':', node.test ? node.test.end : node.start) + 1;
157
+ return { ...mutant, start, end: last.end, replacement: '' };
158
+ };
159
+ // Crush's mutants of a file from its ported mutators, visited the way its scan visits them, inside functions only.
160
+ export const crushMutants = ({ ports, program, around }) => {
161
+ const found = [];
162
+ ports.walk(program, (visit) => {
163
+ if (!visit.inFunction)
164
+ return;
165
+ for (const port of ports.mutators) {
166
+ for (const { start, end, replacement } of mutationsOf(port, { ...visit, ...around }))
167
+ found.push({ mutator: port.name, start, end, replacement });
168
+ }
169
+ });
170
+ return found;
171
+ };
172
+ // Whether a crush mutant's span may stand for a StrykerJS one's: the same span, or the optional chain holding it, which crush widens a site on the chain's spine to.
173
+ export const spanFits = ({ chains }, stryker, crush) => (stryker.start === crush.start && stryker.end === crush.end) || (chains.has(spanKey(crush)) && crush.start <= stryker.start && stryker.end <= crush.end);
174
+ // The contexts at each unmatched span, from a second walk, so only those few copy their ancestors.
175
+ // A mutant no node spans exactly, as a case's statements removed from after its colon, is read by the innermost node holding it, the last a preorder walk meets.
176
+ export const sitesOf = (scan, unmatched) => {
177
+ const exact = new Map();
178
+ const holders = new Map();
179
+ for (const { edit } of unmatched)
180
+ exact.set(spanKey(edit.mutant), []);
181
+ const loose = unmatched.map(({ edit }) => edit.mutant);
182
+ scan.ports.walk(scan.program, (visit) => {
183
+ const list = exact.get(spanKey(visit.node));
184
+ const context = () => ({ ...visit, ...scan.around, ancestors: [...visit.ancestors] });
185
+ if (list)
186
+ list.push(context());
187
+ for (const mutant of loose) {
188
+ if (visit.node.start <= mutant.start && mutant.end <= visit.node.end)
189
+ holders.set(spanKey(mutant), context());
190
+ }
191
+ });
192
+ return unmatched.map(({ edit, side }) => {
193
+ const found = exact.get(spanKey(edit.mutant)) ?? [];
194
+ const holder = holders.get(spanKey(edit.mutant));
195
+ return { edit, side, contexts: found.length || !holder ? found : [holder] };
196
+ });
197
+ };
198
+ // Whether a span lies inside a function, the code crush's walk mutates, read from the node at that span where crush's tree has one.
199
+ export const insideFunction = ({ spans, functions }, span) => spans.get(spanKey(span)) ?? functions.some((fn) => fn.start <= span.start && span.end <= fn.end && (fn.start !== span.start || fn.end !== span.end));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,147 @@
1
+ import { relative } from 'node:path';
2
+ import { describe, expect, inject, it } from 'vite-plus/test';
3
+ import { z } from 'zod';
4
+ import { locate } from '../../utils/ast.js';
5
+ import { safe, safeAsync } from '../../utils/safe.js';
6
+ import { corpusFilesOf, readCorpusSource } from '../edges/corpus.fs.js';
7
+ import { strykerParityProvideKey } from '../edges/vitest.js';
8
+ import { overflows, parsedAsModule, problemsOf, skipOf, summaryOf, tallyOf } from '../parity.operations.js';
9
+ import { compare } from './compare.js';
10
+ import { portsIn } from './edges/ports.js';
11
+ import { explain, pairArrowBodies } from './intended.js';
12
+ import { isMinified } from './normalize.js';
13
+ import { corpusImportResolverOf, crushMutants, insideFunction, narrowed, scanOf, sitesOf, spanFits, strykerMutants } from './sides.js';
14
+ import { strykerParityInput } from './stryker.schema.js';
15
+ // A full corpus run takes many minutes, so the walk stops starting files once this passes and the run fails as incomplete.
16
+ const budgetMs = 90 * 60 * 1000;
17
+ const progressEvery = 1000;
18
+ // Vitest holds a test's console output until it ends and drops it when the test passes, so progress and results go straight to the streams.
19
+ const print = (line) => {
20
+ process.stdout.write(`${line}\n`);
21
+ };
22
+ const input = strykerParityInput.safeParse(inject(strykerParityProvideKey));
23
+ if (!input.success)
24
+ throw new Error(z.prettifyError(input.error));
25
+ const { folder, ports: src, every } = input.data;
26
+ // One port bug as `stryker only StringLiteral at 3:9: 'a' > ""`, beside the node types at its span.
27
+ const describeSite = (source, { edit: { mutator, mutant }, side, contexts }) => {
28
+ const { line, column } = locate(source)(mutant.start);
29
+ const shapes = contexts.map(({ node, parent, key }) => `${parent.type}.${key} ${node.type}`).join(', ');
30
+ return `${side} only ${mutator} at ${line}:${column + 1}: ${JSON.stringify(source.slice(mutant.start, mutant.end))} > ${JSON.stringify(mutant.replacement)} (${shapes || 'no node at its span'})`;
31
+ };
32
+ const bump = (map, key, by = 1) => {
33
+ map.set(key, (map.get(key) ?? 0) + by);
34
+ };
35
+ describe('All Stryker Parity Tests', () => {
36
+ it("matches StrykerJS's mutants with crush's ports on every corpus file, apart from the intended differences", async () => {
37
+ const ports = await portsIn(src);
38
+ const files = corpusFilesOf(folder);
39
+ const resolveImport = corpusImportResolverOf(folder, files);
40
+ const tally = tallyOf();
41
+ const skipped = { commonjs: 0, jsx: 0, minified: 0, unparsed: 0 };
42
+ const counts = { matched: 0, bugs: 0 };
43
+ const reasons = new Map();
44
+ const bugsByMutator = new Map();
45
+ const started = performance.now();
46
+ let read = 0;
47
+ let gone = 0;
48
+ let undecodable = 0;
49
+ for (const path of files) {
50
+ if (performance.now() - started > budgetMs)
51
+ break;
52
+ read++;
53
+ if (read % progressEvery === 0)
54
+ print(`parity:stryker: ${read}/${files.length} files, ${Math.round((performance.now() - started) / 1000)}s`);
55
+ const where = relative(folder, path);
56
+ // Another session can move a file between the walk and its read, which leaves nothing to compare.
57
+ const { data: source, error: readError } = readCorpusSource(path);
58
+ if (readError) {
59
+ gone++;
60
+ continue;
61
+ }
62
+ const skip = skipOf(path);
63
+ if (skip) {
64
+ skipped[skip]++;
65
+ continue;
66
+ }
67
+ // StrykerJS reprints each mutant's whole node, so a minified bundle's long lines make every replacement most of the file and exhaust the heap.
68
+ if (isMinified(source)) {
69
+ skipped.minified++;
70
+ continue;
71
+ }
72
+ // Oxc builds its tree lazily and throws on a string it cannot decode, as a lone surrogate escape.
73
+ const { data: errorCount, error: parseError } = safe(() => parsedAsModule(source, path).errors.length);
74
+ if (parseError) {
75
+ undecodable++;
76
+ continue;
77
+ }
78
+ if (errorCount) {
79
+ skipped.unparsed++;
80
+ continue;
81
+ }
82
+ const fail = (side, error) => {
83
+ if (overflows(error) && side === 'StrykerJS')
84
+ tally.oracleOverflowed++;
85
+ else if (overflows(error))
86
+ tally.crushOverflowed++;
87
+ else
88
+ tally.failed++;
89
+ print(`mutants failed in ${where}: ${side} threw ${error.message}`);
90
+ };
91
+ const { data: scan, error: scanError } = scanOf({ source, path, ports, resolveImport });
92
+ if (scanError) {
93
+ fail('crush', scanError);
94
+ continue;
95
+ }
96
+ // A walk too deep for the stack overflows inside crush's mutators, which the tally counts apart from a failed check.
97
+ const { data: crush, error: crushError } = safe(() => crushMutants(scan));
98
+ if (crushError) {
99
+ fail('crush', crushError);
100
+ continue;
101
+ }
102
+ // oxlint-disable-next-line no-await-in-loop -- one file's StrykerJS run at a time, so a corpus of tens of thousands of files never holds every parse in memory at once
103
+ const { data: stryker, error: strykerError } = await safeAsync(() => strykerMutants({ source, path }));
104
+ if (strykerError) {
105
+ fail('StrykerJS', strykerError);
106
+ continue;
107
+ }
108
+ const inside = stryker.filter((mutant) => insideFunction(scan, mutant)).map((mutant) => narrowed(scan, source, mutant));
109
+ const { matched, onlyStryker, onlyCrush } = compare({ source, stryker: inside, crush, fits: (a, b) => spanFits(scan, a, b) });
110
+ counts.matched += matched;
111
+ const arrows = pairArrowBodies({ stryker: onlyStryker, crush: onlyCrush, arrows: scan.arrows });
112
+ if (arrows.paired)
113
+ bump(reasons, 'arrow-body-only', arrows.paired);
114
+ const unmatched = [...arrows.stryker.map((edit) => ({ edit, side: 'stryker' })), ...arrows.crush.map((edit) => ({ edit, side: 'crush' }))];
115
+ const bugs = [];
116
+ for (const site of sitesOf(scan, unmatched)) {
117
+ const reason = explain(site);
118
+ if (reason)
119
+ bump(reasons, reason.name);
120
+ else {
121
+ bugs.push(site);
122
+ bump(bugsByMutator, `${site.side} only ${site.edit.mutator}`);
123
+ }
124
+ }
125
+ const [first] = bugs.sort((a, b) => a.edit.at - b.edit.at);
126
+ if (!first) {
127
+ tally.same++;
128
+ continue;
129
+ }
130
+ tally.differ++;
131
+ counts.bugs += bugs.length;
132
+ print(`mutants differ in ${where}: ${matched} matched, ${bugs.length} port bugs`);
133
+ for (const site of every ? bugs : [first])
134
+ print(` ${describeSite(source, site)}`);
135
+ }
136
+ const seconds = Math.round((performance.now() - started) / 1000);
137
+ print(`parity:stryker: ${read} of ${files.length} files under ${folder} in ${seconds}s, ${gone} gone before their read, ${undecodable} undecodable, ports from ${src}`);
138
+ print(`skipped: ${skipped.commonjs} commonjs, ${skipped.jsx} jsx, ${skipped.minified} minified, ${skipped.unparsed} unparsed`);
139
+ print(`${counts.matched} mutants matched, ${counts.bugs} port bugs`);
140
+ print(summaryOf('mutants', tally));
141
+ for (const [name, count] of [...reasons].toSorted(([a], [b]) => a.localeCompare(b)))
142
+ print(`intended ${name}: ${count}`);
143
+ for (const [name, count] of [...bugsByMutator].toSorted(([a], [b]) => a.localeCompare(b)))
144
+ print(`port bug ${name}: ${count}`);
145
+ expect(problemsOf({ total: files.length, read, undecodable, tallies: { mutants: tally } })).toEqual([]);
146
+ }, budgetMs + 60_000);
147
+ });
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export declare const strykerParityInput: z.ZodObject<{
3
+ folder: z.ZodString;
4
+ ports: z.ZodString;
5
+ every: z.ZodCodec<z.ZodString, z.ZodBoolean>;
6
+ }, z.core.$strip>;
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ // The folder a Stryker parity run walks, the crush `src` folder whose ports it checks, and whether it prints every port bug of a file rather than its first, as `vite.config.ts` provides them on the `parity:stryker` project from the caller's environment.
3
+ export const strykerParityInput = z.object({
4
+ folder: z.string().min(1, 'strykerFolder names no folder to check, so set it in vite.config.ts and run `vp run parity:stryker`').max(2048),
5
+ ports: z.string().min(1).max(2048),
6
+ every: z.stringbool({ error: 'strykerEvery in vite.config.ts must be `true` or `false`' }),
7
+ });
@@ -0,0 +1,21 @@
1
+ import { type Program } from 'oxc-parser';
2
+ import type { codePathWalker } from '../graph/cfg/code-paths/analyzer.ts';
3
+ import type { resolvedOf, scopeWalker } from '../graph/cfg/scopes/scopes.ts';
4
+ import { type CrushError } from '../utils/errors.ts';
5
+ import type { Safe } from '../utils/safe.ts';
6
+ import type { View } from './parity.operations.ts';
7
+ export type Ports = {
8
+ codePathWalker: typeof codePathWalker;
9
+ scopeWalker: typeof scopeWalker;
10
+ resolvedOf: typeof resolvedOf;
11
+ };
12
+ export declare const portCodePathsOf: (ports: Ports, program: Program) => View;
13
+ export declare const portScopesOf: (ports: Ports, program: Program) => View;
14
+ export declare const eslintScopesOf: (program: Program) => View;
15
+ type CodePathsInput = {
16
+ program: Program;
17
+ source: string;
18
+ path: string;
19
+ };
20
+ export declare const eslintCodePathsOf: ({ program, source, path }: CodePathsInput) => Safe<View, CrushError>;
21
+ export {};
@@ -0,0 +1,119 @@
1
+ import { Linter } from 'eslint';
2
+ import { analyze } from 'eslint-scope';
3
+ import { visitorKeys } from 'oxc-parser';
4
+ import { z } from 'zod';
5
+ import { failed } from '../utils/errors.js';
6
+ import { valueAt } from '../utils/lookup.js';
7
+ const isNode = (value) => typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
8
+ // Enters and leaves every node by oxc's child keys in order, the root as its own parent, on a stack of its own so a deeply nested file never overflows the call stack.
9
+ const walkTree = (program, enter, exit) => {
10
+ const stack = [{ node: program, parent: program, key: program.type, isLeaving: false }];
11
+ for (let visit = stack.pop(); visit; visit = stack.pop()) {
12
+ const { node, parent, key } = visit;
13
+ if (visit.isLeaving) {
14
+ exit(node, parent, key);
15
+ continue;
16
+ }
17
+ enter(node, parent, key);
18
+ stack.push({ ...visit, isLeaving: true });
19
+ const children = valueAt(visitorKeys, node.type).flatMap((childKey) => {
20
+ const held = Reflect.get(node, childKey);
21
+ return [held]
22
+ .flat()
23
+ .filter(isNode)
24
+ .map((child) => ({ node: child, parent: node, key: childKey, isLeaving: false }));
25
+ });
26
+ for (const child of children.toReversed())
27
+ stack.push(child);
28
+ }
29
+ };
30
+ const segmentOf = (id, reachable, next) => `${id}${reachable ? '' : '!'}>${next.join(',')}`;
31
+ export const portCodePathsOf = (ports, program) => {
32
+ const walker = ports.codePathWalker(program);
33
+ walkTree(program, (node, parent) => walker.enter(node, parent), (node, parent) => walker.exit(node, parent));
34
+ return walker.graphs.map((graph) => graph.segments.map(({ id, reachable, next }) => segmentOf(id, reachable, next)).toSorted());
35
+ };
36
+ const referenceOf = ({ name, read, write, start, definition }) => `${name}${read ? 'R' : ''}${write ? 'W' : ''}@${start}>${definition}`;
37
+ export const portScopesOf = (ports, program) => {
38
+ const walker = ports.scopeWalker(program);
39
+ walkTree(program, (node, parent, key) => walker.enter(node, parent, key, true), walker.exit);
40
+ const rowOf = (reference) => {
41
+ const variable = ports.resolvedOf(reference);
42
+ const [found] = variable ? variable.defs : [];
43
+ const definition = found ? `${found.type}@${found.name.start}` : '-';
44
+ return referenceOf({ name: 'name' in reference.identifier ? String(reference.identifier.name) : '', read: reference.isRead, write: reference.isWrite, start: reference.identifier.start, definition });
45
+ };
46
+ return walker.scopes.map((scope) => Array.of(scope.type).concat(scope.references.map(rowOf)));
47
+ };
48
+ // The oracles locate nodes by range and ESLint by line and column too, which oxc leaves off, so each node gets them, every column on one line.
49
+ const ranged = (program) => {
50
+ const stack = [program];
51
+ while (stack.length) {
52
+ const value = stack.pop();
53
+ if (Array.isArray(value)) {
54
+ // oxlint-disable-next-line typescript/no-unsafe-argument -- the walk reads slots by visitor keys chosen at run time, so no static type names what they hold
55
+ stack.push(...value);
56
+ continue;
57
+ }
58
+ if (!isNode(value))
59
+ continue;
60
+ Reflect.set(value, 'range', [value.start, value.end]);
61
+ Reflect.set(value, 'loc', { start: { line: 1, column: value.start }, end: { line: 1, column: value.end } });
62
+ for (const key of Object.keys(value)) {
63
+ const child = Reflect.get(value, key);
64
+ if (key !== 'range' && key !== 'loc' && key !== 'parent' && typeof child === 'object')
65
+ stack.push(child);
66
+ }
67
+ }
68
+ };
69
+ // Oxc's tree is ESTree with ranges once `ranged` has run, which is all the oracles read.
70
+ const rangedProgram = z.custom((value) => isNode(value) && value.type === 'Program' && 'range' in value && Array.isArray(value.range));
71
+ const startOf = (node) => {
72
+ if (!node.range)
73
+ throw new Error('node without a range');
74
+ return node.range[0];
75
+ };
76
+ export const eslintScopesOf = (program) => {
77
+ ranged(program);
78
+ const options = { ignoreEval: true, ecmaVersion: 2026, sourceType: 'module', childVisitorKeys: visitorKeys, fallback: 'iteration' };
79
+ const { scopes } = analyze(rangedProgram.parse(program), options);
80
+ const rowOf = (reference) => {
81
+ const [found] = reference.resolved ? reference.resolved.defs : [];
82
+ const definition = found ? `${found.type}@${startOf(found.name)}` : '-';
83
+ return referenceOf({ name: reference.identifier.name, read: reference.isRead(), write: reference.isWrite(), start: startOf(reference.identifier), definition });
84
+ };
85
+ return scopes.map((scope) => Array.of(scope.type).concat(scope.references.map(rowOf)));
86
+ };
87
+ const linter = new Linter({ configType: 'flat' });
88
+ const segmentsFrom = (codePath) => {
89
+ const seen = new Map();
90
+ const stack = [codePath.initialSegment];
91
+ for (let segment = stack.pop(); segment; segment = stack.pop()) {
92
+ if (seen.has(segment.id))
93
+ continue;
94
+ seen.set(segment.id, segment);
95
+ stack.push(...segment.allNextSegments);
96
+ }
97
+ return [...seen.values()]
98
+ .map((segment) => {
99
+ return segmentOf(segment.id, segment.reachable, segment.allNextSegments.map(({ id }) => id));
100
+ })
101
+ .toSorted();
102
+ };
103
+ export const eslintCodePathsOf = ({ program, source, path }) => {
104
+ ranged(program);
105
+ const ast = { ...rangedProgram.parse(program), tokens: [], comments: [] };
106
+ const views = [];
107
+ const rule = { create: () => ({ onCodePathEnd: (codePath) => views.push(segmentsFrom(codePath)) }) };
108
+ const parser = { parseForESLint: () => ({ ast, visitorKeys }) };
109
+ const config = {
110
+ files: ['**/*.ts', '**/*.js', '**/*.mjs'],
111
+ languageOptions: { ecmaVersion: 'latest', sourceType: 'module', parser },
112
+ plugins: { parity: { rules: { paths: rule } } },
113
+ rules: { 'parity/paths': 'error' },
114
+ };
115
+ const fatal = linter.verify(source, config, { filename: `file${path.slice(path.lastIndexOf('.'))}` }).find((message) => message.fatal);
116
+ if (fatal)
117
+ return failed(fatal.message);
118
+ return { data: views, error: null };
119
+ };
@@ -0,0 +1,110 @@
1
+ import type { ReachNodeOutput } from '../graph/symbols/symbols.schema.ts';
2
+ import type { Removable } from '../judge/judge.operations.ts';
3
+ import type { TestName } from '../judge/judge.schema.ts';
4
+ import type { QuestionInput, QuestionOutput } from './questions.schema.ts';
5
+ export declare const quote: (code: string) => string;
6
+ type Worded = Exclude<QuestionInput['kind'], 'steps' | 'answers'>;
7
+ export declare const questionsOf: (items: (QuestionInput & {
8
+ kind: Worded;
9
+ })[]) => QuestionOutput[];
10
+ export type JudgedSite = {
11
+ key: string;
12
+ kind: 'crush' | 'tell';
13
+ mutator: string;
14
+ file: string;
15
+ owner: string;
16
+ code: string;
17
+ replacement: string;
18
+ side: string;
19
+ start: number;
20
+ line: number;
21
+ status: 'caught' | 'survived' | 'unjudged' | 'unreached';
22
+ point: string;
23
+ crush: string;
24
+ edits?: readonly {
25
+ start: number;
26
+ end: number;
27
+ }[];
28
+ forcedEffect?: {
29
+ code: string;
30
+ kind: 'short' | 'logicalAssign';
31
+ always: boolean;
32
+ };
33
+ };
34
+ export type Asked = QuestionOutput & {
35
+ sites: string[];
36
+ file: string;
37
+ line: number;
38
+ };
39
+ type SiteQuestions = {
40
+ all: Asked[];
41
+ open: Asked[];
42
+ openWith: (justified: ReadonlySet<string>) => Asked[];
43
+ enteredFor: Map<string, ReadonlySet<string>>;
44
+ };
45
+ export declare const siteQuestionsOf: (sites: JudgedSite[], held?: ReadonlySet<string>, takenPoints?: ReadonlySet<string>, functions?: Functions) => SiteQuestions;
46
+ export type Functions = {
47
+ named: ReadonlySet<string>;
48
+ enteredBy: ReadonlyMap<string, ReadonlySet<string>>;
49
+ taken: ReadonlySet<string>;
50
+ };
51
+ export declare const unusedQuestionsOf: (nodes: ReachNodeOutput[]) => {
52
+ all: Asked[];
53
+ open: Asked[];
54
+ };
55
+ export type ExploreFinding = {
56
+ key: string;
57
+ file: string;
58
+ line: number;
59
+ function: string;
60
+ input: string;
61
+ };
62
+ export declare const exploreQuestionsOf: (all: readonly ExploreFinding[]) => Asked[];
63
+ type PathFinding = Pick<QuestionInput, 'file' | 'function' | 'code'> & {
64
+ kind: 'same-result' | 'no-split';
65
+ siteKey: string;
66
+ line: number;
67
+ uncompared: number;
68
+ };
69
+ export declare const pathQuestionsOf: (findings: readonly PathFinding[]) => Asked[];
70
+ type CaughtCall = {
71
+ exportKey: string;
72
+ testKey: string;
73
+ thrownAt: string | null;
74
+ };
75
+ type CaughtInput = {
76
+ calls: readonly CaughtCall[];
77
+ properties: ReadonlySet<string>;
78
+ };
79
+ export declare const exploreCaughtOf: ({ calls, properties }: CaughtInput) => Map<string, Set<string>>;
80
+ export declare const reachingKinds: ReadonlySet<string>;
81
+ export type Answer = {
82
+ test: string;
83
+ id: string;
84
+ };
85
+ export type AnswerProblem = Answer & {
86
+ problem: string;
87
+ };
88
+ export type AnswerEvidence = {
89
+ caughtBy: ReadonlyMap<string, ReadonlySet<string>>;
90
+ reachedBy: ReadonlyMap<string, ReadonlySet<string>>;
91
+ enteredFor: ReadonlyMap<string, ReadonlySet<string>>;
92
+ };
93
+ export declare const answerProblemsOf: (answers: Answer[], all: Asked[], evidence: AnswerEvidence) => AnswerProblem[];
94
+ type NamedTest = TestName & {
95
+ file: string;
96
+ };
97
+ export declare const testTitleOf: ({ title, occurrence }: TestName) => string;
98
+ export declare const answerChoicesOf: (tests: ReadonlySet<string>, all: Asked[], evidence: AnswerEvidence) => Map<string, string[]>;
99
+ export declare const testQuestionsOf: (removable: Removable[], names: ReadonlyMap<string, NamedTest>) => QuestionOutput[];
100
+ export type Counted = NamedTest & {
101
+ key: string;
102
+ steps: number;
103
+ statedSteps: number | null;
104
+ stepsReason: string | null;
105
+ outside: string[];
106
+ isSteady: boolean;
107
+ };
108
+ export declare const generatedFolderPattern: RegExp;
109
+ export declare const stepsQuestionsOf: (counted: Counted[]) => QuestionOutput[];
110
+ export {};