@codyswann/lisa 5.3.2 → 5.5.0

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 (373) hide show
  1. package/README.md +60 -3
  2. package/all/copy-contents/gitignore +16 -0
  3. package/all/copy-contents/scripts/lisa-mutation.sh +4 -6
  4. package/all/copy-overwrite/scripts/fetch-test-access-map.d.mts +71 -0
  5. package/all/copy-overwrite/scripts/fetch-test-access-map.mjs +674 -0
  6. package/all/copy-overwrite/scripts/lib/affected-tests.mjs +818 -0
  7. package/all/copy-overwrite/scripts/lib/automation-provenance-contract.mjs +13 -3
  8. package/all/copy-overwrite/scripts/lib/automation-provenance-local.mjs +22 -1
  9. package/all/copy-overwrite/scripts/lib/build-marker.mjs +410 -0
  10. package/all/copy-overwrite/scripts/lib/gate-pass-cache.mjs +537 -0
  11. package/all/copy-overwrite/scripts/lib/kill-marks.mjs +1 -2
  12. package/all/copy-overwrite/scripts/lib/lisa-cleanup-sweep-processes.mjs +3 -4
  13. package/all/copy-overwrite/scripts/lib/npm-update-bun.mjs +39 -14
  14. package/all/copy-overwrite/scripts/lib/npm-update-controller-broker.mjs +1 -1
  15. package/all/copy-overwrite/scripts/lib/npm-update-gate-hooks.mjs +2 -1
  16. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +8 -1
  17. package/all/copy-overwrite/scripts/lib/npm-update-hosted-gate.mjs +25 -9
  18. package/all/copy-overwrite/scripts/lib/npm-update-hosted-hook.mjs +1 -1
  19. package/all/copy-overwrite/scripts/lib/npm-update-tool-launcher.mjs +1 -1
  20. package/all/copy-overwrite/scripts/lib/push-admission.mjs +158 -0
  21. package/all/copy-overwrite/scripts/lib/push-gate-defaults.d.mts +34 -0
  22. package/all/copy-overwrite/scripts/lib/push-gate-defaults.mjs +147 -0
  23. package/all/copy-overwrite/scripts/lib/push-timing.mjs +323 -0
  24. package/all/copy-overwrite/scripts/lib/rspec-selection.mjs +672 -0
  25. package/all/copy-overwrite/scripts/lisa-affected-tests.mjs +566 -0
  26. package/all/copy-overwrite/scripts/lisa-gates.mjs +29 -0
  27. package/all/copy-overwrite/scripts/lisa-lint-staged-preflight.mjs +10 -1
  28. package/all/copy-overwrite/scripts/lisa-push-timing-report.mjs +153 -0
  29. package/all/copy-overwrite/scripts/lisa-rspec-select.mjs +982 -0
  30. package/all/copy-overwrite/scripts/lisa-run-gates.mjs +231 -6
  31. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +108 -20
  32. package/all/deletions.json +11 -2
  33. package/cdk/create-only/vitest.config.local.ts +1 -7
  34. package/cdk/package-lisa/package.lisa.json +4 -4
  35. package/dist/cli/admit-cmd.d.ts +21 -0
  36. package/dist/cli/admit-cmd.d.ts.map +1 -0
  37. package/dist/cli/admit-cmd.js +142 -0
  38. package/dist/cli/admit-cmd.js.map +1 -0
  39. package/dist/cli/check-cmd.d.ts +72 -0
  40. package/dist/cli/check-cmd.d.ts.map +1 -0
  41. package/dist/cli/check-cmd.js +316 -0
  42. package/dist/cli/check-cmd.js.map +1 -0
  43. package/dist/cli/index.d.ts.map +1 -1
  44. package/dist/cli/index.js +6 -4
  45. package/dist/cli/index.js.map +1 -1
  46. package/dist/cli/lisa-test-run-admission.d.ts +18 -0
  47. package/dist/cli/lisa-test-run-admission.d.ts.map +1 -0
  48. package/dist/cli/lisa-test-run-admission.js +62 -0
  49. package/dist/cli/lisa-test-run-admission.js.map +1 -0
  50. package/dist/cli/lisa-test-run-payload.d.ts +37 -0
  51. package/dist/cli/lisa-test-run-payload.d.ts.map +1 -0
  52. package/dist/cli/lisa-test-run-payload.js +55 -0
  53. package/dist/cli/lisa-test-run-payload.js.map +1 -0
  54. package/dist/cli/lisa-test-run-shard-files.d.ts +89 -0
  55. package/dist/cli/lisa-test-run-shard-files.d.ts.map +1 -0
  56. package/dist/cli/lisa-test-run-shard-files.js +239 -0
  57. package/dist/cli/lisa-test-run-shard-files.js.map +1 -0
  58. package/dist/cli/lisa-test-run-shard.d.ts +6 -2
  59. package/dist/cli/lisa-test-run-shard.d.ts.map +1 -1
  60. package/dist/cli/lisa-test-run-shard.js +25 -13
  61. package/dist/cli/lisa-test-run-shard.js.map +1 -1
  62. package/dist/cli/lisa-test-run.d.ts +1 -1
  63. package/dist/cli/lisa-test-run.d.ts.map +1 -1
  64. package/dist/cli/lisa-test-run.js +47 -10
  65. package/dist/cli/lisa-test-run.js.map +1 -1
  66. package/dist/cli/update-check-hook.d.ts.map +1 -1
  67. package/dist/cli/update-check-hook.js +3 -0
  68. package/dist/cli/update-check-hook.js.map +1 -1
  69. package/dist/configs/vitest/base.d.ts +58 -135
  70. package/dist/configs/vitest/base.d.ts.map +1 -1
  71. package/dist/configs/vitest/base.js +76 -228
  72. package/dist/configs/vitest/base.js.map +1 -1
  73. package/dist/configs/vitest/cdk.d.ts.map +1 -1
  74. package/dist/configs/vitest/cdk.js +3 -2
  75. package/dist/configs/vitest/cdk.js.map +1 -1
  76. package/dist/configs/vitest/coverage-include-global-setup.d.ts.map +1 -1
  77. package/dist/configs/vitest/coverage-include-global-setup.js +3 -4
  78. package/dist/configs/vitest/coverage-include-global-setup.js.map +1 -1
  79. package/dist/configs/vitest/coverage-reports-directory.d.ts +27 -5
  80. package/dist/configs/vitest/coverage-reports-directory.d.ts.map +1 -1
  81. package/dist/configs/vitest/coverage-reports-directory.js +47 -10
  82. package/dist/configs/vitest/coverage-reports-directory.js.map +1 -1
  83. package/dist/configs/vitest/harper-fabric.d.ts.map +1 -1
  84. package/dist/configs/vitest/harper-fabric.js +3 -2
  85. package/dist/configs/vitest/harper-fabric.js.map +1 -1
  86. package/dist/configs/vitest/nestjs.d.ts.map +1 -1
  87. package/dist/configs/vitest/nestjs.js +3 -2
  88. package/dist/configs/vitest/nestjs.js.map +1 -1
  89. package/dist/configs/vitest/phaser.d.ts.map +1 -1
  90. package/dist/configs/vitest/phaser.js +3 -2
  91. package/dist/configs/vitest/phaser.js.map +1 -1
  92. package/dist/configs/vitest/refusal-announcement.d.ts +51 -0
  93. package/dist/configs/vitest/refusal-announcement.d.ts.map +1 -0
  94. package/dist/configs/vitest/refusal-announcement.js +97 -0
  95. package/dist/configs/vitest/refusal-announcement.js.map +1 -0
  96. package/dist/configs/vitest/socket-safe-temp-base.d.ts +3 -4
  97. package/dist/configs/vitest/socket-safe-temp-base.d.ts.map +1 -1
  98. package/dist/configs/vitest/socket-safe-temp-base.js +7 -6
  99. package/dist/configs/vitest/socket-safe-temp-base.js.map +1 -1
  100. package/dist/configs/vitest/typescript.d.ts.map +1 -1
  101. package/dist/configs/vitest/typescript.js +3 -2
  102. package/dist/configs/vitest/typescript.js.map +1 -1
  103. package/dist/core/admission-decision.d.ts +110 -0
  104. package/dist/core/admission-decision.d.ts.map +1 -0
  105. package/dist/core/admission-decision.js +91 -0
  106. package/dist/core/admission-decision.js.map +1 -0
  107. package/dist/core/admission-lock.d.ts +69 -0
  108. package/dist/core/admission-lock.d.ts.map +1 -0
  109. package/dist/core/admission-lock.js +278 -0
  110. package/dist/core/admission-lock.js.map +1 -0
  111. package/dist/core/admission-settings.d.ts +69 -0
  112. package/dist/core/admission-settings.d.ts.map +1 -0
  113. package/dist/core/admission-settings.js +204 -0
  114. package/dist/core/admission-settings.js.map +1 -0
  115. package/dist/core/admission-state.d.ts +50 -0
  116. package/dist/core/admission-state.d.ts.map +1 -0
  117. package/dist/core/admission-state.js +168 -0
  118. package/dist/core/admission-state.js.map +1 -0
  119. package/dist/core/admission.d.ts +70 -0
  120. package/dist/core/admission.d.ts.map +1 -0
  121. package/dist/core/admission.js +205 -0
  122. package/dist/core/admission.js.map +1 -0
  123. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  124. package/dist/core/lisa-owned-hash-ledger.js +336 -0
  125. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  126. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  127. package/dist/core/project-config-push-gate.d.ts +66 -0
  128. package/dist/core/project-config-push-gate.d.ts.map +1 -0
  129. package/dist/core/project-config-push-gate.js +82 -0
  130. package/dist/core/project-config-push-gate.js.map +1 -0
  131. package/dist/core/project-config.d.ts +4 -0
  132. package/dist/core/project-config.d.ts.map +1 -1
  133. package/dist/core/project-config.js +14 -9
  134. package/dist/core/project-config.js.map +1 -1
  135. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  136. package/dist/core/upstream-evidence-manifest.js +207 -126
  137. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  138. package/expo/package-lisa/package.lisa.json +2 -2
  139. package/harper-fabric/package-lisa/package.lisa.json +4 -4
  140. package/nestjs/create-only/vitest.config.local.ts +1 -7
  141. package/nestjs/package-lisa/package.lisa.json +4 -4
  142. package/npm-package/package-lisa/package.lisa.json +4 -4
  143. package/package.json +12 -11
  144. package/phaser/package-lisa/package.lisa.json +4 -4
  145. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  146. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  147. package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  148. package/plugins/lisa/.codex-plugin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  149. package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +1 -1
  150. package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  151. package/plugins/lisa/skills/lisa-git-submit-pr/SKILL.md +1 -1
  152. package/plugins/lisa/skills/lisa-implement/SKILL.md +1 -1
  153. package/plugins/lisa-agy/plugin.json +1 -1
  154. package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  155. package/plugins/lisa-agy/skills/lisa-git-submit-pr/SKILL.md +1 -1
  156. package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +1 -1
  157. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  159. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  160. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  161. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  162. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  163. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  164. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  165. package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  166. package/plugins/lisa-copilot/skills/lisa-git-submit-pr/SKILL.md +1 -1
  167. package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +1 -1
  168. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  169. package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  170. package/plugins/lisa-cursor/skills/lisa-git-submit-pr/SKILL.md +1 -1
  171. package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +1 -1
  172. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  173. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  174. package/plugins/lisa-devin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  175. package/plugins/lisa-devin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  176. package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +1 -1
  177. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  178. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  179. package/plugins/lisa-expo-agy/plugin.json +1 -1
  180. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  181. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  182. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  183. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  184. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  185. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  186. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  187. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  188. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  189. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  190. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  191. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  192. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  193. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  194. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  195. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  196. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  197. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  198. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  199. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  200. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  201. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  202. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  203. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  204. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  205. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  206. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  207. package/plugins/lisa-rails-agy/plugin.json +1 -1
  208. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  209. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  210. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  211. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  212. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  213. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  214. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  215. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  216. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  217. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  218. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  219. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  220. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  221. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  222. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  223. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  224. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  225. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  226. package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  227. package/plugins/src/base/skills/lisa-git-submit-pr/SKILL.md +1 -1
  228. package/plugins/src/base/skills/lisa-implement/SKILL.md +1 -1
  229. package/rails/copy-overwrite/Gemfile.lisa +8 -0
  230. package/rails/copy-overwrite/lefthook.yml +25 -11
  231. package/rails/copy-overwrite/scripts/lisa-rails-gates.mjs +686 -0
  232. package/rails/copy-overwrite/scripts/lisa-rspec-shards.mjs +2 -2
  233. package/rails/copy-overwrite/scripts/lisa_crystalball_recorder.rb +239 -0
  234. package/rails/copy-overwrite/scripts/lisa_rspec_partial_coverage.rb +83 -0
  235. package/scripts/build-unless-marked.mjs +83 -0
  236. package/scripts/check-plugins-sync.sh +22 -5
  237. package/scripts/classify-markdown-assertions.mjs +141 -0
  238. package/scripts/integration-shard-build.mjs +143 -0
  239. package/scripts/lib/history-scanner-suites.mjs +19 -0
  240. package/scripts/lib/markdown-assertions/classify.mjs +289 -0
  241. package/scripts/lib/markdown-assertions/context.mjs +53 -0
  242. package/scripts/lib/markdown-assertions/corpus.mjs +222 -0
  243. package/scripts/lib/markdown-assertions/manifest-cull.mjs +86 -0
  244. package/scripts/lib/markdown-assertions/record-setup.mjs +265 -0
  245. package/scripts/lib/markdown-assertions/record.mjs +115 -0
  246. package/scripts/lib/markdown-assertions/record.vitest.config.mjs +24 -0
  247. package/scripts/lib/markdown-assertions/sites.mjs +273 -0
  248. package/scripts/lib/markdown-assertions/test-cull.mjs +768 -0
  249. package/scripts/lib/markdown-assertions/tokens.mjs +158 -0
  250. package/scripts/lib/shell-guard-trace.mjs +6 -0
  251. package/scripts/lib/test-access-map-setup.mjs +40 -0
  252. package/scripts/lib/test-access-map-tracer.mjs +205 -0
  253. package/scripts/lib/test-access-map.d.mts +72 -0
  254. package/scripts/lib/test-access-map.mjs +395 -0
  255. package/scripts/lib/test-timings-reporter.d.mts +17 -0
  256. package/scripts/lib/test-timings-reporter.mjs +99 -0
  257. package/scripts/plan-integration-shards.mjs +300 -0
  258. package/scripts/test-timing-report.d.mts +41 -0
  259. package/scripts/test-timing-report.mjs +361 -0
  260. package/scripts/two-channel-couplings.json +132 -36
  261. package/scripts/verify-npm-advisories-4333.mjs +3 -12
  262. package/typescript/copy-overwrite/.prettierignore +12 -0
  263. package/typescript/create-only/vitest.config.local.ts +1 -7
  264. package/typescript/package-lisa/package.lisa.json +4 -4
  265. package/all/copy-overwrite/scripts/lisa-scratch-run.sh +0 -1078
  266. package/dist/cli/lisa-test-run-bootstrap.d.ts +0 -3
  267. package/dist/cli/lisa-test-run-bootstrap.d.ts.map +0 -1
  268. package/dist/cli/lisa-test-run-bootstrap.js +0 -229
  269. package/dist/cli/lisa-test-run-bootstrap.js.map +0 -1
  270. package/dist/cli/lisa-test-run-ipc.d.ts +0 -49
  271. package/dist/cli/lisa-test-run-ipc.d.ts.map +0 -1
  272. package/dist/cli/lisa-test-run-ipc.js +0 -226
  273. package/dist/cli/lisa-test-run-ipc.js.map +0 -1
  274. package/dist/cli/lisa-test-run-process-group.d.ts +0 -30
  275. package/dist/cli/lisa-test-run-process-group.d.ts.map +0 -1
  276. package/dist/cli/lisa-test-run-process-group.js +0 -140
  277. package/dist/cli/lisa-test-run-process-group.js.map +0 -1
  278. package/dist/cli/lisa-test-run-reaper.d.ts +0 -3
  279. package/dist/cli/lisa-test-run-reaper.d.ts.map +0 -1
  280. package/dist/cli/lisa-test-run-reaper.js +0 -195
  281. package/dist/cli/lisa-test-run-reaper.js.map +0 -1
  282. package/dist/cli/lisa-test-run-runtime.d.ts +0 -46
  283. package/dist/cli/lisa-test-run-runtime.d.ts.map +0 -1
  284. package/dist/cli/lisa-test-run-runtime.js +0 -123
  285. package/dist/cli/lisa-test-run-runtime.js.map +0 -1
  286. package/dist/cli/lisa-test-run-supervisor.d.ts +0 -13
  287. package/dist/cli/lisa-test-run-supervisor.d.ts.map +0 -1
  288. package/dist/cli/lisa-test-run-supervisor.js +0 -265
  289. package/dist/cli/lisa-test-run-supervisor.js.map +0 -1
  290. package/dist/configs/vitest/fleet-admission-global-setup.d.ts +0 -34
  291. package/dist/configs/vitest/fleet-admission-global-setup.d.ts.map +0 -1
  292. package/dist/configs/vitest/fleet-admission-global-setup.js +0 -123
  293. package/dist/configs/vitest/fleet-admission-global-setup.js.map +0 -1
  294. package/dist/configs/vitest/fleet-admission.d.ts +0 -129
  295. package/dist/configs/vitest/fleet-admission.d.ts.map +0 -1
  296. package/dist/configs/vitest/fleet-admission.js +0 -239
  297. package/dist/configs/vitest/fleet-admission.js.map +0 -1
  298. package/dist/configs/vitest/scratch-authority.d.ts +0 -25
  299. package/dist/configs/vitest/scratch-authority.d.ts.map +0 -1
  300. package/dist/configs/vitest/scratch-authority.js +0 -107
  301. package/dist/configs/vitest/scratch-authority.js.map +0 -1
  302. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts +0 -5
  303. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts.map +0 -1
  304. package/dist/configs/vitest/scratch-bound-cleanup-programs.js +0 -219
  305. package/dist/configs/vitest/scratch-bound-cleanup-programs.js.map +0 -1
  306. package/dist/configs/vitest/scratch-bound-cleanup.d.ts +0 -28
  307. package/dist/configs/vitest/scratch-bound-cleanup.d.ts.map +0 -1
  308. package/dist/configs/vitest/scratch-bound-cleanup.js +0 -155
  309. package/dist/configs/vitest/scratch-bound-cleanup.js.map +0 -1
  310. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts +0 -17
  311. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts.map +0 -1
  312. package/dist/configs/vitest/scratch-bound-root-cleanup.js +0 -149
  313. package/dist/configs/vitest/scratch-bound-root-cleanup.js.map +0 -1
  314. package/dist/configs/vitest/scratch-global-setup.d.ts +0 -258
  315. package/dist/configs/vitest/scratch-global-setup.d.ts.map +0 -1
  316. package/dist/configs/vitest/scratch-global-setup.js +0 -505
  317. package/dist/configs/vitest/scratch-global-setup.js.map +0 -1
  318. package/dist/configs/vitest/scratch-leak-setup.d.ts +0 -2
  319. package/dist/configs/vitest/scratch-leak-setup.d.ts.map +0 -1
  320. package/dist/configs/vitest/scratch-leak-setup.js +0 -108
  321. package/dist/configs/vitest/scratch-leak-setup.js.map +0 -1
  322. package/dist/configs/vitest/scratch-namespace-authority.d.ts +0 -80
  323. package/dist/configs/vitest/scratch-namespace-authority.d.ts.map +0 -1
  324. package/dist/configs/vitest/scratch-namespace-authority.js +0 -291
  325. package/dist/configs/vitest/scratch-namespace-authority.js.map +0 -1
  326. package/dist/configs/vitest/scratch-owner.d.ts +0 -131
  327. package/dist/configs/vitest/scratch-owner.d.ts.map +0 -1
  328. package/dist/configs/vitest/scratch-owner.js +0 -297
  329. package/dist/configs/vitest/scratch-owner.js.map +0 -1
  330. package/dist/configs/vitest/scratch-route-profile.d.ts +0 -46
  331. package/dist/configs/vitest/scratch-route-profile.d.ts.map +0 -1
  332. package/dist/configs/vitest/scratch-route-profile.js +0 -233
  333. package/dist/configs/vitest/scratch-route-profile.js.map +0 -1
  334. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts +0 -33
  335. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts.map +0 -1
  336. package/dist/configs/vitest/scratch-run-root-compatibility.js +0 -137
  337. package/dist/configs/vitest/scratch-run-root-compatibility.js.map +0 -1
  338. package/dist/configs/vitest/scratch-run-root-intent.d.ts +0 -66
  339. package/dist/configs/vitest/scratch-run-root-intent.d.ts.map +0 -1
  340. package/dist/configs/vitest/scratch-run-root-intent.js +0 -183
  341. package/dist/configs/vitest/scratch-run-root-intent.js.map +0 -1
  342. package/dist/configs/vitest/scratch-setup.d.ts +0 -46
  343. package/dist/configs/vitest/scratch-setup.d.ts.map +0 -1
  344. package/dist/configs/vitest/scratch-setup.js +0 -226
  345. package/dist/configs/vitest/scratch-setup.js.map +0 -1
  346. package/dist/configs/vitest/scratch-supervision-intent.d.ts +0 -8
  347. package/dist/configs/vitest/scratch-supervision-intent.d.ts.map +0 -1
  348. package/dist/configs/vitest/scratch-supervision-intent.js +0 -125
  349. package/dist/configs/vitest/scratch-supervision-intent.js.map +0 -1
  350. package/dist/configs/vitest/scratch-supervision-protocol.d.ts +0 -12
  351. package/dist/configs/vitest/scratch-supervision-protocol.d.ts.map +0 -1
  352. package/dist/configs/vitest/scratch-supervision-protocol.js +0 -230
  353. package/dist/configs/vitest/scratch-supervision-protocol.js.map +0 -1
  354. package/dist/configs/vitest/scratch-supervision.d.ts +0 -69
  355. package/dist/configs/vitest/scratch-supervision.d.ts.map +0 -1
  356. package/dist/configs/vitest/scratch-supervision.js +0 -244
  357. package/dist/configs/vitest/scratch-supervision.js.map +0 -1
  358. package/dist/configs/vitest/scratch-sweep.d.ts +0 -66
  359. package/dist/configs/vitest/scratch-sweep.d.ts.map +0 -1
  360. package/dist/configs/vitest/scratch-sweep.js +0 -82
  361. package/dist/configs/vitest/scratch-sweep.js.map +0 -1
  362. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts +0 -48
  363. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts.map +0 -1
  364. package/dist/configs/vitest/scratch-tmpdir-trust.js +0 -194
  365. package/dist/configs/vitest/scratch-tmpdir-trust.js.map +0 -1
  366. package/dist/configs/vitest/scratch.d.ts +0 -19
  367. package/dist/configs/vitest/scratch.d.ts.map +0 -1
  368. package/dist/configs/vitest/scratch.js +0 -34
  369. package/dist/configs/vitest/scratch.js.map +0 -1
  370. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts +0 -86
  371. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts.map +0 -1
  372. package/dist/configs/vitest/synthesis-scratch-reclaim.js +0 -226
  373. package/dist/configs/vitest/synthesis-scratch-reclaim.js.map +0 -1
