@whaaaley/crush 0.0.0-stage → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +185 -2
  3. package/SKILL.md +187 -0
  4. package/THIRD_PARTY_NOTICES.md +277 -0
  5. package/dist/capture/capture.operations.d.ts +23 -0
  6. package/dist/capture/capture.operations.js +231 -0
  7. package/dist/capture/capture.schema.d.ts +73 -0
  8. package/dist/capture/capture.schema.js +28 -0
  9. package/dist/collapse/collapse.operations.d.ts +2 -0
  10. package/dist/collapse/collapse.operations.js +82 -0
  11. package/dist/collapse/collapse.schema.d.ts +40 -0
  12. package/dist/collapse/collapse.schema.js +35 -0
  13. package/dist/crush.tables.d.ts +3583 -0
  14. package/dist/crush.tables.js +456 -0
  15. package/dist/crushes/callback.crush.d.ts +2 -0
  16. package/dist/crushes/callback.crush.js +19 -0
  17. package/dist/crushes/crush.d.ts +36 -0
  18. package/dist/crushes/crush.js +12 -0
  19. package/dist/crushes/crush.names.d.ts +1 -0
  20. package/dist/crushes/crush.names.js +2 -0
  21. package/dist/crushes/crushes.d.ts +2 -0
  22. package/dist/crushes/crushes.js +9 -0
  23. package/dist/crushes/default-value.crush.d.ts +2 -0
  24. package/dist/crushes/default-value.crush.js +29 -0
  25. package/dist/crushes/drop-operand.crush.d.ts +2 -0
  26. package/dist/crushes/drop-operand.crush.js +37 -0
  27. package/dist/crushes/fold.d.ts +64 -0
  28. package/dist/crushes/fold.js +366 -0
  29. package/dist/crushes/force-fork.crush.d.ts +2 -0
  30. package/dist/crushes/force-fork.crush.js +79 -0
  31. package/dist/crushes/loop-once.crush.d.ts +2 -0
  32. package/dist/crushes/loop-once.crush.js +71 -0
  33. package/dist/crushes/optional-chain.crush.d.ts +2 -0
  34. package/dist/crushes/optional-chain.crush.js +30 -0
  35. package/dist/crushes/switch-case.crush.d.ts +2 -0
  36. package/dist/crushes/switch-case.crush.js +19 -0
  37. package/dist/decisions/decide.d.ts +61 -0
  38. package/dist/decisions/decide.js +161 -0
  39. package/dist/decisions/decisions.d.ts +24 -0
  40. package/dist/decisions/decisions.js +62 -0
  41. package/dist/decisions/forks.decision.d.ts +4 -0
  42. package/dist/decisions/forks.decision.js +32 -0
  43. package/dist/decisions/kinds.d.ts +101 -0
  44. package/dist/decisions/kinds.js +38 -0
  45. package/dist/decisions/loops.decision.d.ts +4 -0
  46. package/dist/decisions/loops.decision.js +39 -0
  47. package/dist/decisions/shorts.decision.d.ts +3 -0
  48. package/dist/decisions/shorts.decision.js +66 -0
  49. package/dist/decisions/switches.decision.d.ts +3 -0
  50. package/dist/decisions/switches.decision.js +20 -0
  51. package/dist/decisions/throws.decision.d.ts +3 -0
  52. package/dist/decisions/throws.decision.js +35 -0
  53. package/dist/decisions/values.decision.d.ts +3 -0
  54. package/dist/decisions/values.decision.js +67 -0
  55. package/dist/explore/edges/explore.d.ts +60 -0
  56. package/dist/explore/edges/explore.db.d.ts +22 -0
  57. package/dist/explore/edges/explore.db.js +55 -0
  58. package/dist/explore/edges/explore.js +305 -0
  59. package/dist/explore/edges/random.d.ts +2 -0
  60. package/dist/explore/edges/random.js +32 -0
  61. package/dist/explore/explore.operations.d.ts +30 -0
  62. package/dist/explore/explore.operations.js +117 -0
  63. package/dist/explore/limits.operations.d.ts +14 -0
  64. package/dist/explore/limits.operations.js +20 -0
  65. package/dist/explore/targets.operations.d.ts +36 -0
  66. package/dist/explore/targets.operations.js +32 -0
  67. package/dist/explore/utils/draws.d.ts +6 -0
  68. package/dist/explore/utils/draws.js +2 -0
  69. package/dist/explore/utils/edits.d.ts +15 -0
  70. package/dist/explore/utils/edits.js +151 -0
  71. package/dist/explore/utils/guide.d.ts +23 -0
  72. package/dist/explore/utils/guide.js +35 -0
  73. package/dist/explore/utils/keep.d.ts +10 -0
  74. package/dist/explore/utils/keep.js +61 -0
  75. package/dist/explore/utils/pools.d.ts +17 -0
  76. package/dist/explore/utils/pools.js +121 -0
  77. package/dist/explore/utils/reads.d.ts +19 -0
  78. package/dist/explore/utils/reads.js +118 -0
  79. package/dist/explore/utils/twin.d.ts +21 -0
  80. package/dist/explore/utils/twin.js +55 -0
  81. package/dist/forks/forks.operations.d.ts +32 -0
  82. package/dist/forks/forks.operations.js +134 -0
  83. package/dist/forks/forks.schema.d.ts +20 -0
  84. package/dist/forks/forks.schema.js +14 -0
  85. package/dist/graph/cfg/cfg.d.ts +28 -0
  86. package/dist/graph/cfg/cfg.js +31 -0
  87. package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
  88. package/dist/graph/cfg/code-paths/analyzer.js +358 -0
  89. package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
  90. package/dist/graph/cfg/code-paths/segments.js +105 -0
  91. package/dist/graph/cfg/code-paths/state.d.ts +121 -0
  92. package/dist/graph/cfg/code-paths/state.js +611 -0
  93. package/dist/graph/cfg/entries.d.ts +13 -0
  94. package/dist/graph/cfg/entries.js +120 -0
  95. package/dist/graph/cfg/functions.d.ts +6 -0
  96. package/dist/graph/cfg/functions.js +47 -0
  97. package/dist/graph/cfg/paths.d.ts +27 -0
  98. package/dist/graph/cfg/paths.js +91 -0
  99. package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
  100. package/dist/graph/cfg/scopes/scopes.js +375 -0
  101. package/dist/graph/symbols/file.d.ts +90 -0
  102. package/dist/graph/symbols/file.js +427 -0
  103. package/dist/graph/symbols/keys.d.ts +13 -0
  104. package/dist/graph/symbols/keys.js +22 -0
  105. package/dist/graph/symbols/resolve.operations.d.ts +4 -0
  106. package/dist/graph/symbols/resolve.operations.js +33 -0
  107. package/dist/graph/symbols/symbols.d.ts +12 -0
  108. package/dist/graph/symbols/symbols.js +155 -0
  109. package/dist/graph/symbols/symbols.schema.d.ts +32 -0
  110. package/dist/graph/symbols/symbols.schema.js +19 -0
  111. package/dist/graph/unused/tests.d.ts +7 -0
  112. package/dist/graph/unused/tests.js +95 -0
  113. package/dist/graph/unused/unused.d.ts +53 -0
  114. package/dist/graph/unused/unused.js +319 -0
  115. package/dist/graph/walk/walk.d.ts +7 -0
  116. package/dist/graph/walk/walk.js +39 -0
  117. package/dist/instrument/instrument.operations.d.ts +72 -0
  118. package/dist/instrument/instrument.operations.js +786 -0
  119. package/dist/instrument/instrument.schema.d.ts +257 -0
  120. package/dist/instrument/instrument.schema.js +100 -0
  121. package/dist/judge/counters.d.ts +86 -0
  122. package/dist/judge/counters.js +402 -0
  123. package/dist/judge/edges/api.d.ts +14 -0
  124. package/dist/judge/edges/api.js +80 -0
  125. package/dist/judge/edges/completion.reporter.d.ts +9 -0
  126. package/dist/judge/edges/completion.reporter.js +51 -0
  127. package/dist/judge/edges/hints.reporter.d.ts +13 -0
  128. package/dist/judge/edges/hints.reporter.js +29 -0
  129. package/dist/judge/edges/judge.edges.d.ts +52 -0
  130. package/dist/judge/edges/judge.edges.js +59 -0
  131. package/dist/judge/edges/judge.fs.d.ts +8 -0
  132. package/dist/judge/edges/judge.fs.js +45 -0
  133. package/dist/judge/edges/merge.d.ts +11 -0
  134. package/dist/judge/edges/merge.js +60 -0
  135. package/dist/judge/edges/plugin.d.ts +132 -0
  136. package/dist/judge/edges/plugin.js +441 -0
  137. package/dist/judge/edges/reach.d.ts +68 -0
  138. package/dist/judge/edges/reach.js +132 -0
  139. package/dist/judge/edges/speed.d.ts +32 -0
  140. package/dist/judge/edges/speed.js +34 -0
  141. package/dist/judge/edges/strays.d.ts +1 -0
  142. package/dist/judge/edges/strays.js +14 -0
  143. package/dist/judge/edges/vitest.d.ts +20 -0
  144. package/dist/judge/edges/vitest.js +36 -0
  145. package/dist/judge/edges/vitest.schema.d.ts +14 -0
  146. package/dist/judge/edges/vitest.schema.js +16 -0
  147. package/dist/judge/explore.test.d.ts +1 -0
  148. package/dist/judge/explore.test.js +101 -0
  149. package/dist/judge/hints.d.ts +11 -0
  150. package/dist/judge/hints.js +44 -0
  151. package/dist/judge/judge.operations.d.ts +218 -0
  152. package/dist/judge/judge.operations.js +464 -0
  153. package/dist/judge/judge.schema.d.ts +135 -0
  154. package/dist/judge/judge.schema.js +129 -0
  155. package/dist/judge/judge.shard-1.test.d.ts +1 -0
  156. package/dist/judge/judge.shard-1.test.js +3 -0
  157. package/dist/judge/judge.shard-2.test.d.ts +1 -0
  158. package/dist/judge/judge.shard-2.test.js +3 -0
  159. package/dist/judge/judge.test.d.ts +1 -0
  160. package/dist/judge/judge.test.js +3 -0
  161. package/dist/judge/refusals.d.ts +14 -0
  162. package/dist/judge/refusals.js +10 -0
  163. package/dist/judge/report.test.d.ts +1 -0
  164. package/dist/judge/report.test.js +432 -0
  165. package/dist/judge/runner.d.ts +3 -0
  166. package/dist/judge/runner.js +1602 -0
  167. package/dist/judge/stresses.test.d.ts +1 -0
  168. package/dist/judge/stresses.test.js +12 -0
  169. package/dist/judge/task-meta.d.ts +14 -0
  170. package/dist/judge/task-meta.js +1 -0
  171. package/dist/justify/edges/load.d.ts +7 -0
  172. package/dist/justify/edges/load.js +40 -0
  173. package/dist/justify/edges/refresh.fs.d.ts +8 -0
  174. package/dist/justify/edges/refresh.fs.js +15 -0
  175. package/dist/justify/justify.operations.d.ts +46 -0
  176. package/dist/justify/justify.operations.js +80 -0
  177. package/dist/justify/justify.schema.d.ts +21 -0
  178. package/dist/justify/justify.schema.js +11 -0
  179. package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
  180. package/dist/mutators/arithmetic-operator.mutator.js +22 -0
  181. package/dist/mutators/array-declaration.mutator.d.ts +2 -0
  182. package/dist/mutators/array-declaration.mutator.js +12 -0
  183. package/dist/mutators/arrow-function.mutator.d.ts +2 -0
  184. package/dist/mutators/arrow-function.mutator.js +10 -0
  185. package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
  186. package/dist/mutators/assignment-operator.mutator.js +29 -0
  187. package/dist/mutators/await-expression.mutator.d.ts +2 -0
  188. package/dist/mutators/await-expression.mutator.js +7 -0
  189. package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
  190. package/dist/mutators/bitwise-operator.mutator.js +19 -0
  191. package/dist/mutators/block-statement.mutator.d.ts +2 -0
  192. package/dist/mutators/block-statement.mutator.js +30 -0
  193. package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
  194. package/dist/mutators/boolean-literal.mutator.js +5 -0
  195. package/dist/mutators/coercion.mutator.d.ts +2 -0
  196. package/dist/mutators/coercion.mutator.js +28 -0
  197. package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
  198. package/dist/mutators/conditional-expression.mutator.js +36 -0
  199. package/dist/mutators/disposal.mutator.d.ts +2 -0
  200. package/dist/mutators/disposal.mutator.js +13 -0
  201. package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
  202. package/dist/mutators/empty-destructuring.mutator.js +35 -0
  203. package/dist/mutators/empty-return.mutator.d.ts +2 -0
  204. package/dist/mutators/empty-return.mutator.js +35 -0
  205. package/dist/mutators/equality-operator.mutator.d.ts +2 -0
  206. package/dist/mutators/equality-operator.mutator.js +16 -0
  207. package/dist/mutators/loop-exit.mutator.d.ts +2 -0
  208. package/dist/mutators/loop-exit.mutator.js +5 -0
  209. package/dist/mutators/method-expression.mutator.d.ts +2 -0
  210. package/dist/mutators/method-expression.mutator.js +59 -0
  211. package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
  212. package/dist/mutators/missing-lookup.mutator.js +25 -0
  213. package/dist/mutators/mutator.d.ts +40 -0
  214. package/dist/mutators/mutator.js +49 -0
  215. package/dist/mutators/mutator.names.d.ts +3 -0
  216. package/dist/mutators/mutator.names.js +43 -0
  217. package/dist/mutators/mutators.d.ts +8 -0
  218. package/dist/mutators/mutators.js +84 -0
  219. package/dist/mutators/nested-condition.mutator.d.ts +2 -0
  220. package/dist/mutators/nested-condition.mutator.js +16 -0
  221. package/dist/mutators/number-literal.mutator.d.ts +3 -0
  222. package/dist/mutators/number-literal.mutator.js +13 -0
  223. package/dist/mutators/object-literal.mutator.d.ts +2 -0
  224. package/dist/mutators/object-literal.mutator.js +6 -0
  225. package/dist/mutators/odd-number.mutator.d.ts +2 -0
  226. package/dist/mutators/odd-number.mutator.js +15 -0
  227. package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
  228. package/dist/mutators/operand-deletion.mutator.js +9 -0
  229. package/dist/mutators/outcome.mutator.d.ts +3 -0
  230. package/dist/mutators/outcome.mutator.js +45 -0
  231. package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
  232. package/dist/mutators/plain-assignment.mutator.js +7 -0
  233. package/dist/mutators/power-operator.mutator.d.ts +2 -0
  234. package/dist/mutators/power-operator.mutator.js +13 -0
  235. package/dist/mutators/private-brand.mutator.d.ts +2 -0
  236. package/dist/mutators/private-brand.mutator.js +7 -0
  237. package/dist/mutators/regex.mutator.d.ts +2 -0
  238. package/dist/mutators/regex.mutator.js +29 -0
  239. package/dist/mutators/short-iteration.mutator.d.ts +2 -0
  240. package/dist/mutators/short-iteration.mutator.js +8 -0
  241. package/dist/mutators/string-literal.mutator.d.ts +3 -0
  242. package/dist/mutators/string-literal.mutator.js +149 -0
  243. package/dist/mutators/switch-default.mutator.d.ts +2 -0
  244. package/dist/mutators/switch-default.mutator.js +13 -0
  245. package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
  246. package/dist/mutators/sync-iteration.mutator.js +9 -0
  247. package/dist/mutators/thrown-call.mutator.d.ts +2 -0
  248. package/dist/mutators/thrown-call.mutator.js +7 -0
  249. package/dist/mutators/unary-operator.mutator.d.ts +2 -0
  250. package/dist/mutators/unary-operator.mutator.js +18 -0
  251. package/dist/mutators/unbound-call.mutator.d.ts +2 -0
  252. package/dist/mutators/unbound-call.mutator.js +14 -0
  253. package/dist/mutators/update-operator.mutator.d.ts +2 -0
  254. package/dist/mutators/update-operator.mutator.js +15 -0
  255. package/dist/mutators/yield-value.mutator.d.ts +2 -0
  256. package/dist/mutators/yield-value.mutator.js +7 -0
  257. package/dist/parity/compare.d.ts +27 -0
  258. package/dist/parity/compare.js +26 -0
  259. package/dist/parity/corpus.parity.d.ts +1 -0
  260. package/dist/parity/corpus.parity.js +97 -0
  261. package/dist/parity/edges/corpus.fs.d.ts +3 -0
  262. package/dist/parity/edges/corpus.fs.js +30 -0
  263. package/dist/parity/edges/ports.d.ts +2 -0
  264. package/dist/parity/edges/ports.js +21 -0
  265. package/dist/parity/edges/vitest.d.ts +2 -0
  266. package/dist/parity/edges/vitest.js +3 -0
  267. package/dist/parity/parity.operations.d.ts +33 -0
  268. package/dist/parity/parity.operations.js +60 -0
  269. package/dist/parity/parity.schema.d.ts +5 -0
  270. package/dist/parity/parity.schema.js +6 -0
  271. package/dist/parity/stryker/compare.d.ts +14 -0
  272. package/dist/parity/stryker/compare.js +52 -0
  273. package/dist/parity/stryker/edges/ports.d.ts +12 -0
  274. package/dist/parity/stryker/edges/ports.js +28 -0
  275. package/dist/parity/stryker/equivalence.d.ts +1 -0
  276. package/dist/parity/stryker/equivalence.js +42 -0
  277. package/dist/parity/stryker/intended.d.ts +29 -0
  278. package/dist/parity/stryker/intended.js +152 -0
  279. package/dist/parity/stryker/normalize.d.ts +27 -0
  280. package/dist/parity/stryker/normalize.js +181 -0
  281. package/dist/parity/stryker/rules.d.ts +6 -0
  282. package/dist/parity/stryker/rules.js +116 -0
  283. package/dist/parity/stryker/sides.d.ts +46 -0
  284. package/dist/parity/stryker/sides.js +199 -0
  285. package/dist/parity/stryker/stryker.parity.d.ts +1 -0
  286. package/dist/parity/stryker/stryker.parity.js +147 -0
  287. package/dist/parity/stryker/stryker.schema.d.ts +6 -0
  288. package/dist/parity/stryker/stryker.schema.js +7 -0
  289. package/dist/parity/views.d.ts +21 -0
  290. package/dist/parity/views.js +119 -0
  291. package/dist/questions/questions.operations.d.ts +110 -0
  292. package/dist/questions/questions.operations.js +446 -0
  293. package/dist/questions/questions.schema.d.ts +57 -0
  294. package/dist/questions/questions.schema.js +28 -0
  295. package/dist/record/edges/calls.db.d.ts +10 -0
  296. package/dist/record/edges/calls.db.js +91 -0
  297. package/dist/record/edges/hits.db.d.ts +3 -0
  298. package/dist/record/edges/hits.db.js +5 -0
  299. package/dist/record/edges/holds.db.d.ts +4 -0
  300. package/dist/record/edges/holds.db.js +31 -0
  301. package/dist/record/edges/judged-state.db.d.ts +5 -0
  302. package/dist/record/edges/judged-state.db.js +25 -0
  303. package/dist/record/edges/markers.db.d.ts +11 -0
  304. package/dist/record/edges/markers.db.js +55 -0
  305. package/dist/record/edges/merge.db.d.ts +7 -0
  306. package/dist/record/edges/merge.db.js +46 -0
  307. package/dist/record/edges/parts.db.d.ts +42 -0
  308. package/dist/record/edges/parts.db.js +389 -0
  309. package/dist/record/edges/parts.edges.d.ts +2 -0
  310. package/dist/record/edges/parts.edges.js +7 -0
  311. package/dist/record/edges/parts.fs.d.ts +1 -0
  312. package/dist/record/edges/parts.fs.js +11 -0
  313. package/dist/record/edges/parts.writer.d.ts +1 -0
  314. package/dist/record/edges/parts.writer.js +85 -0
  315. package/dist/record/edges/passes.db.d.ts +19 -0
  316. package/dist/record/edges/passes.db.js +31 -0
  317. package/dist/record/edges/plan.db.d.ts +21 -0
  318. package/dist/record/edges/plan.db.js +174 -0
  319. package/dist/record/edges/reach.db.d.ts +6 -0
  320. package/dist/record/edges/reach.db.js +62 -0
  321. package/dist/record/edges/record.db.d.ts +22 -0
  322. package/dist/record/edges/record.db.js +176 -0
  323. package/dist/record/edges/record.fs.d.ts +3 -0
  324. package/dist/record/edges/record.fs.js +7 -0
  325. package/dist/record/edges/site-verdicts.db.d.ts +11 -0
  326. package/dist/record/edges/site-verdicts.db.js +66 -0
  327. package/dist/record/edges/verified.db.d.ts +7 -0
  328. package/dist/record/edges/verified.db.js +71 -0
  329. package/dist/record/parts.operations.d.ts +26 -0
  330. package/dist/record/parts.operations.js +31 -0
  331. package/dist/record/path-checks.operations.d.ts +15 -0
  332. package/dist/record/path-checks.operations.js +84 -0
  333. package/dist/record/record.operations.d.ts +36 -0
  334. package/dist/record/record.operations.js +11 -0
  335. package/dist/stresses/edges/stresses.record.d.ts +4 -0
  336. package/dist/stresses/edges/stresses.record.js +37 -0
  337. package/dist/stresses/stresses.operations.d.ts +28 -0
  338. package/dist/stresses/stresses.operations.js +22 -0
  339. package/dist/utils/ast.d.ts +55 -0
  340. package/dist/utils/ast.js +181 -0
  341. package/dist/utils/errors.d.ts +8 -0
  342. package/dist/utils/errors.js +12 -0
  343. package/dist/utils/faults.d.ts +6 -0
  344. package/dist/utils/faults.js +10 -0
  345. package/dist/utils/lookup.d.ts +4 -0
  346. package/dist/utils/lookup.js +27 -0
  347. package/dist/utils/order.d.ts +2 -0
  348. package/dist/utils/order.js +17 -0
  349. package/dist/utils/retry.d.ts +14 -0
  350. package/dist/utils/retry.js +15 -0
  351. package/dist/utils/safe.d.ts +11 -0
  352. package/dist/utils/safe.js +31 -0
  353. package/migrations/main/20261129123324_initial/migration.sql +418 -0
  354. package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
  355. package/package.json +89 -4
  356. package/references/consumer-setup.md +92 -0
  357. package/src/graph/cfg/code-paths/LICENSE +21 -0
  358. package/src/graph/cfg/scopes/LICENSE +24 -0
