@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,982 @@
1
+ #!/usr/bin/env node
2
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
3
+ // Do not edit directly — durable changes belong upstream in Lisa.
4
+
5
+ /**
6
+ * Run RSpec at push, narrowed to the specs a change can reach
7
+ * (CodySwannGT/lisa#4612). The decisions are in `lib/rspec-selection.mjs`;
8
+ * this file gathers their inputs (git, `.lisa.config.json`, the Crystalball
9
+ * map CI recorded) and runs RSpec.
10
+ *
11
+ * Usage:
12
+ * node scripts/lisa-rspec-select.mjs [--no-fetch] -- <full rspec command…>
13
+ * node scripts/lisa-rspec-select.mjs merge-maps --out <file> <map.json…>
14
+ *
15
+ * The command after `--` is the FULL command (`bundle exec rspec`), exactly as
16
+ * the pre-push ran it before. With selection off it runs unchanged and this
17
+ * prints nothing. With it on, it runs unchanged whenever a full-suite reason
18
+ * holds (the reason is printed), or with the selected spec files appended
19
+ * otherwise.
20
+ *
21
+ * The map for the branch's merge-base is downloaded with `gh` from the
22
+ * repository's `crystalball-map-<base sha>-<run id>[-<leg>]` artifacts, which
23
+ * `quality-rails.yml` uploads from its full RSpec run. A map decides which
24
+ * specs a push skips, so a run's map is used only when GitHub reports the run
25
+ * as this repository's own code (not a fork pull request's) that concluded
26
+ * `success`, and every piece it recorded names that run, its base and its
27
+ * head commit, with no shard leg missing. A refused run is skipped and older
28
+ * candidates are tried, up to a bound; when none qualifies the full suite
29
+ * runs (the same contract as `fetch-test-access-map.mjs`). Without `gh`, or when
30
+ * the download fails or takes too long, a map already on disk is used if it
31
+ * is still valid for this branch; otherwise the full suite runs.
32
+ * `--no-fetch` uses only the map on disk.
33
+ * @module lisa-rspec-select
34
+ */
35
+ import { spawnSync } from "node:child_process";
36
+ import {
37
+ existsSync,
38
+ mkdirSync,
39
+ mkdtempSync,
40
+ readFileSync,
41
+ readdirSync,
42
+ rmSync,
43
+ writeFileSync,
44
+ } from "node:fs";
45
+ import { tmpdir } from "node:os";
46
+ import { join } from "node:path";
47
+
48
+ import {
49
+ DEFAULT_MAX_AGE_DAYS,
50
+ MAX_AGE_ENV,
51
+ PARTIAL_COVERAGE_SKIP_REASON,
52
+ SELECTION_REPORT_ENV,
53
+ staleMapReason,
54
+ } from "./lib/affected-tests.mjs";
55
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
56
+ import {
57
+ MAP_DIR,
58
+ MAP_TRUST,
59
+ MAX_MAP_RUN_CHECKS,
60
+ SPEC_FILE,
61
+ THRESHOLDS_FILE,
62
+ alwaysRunSpecs,
63
+ changedRubyCoverage,
64
+ explainRspecSelection,
65
+ fullSuite,
66
+ isRailsProject,
67
+ mapPiecesRefusal,
68
+ mapRunRefusal,
69
+ mergeMapDocuments,
70
+ parseMapArtifacts,
71
+ railsCoverageEscalation,
72
+ railsFullSuiteEscalation,
73
+ rankMapRuns,
74
+ rspecSelectionSettings,
75
+ selectRailsSpecs,
76
+ } from "./lib/rspec-selection.mjs";
77
+
78
+ /** The Ruby file that moves a partial run's coverage out of SimpleCov's minimums. */
79
+ export const PARTIAL_COVERAGE_HELPER = "scripts/lisa_rspec_partial_coverage.rb";
80
+
81
+ /** The coverage mode that holds each changed Ruby file to the floor. */
82
+ const CHANGED_FILES = "changed-files";
83
+
84
+ /** How long a failed download is remembered before it is tried again. */
85
+ const MISS_TTL_MS = 15 * 60_000;
86
+
87
+ /** How long the whole map download may take before the push stops waiting. */
88
+ const FETCH_BUDGET_MS = 60_000;
89
+
90
+ /** Artifact listing pages read, newest first, before giving up. */
91
+ const MAX_PAGES = 5;
92
+
93
+ /** Artifacts per listing page. */
94
+ const PAGE_SIZE = 100;
95
+
96
+ /** The fields read from each listed artifact. */
97
+ const LISTING_JQ =
98
+ ".artifacts[] | {name, runId: .workflow_run.id, createdAt: .created_at, expired}";
99
+
100
+ /** The fields read from a workflow run. */
101
+ const RUN_JQ =
102
+ "{conclusion, headSha: .head_sha, headRepository: .head_repository.full_name}";
103
+
104
+ /** The git subcommand that finds a branch point or proves ancestry. */
105
+ const MERGE_BASE = "merge-base";
106
+
107
+ /** The saved map, under {@link MAP_DIR}. */
108
+ const MAP_FILE = "map.json";
109
+
110
+ /** The saved map's metadata, under {@link MAP_DIR}. */
111
+ const META_FILE = "meta.json";
112
+
113
+ /** Git's location variables, which a hook exports to its children. */
114
+ const GIT_LOCATION_ENV = new Set([
115
+ "GIT_DIR",
116
+ "GIT_WORK_TREE",
117
+ "GIT_INDEX_FILE",
118
+ "GIT_PREFIX",
119
+ ]);
120
+
121
+ /**
122
+ * Run a command and return its result, without git's hook location variables.
123
+ * @param {string} command Executable.
124
+ * @param {string[]} args Arguments.
125
+ * @param {object} options Options.
126
+ * @param {string} options.cwd Working directory.
127
+ * @param {number} [options.timeout] Milliseconds.
128
+ * @returns {{status: number|null, stdout: string, stderr: string, error?: Error}} Result.
129
+ */
130
+ function exec(command, args, { cwd, timeout }) {
131
+ const env = Object.fromEntries(
132
+ Object.entries(process.env).filter(([key]) => !GIT_LOCATION_ENV.has(key))
133
+ );
134
+ const child = spawnSync(command, args, {
135
+ cwd,
136
+ env,
137
+ encoding: "utf8",
138
+ timeout,
139
+ maxBuffer: 64 * 1024 * 1024,
140
+ });
141
+ return {
142
+ status: child.status,
143
+ stdout: child.stdout ?? "",
144
+ stderr: child.stderr ?? "",
145
+ error: child.error,
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Run git in `root`.
151
+ * @param {string} root Repository root.
152
+ * @param {string[]} args Git arguments.
153
+ * @returns {string|null} Trimmed stdout, or null when git fails.
154
+ */
155
+ function git(root, args) {
156
+ const child = exec("git", args, { cwd: root });
157
+ return child.status === 0 ? child.stdout.trim() : null;
158
+ }
159
+
160
+ /**
161
+ * Parse a JSON file, or undefined when it is missing or unreadable.
162
+ * @param {string} file Path.
163
+ * @returns {any} Parsed value.
164
+ */
165
+ function readJson(file) {
166
+ try {
167
+ return JSON.parse(readFileSync(file, "utf8"));
168
+ } catch {
169
+ return undefined;
170
+ }
171
+ }
172
+
173
+ /**
174
+ * The commit this branch left the default branch at.
175
+ * @param {string} root Repository root.
176
+ * @param {NodeJS.ProcessEnv} env Environment (`LISA_AFFECTED_BASE_REF` overrides).
177
+ * @returns {{sha: string, ref: string}|null} The merge-base, or null.
178
+ */
179
+ function mergeBaseOf(root, env) {
180
+ const symbolic = git(root, [
181
+ "symbolic-ref",
182
+ "--quiet",
183
+ "refs/remotes/origin/HEAD",
184
+ ]);
185
+ const ref =
186
+ env.LISA_AFFECTED_BASE_REF ||
187
+ (symbolic ? symbolic.replace(/^refs\/remotes\//, "") : "origin/main");
188
+ const sha = git(root, [MERGE_BASE, "HEAD", ref]);
189
+ return sha ? { sha, ref } : null;
190
+ }
191
+
192
+ /**
193
+ * Files that differ between the merge-base and the working tree.
194
+ * @param {string} root Repository root.
195
+ * @param {string} base Merge-base.
196
+ * @returns {Array<{path: string, status: "added"|"modified"|"deleted"}>|null} Changes, or null.
197
+ */
198
+ function changedFiles(root, base) {
199
+ const tracked = git(root, ["diff", "--name-status", "--no-renames", base]);
200
+ const untracked = git(root, ["ls-files", "--others", "--exclude-standard"]);
201
+ if (tracked === null || untracked === null) return null;
202
+ const status = letter =>
203
+ letter === "A" ? "added" : letter === "D" ? "deleted" : "modified";
204
+ const entries = tracked
205
+ .split("\n")
206
+ .filter(Boolean)
207
+ .map(line => {
208
+ const [letter, ...rest] = line.split("\t");
209
+ return { path: rest.join("\t"), status: status(letter[0]) };
210
+ });
211
+ const seen = new Set(entries.map(entry => entry.path));
212
+ const added = untracked
213
+ .split("\n")
214
+ .filter(file => file && !seen.has(file))
215
+ .map(file => ({ path: file, status: "added" }));
216
+ return [...entries, ...added];
217
+ }
218
+
219
+ /**
220
+ * Every `*_spec.rb` under `spec/`, repository-relative.
221
+ * @param {string} root Repository root.
222
+ * @returns {string[]} Spec files, sorted.
223
+ */
224
+ function specFilesIn(root) {
225
+ const walk = dir => {
226
+ let entries;
227
+ try {
228
+ entries = readdirSync(join(root, dir), { withFileTypes: true });
229
+ } catch {
230
+ return [];
231
+ }
232
+ return entries.flatMap(entry => {
233
+ const path = `${dir}/${entry.name}`;
234
+ if (entry.isDirectory()) return walk(path);
235
+ return SPEC_FILE.test(path) ? [path] : [];
236
+ });
237
+ };
238
+ return walk("spec").sort();
239
+ }
240
+
241
+ /**
242
+ * Every `.json` file under a directory, recursively.
243
+ * @param {string} dir Directory.
244
+ * @returns {string[]} Paths.
245
+ */
246
+ function jsonFilesUnder(dir) {
247
+ return readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
248
+ const path = join(dir, entry.name);
249
+ if (entry.isDirectory()) return jsonFilesUnder(path);
250
+ return entry.name.endsWith(".json") ? [path] : [];
251
+ });
252
+ }
253
+
254
+ /**
255
+ * Merge map documents and save `map.json` and `meta.json` into `out`.
256
+ * @param {object} input Inputs.
257
+ * @param {any[]} input.documents Parsed map documents.
258
+ * @param {string} input.out Directory.
259
+ * @param {Record<string, unknown>} input.meta Extra metadata.
260
+ * @returns {boolean} False when there was no map to save.
261
+ */
262
+ function saveMap({ documents, out, meta }) {
263
+ const merged = mergeMapDocuments(documents);
264
+ if (merged.metas.length === 0) return false;
265
+ const createdAt =
266
+ merged.metas
267
+ .map(entry => String(entry.createdAt ?? ""))
268
+ .filter(Boolean)
269
+ .sort()[0] ?? "";
270
+ const baseSha =
271
+ merged.metas.map(entry => entry.baseSha).find(Boolean) ?? meta.baseSha;
272
+ mkdirSync(out, { recursive: true });
273
+ writeFileSync(
274
+ join(out, MAP_FILE),
275
+ `${JSON.stringify({ map: merged.map, alwaysRun: merged.alwaysRun }, null, 2)}\n`
276
+ );
277
+ writeFileSync(
278
+ join(out, META_FILE),
279
+ `${JSON.stringify(
280
+ {
281
+ ...meta,
282
+ baseSha,
283
+ createdAt,
284
+ specFiles: Object.keys(merged.map).length,
285
+ },
286
+ null,
287
+ 2
288
+ )}\n`
289
+ );
290
+ return true;
291
+ }
292
+
293
+ /**
294
+ * Download the newest trusted map for `base` (or its nearest ancestor) with
295
+ * `gh`: candidate runs are tried newest first, each checked with GitHub
296
+ * ({@link mapRunRefusal}) and its pieces checked for completeness
297
+ * ({@link mapPiecesRefusal}), up to {@link MAX_MAP_RUN_CHECKS} runs.
298
+ * @param {object} input Inputs.
299
+ * @param {string} input.root Repository root.
300
+ * @param {string} input.base Merge-base.
301
+ * @param {string} input.dir Where the map lives.
302
+ * @param {() => number} input.remaining Milliseconds left in the budget.
303
+ * @returns {string|null} Why there is no map, or null on success.
304
+ */
305
+ function downloadMap({ root, base, dir, remaining }) {
306
+ const call = args => {
307
+ const left = remaining();
308
+ if (left <= 0) return { status: null, stdout: "", stderr: "out of time" };
309
+ return exec("gh", args, { cwd: root, timeout: left });
310
+ };
311
+ const failure = (child, what) =>
312
+ child.error?.code === "ENOENT"
313
+ ? "the GitHub CLI (gh) is not installed"
314
+ : `${what}: ${(child.stderr || "gh failed").trim().split("\n").at(-1)}`;
315
+ const distance = baseSha => {
316
+ if (baseSha === base) return 0;
317
+ if (git(root, [MERGE_BASE, "--is-ancestor", baseSha, base]) === null) {
318
+ return undefined;
319
+ }
320
+ const count = Number(
321
+ git(root, ["rev-list", "--count", `${baseSha}..${base}`])
322
+ );
323
+ return Number.isFinite(count) ? count : undefined;
324
+ };
325
+ const named = call(["api", "repos/{owner}/{repo}", "--jq", ".full_name"]);
326
+ if (named.status !== 0) {
327
+ return failure(named, "could not read this repository's name");
328
+ }
329
+ const repo = named.stdout.trim();
330
+ const seen = [];
331
+ const tried = new Set();
332
+ const refusals = [];
333
+ for (let page = 1; page <= MAX_PAGES; page += 1) {
334
+ const listing = call([
335
+ "api",
336
+ `repos/{owner}/{repo}/actions/artifacts?per_page=${PAGE_SIZE}&page=${page}`,
337
+ "--jq",
338
+ LISTING_JQ,
339
+ ]);
340
+ if (listing.status !== 0) {
341
+ return failure(listing, "could not list artifacts");
342
+ }
343
+ seen.push(...parseMapArtifacts(listing.stdout));
344
+ for (const candidate of rankMapRuns(seen, distance)) {
345
+ if (tried.has(candidate.runId)) continue;
346
+ if (tried.size >= MAX_MAP_RUN_CHECKS) {
347
+ return noTrustedMap(base, refusals);
348
+ }
349
+ tried.add(candidate.runId);
350
+ const refused = tryRun({ call, repo, candidate, base, dir });
351
+ if (refused === null) return null;
352
+ refusals.push(`refused run ${candidate.runId} (${refused})`);
353
+ }
354
+ if (listing.stdout.split("\n").filter(Boolean).length < PAGE_SIZE) break;
355
+ }
356
+ return noTrustedMap(base, refusals);
357
+ }
358
+
359
+ /**
360
+ * Why no map was usable, naming every refused run.
361
+ * @param {string} base Merge-base.
362
+ * @param {string[]} refusals One entry per refused run.
363
+ * @returns {string} The reason.
364
+ */
365
+ function noTrustedMap(base, refusals) {
366
+ const none = `no crystalball map for ${base.slice(0, 12)} or an ancestor of it`;
367
+ return refusals.length === 0
368
+ ? none
369
+ : `no trusted crystalball map for ${base.slice(0, 12)} or an ancestor of it: ${refusals.join("; ")}`;
370
+ }
371
+
372
+ /**
373
+ * Check one candidate run with GitHub, download its pieces, check them, and
374
+ * save the map when every check passes.
375
+ * @param {object} input Inputs.
376
+ * @param {(args: string[]) => {status: number|null, stdout: string, stderr: string}} input.call Runs gh within the budget.
377
+ * @param {string} input.repo owner/name.
378
+ * @param {import("./lib/rspec-selection.mjs").MapRunChoice} input.candidate The run.
379
+ * @param {string} input.base Merge-base the map is downloaded for.
380
+ * @param {string} input.dir Where the map lives.
381
+ * @returns {string|null} Why the run was refused, or null when its map was saved.
382
+ */
383
+ function tryRun({ call, repo, candidate, base, dir }) {
384
+ const described = call([
385
+ "api",
386
+ `repos/{owner}/{repo}/actions/runs/${candidate.runId}`,
387
+ "--jq",
388
+ RUN_JQ,
389
+ ]);
390
+ // probe-direction: fail-closed — a run GitHub cannot describe is not
391
+ // trusted, so its map is skipped and the push runs more specs.
392
+ const info = described.status === 0 ? parseJson(described.stdout) : null;
393
+ if (!info) return "GitHub could not describe it";
394
+ const distrust = mapRunRefusal(info, repo);
395
+ if (distrust) return distrust;
396
+ const download = mkdtempSync(join(tmpdir(), "lisa-crystalball-map-"));
397
+ try {
398
+ const fetched = call([
399
+ "run",
400
+ "download",
401
+ candidate.runId,
402
+ ...candidate.names.flatMap(name => ["--name", name]),
403
+ "--dir",
404
+ download,
405
+ ]);
406
+ if (fetched.status !== 0) {
407
+ return `its map could not be downloaded: ${(fetched.stderr || "gh failed").trim().split("\n").at(-1)}`;
408
+ }
409
+ const documents = jsonFilesUnder(download).map(readJson);
410
+ const incomplete = mapPiecesRefusal(mergeMapDocuments(documents).metas, {
411
+ runId: candidate.runId,
412
+ baseSha: candidate.baseSha,
413
+ headSha: info.headSha,
414
+ });
415
+ if (incomplete) return incomplete;
416
+ const saved = saveMap({
417
+ documents,
418
+ out: dir,
419
+ meta: {
420
+ requestedBase: base,
421
+ baseSha: candidate.baseSha,
422
+ commitsBehind: candidate.distance,
423
+ runId: candidate.runId,
424
+ headSha: info.headSha,
425
+ artifacts: candidate.names,
426
+ trust: MAP_TRUST,
427
+ },
428
+ });
429
+ return saved ? null : "its artifacts held no map";
430
+ } finally {
431
+ rmSync(download, { recursive: true, force: true });
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Parse JSON text, or null when it is not JSON.
437
+ * @param {string} text Text.
438
+ * @returns {any} Parsed value.
439
+ */
440
+ function parseJson(text) {
441
+ try {
442
+ return JSON.parse(text);
443
+ } catch {
444
+ return null;
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Make sure a map for `base` is on disk, downloading it when needed.
450
+ * @param {object} input Inputs.
451
+ * @param {string} input.root Repository root.
452
+ * @param {string} input.base Merge-base.
453
+ * @param {boolean} input.fetch Whether downloading is allowed.
454
+ * @param {(line: string) => void} input.out Output.
455
+ * @param {() => Date} input.now Clock.
456
+ * @returns {void}
457
+ */
458
+ function ensureMap({ root, base, fetch, out, now }) {
459
+ const dir = join(root, MAP_DIR);
460
+ const saved = readJson(join(dir, META_FILE));
461
+ if (saved?.requestedBase === base && saved?.trust === MAP_TRUST) return;
462
+ if (!fetch) return;
463
+ const missFile = join(dir, "miss.json");
464
+ const miss = readJson(missFile);
465
+ if (
466
+ miss?.requestedBase === base &&
467
+ now().getTime() - Date.parse(miss.at) < MISS_TTL_MS
468
+ ) {
469
+ return;
470
+ }
471
+ out(
472
+ `🎯 affected specs: downloading the crystalball map for ${base.slice(0, 12)}…`
473
+ );
474
+ const started = Date.now();
475
+ const why = downloadMap({
476
+ root,
477
+ base,
478
+ dir,
479
+ remaining: () => FETCH_BUDGET_MS - (Date.now() - started),
480
+ });
481
+ if (why === null) return;
482
+ out(` No new map: ${why}.`);
483
+ mkdirSync(dir, { recursive: true });
484
+ writeFileSync(
485
+ missFile,
486
+ `${JSON.stringify({ requestedBase: base, at: now().toISOString() })}\n`
487
+ );
488
+ }
489
+
490
+ /**
491
+ * Read the map, or say why it cannot be used.
492
+ * @param {object} input Inputs.
493
+ * @param {string} input.root Repository root.
494
+ * @param {string} input.base Merge-base.
495
+ * @param {NodeJS.ProcessEnv} input.env Environment.
496
+ * @param {() => Date} input.now Clock.
497
+ * @returns {{map: Record<string, string[]>, alwaysRun: string[], meta: Record<string, any>}|{problem: string}} The map.
498
+ */
499
+ function loadMap({ root, base, env, now }) {
500
+ const dir = join(root, MAP_DIR);
501
+ const meta = readJson(join(dir, META_FILE));
502
+ if (meta === undefined) {
503
+ return {
504
+ problem:
505
+ "missing map: no crystalball map is available for this branch's base",
506
+ };
507
+ }
508
+ if (meta.trust !== MAP_TRUST) {
509
+ return {
510
+ problem:
511
+ "unverified map: the map on disk was saved before Lisa checked the run that recorded it",
512
+ };
513
+ }
514
+ const configured = Number(env[MAX_AGE_ENV]);
515
+ const maxAgeDays =
516
+ env[MAX_AGE_ENV] !== undefined &&
517
+ env[MAX_AGE_ENV] !== "" &&
518
+ Number.isFinite(configured)
519
+ ? configured
520
+ : DEFAULT_MAX_AGE_DAYS;
521
+ const stale = staleMapReason({
522
+ meta,
523
+ mergeBase: base,
524
+ isAncestor: (a, b) =>
525
+ git(root, [MERGE_BASE, "--is-ancestor", a, b]) !== null,
526
+ now: now(),
527
+ maxAgeDays,
528
+ });
529
+ if (stale) return { problem: stale };
530
+ const saved = readJson(join(dir, MAP_FILE));
531
+ const map = saved?.map;
532
+ if (!map || typeof map !== "object" || Array.isArray(map)) {
533
+ return {
534
+ problem: "missing map: the downloaded map file could not be read",
535
+ };
536
+ }
537
+ return {
538
+ map,
539
+ alwaysRun: Array.isArray(saved.alwaysRun) ? saved.alwaysRun : [],
540
+ meta,
541
+ };
542
+ }
543
+
544
+ /**
545
+ * The project's coverage floors from `simplecov.thresholds.json`.
546
+ * @param {string} root Repository root.
547
+ * @returns {{line?: number, branch?: number}|null} Floors, or null when there are none.
548
+ */
549
+ function thresholdsOf(root) {
550
+ const floors = readJson(join(root, THRESHOLDS_FILE));
551
+ if (!floors || typeof floors !== "object") return null;
552
+ const picked = Object.fromEntries(
553
+ ["line", "branch"]
554
+ .filter(metric => typeof floors[metric] === "number")
555
+ .map(metric => [metric, floors[metric]])
556
+ );
557
+ return Object.keys(picked).length ? picked : null;
558
+ }
559
+
560
+ /**
561
+ * @typedef {object} RspecPlan
562
+ * @property {"full"|"partial"} kind Which run to do.
563
+ * @property {string|null} reason Why the full suite runs.
564
+ * @property {string[]} specs Spec files a partial run passes to RSpec.
565
+ * @property {"changed-files"|"skip"|"none"} coverage What a partial run does about coverage.
566
+ * @property {string[]} lines The plain-language explanation to print.
567
+ * @property {string[]} changedRuby Changed Ruby files outside spec/ (for the coverage check).
568
+ * @property {import("./lib/rspec-selection.mjs").RspecSelection} selection The selection.
569
+ */
570
+
571
+ /** What each coverage outcome means, for the explanation. */
572
+ const COVERAGE_NOTE = Object.freeze({
573
+ full: "measured over the full suite, as before",
574
+ [CHANGED_FILES]: `each changed Ruby file is held to ${THRESHOLDS_FILE} on its own; one below it sends the push to the full suite`,
575
+ skip: `not measured at push (${PARTIAL_COVERAGE_SKIP_REASON})`,
576
+ none: "not measured at push (selection is off)",
577
+ });
578
+
579
+ /**
580
+ * Decide what the push-time RSpec run does. Exported for the Rails gate
581
+ * runner (CodySwannGT/lisa#4613), which may call it instead of this CLI.
582
+ * @param {object} input Inputs.
583
+ * @param {string} input.cwd Working directory.
584
+ * @param {NodeJS.ProcessEnv} input.env Environment.
585
+ * @param {boolean} [input.fetch] Whether the map may be downloaded (default true).
586
+ * @param {(line: string) => void} [input.out] Progress output.
587
+ * @param {() => Date} [input.now] Clock.
588
+ * @returns {RspecPlan} The plan.
589
+ * @throws {Error} When `pushGate` in `.lisa.config.json` is invalid.
590
+ */
591
+ export function planRspecRun({
592
+ cwd,
593
+ env,
594
+ fetch = true,
595
+ out = () => {},
596
+ now = () => new Date(),
597
+ }) {
598
+ const root = git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd;
599
+ const config = readJson(join(root, ".lisa.config.json")) ?? {};
600
+ const exists = file => existsSync(join(root, file));
601
+ const settings = rspecSelectionSettings(config, isRailsProject(exists));
602
+ const finish = (selection, coverage, changedRuby = []) => {
603
+ const full = selection.kind === "full";
604
+ return {
605
+ kind: selection.kind,
606
+ reason: selection.reason,
607
+ specs: full ? [] : selection.specs.map(spec => spec.file),
608
+ coverage: full ? "none" : coverage,
609
+ lines: settings.enabled
610
+ ? explainRspecSelection(
611
+ selection,
612
+ COVERAGE_NOTE[full ? "full" : coverage]
613
+ )
614
+ : [],
615
+ changedRuby,
616
+ selection,
617
+ };
618
+ };
619
+ const fullRun = reason => finish(fullSuite(reason), "none");
620
+ if (!settings.enabled) return fullRun("pushGate.affectedTests is false");
621
+ if (env.CI || env.GITHUB_ACTIONS) {
622
+ return fullRun("this is a CI run, and CI always runs every spec");
623
+ }
624
+ if (settings.coverage === "full") {
625
+ return fullRun(
626
+ 'pushGate.affectedCoverage is "full", so coverage is measured over every spec'
627
+ );
628
+ }
629
+ if (!exists(PARTIAL_COVERAGE_HELPER)) {
630
+ return fullRun(
631
+ `${PARTIAL_COVERAGE_HELPER} is not installed, so a partial run cannot keep the project's coverage minimums off the slice (run lisa to install it)`
632
+ );
633
+ }
634
+ if (settings.coverage === CHANGED_FILES && !thresholdsOf(root)) {
635
+ return fullRun(
636
+ `there is no ${THRESHOLDS_FILE} with line or branch floors to hold the changed files to`
637
+ );
638
+ }
639
+ const base = mergeBaseOf(root, env);
640
+ if (!base) {
641
+ return fullRun("could not find where this branch left the default branch");
642
+ }
643
+ const changed = changedFiles(root, base.sha);
644
+ if (!changed) return fullRun("could not list the changed files");
645
+ if (changed.length === 0) {
646
+ return fullRun(
647
+ `nothing differs from ${base.ref}, so there is no change to narrow to`
648
+ );
649
+ }
650
+ ensureMap({ root, base: base.sha, fetch, out, now });
651
+ const loaded = loadMap({ root, base: base.sha, env, now });
652
+ if ("problem" in loaded) return fullRun(loaded.problem);
653
+ const specFiles = specFilesIn(root);
654
+ const selection = selectRailsSpecs({
655
+ changed,
656
+ map: loaded.map,
657
+ alwaysRun: alwaysRunSpecs({
658
+ specFiles,
659
+ recorded: loaded.alwaysRun,
660
+ read: file => readFileSync(join(root, file), "utf8"),
661
+ }),
662
+ exists,
663
+ coverage: settings.coverage,
664
+ });
665
+ const changedRuby = changed
666
+ .filter(
667
+ entry =>
668
+ entry.status !== "deleted" &&
669
+ entry.path.endsWith(".rb") &&
670
+ !entry.path.startsWith("spec/") &&
671
+ exists(entry.path)
672
+ )
673
+ .map(entry => entry.path);
674
+ return finish(selection, settings.coverage, changedRuby);
675
+ }
676
+
677
+ /**
678
+ * The RSpec command for a plan: unchanged for a full run; for a partial run
679
+ * the coverage hand-off is required and the selected specs are appended.
680
+ * @param {object} input Inputs.
681
+ * @param {RspecPlan} input.plan The plan.
682
+ * @param {ReadonlyArray<string>} [input.command] The full RSpec command.
683
+ * @returns {string[]} The command to run.
684
+ */
685
+ export function rspecArgv({ plan, command = ["bundle", "exec", "rspec"] }) {
686
+ if (plan.kind === "full") return [...command];
687
+ return [
688
+ ...command,
689
+ "--require",
690
+ `./${PARTIAL_COVERAGE_HELPER}`,
691
+ ...plan.specs,
692
+ ];
693
+ }
694
+
695
+ /**
696
+ * Run a command with inherited output and return its exit code.
697
+ * @param {string[]} argv Command.
698
+ * @param {string} cwd Working directory.
699
+ * @param {NodeJS.ProcessEnv} [env] Environment.
700
+ * @returns {number} Exit code (1 for a signal or a spawn failure).
701
+ */
702
+ function run(argv, cwd, env = process.env) {
703
+ const child = spawnSync(argv[0], argv.slice(1), {
704
+ cwd,
705
+ env,
706
+ stdio: "inherit",
707
+ });
708
+ return typeof child.status === "number" ? child.status : 1;
709
+ }
710
+
711
+ /**
712
+ * Hold each changed Ruby file to the floors after a partial run.
713
+ *
714
+ * A push is never stricter than whole-repo coverage (CodySwannGT/lisa#4600):
715
+ * a file below its floor, a hand-off that could not keep the project's
716
+ * minimums off the slice, or a run that left no resultset returns escalation
717
+ * lines instead of failing, and the caller runs the full suite.
718
+ * @param {object} input Inputs.
719
+ * @param {string} input.root Repository root.
720
+ * @param {string} input.coverageDir Where the hand-off wrote its status and resultset.
721
+ * @param {RspecPlan} input.plan The plan.
722
+ * @param {(line: string) => void} input.out Output.
723
+ * @returns {string[]} Escalation lines; empty when the partial run decides the push.
724
+ */
725
+ function checkChangedFiles({ root, coverageDir, plan, out }) {
726
+ const status = readJson(join(coverageDir, "status.json"));
727
+ if (status?.measuring === false) {
728
+ out(
729
+ " Coverage: SimpleCov was not measuring this run, so there was no coverage to check."
730
+ );
731
+ return [];
732
+ }
733
+ if (typeof status?.escalate === "string") {
734
+ return [railsFullSuiteEscalation(status.escalate)];
735
+ }
736
+ const resultset = readJson(join(coverageDir, ".resultset.json"));
737
+ if (!status || !resultset) {
738
+ return [
739
+ railsFullSuiteEscalation("the partial run left no SimpleCov resultset"),
740
+ ];
741
+ }
742
+ const verdict = changedRubyCoverage({
743
+ resultset,
744
+ root,
745
+ files: plan.changedRuby,
746
+ thresholds: thresholdsOf(root) ?? {},
747
+ read: file => readFileSync(join(root, file), "utf8"),
748
+ });
749
+ if (verdict.shortfalls.length > 0) {
750
+ return railsCoverageEscalation({
751
+ files: plan.changedRuby,
752
+ shortfalls: verdict.shortfalls,
753
+ });
754
+ }
755
+ const outside = verdict.unmeasured.length
756
+ ? `; ${verdict.unmeasured.length} are outside coverage`
757
+ : "";
758
+ out(
759
+ `✅ affected specs: ${verdict.measured.length} changed Ruby file(s) meet the coverage floor${outside}`
760
+ );
761
+ return [];
762
+ }
763
+
764
+ /**
765
+ * Whether the hand-off asked for the full suite because it could not run the
766
+ * slice safely: its verdict replaces the slice's exit code, which then only
767
+ * says the hand-off stopped the run.
768
+ * @param {string} coverageDir Where the hand-off wrote its status.
769
+ * @returns {boolean} True when the hand-off escalated.
770
+ */
771
+ function handOffEscalated(coverageDir) {
772
+ return (
773
+ typeof readJson(join(coverageDir, "status.json"))?.escalate === "string"
774
+ );
775
+ }
776
+
777
+ /**
778
+ * `merge-maps --out <file> <map.json…>`: merge CI legs' maps into one file.
779
+ * @param {string[]} argv Arguments after `merge-maps`.
780
+ * @returns {number} Exit code.
781
+ */
782
+ function mergeMapsCli(argv) {
783
+ const at = argv.indexOf("--out");
784
+ const target = at === -1 ? undefined : argv[at + 1];
785
+ const inputs = argv.filter((_, index) => index !== at && index !== at + 1);
786
+ if (!target || inputs.length === 0) {
787
+ console.error(
788
+ "usage: lisa-rspec-select.mjs merge-maps --out <file> <map.json…>"
789
+ );
790
+ return 2;
791
+ }
792
+ const merged = mergeMapDocuments(inputs.map(readJson));
793
+ if (merged.metas.length === 0) {
794
+ console.error("lisa-rspec-select: none of the inputs is a crystalball map");
795
+ return 1;
796
+ }
797
+ const meta = { ...merged.metas[0] };
798
+ meta.createdAt =
799
+ merged.metas
800
+ .map(entry => String(entry.createdAt ?? ""))
801
+ .filter(Boolean)
802
+ .sort()[0] ?? meta.createdAt;
803
+ meta.legs = merged.metas.map(entry => entry.job ?? "");
804
+ // Every leg's own metadata, so the push can prove no leg is missing
805
+ // (mapPiecesRefusal).
806
+ meta.merged = merged.metas;
807
+ writeFileSync(
808
+ target,
809
+ `${JSON.stringify({ meta, map: merged.map, alwaysRun: merged.alwaysRun }, null, 2)}\n`
810
+ );
811
+ console.log(
812
+ `crystalball map: merged ${merged.metas.length} leg(s), ${Object.keys(merged.map).length} spec file(s) -> ${target}`
813
+ );
814
+ return 0;
815
+ }
816
+
817
+ /**
818
+ * The CLI.
819
+ * @param {string[]} argv Arguments after the script.
820
+ * @param {object} [deps] Effects, injectable for tests.
821
+ * @param {NodeJS.ProcessEnv} [deps.env] Environment.
822
+ * @param {string} [deps.cwd] Working directory.
823
+ * @param {(line: string) => void} [deps.out] Output.
824
+ * @param {() => Date} [deps.now] Clock.
825
+ * @returns {number} Exit code.
826
+ */
827
+ export function main(argv, deps = {}) {
828
+ if (argv[0] === "merge-maps") return mergeMapsCli(argv.slice(1));
829
+ const env = deps.env ?? process.env;
830
+ const out = deps.out ?? (line => console.log(line));
831
+ const now = deps.now ?? (() => new Date());
832
+ const separator = argv.indexOf("--");
833
+ const own = separator === -1 ? [] : argv.slice(0, separator);
834
+ const command = separator === -1 ? [] : argv.slice(separator + 1);
835
+ if (command.length === 0) {
836
+ console.error(
837
+ "usage: lisa-rspec-select.mjs [--no-fetch] -- <rspec command…>"
838
+ );
839
+ return 2;
840
+ }
841
+ const cwd = deps.cwd ?? process.cwd();
842
+ let plan;
843
+ try {
844
+ plan = planRspecRun({
845
+ cwd,
846
+ env,
847
+ fetch: !own.includes("--no-fetch"),
848
+ out,
849
+ now,
850
+ });
851
+ } catch (error) {
852
+ console.error(
853
+ `🚫 affected specs: ${error.message} Fix pushGate in .lisa.config.json. Nothing ran.`
854
+ );
855
+ return 2;
856
+ }
857
+ if (env[SELECTION_REPORT_ENV] && plan.lines.length > 0) {
858
+ try {
859
+ writeFileSync(
860
+ env[SELECTION_REPORT_ENV],
861
+ `${JSON.stringify({ selection: plan.kind, reason: plan.reason, coverage: plan.coverage, tests: plan.specs.length })}\n`
862
+ );
863
+ } catch {
864
+ // Without the report the runner reads nothing and reports as before.
865
+ }
866
+ }
867
+ for (const line of plan.lines) out(line);
868
+ return runRspecPlan({ plan, command, cwd, env, out });
869
+ }
870
+
871
+ /**
872
+ * Run a plan from {@link planRspecRun}: the full command unchanged, or the
873
+ * partial command with the coverage hand-off and, in `changed-files` mode,
874
+ * the per-file coverage check. Exported for the Rails gate runner
875
+ * (CodySwannGT/lisa#4613): a caller that runs a partial plan's specs any
876
+ * other way leaves SimpleCov's project minimums armed against the slice and
877
+ * skips the changed-file check.
878
+ *
879
+ * When the partial run cannot clear every changed file, the push escalates to
880
+ * the full suite with whole-repo coverage (CodySwannGT/lisa#4600: a push is
881
+ * never stricter than whole-repo coverage) and that run's exit code is the
882
+ * verdict. `runFull` is how the caller runs its full suite, so the gate runner
883
+ * can keep its parallel run for the escalation.
884
+ * @param {object} input Inputs.
885
+ * @param {RspecPlan} input.plan The plan.
886
+ * @param {ReadonlyArray<string>} [input.command] The full RSpec command.
887
+ * @param {string} input.cwd Working directory.
888
+ * @param {NodeJS.ProcessEnv} [input.env] Environment.
889
+ * @param {(line: string) => void} [input.out] Output.
890
+ * @param {() => number} [input.runFull] Runs the full suite (default: `command` unchanged).
891
+ * @returns {number} Exit code.
892
+ */
893
+ export function runRspecPlan({
894
+ plan,
895
+ command = ["bundle", "exec", "rspec"],
896
+ cwd,
897
+ env = process.env,
898
+ out = line => console.log(line),
899
+ runFull = () => run([...command], cwd, env),
900
+ }) {
901
+ if (plan.kind === "full") return runFull();
902
+ const unmeasured =
903
+ plan.specs.length === 0 && plan.coverage === CHANGED_FILES
904
+ ? (plan.changedRuby ?? [])
905
+ : [];
906
+ if (plan.specs.length === 0 && unmeasured.length === 0) {
907
+ out(" No spec can reach the changed files, so there is nothing to run.");
908
+ return 0;
909
+ }
910
+ // No spec selected, but changed Ruby files are owed a coverage check: with
911
+ // nothing run there is nothing to measure them by, and passing would let
912
+ // their coverage go unchecked. Fail closed to the full suite.
913
+ const escalation =
914
+ unmeasured.length > 0
915
+ ? [
916
+ railsFullSuiteEscalation(
917
+ `no selected spec runs ${unmeasured.join(", ")}, so the partial run could not measure ${unmeasured.length === 1 ? "its" : "their"} coverage`
918
+ ),
919
+ ]
920
+ : runPartial({ plan, command, cwd, env, out });
921
+ if (typeof escalation === "number") return escalation;
922
+ return escalate({ escalation, env, out, runFull });
923
+ }
924
+
925
+ /**
926
+ * Run a partial plan's specs with the coverage hand-off and, in
927
+ * `changed-files` mode, check each changed Ruby file afterwards.
928
+ * @param {object} input Inputs.
929
+ * @param {RspecPlan} input.plan The plan.
930
+ * @param {ReadonlyArray<string>} input.command The full RSpec command.
931
+ * @param {string} input.cwd Working directory.
932
+ * @param {NodeJS.ProcessEnv} input.env Environment.
933
+ * @param {(line: string) => void} input.out Output.
934
+ * @returns {number|string[]} The run's verdict, or escalation lines (empty
935
+ * when the partial run passed and decides the push).
936
+ */
937
+ function runPartial({ plan, command, cwd, env, out }) {
938
+ const root = git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd;
939
+ const coverageDir = mkdtempSync(join(tmpdir(), "lisa-rspec-coverage-"));
940
+ try {
941
+ const code = run(rspecArgv({ plan, command }), cwd, {
942
+ ...env,
943
+ LISA_RSPEC_PARTIAL_COVERAGE_DIR: coverageDir,
944
+ });
945
+ if (plan.coverage !== CHANGED_FILES) return code;
946
+ if (code !== 0 && !handOffEscalated(coverageDir)) return code;
947
+ return checkChangedFiles({ root, coverageDir, plan, out });
948
+ } finally {
949
+ rmSync(coverageDir, { recursive: true, force: true });
950
+ }
951
+ }
952
+
953
+ /**
954
+ * Escalate a partial push to the full suite, or pass it when there is nothing
955
+ * to escalate: print why, tell the gate runner the run became a full one, and
956
+ * return the full run's verdict.
957
+ * @param {object} input Inputs.
958
+ * @param {string[]} input.escalation Escalation lines; empty passes the push.
959
+ * @param {NodeJS.ProcessEnv} input.env Environment.
960
+ * @param {(line: string) => void} input.out Output.
961
+ * @param {() => number} input.runFull Runs the full suite.
962
+ * @returns {number} Exit code.
963
+ */
964
+ function escalate({ escalation, env, out, runFull }) {
965
+ if (escalation.length === 0) return 0;
966
+ for (const line of escalation) out(line);
967
+ if (env[SELECTION_REPORT_ENV]) {
968
+ try {
969
+ writeFileSync(
970
+ env[SELECTION_REPORT_ENV],
971
+ `${JSON.stringify({ selection: "full", reason: escalation.join(" "), coverage: "none", tests: 0, escalated: true })}\n`
972
+ );
973
+ } catch {
974
+ // Without the report the runner reads nothing and reports as before.
975
+ }
976
+ }
977
+ return runFull();
978
+ }
979
+
980
+ if (invokedAsScript(import.meta.url)) {
981
+ process.exitCode = main(process.argv.slice(2));
982
+ }