@codyswann/lisa 5.4.0 → 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 (370) 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-local.mjs +22 -1
  8. package/all/copy-overwrite/scripts/lib/build-marker.mjs +410 -0
  9. package/all/copy-overwrite/scripts/lib/gate-pass-cache.mjs +537 -0
  10. package/all/copy-overwrite/scripts/lib/kill-marks.mjs +1 -2
  11. package/all/copy-overwrite/scripts/lib/lisa-cleanup-sweep-processes.mjs +3 -4
  12. package/all/copy-overwrite/scripts/lib/npm-update-controller-broker.mjs +1 -1
  13. package/all/copy-overwrite/scripts/lib/npm-update-gate-hooks.mjs +2 -1
  14. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +8 -1
  15. package/all/copy-overwrite/scripts/lib/npm-update-hosted-hook.mjs +1 -1
  16. package/all/copy-overwrite/scripts/lib/npm-update-tool-launcher.mjs +1 -1
  17. package/all/copy-overwrite/scripts/lib/push-admission.mjs +158 -0
  18. package/all/copy-overwrite/scripts/lib/push-gate-defaults.d.mts +34 -0
  19. package/all/copy-overwrite/scripts/lib/push-gate-defaults.mjs +147 -0
  20. package/all/copy-overwrite/scripts/lib/push-timing.mjs +323 -0
  21. package/all/copy-overwrite/scripts/lib/rspec-selection.mjs +672 -0
  22. package/all/copy-overwrite/scripts/lisa-affected-tests.mjs +566 -0
  23. package/all/copy-overwrite/scripts/lisa-gates.mjs +29 -0
  24. package/all/copy-overwrite/scripts/lisa-lint-staged-preflight.mjs +10 -1
  25. package/all/copy-overwrite/scripts/lisa-push-timing-report.mjs +153 -0
  26. package/all/copy-overwrite/scripts/lisa-rspec-select.mjs +982 -0
  27. package/all/copy-overwrite/scripts/lisa-run-gates.mjs +231 -6
  28. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +105 -17
  29. package/all/deletions.json +11 -2
  30. package/cdk/create-only/vitest.config.local.ts +1 -7
  31. package/cdk/package-lisa/package.lisa.json +4 -4
  32. package/dist/cli/admit-cmd.d.ts +21 -0
  33. package/dist/cli/admit-cmd.d.ts.map +1 -0
  34. package/dist/cli/admit-cmd.js +142 -0
  35. package/dist/cli/admit-cmd.js.map +1 -0
  36. package/dist/cli/check-cmd.d.ts +72 -0
  37. package/dist/cli/check-cmd.d.ts.map +1 -0
  38. package/dist/cli/check-cmd.js +316 -0
  39. package/dist/cli/check-cmd.js.map +1 -0
  40. package/dist/cli/index.d.ts.map +1 -1
  41. package/dist/cli/index.js +6 -4
  42. package/dist/cli/index.js.map +1 -1
  43. package/dist/cli/lisa-test-run-admission.d.ts +18 -0
  44. package/dist/cli/lisa-test-run-admission.d.ts.map +1 -0
  45. package/dist/cli/lisa-test-run-admission.js +62 -0
  46. package/dist/cli/lisa-test-run-admission.js.map +1 -0
  47. package/dist/cli/lisa-test-run-payload.d.ts +37 -0
  48. package/dist/cli/lisa-test-run-payload.d.ts.map +1 -0
  49. package/dist/cli/lisa-test-run-payload.js +55 -0
  50. package/dist/cli/lisa-test-run-payload.js.map +1 -0
  51. package/dist/cli/lisa-test-run-shard-files.d.ts +89 -0
  52. package/dist/cli/lisa-test-run-shard-files.d.ts.map +1 -0
  53. package/dist/cli/lisa-test-run-shard-files.js +239 -0
  54. package/dist/cli/lisa-test-run-shard-files.js.map +1 -0
  55. package/dist/cli/lisa-test-run-shard.d.ts +6 -2
  56. package/dist/cli/lisa-test-run-shard.d.ts.map +1 -1
  57. package/dist/cli/lisa-test-run-shard.js +25 -13
  58. package/dist/cli/lisa-test-run-shard.js.map +1 -1
  59. package/dist/cli/lisa-test-run.d.ts +1 -1
  60. package/dist/cli/lisa-test-run.d.ts.map +1 -1
  61. package/dist/cli/lisa-test-run.js +47 -10
  62. package/dist/cli/lisa-test-run.js.map +1 -1
  63. package/dist/cli/update-check-hook.d.ts.map +1 -1
  64. package/dist/cli/update-check-hook.js +3 -0
  65. package/dist/cli/update-check-hook.js.map +1 -1
  66. package/dist/configs/vitest/base.d.ts +58 -135
  67. package/dist/configs/vitest/base.d.ts.map +1 -1
  68. package/dist/configs/vitest/base.js +76 -228
  69. package/dist/configs/vitest/base.js.map +1 -1
  70. package/dist/configs/vitest/cdk.d.ts.map +1 -1
  71. package/dist/configs/vitest/cdk.js +3 -2
  72. package/dist/configs/vitest/cdk.js.map +1 -1
  73. package/dist/configs/vitest/coverage-include-global-setup.d.ts.map +1 -1
  74. package/dist/configs/vitest/coverage-include-global-setup.js +3 -4
  75. package/dist/configs/vitest/coverage-include-global-setup.js.map +1 -1
  76. package/dist/configs/vitest/coverage-reports-directory.d.ts +27 -5
  77. package/dist/configs/vitest/coverage-reports-directory.d.ts.map +1 -1
  78. package/dist/configs/vitest/coverage-reports-directory.js +47 -10
  79. package/dist/configs/vitest/coverage-reports-directory.js.map +1 -1
  80. package/dist/configs/vitest/harper-fabric.d.ts.map +1 -1
  81. package/dist/configs/vitest/harper-fabric.js +3 -2
  82. package/dist/configs/vitest/harper-fabric.js.map +1 -1
  83. package/dist/configs/vitest/nestjs.d.ts.map +1 -1
  84. package/dist/configs/vitest/nestjs.js +3 -2
  85. package/dist/configs/vitest/nestjs.js.map +1 -1
  86. package/dist/configs/vitest/phaser.d.ts.map +1 -1
  87. package/dist/configs/vitest/phaser.js +3 -2
  88. package/dist/configs/vitest/phaser.js.map +1 -1
  89. package/dist/configs/vitest/refusal-announcement.d.ts +51 -0
  90. package/dist/configs/vitest/refusal-announcement.d.ts.map +1 -0
  91. package/dist/configs/vitest/refusal-announcement.js +97 -0
  92. package/dist/configs/vitest/refusal-announcement.js.map +1 -0
  93. package/dist/configs/vitest/socket-safe-temp-base.d.ts +3 -4
  94. package/dist/configs/vitest/socket-safe-temp-base.d.ts.map +1 -1
  95. package/dist/configs/vitest/socket-safe-temp-base.js +7 -6
  96. package/dist/configs/vitest/socket-safe-temp-base.js.map +1 -1
  97. package/dist/configs/vitest/typescript.d.ts.map +1 -1
  98. package/dist/configs/vitest/typescript.js +3 -2
  99. package/dist/configs/vitest/typescript.js.map +1 -1
  100. package/dist/core/admission-decision.d.ts +110 -0
  101. package/dist/core/admission-decision.d.ts.map +1 -0
  102. package/dist/core/admission-decision.js +91 -0
  103. package/dist/core/admission-decision.js.map +1 -0
  104. package/dist/core/admission-lock.d.ts +69 -0
  105. package/dist/core/admission-lock.d.ts.map +1 -0
  106. package/dist/core/admission-lock.js +278 -0
  107. package/dist/core/admission-lock.js.map +1 -0
  108. package/dist/core/admission-settings.d.ts +69 -0
  109. package/dist/core/admission-settings.d.ts.map +1 -0
  110. package/dist/core/admission-settings.js +204 -0
  111. package/dist/core/admission-settings.js.map +1 -0
  112. package/dist/core/admission-state.d.ts +50 -0
  113. package/dist/core/admission-state.d.ts.map +1 -0
  114. package/dist/core/admission-state.js +168 -0
  115. package/dist/core/admission-state.js.map +1 -0
  116. package/dist/core/admission.d.ts +70 -0
  117. package/dist/core/admission.d.ts.map +1 -0
  118. package/dist/core/admission.js +205 -0
  119. package/dist/core/admission.js.map +1 -0
  120. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  121. package/dist/core/lisa-owned-hash-ledger.js +318 -0
  122. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  123. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  124. package/dist/core/project-config-push-gate.d.ts +66 -0
  125. package/dist/core/project-config-push-gate.d.ts.map +1 -0
  126. package/dist/core/project-config-push-gate.js +82 -0
  127. package/dist/core/project-config-push-gate.js.map +1 -0
  128. package/dist/core/project-config.d.ts +4 -0
  129. package/dist/core/project-config.d.ts.map +1 -1
  130. package/dist/core/project-config.js +14 -9
  131. package/dist/core/project-config.js.map +1 -1
  132. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  133. package/dist/core/upstream-evidence-manifest.js +197 -123
  134. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  135. package/expo/package-lisa/package.lisa.json +2 -2
  136. package/harper-fabric/package-lisa/package.lisa.json +4 -4
  137. package/nestjs/create-only/vitest.config.local.ts +1 -7
  138. package/nestjs/package-lisa/package.lisa.json +4 -4
  139. package/npm-package/package-lisa/package.lisa.json +4 -4
  140. package/package.json +12 -11
  141. package/phaser/package-lisa/package.lisa.json +4 -4
  142. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  143. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  144. package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  145. package/plugins/lisa/.codex-plugin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  146. package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +1 -1
  147. package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  148. package/plugins/lisa/skills/lisa-git-submit-pr/SKILL.md +1 -1
  149. package/plugins/lisa/skills/lisa-implement/SKILL.md +1 -1
  150. package/plugins/lisa-agy/plugin.json +1 -1
  151. package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  152. package/plugins/lisa-agy/skills/lisa-git-submit-pr/SKILL.md +1 -1
  153. package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +1 -1
  154. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  155. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  156. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  157. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  159. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  160. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  161. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  162. package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  163. package/plugins/lisa-copilot/skills/lisa-git-submit-pr/SKILL.md +1 -1
  164. package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +1 -1
  165. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  166. package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  167. package/plugins/lisa-cursor/skills/lisa-git-submit-pr/SKILL.md +1 -1
  168. package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +1 -1
  169. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  170. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  171. package/plugins/lisa-devin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  172. package/plugins/lisa-devin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  173. package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +1 -1
  174. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  175. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  176. package/plugins/lisa-expo-agy/plugin.json +1 -1
  177. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  178. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  179. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  180. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  181. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  182. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  183. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  184. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  185. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  186. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  187. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  188. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  189. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  190. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  191. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  192. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  193. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  194. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  195. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  196. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  197. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  198. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  199. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  200. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  201. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  202. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  203. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  204. package/plugins/lisa-rails-agy/plugin.json +1 -1
  205. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  206. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  207. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  208. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  209. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  210. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  211. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  212. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  213. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  214. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  215. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  216. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  217. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  218. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  219. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  220. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  221. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  222. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  223. package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  224. package/plugins/src/base/skills/lisa-git-submit-pr/SKILL.md +1 -1
  225. package/plugins/src/base/skills/lisa-implement/SKILL.md +1 -1
  226. package/rails/copy-overwrite/Gemfile.lisa +8 -0
  227. package/rails/copy-overwrite/lefthook.yml +25 -11
  228. package/rails/copy-overwrite/scripts/lisa-rails-gates.mjs +686 -0
  229. package/rails/copy-overwrite/scripts/lisa-rspec-shards.mjs +2 -2
  230. package/rails/copy-overwrite/scripts/lisa_crystalball_recorder.rb +239 -0
  231. package/rails/copy-overwrite/scripts/lisa_rspec_partial_coverage.rb +83 -0
  232. package/scripts/build-unless-marked.mjs +83 -0
  233. package/scripts/check-plugins-sync.sh +22 -5
  234. package/scripts/classify-markdown-assertions.mjs +141 -0
  235. package/scripts/integration-shard-build.mjs +143 -0
  236. package/scripts/lib/history-scanner-suites.mjs +19 -0
  237. package/scripts/lib/markdown-assertions/classify.mjs +289 -0
  238. package/scripts/lib/markdown-assertions/context.mjs +53 -0
  239. package/scripts/lib/markdown-assertions/corpus.mjs +222 -0
  240. package/scripts/lib/markdown-assertions/manifest-cull.mjs +86 -0
  241. package/scripts/lib/markdown-assertions/record-setup.mjs +265 -0
  242. package/scripts/lib/markdown-assertions/record.mjs +115 -0
  243. package/scripts/lib/markdown-assertions/record.vitest.config.mjs +24 -0
  244. package/scripts/lib/markdown-assertions/sites.mjs +273 -0
  245. package/scripts/lib/markdown-assertions/test-cull.mjs +768 -0
  246. package/scripts/lib/markdown-assertions/tokens.mjs +158 -0
  247. package/scripts/lib/shell-guard-trace.mjs +6 -0
  248. package/scripts/lib/test-access-map-setup.mjs +40 -0
  249. package/scripts/lib/test-access-map-tracer.mjs +205 -0
  250. package/scripts/lib/test-access-map.d.mts +72 -0
  251. package/scripts/lib/test-access-map.mjs +395 -0
  252. package/scripts/lib/test-timings-reporter.d.mts +17 -0
  253. package/scripts/lib/test-timings-reporter.mjs +99 -0
  254. package/scripts/plan-integration-shards.mjs +300 -0
  255. package/scripts/test-timing-report.d.mts +41 -0
  256. package/scripts/test-timing-report.mjs +361 -0
  257. package/scripts/two-channel-couplings.json +132 -36
  258. package/scripts/verify-npm-advisories-4333.mjs +3 -12
  259. package/typescript/copy-overwrite/.prettierignore +12 -0
  260. package/typescript/create-only/vitest.config.local.ts +1 -7
  261. package/typescript/package-lisa/package.lisa.json +4 -4
  262. package/all/copy-overwrite/scripts/lisa-scratch-run.sh +0 -1078
  263. package/dist/cli/lisa-test-run-bootstrap.d.ts +0 -3
  264. package/dist/cli/lisa-test-run-bootstrap.d.ts.map +0 -1
  265. package/dist/cli/lisa-test-run-bootstrap.js +0 -229
  266. package/dist/cli/lisa-test-run-bootstrap.js.map +0 -1
  267. package/dist/cli/lisa-test-run-ipc.d.ts +0 -49
  268. package/dist/cli/lisa-test-run-ipc.d.ts.map +0 -1
  269. package/dist/cli/lisa-test-run-ipc.js +0 -226
  270. package/dist/cli/lisa-test-run-ipc.js.map +0 -1
  271. package/dist/cli/lisa-test-run-process-group.d.ts +0 -30
  272. package/dist/cli/lisa-test-run-process-group.d.ts.map +0 -1
  273. package/dist/cli/lisa-test-run-process-group.js +0 -140
  274. package/dist/cli/lisa-test-run-process-group.js.map +0 -1
  275. package/dist/cli/lisa-test-run-reaper.d.ts +0 -3
  276. package/dist/cli/lisa-test-run-reaper.d.ts.map +0 -1
  277. package/dist/cli/lisa-test-run-reaper.js +0 -195
  278. package/dist/cli/lisa-test-run-reaper.js.map +0 -1
  279. package/dist/cli/lisa-test-run-runtime.d.ts +0 -46
  280. package/dist/cli/lisa-test-run-runtime.d.ts.map +0 -1
  281. package/dist/cli/lisa-test-run-runtime.js +0 -123
  282. package/dist/cli/lisa-test-run-runtime.js.map +0 -1
  283. package/dist/cli/lisa-test-run-supervisor.d.ts +0 -13
  284. package/dist/cli/lisa-test-run-supervisor.d.ts.map +0 -1
  285. package/dist/cli/lisa-test-run-supervisor.js +0 -265
  286. package/dist/cli/lisa-test-run-supervisor.js.map +0 -1
  287. package/dist/configs/vitest/fleet-admission-global-setup.d.ts +0 -34
  288. package/dist/configs/vitest/fleet-admission-global-setup.d.ts.map +0 -1
  289. package/dist/configs/vitest/fleet-admission-global-setup.js +0 -123
  290. package/dist/configs/vitest/fleet-admission-global-setup.js.map +0 -1
  291. package/dist/configs/vitest/fleet-admission.d.ts +0 -129
  292. package/dist/configs/vitest/fleet-admission.d.ts.map +0 -1
  293. package/dist/configs/vitest/fleet-admission.js +0 -239
  294. package/dist/configs/vitest/fleet-admission.js.map +0 -1
  295. package/dist/configs/vitest/scratch-authority.d.ts +0 -25
  296. package/dist/configs/vitest/scratch-authority.d.ts.map +0 -1
  297. package/dist/configs/vitest/scratch-authority.js +0 -107
  298. package/dist/configs/vitest/scratch-authority.js.map +0 -1
  299. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts +0 -5
  300. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts.map +0 -1
  301. package/dist/configs/vitest/scratch-bound-cleanup-programs.js +0 -219
  302. package/dist/configs/vitest/scratch-bound-cleanup-programs.js.map +0 -1
  303. package/dist/configs/vitest/scratch-bound-cleanup.d.ts +0 -28
  304. package/dist/configs/vitest/scratch-bound-cleanup.d.ts.map +0 -1
  305. package/dist/configs/vitest/scratch-bound-cleanup.js +0 -155
  306. package/dist/configs/vitest/scratch-bound-cleanup.js.map +0 -1
  307. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts +0 -17
  308. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts.map +0 -1
  309. package/dist/configs/vitest/scratch-bound-root-cleanup.js +0 -149
  310. package/dist/configs/vitest/scratch-bound-root-cleanup.js.map +0 -1
  311. package/dist/configs/vitest/scratch-global-setup.d.ts +0 -258
  312. package/dist/configs/vitest/scratch-global-setup.d.ts.map +0 -1
  313. package/dist/configs/vitest/scratch-global-setup.js +0 -505
  314. package/dist/configs/vitest/scratch-global-setup.js.map +0 -1
  315. package/dist/configs/vitest/scratch-leak-setup.d.ts +0 -2
  316. package/dist/configs/vitest/scratch-leak-setup.d.ts.map +0 -1
  317. package/dist/configs/vitest/scratch-leak-setup.js +0 -108
  318. package/dist/configs/vitest/scratch-leak-setup.js.map +0 -1
  319. package/dist/configs/vitest/scratch-namespace-authority.d.ts +0 -80
  320. package/dist/configs/vitest/scratch-namespace-authority.d.ts.map +0 -1
  321. package/dist/configs/vitest/scratch-namespace-authority.js +0 -291
  322. package/dist/configs/vitest/scratch-namespace-authority.js.map +0 -1
  323. package/dist/configs/vitest/scratch-owner.d.ts +0 -131
  324. package/dist/configs/vitest/scratch-owner.d.ts.map +0 -1
  325. package/dist/configs/vitest/scratch-owner.js +0 -297
  326. package/dist/configs/vitest/scratch-owner.js.map +0 -1
  327. package/dist/configs/vitest/scratch-route-profile.d.ts +0 -46
  328. package/dist/configs/vitest/scratch-route-profile.d.ts.map +0 -1
  329. package/dist/configs/vitest/scratch-route-profile.js +0 -233
  330. package/dist/configs/vitest/scratch-route-profile.js.map +0 -1
  331. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts +0 -33
  332. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts.map +0 -1
  333. package/dist/configs/vitest/scratch-run-root-compatibility.js +0 -137
  334. package/dist/configs/vitest/scratch-run-root-compatibility.js.map +0 -1
  335. package/dist/configs/vitest/scratch-run-root-intent.d.ts +0 -66
  336. package/dist/configs/vitest/scratch-run-root-intent.d.ts.map +0 -1
  337. package/dist/configs/vitest/scratch-run-root-intent.js +0 -183
  338. package/dist/configs/vitest/scratch-run-root-intent.js.map +0 -1
  339. package/dist/configs/vitest/scratch-setup.d.ts +0 -46
  340. package/dist/configs/vitest/scratch-setup.d.ts.map +0 -1
  341. package/dist/configs/vitest/scratch-setup.js +0 -226
  342. package/dist/configs/vitest/scratch-setup.js.map +0 -1
  343. package/dist/configs/vitest/scratch-supervision-intent.d.ts +0 -8
  344. package/dist/configs/vitest/scratch-supervision-intent.d.ts.map +0 -1
  345. package/dist/configs/vitest/scratch-supervision-intent.js +0 -125
  346. package/dist/configs/vitest/scratch-supervision-intent.js.map +0 -1
  347. package/dist/configs/vitest/scratch-supervision-protocol.d.ts +0 -12
  348. package/dist/configs/vitest/scratch-supervision-protocol.d.ts.map +0 -1
  349. package/dist/configs/vitest/scratch-supervision-protocol.js +0 -230
  350. package/dist/configs/vitest/scratch-supervision-protocol.js.map +0 -1
  351. package/dist/configs/vitest/scratch-supervision.d.ts +0 -69
  352. package/dist/configs/vitest/scratch-supervision.d.ts.map +0 -1
  353. package/dist/configs/vitest/scratch-supervision.js +0 -244
  354. package/dist/configs/vitest/scratch-supervision.js.map +0 -1
  355. package/dist/configs/vitest/scratch-sweep.d.ts +0 -66
  356. package/dist/configs/vitest/scratch-sweep.d.ts.map +0 -1
  357. package/dist/configs/vitest/scratch-sweep.js +0 -82
  358. package/dist/configs/vitest/scratch-sweep.js.map +0 -1
  359. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts +0 -48
  360. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts.map +0 -1
  361. package/dist/configs/vitest/scratch-tmpdir-trust.js +0 -194
  362. package/dist/configs/vitest/scratch-tmpdir-trust.js.map +0 -1
  363. package/dist/configs/vitest/scratch.d.ts +0 -19
  364. package/dist/configs/vitest/scratch.d.ts.map +0 -1
  365. package/dist/configs/vitest/scratch.js +0 -34
  366. package/dist/configs/vitest/scratch.js.map +0 -1
  367. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts +0 -86
  368. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts.map +0 -1
  369. package/dist/configs/vitest/synthesis-scratch-reclaim.js +0 -226
  370. package/dist/configs/vitest/synthesis-scratch-reclaim.js.map +0 -1