@@ -0,0 +1,149 @@
1
+ import { itemAt, walk } from '../utils/ast.js';
2
+ import { inForkTest, on, replace, text } from './mutator.js';
3
+ const declarationParents = new Set([
4
+ 'ImportDeclaration',
5
+ 'ExportNamedDeclaration',
6
+ 'ExportAllDeclaration',
7
+ 'ImportSpecifier',
8
+ 'ExportSpecifier',
9
+ 'ImportAttribute',
10
+ 'ImportExpression',
11
+ 'JSXAttribute',
12
+ 'ExpressionStatement',
13
+ ]);
14
+ const namingCalls = new Set(['require', 'Symbol']);
15
+ const strictEqualities = new Set(['===', '!==']);
16
+ // Matches the name of an error class, as `Error` or `RangeError`.
17
+ export const errorNamePattern = /Error$/;
18
+ // Whether a node builds an error: a throw, or a call or `new` of an error class.
19
+ const buildsError = (node) => node.type === 'ThrowStatement' || ((node.type === 'NewExpression' || node.type === 'CallExpression') && node.callee.type === 'Identifier' && errorNamePattern.test(node.callee.name));
20
+ // Whether a parameter is read, and read only to build an error, so what it is handed is only a message.
21
+ const readsOnlyInErrors = (fn, name) => {
22
+ let reads = 0;
23
+ let isElsewhere = false;
24
+ walk(fn.body ?? fn, ({ node, ancestors }) => {
25
+ if (node.type !== 'Identifier' || node.name !== name)
26
+ return;
27
+ reads++;
28
+ if (!ancestors.some(buildsError))
29
+ isElsewhere = true;
30
+ });
31
+ return reads > 0 && !isElsewhere;
32
+ };
33
+ // A relative specifier from a file, worked out to the project path it names, or null for any other specifier or one climbing past the project's root.
34
+ const resolvedOf = (from, specifier) => {
35
+ if (!specifier.startsWith('./') && !specifier.startsWith('../'))
36
+ return null;
37
+ const parts = from.split('/').slice(0, -1);
38
+ for (const part of specifier.split('/')) {
39
+ if (part === '..' && !parts.length)
40
+ return null;
41
+ if (part === '..')
42
+ parts.pop();
43
+ else if (part !== '.')
44
+ parts.push(part);
45
+ }
46
+ return parts.join('/');
47
+ };
48
+ const nameOf = (node) => (node.type === 'Identifier' ? node.name : node.value);
49
+ // The function a declaration gives a name, as `function x` or `const x = () => ...`.
50
+ const declaredIn = (declaration, name) => {
51
+ if (declaration.type === 'FunctionDeclaration')
52
+ return declaration.id?.name === name ? declaration : undefined;
53
+ if (declaration.type === 'VariableDeclaration')
54
+ return declaration.declarations.map((declarator) => declaredIn(declarator, name)).find(Boolean);
55
+ if (declaration.type !== 'VariableDeclarator')
56
+ return undefined;
57
+ const { id, init } = declaration;
58
+ return id.type === 'Identifier' && id.name === name && (init?.type === 'ArrowFunctionExpression' || init?.type === 'FunctionExpression') ? init : undefined;
59
+ };
60
+ // The function a file's top-level name binds: declared there, or imported from a file of the project.
61
+ const boundIn = (project, path, name, seen) => {
62
+ const program = project.get(path);
63
+ if (!program)
64
+ return undefined;
65
+ for (const item of program.body) {
66
+ const declared = declaredIn(item.type === 'ExportNamedDeclaration' && item.declaration ? item.declaration : item, name);
67
+ if (declared)
68
+ return declared;
69
+ if (item.type !== 'ImportDeclaration')
70
+ continue;
71
+ for (const specifier of item.specifiers) {
72
+ if (specifier.type !== 'ImportSpecifier' || specifier.local.name !== name)
73
+ continue;
74
+ const target = resolvedOf(path, item.source.value);
75
+ return target === null ? undefined : exportedFrom(project, target, nameOf(specifier.imported), seen);
76
+ }
77
+ }
78
+ return undefined;
79
+ };
80
+ // The function a file of the project exports under a name, followed through re-exports, each file asked once so a cycle ends.
81
+ const exportedFrom = (project, path, name, seen) => {
82
+ const program = project.get(path);
83
+ if (!program || seen.has(path))
84
+ return undefined;
85
+ const next = new Set([...seen, path]);
86
+ for (const item of program.body) {
87
+ if (item.type !== 'ExportNamedDeclaration')
88
+ continue;
89
+ if (item.declaration) {
90
+ const declared = declaredIn(item.declaration, name);
91
+ if (declared)
92
+ return declared;
93
+ }
94
+ for (const specifier of item.specifiers) {
95
+ if (nameOf(specifier.exported) !== name)
96
+ continue;
97
+ const local = nameOf(specifier.local);
98
+ if (!item.source)
99
+ return boundIn(project, path, local, next);
100
+ const target = resolvedOf(path, item.source.value);
101
+ return target === null ? undefined : exportedFrom(project, target, local, next);
102
+ }
103
+ }
104
+ return undefined;
105
+ };
106
+ // The function a callee names: the declaration in scope where it is called, or the export a named import of it binds.
107
+ const calledBy = ({ bindings, project, path, ancestors }, callee) => {
108
+ const definition = bindings.get(callee);
109
+ if (definition?.type !== 'ImportSpecifier')
110
+ return definition && declaredIn(definition, callee.name);
111
+ const program = itemAt(ancestors, 0);
112
+ const declaration = program.type === 'Program' ? program.body.find((item) => item.type === 'ImportDeclaration' && item.specifiers.some((specifier) => specifier === definition)) : undefined;
113
+ const target = declaration?.type === 'ImportDeclaration' ? resolvedOf(path, declaration.source.value) : null;
114
+ return target === null ? undefined : exportedFrom(project, target, nameOf(definition.imported), new Set());
115
+ };
116
+ // A string only a person reads: one inside an error being built, or one handed to a parameter of a named function read only to build an error.
117
+ const isDiagnostic = (context) => {
118
+ const { node, parent, key, ancestors } = context;
119
+ if (ancestors.some(buildsError))
120
+ return true;
121
+ if (parent.type !== 'CallExpression' || key !== 'arguments' || parent.callee.type !== 'Identifier')
122
+ return false;
123
+ const fn = calledBy(context, parent.callee);
124
+ if (!fn)
125
+ return false;
126
+ const param = fn.params[parent.arguments.findIndex((argument) => argument === node)];
127
+ return param?.type === 'Identifier' && readsOnlyInErrors(fn, param.name);
128
+ };
129
+ // A template empties and an empty one gains text, except a tagged one.
130
+ const template = on('TemplateLiteral', (node, context) => {
131
+ if (context.key === 'quasi' || isDiagnostic(context))
132
+ return [];
133
+ return [replace(context, node, text(context.source, node) === '``' ? '`Stryker was here!`' : '``')];
134
+ });
135
+ // A string empties and an empty one gains text, except one naming a module, a key, a symbol or a statement of its own.
136
+ // A string compared strictly inside a fork test is left out, since forcing the test already tells the comparison apart.
137
+ const literal = on('Literal', (node, context) => {
138
+ const { parent, key, source } = context;
139
+ if (typeof node.value !== 'string' || declarationParents.has(parent.type) || key === 'key')
140
+ return [];
141
+ if (parent.type === 'CallExpression' && namingCalls.has(text(source, parent.callee)))
142
+ return [];
143
+ if (parent.type === 'BinaryExpression' && strictEqualities.has(parent.operator) && inForkTest(context))
144
+ return [];
145
+ if (isDiagnostic(context))
146
+ return [];
147
+ return [replace(context, node, node.value ? '""' : '"Stryker was here!"')];
148
+ });
149
+ export const stringLiteral = { name: 'StringLiteral', source: 'stryker', parts: [template, literal] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const switchDefault: Mutator;
@@ -0,0 +1,13 @@
1
+ import { on, statement, text } from './mutator.js';
2
+ // A switch with no default gains one that throws, before its closing brace, so a case must check the path where no case matches.
3
+ export const switchDefault = {
4
+ name: 'SwitchDefault',
5
+ source: 'cfg',
6
+ parts: [
7
+ on('SwitchStatement', (node, { source }) => {
8
+ if (node.cases.some((option) => !option.test))
9
+ return [];
10
+ return [statement(node, `${text(source, node).slice(0, -1)}default: throw new Error('no case matched') }`)];
11
+ }),
12
+ ],
13
+ };
@@ -0,0 +1,3 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const forAwaitPattern: RegExp;
3
+ export declare const syncIteration: Mutator;
@@ -0,0 +1,9 @@
1
+ import { on, statement, text } from './mutator.js';
2
+ // Matches the for await prefix at the beginning of a loop.
3
+ export const forAwaitPattern = /^for\s+await\b/;
4
+ // A `for await` loop made plain, so a test must notice its items no longer being awaited, which no crush removes since loop-once is refused by any test running two items.
5
+ export const syncIteration = {
6
+ name: 'SyncIteration',
7
+ source: 'cfg',
8
+ parts: [on('ForOfStatement', (node, { source }) => (node.await ? [statement(node, text(source, node).replace(forAwaitPattern, 'for'))] : []))],
9
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const thrownCall: Mutator;
@@ -0,0 +1,7 @@
1
+ import { inForkSide, on, replace } from './mutator.js';
2
+ // A call throws instead, except inside a fork side, which force-fork already removes whole.
3
+ export const thrownCall = {
4
+ name: 'ThrownCall',
5
+ source: 'cfg',
6
+ parts: [on('CallExpression', (node, context) => (inForkSide(context) ? [] : [replace(context, node, "(() => { throw new Error('thrown by crush') })()")]))],
7
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const unaryOperator: Mutator;
@@ -0,0 +1,18 @@
1
+ import { joined, on, operandOf, replace } from './mutator.js';
2
+ const unary = new Map([
3
+ ['+', '-'],
4
+ ['-', '+'],
5
+ ['~', ''],
6
+ ]);
7
+ export const unaryOperator = {
8
+ name: 'UnaryOperator',
9
+ source: 'stryker',
10
+ parts: [
11
+ on('UnaryExpression', (node, context) => {
12
+ const swap = unary.get(node.operator);
13
+ if (swap === undefined)
14
+ return [];
15
+ return [replace(context, node, joined(swap, operandOf(context.source, node, node.operator, true)))];
16
+ }),
17
+ ],
18
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const unboundCall: Mutator;
@@ -0,0 +1,14 @@
1
+ import { on, replace, text } from './mutator.js';
2
+ // A method called without its receiver, so a case must notice `this` going missing.
3
+ export const unboundCall = {
4
+ name: 'UnboundCall',
5
+ source: 'cfg',
6
+ parts: [
7
+ on('CallExpression', (node, context) => {
8
+ const { callee } = node;
9
+ if (callee.type !== 'MemberExpression' || callee.computed)
10
+ return [];
11
+ return [replace(context, node, `(0, ${text(context.source, callee)})${context.source.slice(callee.end, node.end)}`)];
12
+ }),
13
+ ],
14
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const updateOperator: Mutator;
@@ -0,0 +1,15 @@
1
+ import { joined, on, operandOf, replace } from './mutator.js';
2
+ // `++` and `--` swap, except a for loop's own counter, the only node under an `update` key, which loop-once already runs at most once.
3
+ export const updateOperator = {
4
+ name: 'UpdateOperator',
5
+ source: 'stryker',
6
+ parts: [
7
+ on('UpdateExpression', (node, context) => {
8
+ if (context.key === 'update')
9
+ return [];
10
+ const operand = operandOf(context.source, node, node.operator, node.prefix);
11
+ const swap = node.operator === '++' ? '--' : '++';
12
+ return [replace(context, node, node.prefix ? joined(swap, operand) : joined(operand, swap))];
13
+ }),
14
+ ],
15
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const yieldValue: Mutator;
@@ -0,0 +1,7 @@
1
+ import { on, replace } from './mutator.js';
2
+ // A yielded value becomes undefined, leaving a bare `yield` and a delegated `yield*` alone.
3
+ export const yieldValue = {
4
+ name: 'YieldValue',
5
+ source: 'cfg',
6
+ parts: [on('YieldExpression', (node, context) => (node.delegate || !node.argument ? [] : [replace({ ...context, chain: null }, node.argument, 'undefined')]))],
7
+ };
@@ -0,0 +1,27 @@
1
+ import type { Program } from 'oxc-parser';
2
+ import { type Ports } from './views.ts';
3
+ export declare const checks: readonly ['code paths', 'scopes'];
4
+ export type Check = (typeof checks)[number];
5
+ export declare const oracles: Record<Check, string>;
6
+ type Side = 'crush' | 'oracle';
7
+ export type Outcome = {
8
+ kind: 'same';
9
+ } | {
10
+ kind: 'differ';
11
+ difference: string;
12
+ } | {
13
+ kind: 'failed';
14
+ side: Side;
15
+ message: string;
16
+ } | {
17
+ kind: 'overflowed';
18
+ side: Side;
19
+ };
20
+ type OutcomesInput = {
21
+ ports: Ports;
22
+ program: Program;
23
+ source: string;
24
+ path: string;
25
+ };
26
+ export declare const outcomesOf: ({ ports, program, source, path }: OutcomesInput) => Record<Check, Outcome>;
27
+ export {};
@@ -0,0 +1,26 @@
1
+ import { safe } from '../utils/safe.js';
2
+ import { firstDifference, overflows } from './parity.operations.js';
3
+ import { eslintCodePathsOf, eslintScopesOf, portCodePathsOf, portScopesOf } from './views.js';
4
+ export const checks = ['code paths', 'scopes'];
5
+ export const oracles = { 'code paths': 'ESLint', scopes: 'eslint-scope' };
6
+ const nouns = { 'code paths': 'code path', scopes: 'scope' };
7
+ const outcomeOf = (check, ours, theirs) => {
8
+ const { data: mine, error: ourError } = ours;
9
+ if (ourError)
10
+ return overflows(ourError) ? { kind: 'overflowed', side: 'crush' } : { kind: 'failed', side: 'crush', message: ourError.message };
11
+ const { data: other, error: theirError } = theirs;
12
+ if (theirError)
13
+ return overflows(theirError) ? { kind: 'overflowed', side: 'oracle' } : { kind: 'failed', side: 'oracle', message: theirError.message };
14
+ const difference = firstDifference({ ours: mine, theirs: other, noun: nouns[check], oracle: oracles[check] });
15
+ return difference ? { kind: 'differ', difference } : { kind: 'same' };
16
+ };
17
+ // Both checks on one parsed file, the ports reading the tree before the oracles add ranges, locations and parents to it.
18
+ export const outcomesOf = ({ ports, program, source, path }) => {
19
+ const ourCodePaths = safe(() => portCodePathsOf(ports, program));
20
+ const ourScopes = safe(() => portScopesOf(ports, program));
21
+ const theirScopes = safe(() => eslintScopesOf(program));
22
+ // ESLint can still overflow the stack on a deep tree, so its run stays inside safe beside the failure it answers.
23
+ const caughtCodePaths = safe(() => eslintCodePathsOf({ program, source, path }));
24
+ const theirCodePaths = caughtCodePaths.error ? caughtCodePaths : caughtCodePaths.data;
25
+ return { 'code paths': outcomeOf('code paths', ourCodePaths, theirCodePaths), scopes: outcomeOf('scopes', ourScopes, theirScopes) };
26
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,97 @@
1
+ import { relative } from 'node:path';
2
+ import { describe, expect, inject, it } from 'vite-plus/test';
3
+ import { z } from 'zod';
4
+ import { safe } from '../utils/safe.js';
5
+ import { corpusFilesOf, readCorpusSource } from './edges/corpus.fs.js';
6
+ import { portsIn } from './edges/ports.js';
7
+ import { parityProvideKey } from './edges/vitest.js';
8
+ import { checks, oracles, outcomesOf } from './compare.js';
9
+ import { parsedAsModule, problemsOf, skipOf, summaryOf, tallyOf } from './parity.operations.js';
10
+ import { parityInput } from './parity.schema.js';
11
+ // A full corpus run takes minutes, so the walk stops starting files once this passes and the run fails as incomplete.
12
+ const budgetMs = 60 * 60 * 1000;
13
+ const progressEvery = 1000;
14
+ // 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.
15
+ const print = (line) => {
16
+ process.stdout.write(`${line}\n`);
17
+ };
18
+ const input = parityInput.safeParse(inject(parityProvideKey));
19
+ if (!input.success)
20
+ throw new Error(z.prettifyError(input.error));
21
+ const { folder, ports: src } = input.data;
22
+ describe('All Parity Tests', () => {
23
+ it("matches ESLint's code paths and eslint-scope's scopes on every corpus file", async () => {
24
+ const ports = await portsIn(src);
25
+ const files = corpusFilesOf(folder);
26
+ const tallies = { 'code paths': tallyOf(), scopes: tallyOf() };
27
+ const skipped = { commonjs: 0, jsx: 0, unparsed: 0 };
28
+ const started = performance.now();
29
+ let read = 0;
30
+ let gone = 0;
31
+ let undecodable = 0;
32
+ for (const path of files) {
33
+ if (performance.now() - started > budgetMs)
34
+ break;
35
+ read++;
36
+ if (read % progressEvery === 0)
37
+ print(`parity: ${read}/${files.length} files, ${Math.round((performance.now() - started) / 1000)}s`);
38
+ // Another session can move a file between the walk and its read, which leaves nothing to compare.
39
+ const { data: source, error: readError } = readCorpusSource(path);
40
+ if (readError) {
41
+ gone++;
42
+ continue;
43
+ }
44
+ const skip = skipOf(path);
45
+ if (skip) {
46
+ skipped[skip]++;
47
+ continue;
48
+ }
49
+ // Oxc builds its tree lazily and throws on a string it cannot decode, as a lone surrogate escape.
50
+ const moduleTree = () => {
51
+ const parsed = parsedAsModule(source, path);
52
+ return { program: parsed.program, errors: parsed.errors };
53
+ };
54
+ const { data: result, error: parseError } = safe(moduleTree);
55
+ if (parseError) {
56
+ undecodable++;
57
+ continue;
58
+ }
59
+ if (result.errors.length) {
60
+ skipped.unparsed++;
61
+ continue;
62
+ }
63
+ const outcomes = outcomesOf({ ports, program: result.program, source, path });
64
+ for (const check of checks) {
65
+ const tally = tallies[check];
66
+ const outcome = outcomes[check];
67
+ const where = relative(folder, path);
68
+ switch (outcome.kind) {
69
+ case 'same':
70
+ tally.same++;
71
+ break;
72
+ case 'differ':
73
+ tally.differ++;
74
+ print(`${check} differ in ${where}: ${outcome.difference}`);
75
+ break;
76
+ case 'failed':
77
+ tally.failed++;
78
+ print(`${check} failed in ${where}: ${outcome.side === 'crush' ? 'crush' : oracles[check]} threw ${outcome.message}`);
79
+ break;
80
+ case 'overflowed':
81
+ if (outcome.side === 'crush')
82
+ tally.crushOverflowed++;
83
+ else
84
+ tally.oracleOverflowed++;
85
+ print(`${check} overflowed in ${where}: ${outcome.side === 'crush' ? 'crush' : oracles[check]} ran out of stack`);
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ const seconds = Math.round((performance.now() - started) / 1000);
91
+ print(`parity: ${read} of ${files.length} files under ${folder} in ${seconds}s, ${gone} gone before their read, ${undecodable} undecodable, ports from ${src}`);
92
+ print(`skipped: ${skipped.commonjs} commonjs, ${skipped.jsx} jsx, ${skipped.unparsed} unparsed`);
93
+ for (const check of checks)
94
+ print(summaryOf(check, tallies[check]));
95
+ expect(problemsOf({ total: files.length, read, undecodable, tallies })).toEqual([]);
96
+ }, budgetMs + 60_000);
97
+ });
@@ -0,0 +1,3 @@
1
+ import { type Safe } from '../../utils/safe.ts';
2
+ export declare const readCorpusSource: (path: string) => Safe<string>;
3
+ export declare const corpusFilesOf: (folder: string) => string[];
@@ -0,0 +1,30 @@
1
+ import { readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { checksFile, skipsFolder } from '../parity.operations.js';
4
+ import { safe } from '../../utils/safe.js';
5
+ export const readCorpusSource = (path) => safe(() => readFileSync(path, 'utf8'));
6
+ // Every file the checks read under a folder, following links into linked folders but into each real folder once, so a link back up never loops.
7
+ export const corpusFilesOf = (folder) => {
8
+ const found = [];
9
+ const walked = new Set();
10
+ const visit = (directory) => {
11
+ const real = realpathSync(directory);
12
+ if (walked.has(real))
13
+ return;
14
+ walked.add(real);
15
+ for (const name of readdirSync(directory)) {
16
+ if (skipsFolder(name))
17
+ continue;
18
+ const path = join(directory, name);
19
+ const stat = statSync(path, { throwIfNoEntry: false });
20
+ if (!stat)
21
+ continue;
22
+ if (stat.isDirectory())
23
+ visit(path);
24
+ else if (checksFile(name, stat.size))
25
+ found.push(path);
26
+ }
27
+ };
28
+ visit(folder);
29
+ return found;
30
+ };
@@ -0,0 +1,2 @@
1
+ import type { Ports } from '../views.ts';
2
+ export declare const portsIn: (src: string) => Promise<Ports>;
@@ -0,0 +1,21 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { join } from 'node:path';
10
+ import { z } from 'zod';
11
+ const portsOutput = z.object({
12
+ codePathWalker: z.custom((value) => typeof value === 'function'),
13
+ scopeWalker: z.custom((value) => typeof value === 'function'),
14
+ resolvedOf: z.custom((value) => typeof value === 'function'),
15
+ });
16
+ // The ports from any crush `src` folder, as the main tree's while a worktree checks against it, so the import path is known only at run time.
17
+ export const portsIn = async (src) => {
18
+ // oxlint-disable-next-line typescript/no-unsafe-assignment -- a module imported by a computed path carries no static type
19
+ const [codePaths, scopes] = await Promise.all([import(__rewriteRelativeImportExtension(join(src, 'graph/cfg/code-paths/analyzer.ts'))), import(__rewriteRelativeImportExtension(join(src, 'graph/cfg/scopes/scopes.ts')))]);
20
+ return portsOutput.parse({ ...codePaths, ...scopes });
21
+ };
@@ -0,0 +1,2 @@
1
+ export declare const parityProvideKey = "crushParity";
2
+ export declare const strykerParityProvideKey = "crushParityStryker";
@@ -0,0 +1,3 @@
1
+ // The keys `vite.config.ts` provides each parity project's settings under, which Vitest hands that project's workers alone.
2
+ export const parityProvideKey = 'crushParity';
3
+ export const strykerParityProvideKey = 'crushParityStryker';
@@ -0,0 +1,33 @@
1
+ import { type ParseResult } from 'oxc-parser';
2
+ export declare const checkedFilePattern: RegExp;
3
+ export declare const skipsFolder: (name: string) => boolean;
4
+ export declare const checksFile: (name: string, size: number) => boolean;
5
+ export type Skip = 'commonjs' | 'jsx';
6
+ export declare const skipOf: (path: string) => Skip | null;
7
+ export declare const overflows: (error: Error) => boolean;
8
+ export declare const parsedAsModule: (source: string, path: string) => ParseResult;
9
+ export type View = string[][];
10
+ type DifferenceInput = {
11
+ ours: View;
12
+ theirs: View;
13
+ noun: string;
14
+ oracle: string;
15
+ };
16
+ export declare const firstDifference: ({ ours, theirs, noun, oracle }: DifferenceInput) => string | null;
17
+ export type Tally = {
18
+ same: number;
19
+ differ: number;
20
+ failed: number;
21
+ crushOverflowed: number;
22
+ oracleOverflowed: number;
23
+ };
24
+ export declare const tallyOf: () => Tally;
25
+ export declare const summaryOf: (name: string, { same, differ, failed, crushOverflowed, oracleOverflowed }: Tally) => string;
26
+ type ProblemsInput = {
27
+ total: number;
28
+ read: number;
29
+ undecodable: number;
30
+ tallies: Record<string, Tally>;
31
+ };
32
+ export declare const problemsOf: ({ total, read, undecodable, tallies }: ProblemsInput) => string[];
33
+ export {};
@@ -0,0 +1,60 @@
1
+ import { extname } from 'node:path';
2
+ import { parseSync } from 'oxc-parser';
3
+ import { itemAt } from '../utils/lookup.js';
4
+ // A JavaScript or TypeScript source file, as a name ending in .ts, .tsx, .js, .jsx, .mjs or .cjs.
5
+ export const checkedFilePattern = /\.(tsx?|jsx?|mjs|cjs)$/;
6
+ // Larger files are generated bundles, which no project writes by hand and which slow the walk most.
7
+ const sizeLimit = 1_000_000;
8
+ export const skipsFolder = (name) => name === 'node_modules' || name.startsWith('.');
9
+ export const checksFile = (name, size) => checkedFilePattern.test(name) && !name.endsWith('.d.ts') && size < sizeLimit;
10
+ const skips = new Map([
11
+ ['.cjs', 'commonjs'],
12
+ ['.jsx', 'jsx'],
13
+ ['.tsx', 'jsx'],
14
+ ]);
15
+ // crush reads neither CommonJS nor JSX, so those files are never compared.
16
+ export const skipOf = (path) => skips.get(extname(path)) ?? null;
17
+ // A walk too deep for the call stack, which neither side can finish, as against a check that went wrong.
18
+ export const overflows = (error) => error instanceof RangeError && error.message === 'Maximum call stack size exceeded';
19
+ // Oxc otherwise guesses a script for a file with no import or export, so a module is parsed as one.
20
+ export const parsedAsModule = (source, path) => parseSync(path, source, { preserveParens: false, sourceType: 'module' });
21
+ const tokenAt = (entry, index) => entry.at(index) ?? 'nothing';
22
+ // The first token where crush and the oracle part, as `scope 3: crush xR@4>-, eslint-scope xR@4>Variable@0`, or null when they agree.
23
+ export const firstDifference = ({ ours, theirs, noun, oracle }) => {
24
+ const shared = Math.min(ours.length, theirs.length);
25
+ for (let index = 0; index < shared; index++) {
26
+ const mine = itemAt(ours, index);
27
+ const other = itemAt(theirs, index);
28
+ const at = mine.findIndex((token, place) => token !== other[place]);
29
+ const token = at === -1 && mine.length !== other.length ? mine.length : at;
30
+ if (token !== -1)
31
+ return `${noun} ${index + 1}: crush ${tokenAt(mine, token)}, ${oracle} ${tokenAt(other, token)}`;
32
+ }
33
+ if (ours.length === theirs.length)
34
+ return null;
35
+ return `crush has ${ours.length} ${noun}s, ${oracle} ${theirs.length}`;
36
+ };
37
+ export const tallyOf = () => ({ same: 0, differ: 0, failed: 0, crushOverflowed: 0, oracleOverflowed: 0 });
38
+ export const summaryOf = (name, { same, differ, failed, crushOverflowed, oracleOverflowed }) => {
39
+ return `${name}: ${same} same, ${differ} differ, ${failed} failed, ${crushOverflowed} overflowed in crush, ${oracleOverflowed} in the oracle`;
40
+ };
41
+ // What fails a run: a stop on the budget, a file oxc could not decode, and per check a difference, a throw, an overflow in crush, or nothing compared.
42
+ // An oracle's walk is the library's own recursion, so its overflow leaves nothing to compare but is no fault of crush.
43
+ export const problemsOf = ({ total, read, undecodable, tallies }) => {
44
+ const problems = [];
45
+ if (read < total)
46
+ problems.push(`stopped after ${read} of ${total} files`);
47
+ if (undecodable)
48
+ problems.push(`${undecodable} undecodable`);
49
+ for (const [check, { same, differ, failed, crushOverflowed }] of Object.entries(tallies)) {
50
+ if (differ)
51
+ problems.push(`${check}: ${differ} differ`);
52
+ if (failed)
53
+ problems.push(`${check}: ${failed} failed`);
54
+ if (crushOverflowed)
55
+ problems.push(`${check}: ${crushOverflowed} overflowed in crush`);
56
+ if (!same && !differ)
57
+ problems.push(`${check}: no file compared`);
58
+ }
59
+ return problems;
60
+ };
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ export declare const parityInput: z.ZodObject<{
3
+ folder: z.ZodString;
4
+ ports: z.ZodString;
5
+ }, z.core.$strip>;
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ // The folder a parity run walks and the crush `src` folder whose ports it checks, as `vite.config.ts` provides them on the `parity` project from the caller's environment.
3
+ export const parityInput = z.object({
4
+ folder: z.string().min(1, 'parityFolder names no folder to check, so set it in vite.config.ts and run `vp run parity:eslint`').max(2048),
5
+ ports: z.string().min(1).max(2048),
6
+ });
@@ -0,0 +1,14 @@
1
+ import { type Edit, type Mutant } from './normalize.ts';
2
+ export type Comparison = {
3
+ matched: number;
4
+ onlyStryker: Edit[];
5
+ onlyCrush: Edit[];
6
+ };
7
+ type CompareInput = {
8
+ source: string;
9
+ stryker: readonly Mutant[];
10
+ crush: readonly Mutant[];
11
+ fits: (stryker: Mutant, crush: Mutant) => boolean;
12
+ };
13
+ export declare const compare: ({ source, stryker, crush, fits }: CompareInput) => Comparison;
14
+ export {};