@@ -0,0 +1,768 @@
1
+ /**
2
+ * Delete WORDING assertion sites from test files (CodySwannGT/lisa#4867).
3
+ *
4
+ * Works on the TypeScript AST, never on text patterns:
5
+ *
6
+ * 1. Each WORDING site (a recorded `file:line:column`) is mapped to the
7
+ * `expect(...)` chain whose matcher call contains that position. Its
8
+ * statement is deleted when it is a plain expression statement in a
9
+ * block, or when it is the whole body of a `forEach` callback (the
10
+ * `forEach` statement goes). Any other shape is left alone and counted
11
+ * as kept-uneditable.
12
+ * 2. Emptied containers go too, to a fixed point: a loop or `if` whose body
13
+ * lost every statement; a test (`it` / `test`, any modifier or `.each`)
14
+ * that had assertions and lost all of them; a `describe` that had tests
15
+ * and lost all of them.
16
+ * 3. Declarations and imports nothing references any more are removed,
17
+ * again to a fixed point.
18
+ * 4. A file with no test left is deleted.
19
+ * @module scripts/lib/markdown-assertions/test-cull
20
+ */
21
+ import { readFileSync, rmSync, writeFileSync } from "node:fs";
22
+ import path from "node:path";
23
+
24
+ import ts from "typescript";
25
+
26
+ import {
27
+ isExpectCall,
28
+ parseSource,
29
+ readExpectChain,
30
+ walk,
31
+ } from "../phrase-tests/ast.mjs";
32
+
33
+ /** Runner calls that declare a test. */
34
+ const TEST_NAMES = new Set(["it", "test"]);
35
+
36
+ /** Runner calls that declare a suite. */
37
+ const SUITE_NAMES = new Set(["describe", "suite"]);
38
+
39
+ /**
40
+ * The runner name a call starts from: `it`, `it.each(...)`, `describe.skip`.
41
+ * @param {ts.Node} node - A node.
42
+ * @returns {string | undefined} The root identifier of a call's callee.
43
+ */
44
+ function runnerName(node) {
45
+ if (!ts.isCallExpression(node)) return undefined;
46
+ /** @type {ts.Expression} */
47
+ let callee = node.expression;
48
+ while (ts.isCallExpression(callee) || ts.isPropertyAccessExpression(callee)) {
49
+ callee = callee.expression;
50
+ }
51
+ return ts.isIdentifier(callee) ? callee.text : undefined;
52
+ }
53
+
54
+ /**
55
+ * An expression with any `await` and parentheses taken off.
56
+ * @param {ts.Expression} node - An expression.
57
+ * @returns {ts.Expression} The inner expression.
58
+ */
59
+ function unwrapAwait(node) {
60
+ let inner = node;
61
+ while (ts.isAwaitExpression(inner) || ts.isParenthesizedExpression(inner)) {
62
+ inner = inner.expression;
63
+ }
64
+ return inner;
65
+ }
66
+
67
+ /**
68
+ * The statement a node sits in directly, if its parent is a block-like list.
69
+ * @param {ts.Node} node - An expression.
70
+ * @returns {ts.Statement | undefined} The expression statement.
71
+ */
72
+ function ownStatement(node) {
73
+ /** @type {ts.Node} */
74
+ let current = node;
75
+ while (
76
+ ts.isAwaitExpression(current.parent) ||
77
+ ts.isParenthesizedExpression(current.parent)
78
+ ) {
79
+ current = current.parent;
80
+ }
81
+ const statement = current.parent;
82
+ return statement && ts.isExpressionStatement(statement)
83
+ ? statement
84
+ : undefined;
85
+ }
86
+
87
+ /**
88
+ * The statement to delete for one assertion site, or undefined when its
89
+ * shape is not one the cull edits.
90
+ * @param {ts.Node} site - The matcher call that ends the expect chain.
91
+ * @returns {ts.Statement | undefined} The statement.
92
+ */
93
+ function deletableStatement(site) {
94
+ const statement = ownStatement(site);
95
+ if (statement && isStatementList(statement.parent)) return statement;
96
+ const arrow = site.parent;
97
+ if (arrow && ts.isArrowFunction(arrow) && arrow.body === site) {
98
+ const call = arrow.parent;
99
+ if (
100
+ call &&
101
+ ts.isCallExpression(call) &&
102
+ ts.isPropertyAccessExpression(call.expression) &&
103
+ call.expression.name.text === "forEach"
104
+ ) {
105
+ const loop = ownStatement(call);
106
+ if (loop && isStatementList(loop.parent)) return loop;
107
+ }
108
+ }
109
+ return undefined;
110
+ }
111
+
112
+ /**
113
+ * Whether a node holds a list of statements.
114
+ * @param {ts.Node | undefined} node - A node.
115
+ * @returns {boolean} True for blocks, files and case clauses.
116
+ */
117
+ function isStatementList(node) {
118
+ return (
119
+ node !== undefined &&
120
+ (ts.isBlock(node) ||
121
+ ts.isSourceFile(node) ||
122
+ ts.isCaseClause(node) ||
123
+ ts.isDefaultClause(node))
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Whether every statement of a body is deleted (and it had one).
129
+ * @param {ts.Node | undefined} body - A statement or block.
130
+ * @param {Set<ts.Node>} deleted - Deleted nodes.
131
+ * @returns {boolean} True when the body is emptied.
132
+ */
133
+ function emptied(body, deleted) {
134
+ if (body === undefined) return true;
135
+ if (deleted.has(body)) return true;
136
+ if (!ts.isBlock(body)) return false;
137
+ return (
138
+ body.statements.length > 0 &&
139
+ body.statements.every(statement => deleted.has(statement))
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Whether a node lies inside a deleted node.
145
+ * @param {ts.Node} node - A node.
146
+ * @param {Set<ts.Node>} deleted - Deleted nodes.
147
+ * @returns {boolean} True when an ancestor (or itself) is deleted.
148
+ */
149
+ function isGone(node, deleted) {
150
+ for (let current = node; current; current = current.parent) {
151
+ if (deleted.has(current)) return true;
152
+ }
153
+ return false;
154
+ }
155
+
156
+ /**
157
+ * Grow the deleted set with emptied loops, ifs, tests and suites, to a fixed point.
158
+ * @param {ts.SourceFile} source - The file.
159
+ * @param {Set<ts.Node>} deleted - Deleted statements; grows.
160
+ */
161
+ function deleteEmptied(source, deleted) {
162
+ const assertions = assertionIndex(source);
163
+ let changed = true;
164
+ while (changed) {
165
+ changed = false;
166
+ walk(source, node => {
167
+ if (!ts.isStatement(node) || isGone(node, deleted)) return;
168
+ if (!isStatementList(node.parent)) return;
169
+ if (containerEmptied(node, deleted, assertions)) {
170
+ deleted.add(node);
171
+ changed = true;
172
+ }
173
+ });
174
+ }
175
+ }
176
+
177
+ /**
178
+ * @typedef {object} AssertionIndex
179
+ * @property {Map<string, ts.Node>} helpers - Local functions that assert, by name, to their body.
180
+ * @property {ts.Node[]} bearing - Every `expect(...)` call and every call to a helper.
181
+ */
182
+
183
+ /**
184
+ * The file's assertion-bearing calls: `expect(...)`, and calls to local
185
+ * helper functions whose bodies (transitively) assert.
186
+ * @param {ts.SourceFile} source - The file.
187
+ * @returns {AssertionIndex} The index.
188
+ */
189
+ function assertionIndex(source) {
190
+ /** @type {Map<string, ts.Node>} */
191
+ const functions = new Map();
192
+ walk(source, node => {
193
+ if (ts.isFunctionDeclaration(node) && node.name && node.body) {
194
+ functions.set(node.name.text, node.body);
195
+ } else if (
196
+ ts.isVariableDeclaration(node) &&
197
+ ts.isIdentifier(node.name) &&
198
+ node.initializer &&
199
+ (ts.isArrowFunction(node.initializer) ||
200
+ ts.isFunctionExpression(node.initializer))
201
+ ) {
202
+ functions.set(node.name.text, node.initializer.body);
203
+ }
204
+ });
205
+ /** @type {Map<string, ts.Node>} */
206
+ const helpers = new Map();
207
+ let grew = true;
208
+ while (grew) {
209
+ grew = false;
210
+ for (const [name, body] of functions) {
211
+ if (helpers.has(name)) continue;
212
+ let asserts = false;
213
+ walk(body, node => {
214
+ if (isExpectCall(node) || helperCallee(node, helpers)) asserts = true;
215
+ });
216
+ if (asserts) {
217
+ helpers.set(name, body);
218
+ grew = true;
219
+ }
220
+ }
221
+ }
222
+ /** @type {ts.Node[]} */
223
+ const bearing = [];
224
+ walk(source, node => {
225
+ if (isExpectCall(node) || helperCallee(node, helpers)) bearing.push(node);
226
+ });
227
+ return { helpers, bearing };
228
+ }
229
+
230
+ /**
231
+ * The helper a call invokes, if it is a call to one.
232
+ * @param {ts.Node} node - A node.
233
+ * @param {Map<string, ts.Node>} helpers - Known helpers.
234
+ * @returns {string | undefined} The helper's name.
235
+ */
236
+ function helperCallee(node, helpers) {
237
+ return ts.isCallExpression(node) &&
238
+ ts.isIdentifier(node.expression) &&
239
+ helpers.has(node.expression.text)
240
+ ? node.expression.text
241
+ : undefined;
242
+ }
243
+
244
+ /**
245
+ * Whether an assertion-bearing call no longer asserts: it was deleted, or it
246
+ * calls a helper whose every assertion is gone.
247
+ * @param {ts.Node} node - An expect call or helper call.
248
+ * @param {Set<ts.Node>} deleted - Deleted nodes.
249
+ * @param {AssertionIndex} assertions - The index.
250
+ * @param {Set<string>} [visiting] - Helpers on the current path (cycles).
251
+ * @returns {boolean} True when it asserts nothing any more.
252
+ */
253
+ function bearingGone(node, deleted, assertions, visiting = new Set()) {
254
+ if (isGone(node, deleted)) return true;
255
+ const name = helperCallee(node, assertions.helpers);
256
+ if (name === undefined || visiting.has(name)) return false;
257
+ const body = assertions.helpers.get(name);
258
+ const inside = assertions.bearing.filter(
259
+ other => body !== undefined && contains(body, other)
260
+ );
261
+ const path = new Set([...visiting, name]);
262
+ return (
263
+ inside.length > 0 &&
264
+ inside.every(other => bearingGone(other, deleted, assertions, path))
265
+ );
266
+ }
267
+
268
+ /**
269
+ * Whether one statement became an empty container.
270
+ * @param {ts.Statement} node - A statement.
271
+ * @param {Set<ts.Node>} deleted - Deleted nodes.
272
+ * @param {AssertionIndex} assertions - The file's assertion-bearing calls.
273
+ * @returns {boolean} True when it should be deleted.
274
+ */
275
+ function containerEmptied(node, deleted, assertions) {
276
+ if (
277
+ ts.isForStatement(node) ||
278
+ ts.isForOfStatement(node) ||
279
+ ts.isForInStatement(node) ||
280
+ ts.isWhileStatement(node)
281
+ ) {
282
+ return emptied(node.statement, deleted);
283
+ }
284
+ if (ts.isIfStatement(node)) {
285
+ return (
286
+ emptied(node.thenStatement, deleted) &&
287
+ (node.elseStatement === undefined || emptied(node.elseStatement, deleted))
288
+ );
289
+ }
290
+ if (!ts.isExpressionStatement(node)) return false;
291
+ const call = unwrapAwait(node.expression);
292
+ if (
293
+ helperCallee(call, assertions.helpers) &&
294
+ bearingGone(call, deleted, assertions)
295
+ ) {
296
+ return true;
297
+ }
298
+ const name = runnerName(call);
299
+ if (name && TEST_NAMES.has(name)) {
300
+ const inside = assertions.bearing.filter(other => contains(node, other));
301
+ return (
302
+ inside.length > 0 &&
303
+ inside.every(other => bearingGone(other, deleted, assertions))
304
+ );
305
+ }
306
+ if (name && SUITE_NAMES.has(name)) {
307
+ const tests = [];
308
+ walk(node, child => {
309
+ if (
310
+ child !== node &&
311
+ ts.isExpressionStatement(child) &&
312
+ TEST_NAMES.has(runnerName(child.expression) ?? "")
313
+ ) {
314
+ tests.push(child);
315
+ }
316
+ });
317
+ return tests.length > 0 && tests.every(test => isGone(test, deleted));
318
+ }
319
+ if (
320
+ ts.isCallExpression(call) &&
321
+ ts.isPropertyAccessExpression(call.expression) &&
322
+ call.expression.name.text === "forEach"
323
+ ) {
324
+ const callback = call.arguments[0];
325
+ return (
326
+ callback !== undefined &&
327
+ (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) &&
328
+ emptied(callback.body, deleted)
329
+ );
330
+ }
331
+ return false;
332
+ }
333
+
334
+ /**
335
+ * Whether `outer` contains `inner`.
336
+ * @param {ts.Node} outer - Container.
337
+ * @param {ts.Node} inner - Candidate.
338
+ * @returns {boolean} True when inner is within outer.
339
+ */
340
+ function contains(outer, inner) {
341
+ return (
342
+ inner.getStart() >= outer.getStart() && inner.getEnd() <= outer.getEnd()
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Remove nodes from text, outermost only, with their leading trivia.
348
+ * @param {ts.SourceFile} source - The file.
349
+ * @param {Set<ts.Node>} deleted - Nodes to remove.
350
+ * @returns {string} The new text.
351
+ */
352
+ function removeNodes(source, deleted) {
353
+ const ranges = [...deleted]
354
+ .filter(node => !isGone(node.parent, deleted))
355
+ .map(node => [node.getFullStart(), node.getEnd()])
356
+ .sort((a, b) => (b[0] ?? 0) - (a[0] ?? 0));
357
+ let text = source.text;
358
+ for (const [start = 0, end = 0] of ranges) {
359
+ text = text.slice(0, start) + text.slice(end);
360
+ }
361
+ return text;
362
+ }
363
+
364
+ /**
365
+ * Names a declaration binds.
366
+ * @param {ts.BindingName} name - A binding name.
367
+ * @returns {string[]} Identifiers.
368
+ */
369
+ function boundNames(name) {
370
+ if (ts.isIdentifier(name)) return [name.text];
371
+ return name.elements.flatMap(element =>
372
+ ts.isOmittedExpression(element) ? [] : boundNames(element.name)
373
+ );
374
+ }
375
+
376
+ /**
377
+ * Whether an identifier sits where a name is declared, not referenced.
378
+ * @param {ts.Identifier} node - An identifier.
379
+ * @returns {boolean} True for declaration and member-name positions.
380
+ */
381
+ function isDeclaringPosition(node) {
382
+ const parent = node.parent;
383
+ return (
384
+ (ts.isVariableDeclaration(parent) && parent.name === node) ||
385
+ (ts.isBindingElement(parent) && parent.name === node) ||
386
+ (ts.isParameter(parent) && parent.name === node) ||
387
+ (ts.isFunctionDeclaration(parent) && parent.name === node) ||
388
+ ts.isImportSpecifier(parent) ||
389
+ ts.isImportClause(parent) ||
390
+ ts.isNamespaceImport(parent) ||
391
+ (ts.isPropertyAccessExpression(parent) && parent.name === node) ||
392
+ (ts.isPropertyAssignment(parent) && parent.name === node) ||
393
+ (ts.isPropertySignature(parent) && parent.name === node) ||
394
+ (ts.isTypeAliasDeclaration(parent) && parent.name === node) ||
395
+ (ts.isInterfaceDeclaration(parent) && parent.name === node)
396
+ );
397
+ }
398
+
399
+ /**
400
+ * Whether a name is referenced anywhere inside a scope.
401
+ * @param {string} name - The name.
402
+ * @param {ts.Node} scope - Where to look.
403
+ * @returns {boolean} True when some identifier refers to it.
404
+ */
405
+ function referencedIn(name, scope) {
406
+ let found = false;
407
+ walk(scope, node => {
408
+ if (!found && ts.isIdentifier(node) && node.text === name) {
409
+ found = !isDeclaringPosition(node);
410
+ }
411
+ });
412
+ return found;
413
+ }
414
+
415
+ /**
416
+ * Parameter renames that mark a callback's now-unused parameters with `_`.
417
+ * @param {ts.SourceFile} source - The file.
418
+ * @returns {{ start: number, end: number, text: string }[]} Rewrites.
419
+ */
420
+ function unusedParameterRenames(source) {
421
+ /** @type {{ start: number, end: number, text: string }[]} */
422
+ const rewrites = [];
423
+ walk(source, node => {
424
+ if (!ts.isParameter(node) || !ts.isIdentifier(node.name)) return;
425
+ const owner = node.parent;
426
+ const name = node.name.text;
427
+ if (name.startsWith("_") || name === "this") return;
428
+ if (!(ts.isArrowFunction(owner) || ts.isFunctionExpression(owner))) return;
429
+ if (owner.body && !referencedIn(name, owner.body)) {
430
+ rewrites.push({
431
+ start: node.name.getStart(),
432
+ end: node.name.getEnd(),
433
+ text: `_${name}`,
434
+ });
435
+ }
436
+ });
437
+ return rewrites;
438
+ }
439
+
440
+ /**
441
+ * Whether a statement is exported.
442
+ * @param {ts.Statement} node - A statement.
443
+ * @returns {boolean} True when it carries `export`.
444
+ */
445
+ function isExported(node) {
446
+ return (ts.canHaveModifiers(node) ? (ts.getModifiers(node) ?? []) : []).some(
447
+ modifier => modifier.kind === ts.SyntaxKind.ExportKeyword
448
+ );
449
+ }
450
+
451
+ /**
452
+ * One pass of unused-declaration removal.
453
+ * @param {string} fileName - File name.
454
+ * @param {string} text - File text.
455
+ * @returns {string} New text (unchanged when nothing is unused).
456
+ */
457
+ function removeUnusedOnce(fileName, text) {
458
+ const source = parseSource(fileName, text);
459
+ const fileUnused = (/** @type {string} */ name) =>
460
+ !referencedIn(name, source);
461
+ /** @type {Set<ts.Node>} */
462
+ const deleted = new Set();
463
+ /** @type {{ start: number, end: number, text: string }[]} */
464
+ const rewrites = [];
465
+ walk(source, node => {
466
+ const scope = node.parent;
467
+ const local = isStatementList(scope);
468
+ if (ts.isVariableStatement(node) && !isExported(node) && local) {
469
+ const names = node.declarationList.declarations.flatMap(d =>
470
+ boundNames(d.name)
471
+ );
472
+ if (names.length > 0 && names.every(name => !referencedIn(name, scope)))
473
+ deleted.add(node);
474
+ } else if (
475
+ ts.isFunctionDeclaration(node) &&
476
+ node.name &&
477
+ !isExported(node) &&
478
+ local
479
+ ) {
480
+ if (!referencedIn(node.name.text, scope)) deleted.add(node);
481
+ } else if (
482
+ (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) &&
483
+ !isExported(node)
484
+ ) {
485
+ if (fileUnused(node.name.text)) deleted.add(node);
486
+ } else if (ts.isImportDeclaration(node) && node.importClause) {
487
+ const rewrite = importRewrite(node, fileUnused, source);
488
+ if (rewrite === null) deleted.add(node);
489
+ else if (rewrite) rewrites.push(rewrite);
490
+ }
491
+ });
492
+ const outermost = [...deleted].filter(node => !isGone(node.parent, deleted));
493
+ const renames =
494
+ outermost.length === 0 && rewrites.length === 0
495
+ ? unusedParameterRenames(source)
496
+ : [];
497
+ if (outermost.length === 0 && rewrites.length === 0 && renames.length === 0)
498
+ return text;
499
+ let next = text;
500
+ const edits = [
501
+ ...outermost.map(node => ({
502
+ start: node.getFullStart(),
503
+ end: node.getEnd(),
504
+ text: "",
505
+ })),
506
+ ...rewrites,
507
+ ...renames,
508
+ ].sort((a, b) => b.start - a.start);
509
+ for (const edit of edits)
510
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
511
+ return next;
512
+ }
513
+
514
+ /**
515
+ * How to rewrite an import whose bindings are partly or wholly unused.
516
+ * @param {ts.ImportDeclaration} node - The import.
517
+ * @param {(name: string) => boolean} unused - Whether a name is unreferenced.
518
+ * @param {ts.SourceFile} source - The file.
519
+ * @returns {{ start: number, end: number, text: string } | null | undefined}
520
+ * A rewrite, null to delete the import, undefined to leave it.
521
+ */
522
+ function importRewrite(node, unused, source) {
523
+ const clause = /** @type {ts.ImportClause} */ (node.importClause);
524
+ const defaultUnused = clause.name ? unused(clause.name.text) : true;
525
+ const bindings = clause.namedBindings;
526
+ if (bindings && ts.isNamespaceImport(bindings)) {
527
+ return defaultUnused && unused(bindings.name.text) ? null : undefined;
528
+ }
529
+ const elements =
530
+ bindings && ts.isNamedImports(bindings) ? bindings.elements : [];
531
+ const kept = elements.filter(element => !unused(element.name.text));
532
+ if (defaultUnused && kept.length === 0) return null;
533
+ if (
534
+ kept.length === elements.length &&
535
+ (clause.name === undefined || !defaultUnused)
536
+ )
537
+ return undefined;
538
+ if (!bindings || !ts.isNamedImports(bindings)) return undefined;
539
+ if (kept.length === 0) {
540
+ const name = clause.name?.getText(source) ?? "";
541
+ return { start: clause.getStart(), end: clause.getEnd(), text: name };
542
+ }
543
+ return {
544
+ start: bindings.getStart(),
545
+ end: bindings.getEnd(),
546
+ text: `{ ${kept.map(element => element.getText(source)).join(", ")} }`,
547
+ };
548
+ }
549
+
550
+ /**
551
+ * Whether a file still declares a test.
552
+ * @param {string} fileName - File name.
553
+ * @param {string} text - File text.
554
+ * @returns {boolean} True when a test remains.
555
+ */
556
+ function hasTests(fileName, text) {
557
+ let found = false;
558
+ walk(parseSource(fileName, text), node => {
559
+ if (
560
+ ts.isExpressionStatement(node) &&
561
+ TEST_NAMES.has(runnerName(node.expression) ?? "")
562
+ )
563
+ found = true;
564
+ });
565
+ return found;
566
+ }
567
+
568
+ /**
569
+ * The expect chains of a file whose matcher call contains a position.
570
+ * @param {ts.SourceFile} source - The file.
571
+ * @param {{ line: number, column: number }} site - 1-based position.
572
+ * @returns {ts.Node | undefined} The innermost matching site node.
573
+ */
574
+ function siteNode(source, site) {
575
+ const lineStarts = source.getLineStarts();
576
+ const lineStart = lineStarts[site.line - 1];
577
+ if (lineStart === undefined) return undefined;
578
+ const position = lineStart + site.column - 1;
579
+ /** @type {ts.Node | undefined} */
580
+ let best;
581
+ walk(source, node => {
582
+ if (!isExpectCall(node)) return;
583
+ const chain = readExpectChain(node);
584
+ const start = chain.site.getStart();
585
+ if (start <= position && position <= chain.site.getEnd()) {
586
+ if (!best || chain.site.getStart() >= best.getStart()) best = chain.site;
587
+ }
588
+ });
589
+ return best;
590
+ }
591
+
592
+ /**
593
+ * A runner statement's identity that survives edits: its callee text and
594
+ * title argument.
595
+ * @param {ts.ExpressionStatement} node - A runner statement.
596
+ * @param {ts.SourceFile} source - Its file.
597
+ * @returns {string} The key.
598
+ */
599
+ function runnerKey(node, source) {
600
+ const call = /** @type {ts.CallExpression} */ (node.expression);
601
+ return `${call.expression.getText(source)}(${call.arguments[0]?.getText(source) ?? ""})`;
602
+ }
603
+
604
+ /**
605
+ * Whether a runner call (test or suite) has an empty callback body.
606
+ * @param {ts.ExpressionStatement} node - A runner statement.
607
+ * @returns {boolean} True when its last function argument has no statements.
608
+ */
609
+ function hasEmptyCallback(node) {
610
+ const call = /** @type {ts.CallExpression} */ (node.expression);
611
+ const callback = [...call.arguments]
612
+ .reverse()
613
+ .find(arg => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
614
+ if (!callback) return false;
615
+ const body = /** @type {ts.ArrowFunction | ts.FunctionExpression} */ (
616
+ callback
617
+ ).body;
618
+ return ts.isBlock(body) && body.statements.length === 0;
619
+ }
620
+
621
+ /**
622
+ * Runner statements of a file, with their kind.
623
+ * @param {ts.SourceFile} source - The file.
624
+ * @returns {{ node: ts.ExpressionStatement, kind: "test" | "suite" }[]} Runners.
625
+ */
626
+ function runners(source) {
627
+ /** @type {{ node: ts.ExpressionStatement, kind: "test" | "suite" }[]} */
628
+ const found = [];
629
+ walk(source, node => {
630
+ if (
631
+ !ts.isExpressionStatement(node) ||
632
+ !ts.isCallExpression(node.expression)
633
+ )
634
+ return;
635
+ const name = runnerName(node.expression) ?? "";
636
+ if (TEST_NAMES.has(name)) found.push({ node, kind: "test" });
637
+ else if (SUITE_NAMES.has(name)) found.push({ node, kind: "suite" });
638
+ });
639
+ return found;
640
+ }
641
+
642
+ /**
643
+ * Keys of runner statements that were already empty before the cull, so a
644
+ * deliberate empty one is never taken for an emptied one.
645
+ * @param {ts.SourceFile} source - The original file.
646
+ * @returns {Set<string>} Runner keys.
647
+ */
648
+ function emptyRunnerBodies(source) {
649
+ return new Set(
650
+ runners(source)
651
+ .filter(({ node }) => hasEmptyCallback(node))
652
+ .map(({ node }) => runnerKey(node, source))
653
+ );
654
+ }
655
+
656
+ /**
657
+ * Remove tests left with an empty body and suites left without tests.
658
+ * @param {string} fileName - File name.
659
+ * @param {string} text - File text.
660
+ * @param {Set<string>} keep - Runners that were empty to begin with.
661
+ * @returns {string} New text.
662
+ */
663
+ function pruneEmptyRunners(fileName, text, keep) {
664
+ const source = parseSource(fileName, text);
665
+ /** @type {Set<ts.Node>} */
666
+ const deleted = new Set();
667
+ for (const { node, kind } of runners(source)) {
668
+ if (!isStatementList(node.parent) || keep.has(runnerKey(node, source)))
669
+ continue;
670
+ if (kind === "test" && hasEmptyCallback(node)) deleted.add(node);
671
+ if (kind === "suite") {
672
+ const inner = runners(parseSource(fileName, node.getText(source))).filter(
673
+ runner => runner.kind === "test"
674
+ );
675
+ if (inner.length === 0) deleted.add(node);
676
+ }
677
+ }
678
+ return deleted.size === 0 ? text : removeNodes(source, deleted);
679
+ }
680
+
681
+ /**
682
+ * Cull one test file.
683
+ * @param {string} root - Repository root.
684
+ * @param {string} file - Repository-relative test file.
685
+ * @param {{ line: number, column: number }[]} sites - Its WORDING sites.
686
+ * @returns {{ file: string, deleted: boolean, removedSites: number, keptUneditable: number, testsBefore: number, testsAfter: number }} What changed.
687
+ */
688
+ function cullFile(root, file, sites) {
689
+ const absolute = path.join(root, file);
690
+ const original = readFileSync(absolute, "utf8");
691
+ const source = parseSource(file, original);
692
+ /** @type {Set<ts.Node>} */
693
+ const deleted = new Set();
694
+ let removedSites = 0;
695
+ let keptUneditable = 0;
696
+ for (const site of sites) {
697
+ const node = siteNode(source, site);
698
+ const statement = node && deletableStatement(node);
699
+ if (statement) {
700
+ deleted.add(statement);
701
+ removedSites++;
702
+ } else {
703
+ keptUneditable++;
704
+ }
705
+ }
706
+ deleteEmptied(source, deleted);
707
+ const keep = emptyRunnerBodies(source);
708
+ let text = removeNodes(source, deleted);
709
+ for (let pass = 0; pass < 40; pass++) {
710
+ const unused = removeUnusedOnce(file, text);
711
+ const next = unused === text ? pruneEmptyRunners(file, text, keep) : unused;
712
+ if (next === text) break;
713
+ text = next;
714
+ }
715
+ const testsBefore = countTests(file, original);
716
+ const remains = hasTests(file, text);
717
+ if (!remains) rmSync(absolute);
718
+ else if (text !== original) writeFileSync(absolute, text);
719
+ return {
720
+ file,
721
+ deleted: !remains,
722
+ removedSites,
723
+ keptUneditable,
724
+ testsBefore,
725
+ testsAfter: remains ? countTests(file, text) : 0,
726
+ };
727
+ }
728
+
729
+ /**
730
+ * Declared tests in a file (static; `.each` counts once).
731
+ * @param {string} fileName - File name.
732
+ * @param {string} text - File text.
733
+ * @returns {number} Test declarations.
734
+ */
735
+ function countTests(fileName, text) {
736
+ let count = 0;
737
+ walk(parseSource(fileName, text), node => {
738
+ if (
739
+ ts.isExpressionStatement(node) &&
740
+ TEST_NAMES.has(runnerName(node.expression) ?? "")
741
+ )
742
+ count++;
743
+ });
744
+ return count;
745
+ }
746
+
747
+ /**
748
+ * Delete every WORDING site from its test file.
749
+ * @param {string} root - Repository root.
750
+ * @param {import("./sites.mjs").SiteVerdict[]} sites - Classified sites.
751
+ * @returns {{ edits: ReturnType<typeof cullFile>[], removedSites: number, keptUneditable: number }} The cull.
752
+ */
753
+ export function cullTestFiles(root, sites) {
754
+ /** @type {Map<string, { line: number, column: number }[]>} */
755
+ const byFile = new Map();
756
+ for (const site of sites) {
757
+ if (site.class !== "WORDING") continue;
758
+ byFile.set(site.file, [...(byFile.get(site.file) ?? []), site]);
759
+ }
760
+ const edits = [...byFile.entries()]
761
+ .sort(([a], [b]) => a.localeCompare(b))
762
+ .map(([file, fileSites]) => cullFile(root, file, fileSites));
763
+ return {
764
+ edits,
765
+ removedSites: edits.reduce((sum, edit) => sum + edit.removedSites, 0),
766
+ keptUneditable: edits.reduce((sum, edit) => sum + edit.keptUneditable, 0),
767
+ };
768
+ }