@@ -0,0 +1,818 @@
1
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
2
+ // Do not edit directly — durable changes belong upstream in Lisa.
3
+
4
+ /**
5
+ * Run only the tests a change can affect, at push (CodySwannGT/lisa#4600).
6
+ *
7
+ * The push gate used to run the whole unit suite for any change, a one-line
8
+ * edit included. This module decides, from the files a branch changed and the
9
+ * test-to-file access map CI records (CodySwannGT/lisa#4593), which test files
10
+ * can see the change. Everything here is a pure function of its inputs; the
11
+ * effects (git, the map download, spawning the suite) live in
12
+ * `scripts/lisa-affected-tests.mjs`.
13
+ *
14
+ * The rule it never breaks: when the selection could be wrong it runs the
15
+ * FULL suite and says why. A missing, stale or unreadable map, a changed file
16
+ * the map has never seen, a change to shared test machinery or tool config,
17
+ * running in CI — each one is a reason to run everything, never a reason to
18
+ * run nothing.
19
+ *
20
+ * It is off unless `pushGate.affectedTests` is true. A TypeScript project gets
21
+ * it, and `affectedCoverage: "changed-files"`, by default
22
+ * (`lib/push-gate-defaults.mjs`, CodySwannGT/lisa#4611); this module only ever
23
+ * sees the config with those defaults already applied.
24
+ * `pushGate.affectedCoverage` says what a partial run does about the
25
+ * coverage-adequacy gate at push:
26
+ *
27
+ * - `full` (default): coverage-adequacy declared at push keeps the full,
28
+ * coverage-measured suite, so selection only speeds up test-correctness
29
+ * where coverage-adequacy is not declared at push.
30
+ * - `changed-files`: the selected tests run with coverage on, and each changed
31
+ * source file is held to the project's thresholds on its own. When every
32
+ * one meets them the partial run passes; when one does not, the push is
33
+ * never failed on that alone: it escalates to the full suite with
34
+ * whole-repo coverage, as `full` runs it, and that verdict decides.
35
+ * - `skip`: the selected tests run without coverage and coverage-adequacy
36
+ * reports SKIPPED, "partial selection — enforced by CI".
37
+ *
38
+ * CI's own run of the suites is untouched, so merge protection is unchanged.
39
+ * @module affected-tests
40
+ */
41
+ import { createHash } from "node:crypto";
42
+ import { mkdtempSync, readFileSync, rmSync } from "node:fs";
43
+ import { tmpdir } from "node:os";
44
+ import { join } from "node:path";
45
+
46
+ /** The `pushGate` key that switches selection on. */
47
+ export const AFFECTED_TESTS_KEY = "affectedTests";
48
+
49
+ /** The `pushGate` key that says how a partial run treats coverage. */
50
+ export const AFFECTED_COVERAGE_KEY = "affectedCoverage";
51
+
52
+ /** Every coverage mode, default first. */
53
+ export const COVERAGE_MODES = Object.freeze(["full", "changed-files", "skip"]);
54
+
55
+ /** The environment variable through which the gate runner asks for a report. */
56
+ export const SELECTION_REPORT_ENV = "LISA_SELECTION_REPORT";
57
+
58
+ /** Overrides the seven-day map age limit. */
59
+ export const MAX_AGE_ENV = "LISA_ACCESS_MAP_MAX_AGE_DAYS";
60
+
61
+ /** How old a map may be before it counts as stale. */
62
+ export const DEFAULT_MAX_AGE_DAYS = 7;
63
+
64
+ /** The SKIPPED reason coverage-adequacy reports in `skip` mode. */
65
+ export const PARTIAL_COVERAGE_SKIP_REASON =
66
+ "partial selection — enforced by CI";
67
+
68
+ /**
69
+ * Changes that make any selection untrustworthy, so the full suite runs.
70
+ *
71
+ * One exported list so the TypeScript and Rails host templates (#4611,
72
+ * #4612) reuse it instead of restating it. Each entry names, in plain words,
73
+ * why a change to it reaches tests no map can point at.
74
+ */
75
+ export const FULL_SUITE_TRIGGERS = Object.freeze([
76
+ {
77
+ pattern: /(^|\/)package\.json$/,
78
+ reason: "package.json changed (dependencies or scripts)",
79
+ },
80
+ {
81
+ pattern:
82
+ /(^|\/)(bun\.lockb?|package-lock\.json|pnpm-lock\.yaml|yarn\.lock|Gemfile\.lock)$/,
83
+ reason: "a lockfile changed (installed dependencies)",
84
+ },
85
+ {
86
+ pattern: /(^|\/)vitest\.(config[^/]*\.[cm]?[jt]s|thresholds\.json)$/,
87
+ reason: "the Vitest configuration changed",
88
+ },
89
+ {
90
+ pattern: /(^|\/)tsconfig[^/]*\.json$/,
91
+ reason: "the TypeScript configuration changed",
92
+ },
93
+ {
94
+ pattern: /(^|\/)eslint[^/]*\.config\.[cm]?[jt]s$/,
95
+ reason: "the ESLint configuration changed",
96
+ },
97
+ {
98
+ pattern: /(^|\/)vite\.config[^/]*\.[cm]?[jt]s$/,
99
+ reason: "the Vite configuration changed",
100
+ },
101
+ {
102
+ pattern: /^tests\/(helpers|support|fixtures|integration\/support)\//,
103
+ reason: "shared test helpers, support code or fixtures changed",
104
+ },
105
+ {
106
+ // Any test root, in a host's own layout (CodySwannGT/lisa#4611): a shared
107
+ // helper is read by tests the map may not have seen import it directly.
108
+ pattern:
109
+ /(^|\/)(tests?|__tests__|specs?)\/(.+\/)?(__fixtures__|fixtures|helpers|support|setup)\//,
110
+ reason: "shared test helpers, support code, setup or fixtures changed",
111
+ },
112
+ {
113
+ pattern: /(^|\/)__fixtures__\//,
114
+ reason: "shared test fixtures changed",
115
+ },
116
+ {
117
+ pattern: /^src\/configs\/vitest\//,
118
+ reason: "the shipped Vitest presets changed",
119
+ },
120
+ {
121
+ pattern:
122
+ /(^|\/)scripts\/(lisa-affected-tests\.mjs|lib\/affected-tests\.mjs|lib\/test-access-map[^/]*\.mjs|lib\/push-gate-defaults\.mjs|fetch-test-access-map\.mjs)$/,
123
+ reason: "the test-selection machinery itself changed",
124
+ },
125
+ ]);
126
+
127
+ /** A file Vitest, Jest or RSpec would collect as a test. */
128
+ const TEST_FILE = /(^|\/)[^/]+(\.(test|spec)\.[cm]?[jt]sx?|_spec\.rb)$/;
129
+
130
+ /**
131
+ * Read and validate the selection settings from a parsed `.lisa.config.json`.
132
+ *
133
+ * A wrong type is refused rather than defaulted: a typo must not silently
134
+ * switch selection on, or silently move coverage enforcement off the push.
135
+ * @param {Record<string, unknown>|null|undefined} config Parsed config.
136
+ * @returns {{enabled: boolean, coverage: "full"|"changed-files"|"skip"}} Settings.
137
+ * @throws {Error} When `pushGate`, `affectedTests` or `affectedCoverage` is invalid.
138
+ */
139
+ export function affectedTestsSettings(config) {
140
+ const block = config?.pushGate;
141
+ if (block === undefined) return { enabled: false, coverage: "full" };
142
+ if (block === null || typeof block !== "object" || Array.isArray(block)) {
143
+ throw new Error(
144
+ `pushGate is ${JSON.stringify(block)}; expected an object such as ` +
145
+ `{ "${AFFECTED_TESTS_KEY}": true }.`
146
+ );
147
+ }
148
+ const enabled = block[AFFECTED_TESTS_KEY] ?? false;
149
+ if (typeof enabled !== "boolean") {
150
+ throw new Error(
151
+ `pushGate.${AFFECTED_TESTS_KEY} is ${JSON.stringify(enabled)}; expected true or false.`
152
+ );
153
+ }
154
+ const coverage = block[AFFECTED_COVERAGE_KEY] ?? COVERAGE_MODES[0];
155
+ if (!COVERAGE_MODES.includes(coverage)) {
156
+ throw new Error(
157
+ `pushGate.${AFFECTED_COVERAGE_KEY} is ${JSON.stringify(coverage)}; ` +
158
+ `expected one of ${COVERAGE_MODES.map(mode => `"${mode}"`).join(", ")}.`
159
+ );
160
+ }
161
+ return { enabled, coverage };
162
+ }
163
+
164
+ /**
165
+ * Whether `gates["coverage-adequacy"]` is declared (and not `off`) at push.
166
+ * @param {Record<string, unknown>|null|undefined} gates The gates block.
167
+ * @returns {boolean} True when the push gate must prove coverage.
168
+ */
169
+ export function coverageDeclaredAtPush(gates) {
170
+ const gate = gates?.["coverage-adequacy"];
171
+ if (!gate || typeof gate !== "object") return false;
172
+ const atPush = gate.push;
173
+ const level = atPush && typeof atPush === "object" ? atPush.level : atPush;
174
+ return typeof level === "string" && level !== "off";
175
+ }
176
+
177
+ /**
178
+ * The first trigger any changed file fires, or null.
179
+ * @param {ReadonlyArray<string>} changed Repository-relative changed paths.
180
+ * @param {ReadonlyArray<{pattern: RegExp, reason: string}>} [extra] The project's recorded triggers.
181
+ * @returns {{file: string, reason: string}|null} The trigger.
182
+ */
183
+ export function firedTrigger(changed, extra = []) {
184
+ const triggers = [...FULL_SUITE_TRIGGERS, ...extra];
185
+ for (const file of changed) {
186
+ const trigger = triggers.find(entry => entry.pattern.test(file));
187
+ if (trigger) return { file, reason: trigger.reason };
188
+ }
189
+ return null;
190
+ }
191
+
192
+ /** Why a trigger recorded from the project's resolved Vitest config fires. */
193
+ export const RECORDED_TRIGGER_REASON =
194
+ "a file the project's Vitest config names as a full-rerun trigger, setup file or global setup changed";
195
+
196
+ /**
197
+ * The project's own triggers, recorded with the map from its resolved Vitest
198
+ * config (`forceRerunTriggers`, `setupFiles`, `globalSetup`), as matchers.
199
+ *
200
+ * The host's merged config is only known to Vitest, so the recorder writes
201
+ * these repository-relative globs into the map's metadata and the selector
202
+ * honours them here. A missing or malformed list adds nothing: the built-in
203
+ * triggers still apply.
204
+ * @param {{triggers?: unknown}|null|undefined} meta The map's meta.json.
205
+ * @returns {Array<{pattern: RegExp, reason: string}>} Extra triggers.
206
+ */
207
+ export function recordedTriggers(meta) {
208
+ const globs = Array.isArray(meta?.triggers) ? meta.triggers : [];
209
+ return globs
210
+ .filter(glob => typeof glob === "string" && glob !== "")
211
+ .flatMap(expandBraces)
212
+ .map(glob => ({
213
+ // A trailing `/**` (Vitest writes `**/package.json/**`) matches the
214
+ // path itself or anything under it.
215
+ pattern: glob.endsWith("/**")
216
+ ? new RegExp(
217
+ globToRegExp(glob.slice(0, -3)).source.replace(/\$$/, "(?:/.*)?$")
218
+ )
219
+ : globToRegExp(glob),
220
+ reason: `${RECORDED_TRIGGER_REASON} (${glob})`,
221
+ }));
222
+ }
223
+
224
+ /**
225
+ * Expand `{a,b}` alternatives, as Vitest's own trigger globs use them.
226
+ * @param {string} glob A glob.
227
+ * @returns {string[]} One glob per alternative.
228
+ */
229
+ export function expandBraces(glob) {
230
+ const match = /\{([^{}]*)\}/.exec(glob);
231
+ if (!match) return [glob];
232
+ const [whole, body] = match;
233
+ return body
234
+ .split(",")
235
+ .flatMap(choice =>
236
+ expandBraces(
237
+ glob.slice(0, match.index) +
238
+ choice +
239
+ glob.slice(match.index + whole.length)
240
+ )
241
+ );
242
+ }
243
+
244
+ /**
245
+ * Whether a test command can be narrowed: it must be a `vitest run`.
246
+ *
247
+ * Jest stacks (Expo) and anything else run unchanged with a printed reason,
248
+ * never with a rewrite the runner would misread (CodySwannGT/lisa#4519).
249
+ * @param {ReadonlyArray<string>} argv The test command.
250
+ * @returns {boolean} True for a `vitest run` command.
251
+ */
252
+ export function narrowable(argv) {
253
+ return argv.some(
254
+ (arg, index) => /(^|\/)vitest$/.test(arg) && argv[index + 1] === "run"
255
+ );
256
+ }
257
+
258
+ /**
259
+ * A glob as written in a test command's `--exclude` (`**`, `*`, `?`).
260
+ * @param {string} glob The glob.
261
+ * @returns {RegExp} An anchored matcher for repository-relative paths.
262
+ */
263
+ export function globToRegExp(glob) {
264
+ const source = glob
265
+ .replace(/^\.\//, "")
266
+ .split(/(\*\*\/|\*\*|\*|\?)/)
267
+ .map(part => {
268
+ if (part === "**/") return "(?:.*/)?";
269
+ if (part === "**") return ".*";
270
+ if (part === "*") return "[^/]*";
271
+ if (part === "?") return "[^/]";
272
+ return part.replace(/[.+^${}()|[\]\\]/g, "\\$&");
273
+ })
274
+ .join("");
275
+ return new RegExp(`^${source}$`);
276
+ }
277
+
278
+ /**
279
+ * The `--exclude` globs a test command passes, as matchers.
280
+ * @param {ReadonlyArray<string>} argv The test command.
281
+ * @returns {RegExp[]} Matchers.
282
+ */
283
+ export function excludedBy(argv) {
284
+ return argv.flatMap((arg, index) => {
285
+ if (arg.startsWith("--exclude=")) {
286
+ return [globToRegExp(arg.slice("--exclude=".length))];
287
+ }
288
+ if (arg === "--exclude" && argv[index + 1] !== undefined) {
289
+ return [globToRegExp(argv[index + 1])];
290
+ }
291
+ return [];
292
+ });
293
+ }
294
+
295
+ /**
296
+ * Whether the map describes the tree this push builds on.
297
+ *
298
+ * Stale means: recorded for a base that is not the merge-base or an ancestor
299
+ * of it, or recorded longer ago than the age limit. A map with no creation
300
+ * time cannot be aged, so it is stale too.
301
+ * @param {object} input Inputs.
302
+ * @param {{baseSha?: string, createdAt?: string}|null} input.meta The map's meta.json.
303
+ * @param {string} input.mergeBase The merge-base of this branch.
304
+ * @param {(ancestor: string, descendant: string) => boolean} input.isAncestor Git ancestry.
305
+ * @param {Date} input.now The current time.
306
+ * @param {number} input.maxAgeDays The age limit.
307
+ * @returns {string|null} Why the map cannot be used, or null when it can.
308
+ */
309
+ export function staleMapReason({
310
+ meta,
311
+ mergeBase,
312
+ isAncestor,
313
+ now,
314
+ maxAgeDays,
315
+ }) {
316
+ const base = typeof meta?.baseSha === "string" ? meta.baseSha : "";
317
+ if (base === "")
318
+ return "stale map: it does not say which commit it was recorded for";
319
+ if (base !== mergeBase && !isAncestor(base, mergeBase)) {
320
+ return `stale map: it was recorded for ${base.slice(0, 12)}, which is not this branch's base or an ancestor of it`;
321
+ }
322
+ const created = Date.parse(String(meta?.createdAt ?? ""));
323
+ if (Number.isNaN(created)) {
324
+ return "stale map: it does not say when it was recorded";
325
+ }
326
+ const ageDays = (now.getTime() - created) / 86_400_000;
327
+ if (ageDays > maxAgeDays) {
328
+ return `stale map: it is ${ageDays.toFixed(1)} days old, and the limit is ${maxAgeDays}`;
329
+ }
330
+ return null;
331
+ }
332
+
333
+ /**
334
+ * Which repository files each test file read, inverted: file -> test files.
335
+ * @param {Readonly<Record<string, ReadonlyArray<string>>>} map The access map.
336
+ * @returns {Map<string, Set<string>>} Readers per file.
337
+ */
338
+ export function readersByFile(map) {
339
+ const readers = new Map();
340
+ for (const [test, files] of Object.entries(map)) {
341
+ for (const file of [test, ...files]) {
342
+ const set = readers.get(file) ?? new Set();
343
+ set.add(test);
344
+ readers.set(file, set);
345
+ }
346
+ }
347
+ return readers;
348
+ }
349
+
350
+ /**
351
+ * @typedef {object} ChangedFile
352
+ * @property {string} path Repository-relative path.
353
+ * @property {"added"|"modified"|"deleted"} status What the branch did to it.
354
+ * @property {boolean} existedAtMapBase Whether it existed when the map was recorded.
355
+ */
356
+
357
+ /**
358
+ * @typedef {object} Selection
359
+ * @property {"full"|"partial"} kind Which run to do.
360
+ * @property {string} [reason] Why the full suite runs (kind `full`).
361
+ * @property {Array<{file: string, reason: string}>} tests Test files to run, with why.
362
+ * @property {string[]} related Changed files handed to the runner's import-graph selection.
363
+ * @property {string[]} unread Changed documents no unit test read when the map was recorded.
364
+ */
365
+
366
+ /**
367
+ * Documents no test can reach through a path the recording misses, so a
368
+ * change to one that no test was recorded reading needs no test. It is the
369
+ * Rails selector's list (`lib/rspec-selection.mjs`) narrowed to
370
+ * documentation: in a TypeScript host, Markdown under a template or skill
371
+ * directory is product, copied with `cp` and then read through a path the
372
+ * map never records.
373
+ */
374
+ export const NOT_READ_BY_TESTS = Object.freeze([
375
+ /^(LICENSE|CHANGELOG|README)[^/]*$/i,
376
+ /^(docs|wiki)\//,
377
+ ]);
378
+
379
+ /**
380
+ * Choose the tests a change can affect, or say why everything must run.
381
+ *
382
+ * Every hole the selection cannot see through fails closed (review of
383
+ * CodySwannGT/lisa#4600). A changed file that is not a document and that no
384
+ * test was recorded reading may still be reached through a path the tracer
385
+ * misses (`cp`, `readdir`, a shell `source`), so it runs the full suite. A
386
+ * test the map has never seen (added on the default branch after the
387
+ * recording) is always selected. A deleted test hands every file it read on
388
+ * as if that file had changed, so its coverage is still held to the floor.
389
+ * @param {object} input Inputs.
390
+ * @param {ReadonlyArray<ChangedFile>} input.changed Changed files.
391
+ * @param {Readonly<Record<string, ReadonlyArray<string>>>} input.map The access map.
392
+ * @param {ReadonlyArray<RegExp>} input.excluded Paths the test command excludes.
393
+ * @param {(file: string) => boolean} input.exists Whether a file is in the working tree.
394
+ * @param {ReadonlyArray<string>} input.testFiles Every file in the working tree; the tests among them the map lacks are selected.
395
+ * @param {ReadonlyArray<{pattern: RegExp, reason: string}>} [input.triggers] The project's recorded triggers.
396
+ * @returns {Selection} The selection.
397
+ */
398
+ export function selectAffectedTests({
399
+ changed,
400
+ map,
401
+ excluded,
402
+ exists,
403
+ testFiles,
404
+ triggers = [],
405
+ }) {
406
+ const isExcluded = file => excluded.some(pattern => pattern.test(file));
407
+ const runnable = file =>
408
+ TEST_FILE.test(file) && !isExcluded(file) && exists(file);
409
+ const trigger = firedTrigger(
410
+ changed.map(entry => entry.path),
411
+ triggers
412
+ );
413
+ if (trigger) {
414
+ return full(`${trigger.reason} (${trigger.file})`);
415
+ }
416
+ const inherited = inheritedFromDeletedTests({
417
+ changed,
418
+ map,
419
+ isExcluded,
420
+ exists,
421
+ triggers,
422
+ });
423
+ if (typeof inherited === "string") return full(inherited);
424
+ const readers = readersByFile(map);
425
+ const chosen = new Map();
426
+ const choose = (file, reason) => {
427
+ if (runnable(file) && !chosen.has(file)) chosen.set(file, reason);
428
+ };
429
+ const related = [];
430
+ const unread = [];
431
+ for (const entry of [...changed, ...inherited]) {
432
+ if (TEST_FILE.test(entry.path)) {
433
+ if (entry.status !== "deleted") choose(entry.path, "changed test");
434
+ continue;
435
+ }
436
+ const testsReading = readers.get(entry.path);
437
+ if (testsReading) {
438
+ for (const test of testsReading) choose(test, `map: ${entry.path}`);
439
+ } else if (entry.status !== "deleted" && !entry.existedAtMapBase) {
440
+ return full(
441
+ `unmapped file: ${entry.path} is new since the map was recorded, so no map entry can say which tests read it`
442
+ );
443
+ } else if (NOT_READ_BY_TESTS.some(pattern => pattern.test(entry.path))) {
444
+ // A document no test reads is imported by nothing either, so it is not
445
+ // handed to the import graph: a docs-only push runs nothing.
446
+ unread.push(entry.path);
447
+ continue;
448
+ } else {
449
+ return full(
450
+ `unread file: ${entry.path} is in the map's tree but no test was recorded reading it, and a test may still reach it in a way the recording cannot see (a copy, a directory listing, a shell script)`
451
+ );
452
+ }
453
+ if (entry.status !== "deleted") related.push(entry.path);
454
+ }
455
+ for (const file of testFiles) {
456
+ if (!Object.hasOwn(map, file)) {
457
+ choose(
458
+ file,
459
+ "not in the map: added after the recording, or never recorded"
460
+ );
461
+ }
462
+ }
463
+ return {
464
+ kind: "partial",
465
+ tests: [...chosen].map(([file, reason]) => ({ file, reason })),
466
+ related,
467
+ unread,
468
+ };
469
+ }
470
+
471
+ /**
472
+ * The files the deleted tests read, as changes of their own.
473
+ *
474
+ * Deleting a test can only lower the coverage of what it read, so each of
475
+ * those files is handed on as a modified file: its remaining readers run and
476
+ * it is held to the floor. A setup or trigger file is read by every test, so
477
+ * one deletion cannot move its coverage; it is left out. When a deleted test
478
+ * is not in the map, or was the only test that read a file, only the full
479
+ * suite can say what coverage was lost.
480
+ * @param {object} input Inputs.
481
+ * @param {ReadonlyArray<ChangedFile>} input.changed Changed files.
482
+ * @param {Readonly<Record<string, ReadonlyArray<string>>>} input.map The access map.
483
+ * @param {(file: string) => boolean} input.isExcluded Whether the test command excludes a path.
484
+ * @param {(file: string) => boolean} input.exists Whether a file is in the working tree.
485
+ * @param {ReadonlyArray<{pattern: RegExp, reason: string}>} input.triggers The project's recorded triggers.
486
+ * @returns {ChangedFile[]|string} The inherited changes, or why the full suite must run.
487
+ */
488
+ function inheritedFromDeletedTests({
489
+ changed,
490
+ map,
491
+ isExcluded,
492
+ exists,
493
+ triggers,
494
+ }) {
495
+ const deleted = changed
496
+ .filter(
497
+ entry =>
498
+ entry.status === "deleted" &&
499
+ TEST_FILE.test(entry.path) &&
500
+ !isExcluded(entry.path)
501
+ )
502
+ .map(entry => entry.path);
503
+ const missing = deleted.find(test => !Object.hasOwn(map, test));
504
+ if (missing) {
505
+ return `deleted test: ${missing} is not in the map, so the files whose coverage it carried cannot be known`;
506
+ }
507
+ const gone = new Set(deleted);
508
+ const changedPaths = new Set(changed.map(entry => entry.path));
509
+ const readers = readersByFile(map);
510
+ const inherited = [];
511
+ for (const file of new Set(deleted.flatMap(test => map[test]))) {
512
+ if (
513
+ changedPaths.has(file) ||
514
+ TEST_FILE.test(file) ||
515
+ !exists(file) ||
516
+ firedTrigger([file], triggers)
517
+ ) {
518
+ continue;
519
+ }
520
+ const remaining = [...(readers.get(file) ?? [])].filter(
521
+ test => !gone.has(test) && !isExcluded(test) && exists(test)
522
+ );
523
+ if (remaining.length === 0) {
524
+ return `deleted test: it was the only test that read ${file}, so only the full suite can say what its coverage is now`;
525
+ }
526
+ inherited.push({ path: file, status: "modified", existedAtMapBase: true });
527
+ }
528
+ return inherited;
529
+ }
530
+
531
+ /**
532
+ * A full-suite selection.
533
+ * @param {string} reason Why.
534
+ * @returns {Selection} The selection.
535
+ */
536
+ function full(reason) {
537
+ return { kind: "full", reason, tests: [], related: [], unread: [] };
538
+ }
539
+
540
+ /**
541
+ * Whether a test command switches coverage on with a flag.
542
+ *
543
+ * Every spelling Vitest accepts counts (`--coverage`, `--coverage=true`,
544
+ * `--coverage.enabled`, `--coverage.enabled=true`), and the last one written
545
+ * wins over an earlier `--coverage=false`, `--coverage.enabled=false` or
546
+ * `--no-coverage`. Coverage switched on only in the Vitest config is not
547
+ * visible here; such a command reports coverage `none`, and the gate runner
548
+ * then reports a partial run's coverage-adequacy SKIPPED, never PASSED
549
+ * ({@link coverageLeftToCi}).
550
+ * @param {ReadonlyArray<string>} argv The test command.
551
+ * @returns {boolean} True when coverage is on.
552
+ */
553
+ export function measuresCoverage(argv) {
554
+ let on = false;
555
+ argv.forEach((arg, index) => {
556
+ const match = /^--coverage(?:\.enabled)?(?:=(.*))?$/.exec(arg);
557
+ if (match) {
558
+ const value = match[1] ?? (argv[index + 1] === "false" ? "false" : "");
559
+ on = value !== "false";
560
+ } else if (arg === "--no-coverage") {
561
+ on = false;
562
+ }
563
+ });
564
+ return on;
565
+ }
566
+
567
+ /**
568
+ * The full test command rewritten to run only the selection.
569
+ *
570
+ * `vitest run …` becomes `vitest related --run … <files>`: Vitest adds every
571
+ * test whose import graph reaches a changed file, and an explicitly passed
572
+ * test file is always run. Only the Vitest invocation is touched; whatever
573
+ * launches it (`bun run lisa-test-run -- --adapter vitest --`) is kept.
574
+ * @param {object} input Inputs.
575
+ * @param {ReadonlyArray<string>} input.argv The full test command.
576
+ * @param {Selection} input.selection A partial selection.
577
+ * @param {"on"|"off"} input.coverage Whether this run measures coverage.
578
+ * @param {string} [input.coverageDir] Where a coverage-on run writes its summary.
579
+ * @returns {string[]} The partial command.
580
+ * @throws {Error} When the command has no `vitest run` to rewrite.
581
+ */
582
+ export function partialArgv({ argv, selection, coverage, coverageDir }) {
583
+ const at = argv.findIndex(
584
+ (arg, index) => /(^|\/)vitest$/.test(arg) && argv[index + 1] === "run"
585
+ );
586
+ if (at === -1) {
587
+ throw new Error("the test command has no `vitest run` to narrow");
588
+ }
589
+ // Every coverage flag goes, with the `true`/`false` a bare one may take as
590
+ // its next argument, which would otherwise be read as a file filter.
591
+ const tail = argv.slice(at + 2);
592
+ const rest = tail.filter((arg, index) => {
593
+ const previous = tail[index - 1];
594
+ const takesValue =
595
+ previous === "--coverage" || previous === "--coverage.enabled";
596
+ return !(
597
+ /^--coverage([.=]|$)/.test(arg) ||
598
+ arg === "--no-coverage" ||
599
+ (takesValue && (arg === "true" || arg === "false"))
600
+ );
601
+ });
602
+ const coverageArgs =
603
+ coverage === "on"
604
+ ? [
605
+ "--coverage.enabled=true",
606
+ "--coverage.reporter=json-summary",
607
+ `--coverage.reportsDirectory=${coverageDir}`,
608
+ "--coverage.thresholds.statements=0",
609
+ "--coverage.thresholds.branches=0",
610
+ "--coverage.thresholds.functions=0",
611
+ "--coverage.thresholds.lines=0",
612
+ ]
613
+ : ["--coverage.enabled=false"];
614
+ return [
615
+ ...argv.slice(0, at + 1),
616
+ "related",
617
+ "--run",
618
+ ...rest,
619
+ ...coverageArgs,
620
+ ...selection.related,
621
+ ...selection.tests.map(test => test.file),
622
+ ];
623
+ }
624
+
625
+ /** Coverage metrics checked per changed file, in report order. */
626
+ const METRICS = Object.freeze(["statements", "branches", "functions", "lines"]);
627
+
628
+ /**
629
+ * Check each changed source file against the project's thresholds on its own.
630
+ *
631
+ * A file absent from the summary is outside the coverage population (a test,
632
+ * a document, an excluded path) and is listed as not measured. A metric with
633
+ * nothing to measure (`"Unknown"`, e.g. a type-only module) cannot fall short.
634
+ *
635
+ * A file is matched only exactly, under the root or under its real path
636
+ * (Vitest keys on the real path of a root reached through a symlink: `/tmp`
637
+ * on macOS, a linked worktree). A suffix match could read another file's
638
+ * numbers (`src/index.ts` against `packages/a/src/index.ts`), so a file with
639
+ * no exact entry but an entry that ends in its path fails closed: it is a
640
+ * shortfall, which sends the push to the full suite.
641
+ * @param {object} input Inputs.
642
+ * @param {Record<string, Record<string, {pct: number|string}>>} input.summary Vitest's json-summary, keyed by absolute path.
643
+ * @param {string} input.root Repository root, absolute.
644
+ * @param {string} [input.realRoot] The root's real path, when it differs.
645
+ * @param {ReadonlyArray<string>} input.files Changed, existing, non-test files.
646
+ * @param {Record<string, number>} input.thresholds Minimum percentage per metric.
647
+ * @returns {{shortfalls: string[], measured: string[], unmeasured: string[]}} The verdict.
648
+ */
649
+ export function changedFileCoverage({
650
+ summary,
651
+ root,
652
+ realRoot = root,
653
+ files,
654
+ thresholds,
655
+ }) {
656
+ const shortfalls = [];
657
+ const measured = [];
658
+ const unmeasured = [];
659
+ for (const file of files) {
660
+ const key = [`${root}/${file}`, `${realRoot}/${file}`].find(candidate =>
661
+ Object.hasOwn(summary, candidate)
662
+ );
663
+ const entry = key === undefined ? undefined : summary[key];
664
+ if (!entry) {
665
+ const lookalikes = Object.keys(summary).filter(candidate =>
666
+ candidate.endsWith(`/${file}`)
667
+ ).length;
668
+ if (lookalikes > 0) {
669
+ shortfalls.push(
670
+ `${file}: no coverage entry is exactly this file, and ${lookalikes} other entr${lookalikes === 1 ? "y ends" : "ies end"} in its path`
671
+ );
672
+ } else {
673
+ unmeasured.push(file);
674
+ }
675
+ continue;
676
+ }
677
+ measured.push(file);
678
+ for (const metric of METRICS) {
679
+ const floor = thresholds[metric];
680
+ const pct = entry[metric]?.pct;
681
+ if (typeof floor !== "number" || typeof pct !== "number") continue;
682
+ if (pct < floor) {
683
+ shortfalls.push(`${file}: ${metric} ${pct}% is below ${floor}%`);
684
+ }
685
+ }
686
+ }
687
+ return { shortfalls, measured, unmeasured };
688
+ }
689
+
690
+ /**
691
+ * The line that sends a partial push run to the full suite.
692
+ *
693
+ * A push is never stricter than whole-repo coverage (CodySwannGT/lisa#4600):
694
+ * before selection, a push failed coverage only when the whole suite's
695
+ * coverage did. So a partial run that cannot clear every changed file on its
696
+ * own does not fail the push; it runs the full suite with whole-repo coverage,
697
+ * exactly as `affectedCoverage: "full"` does, and that run's verdict decides.
698
+ * @param {string} subject Who is speaking ("affected tests", "affected specs").
699
+ * @param {string} because Why the partial run could not decide the push.
700
+ * @returns {string} One plain-language line.
701
+ */
702
+ export function fullSuiteEscalation(subject, because) {
703
+ return `↪️ ${subject}: ${because}, so the full suite is running now with whole-repo coverage, and that run decides this push.`;
704
+ }
705
+
706
+ /**
707
+ * One escalation line per changed file below its floor, naming every metric
708
+ * it misses. Shortfalls are matched to a file by its exact `file: ` prefix,
709
+ * the form {@link changedFileCoverage} and the Rails check both write.
710
+ * @param {object} input Inputs.
711
+ * @param {string} input.subject Who is speaking.
712
+ * @param {ReadonlyArray<string>} input.files Changed files, in report order.
713
+ * @param {ReadonlyArray<string>} input.shortfalls The verdict's shortfalls.
714
+ * @returns {string[]} Lines; empty when every file meets its floor.
715
+ */
716
+ export function coverageEscalationLines({ subject, files, shortfalls }) {
717
+ return files.flatMap(file => {
718
+ const prefix = `${file}: `;
719
+ const misses = shortfalls
720
+ .filter(line => line.startsWith(prefix))
721
+ .map(line => line.slice(prefix.length));
722
+ return misses.length === 0
723
+ ? []
724
+ : [
725
+ fullSuiteEscalation(
726
+ subject,
727
+ `${file} is below its coverage floor on its own (${misses.join("; ")})`
728
+ ),
729
+ ];
730
+ });
731
+ }
732
+
733
+ /**
734
+ * The lines that explain a selection before the suite runs.
735
+ * @param {Selection} selection The selection.
736
+ * @param {string} coverageNote What this run does about coverage.
737
+ * @returns {string[]} Plain-language lines.
738
+ */
739
+ export function explainSelection(selection, coverageNote) {
740
+ if (selection.kind === "full") {
741
+ return [`🎯 affected tests: Running the full suite: ${selection.reason}`];
742
+ }
743
+ return [
744
+ `🎯 affected tests: running ${selection.tests.length} test file(s) the change can reach, plus whatever Vitest's import graph adds.`,
745
+ ...selection.tests.map(test => ` ${test.file} (${test.reason})`),
746
+ ...(selection.related.length
747
+ ? [
748
+ " Changed files handed to Vitest's import-graph selection:",
749
+ ...selection.related.map(file => ` ${file}`),
750
+ ]
751
+ : []),
752
+ ...(selection.unread.length
753
+ ? [
754
+ " No unit test read these when the map was recorded:",
755
+ ...selection.unread.map(file => ` ${file}`),
756
+ ]
757
+ : []),
758
+ ` Coverage: ${coverageNote}`,
759
+ " CI still runs every test before merge.",
760
+ ];
761
+ }
762
+
763
+ /**
764
+ * The channel through which a test command tells the gate runner what it ran.
765
+ *
766
+ * The runner opens one per run and calls `before(command)` just before it
767
+ * executes a command, which points `LISA_SELECTION_REPORT` at a fresh file
768
+ * for that command. `read(command)` returns what the command wrote, or null
769
+ * when it wrote nothing (an older command, or one with selection off), which
770
+ * the runner then reports exactly as before.
771
+ * @param {NodeJS.ProcessEnv} [env] The environment the commands inherit.
772
+ * @returns {{before: (command: string) => void, read: (command: string) => any, close: () => void}} The channel.
773
+ */
774
+ export function openSelectionReports(env = process.env) {
775
+ const dir = mkdtempSync(join(tmpdir(), "lisa-selection-"));
776
+ const fileFor = command =>
777
+ join(
778
+ dir,
779
+ `${createHash("sha256").update(command).digest("hex").slice(0, 16)}.json`
780
+ );
781
+ return {
782
+ before(command) {
783
+ const file = fileFor(command);
784
+ rmSync(file, { force: true });
785
+ env[SELECTION_REPORT_ENV] = file;
786
+ },
787
+ read(command) {
788
+ try {
789
+ return JSON.parse(readFileSync(fileFor(command), "utf8"));
790
+ } catch {
791
+ return null;
792
+ }
793
+ },
794
+ close() {
795
+ delete env[SELECTION_REPORT_ENV];
796
+ rmSync(dir, { recursive: true, force: true });
797
+ },
798
+ };
799
+ }
800
+
801
+ /**
802
+ * Whether a gate's verdict is SKIPPED because its command ran a partial
803
+ * selection that measured no coverage: `pushGate.affectedCoverage: "skip"`,
804
+ * or `none`, a command the selector did not see switch coverage on (coverage
805
+ * enabled only in the Vitest config). A partial run that measured nothing
806
+ * proves nothing about coverage, so it is never reported PASSED.
807
+ * Only coverage-adequacy: test-correctness keeps the run's own verdict.
808
+ * @param {{id: string}} gate The gate.
809
+ * @param {{selection?: string, coverage?: string}|null} report What the command reported.
810
+ * @returns {boolean} True when coverage-adequacy is left to CI.
811
+ */
812
+ export function coverageLeftToCi(gate, report) {
813
+ return (
814
+ gate.id === "coverage-adequacy" &&
815
+ report?.selection === "partial" &&
816
+ (report?.coverage === "skip" || report?.coverage === "none")
817
+ );
818
+ }