@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,674 @@
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
+ * Download the test-to-file access map for a base commit (CodySwannGT/lisa#4593).
7
+ *
8
+ * The shared PR CI (`quality.yml`) uploads `test-access-map-<baseSha>-<runId>-<job>`
9
+ * artifacts from the unit job, every unit shard leg and the integration job,
10
+ * for Lisa and for every host whose `pushGate.affectedTests` is on
11
+ * (CodySwannGT/lisa#4611). The repository defaults to the one `origin` points
12
+ * at, so a host downloads its own maps. This picks
13
+ * the newest run whose base is `<sha>` itself or, failing that, the nearest
14
+ * ancestor of it, downloads every map artifact of that run, merges them, and
15
+ * saves:
16
+ *
17
+ * - `.lisa/test-access-map/map.json` — `{ "<test file>": ["<repo file>", …] }`
18
+ * - `.lisa/test-access-map/meta.json` — base, run, creation time, artifacts
19
+ *
20
+ * Usage:
21
+ * node scripts/fetch-test-access-map.mjs --base <sha> [--repo owner/name] [--out <dir>]
22
+ *
23
+ * With no map for `<sha>` or any ancestor still within retention it exits 1
24
+ * with `no access map for <sha>`; B4 (#4600) treats that as "run the full
25
+ * suite". It never invents a map.
26
+ *
27
+ * The push gate calls this, so it must be quick. The repository keeps
28
+ * thousands of artifacts and listing them all takes minutes, so it reads the
29
+ * listing newest first, one page at a time, and stops at the first page that
30
+ * yields a usable run, at a page older than `--max-age-days` (a map that old
31
+ * is stale anyway), or after `--max-pages`. The chosen run's own artifact
32
+ * list then supplies every map file it uploaded.
33
+ *
34
+ * A map decides which tests a push skips, so it is used only when it can be
35
+ * trusted, and otherwise the push runs the full suite. The artifacts of a
36
+ * public repository include those of fork pull requests and of runs whose
37
+ * tests crashed or were cancelled part way, and the newest artifact at a
38
+ * base is not necessarily a sound one. So each candidate run, newest first,
39
+ * must pass three checks before its map is used:
40
+ *
41
+ * - **Same repository.** GitHub's `actions/runs/<id>` must report the run's
42
+ * head repository as this repository. A fork's run recorded the fork's
43
+ * code and tracer, which could write an empty map.
44
+ * - **Succeeded.** The run's conclusion must be `success`, so every test job
45
+ * finished. A failed, cancelled or still-running run is skipped.
46
+ * - **Complete and its own.** Every piece must name this run, its base and
47
+ * the head commit GitHub reports, and each scope (`unit`, `integration`)
48
+ * must have all the pieces its pieces declare (`pieces`, one per shard leg,
49
+ * indexed by `piece`). A shard that never uploaded would otherwise drop its
50
+ * tests from the merged map.
51
+ *
52
+ * A refused run is skipped and the next candidate is tried, up to
53
+ * `MAX_RUN_CHECKS` runs. When none qualifies the reasons are printed on the
54
+ * `no access map` line.
55
+ *
56
+ * Maps are recorded only in pull-request runs, on the pull request's head
57
+ * code, and keyed on its base. Recording on pushes to `main` as well would
58
+ * key a map on the code it was recorded from, but `main` runs no test suite
59
+ * (`deploy.yml` sets `run_quality_checks: false`), and adding one would bill
60
+ * a full suite run per merge, the cost that setting exists to avoid. A
61
+ * same-repository pull request's head is written by someone with push
62
+ * access, so it is trusted to the same degree as the branch itself.
63
+ * @module fetch-test-access-map
64
+ */
65
+ import { execFileSync } from "node:child_process";
66
+ import * as fs from "node:fs";
67
+ import * as os from "node:os";
68
+ import * as path from "node:path";
69
+
70
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
71
+
72
+ /**
73
+ * `owner/name` from a GitHub remote URL (https, ssh or scp-like), or undefined.
74
+ * @param {string} url - Remote URL
75
+ * @returns {string | undefined} The repository
76
+ */
77
+ export function repositoryFromRemote(url) {
78
+ // Parsed by hand rather than with one pattern: a lazy name followed by an
79
+ // optional `.git` and `/` backtracks on a long remote (sonarjs/slow-regex).
80
+ const text = url.trim();
81
+ const host = text.indexOf("github.com");
82
+ if (host === -1) return undefined;
83
+ let rest = text.slice(host + "github.com".length);
84
+ const start = rest.length - rest.replace(/^[:/]+/u, "").length;
85
+ if (start === 0) return undefined;
86
+ rest = rest.slice(start);
87
+ if (rest.endsWith("/")) rest = rest.slice(0, -1);
88
+ const parts = rest.split("/");
89
+ if (parts.length !== 2) return undefined;
90
+ const [owner, raw] = parts;
91
+ const name = raw.endsWith(".git") && raw.length > 4 ? raw.slice(0, -4) : raw;
92
+ const plain = part => part.length > 0 && !/\s/u.test(part);
93
+ return plain(owner) && plain(name) ? `${owner}/${name}` : undefined;
94
+ }
95
+
96
+ /**
97
+ * The repository whose maps to read: `GITHUB_REPOSITORY`, else `origin`.
98
+ * @returns {string | undefined} owner/name, or undefined when neither says
99
+ */
100
+ function defaultRepository() {
101
+ if (process.env.GITHUB_REPOSITORY) return process.env.GITHUB_REPOSITORY;
102
+ try {
103
+ return repositoryFromRemote(
104
+ execFileSync("git", ["remote", "get-url", "origin"], {
105
+ encoding: "utf8",
106
+ stdio: ["ignore", "pipe", "ignore"],
107
+ })
108
+ );
109
+ } catch {
110
+ // probe-direction: fail-closed — no repository means no map, so the push
111
+ // runs the full suite.
112
+ return undefined;
113
+ }
114
+ }
115
+ const DEFAULT_OUT = ".lisa/test-access-map";
116
+ const ARTIFACT_NAME = /^test-access-map-([0-9a-f]{40})-(\d+)-(.+)$/;
117
+ const DEFAULT_MAX_PAGES = 10;
118
+ const DEFAULT_MAX_AGE_DAYS = 7;
119
+ const PAGE_SIZE = 100;
120
+ const LISTING_JQ =
121
+ ".artifacts[] | {name, runId: .workflow_run.id, createdAt: .created_at, expired}";
122
+ const RUN_JQ =
123
+ "{conclusion, headSha: .head_sha, headRepository: .head_repository.full_name}";
124
+ const FULL_SHA = /^[0-9a-f]{40}$/;
125
+ /** Candidate runs checked before giving up; each costs a GitHub API call. */
126
+ const MAX_RUN_CHECKS = 10;
127
+
128
+ /**
129
+ * @typedef {object} MapArtifact
130
+ * @property {string} name - Artifact name
131
+ * @property {string} baseSha - Base commit the map was keyed on
132
+ * @property {string} runId - Workflow run that uploaded it
133
+ * @property {string} createdAt - ISO creation time
134
+ */
135
+
136
+ /**
137
+ * @typedef {object} Deps
138
+ * @property {(command: string, args: ReadonlyArray<string>) => string} run - Run a command, return stdout; throws on a non-zero exit
139
+ * @property {() => Date} now - Current time
140
+ * @property {(line: string) => void} out - Standard output
141
+ * @property {(line: string) => void} err - Standard error
142
+ */
143
+
144
+ /**
145
+ * Parse `--base`, `--repo`, `--out`, `--max-pages` and `--max-age-days`.
146
+ * @param {ReadonlyArray<string>} argv - Arguments after the script
147
+ * @returns {{ base: string | undefined, repo: string | undefined, out: string, maxPages: number, maxAgeDays: number }} Options
148
+ */
149
+ export function parseArgs(argv) {
150
+ const value = flag => {
151
+ const index = argv.indexOf(flag);
152
+ const inline = argv.find(arg => arg.startsWith(`${flag}=`));
153
+ if (inline !== undefined) return inline.slice(flag.length + 1);
154
+ return index === -1 ? undefined : argv[index + 1];
155
+ };
156
+ const number = (flag, fallback) => {
157
+ const parsed = Number(value(flag));
158
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
159
+ };
160
+ return {
161
+ base: value("--base"),
162
+ repo: value("--repo") ?? defaultRepository(),
163
+ out: value("--out") ?? DEFAULT_OUT,
164
+ maxPages: number("--max-pages", DEFAULT_MAX_PAGES),
165
+ maxAgeDays: number("--max-age-days", DEFAULT_MAX_AGE_DAYS),
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Map artifacts from `gh api` NDJSON output (`{name, runId, createdAt}` per
171
+ * line). Expired artifacts and other artifacts are dropped.
172
+ * @param {string} output - NDJSON
173
+ * @returns {ReadonlyArray<MapArtifact>} Artifacts whose name parses
174
+ */
175
+ export function parseArtifacts(output) {
176
+ return output
177
+ .split("\n")
178
+ .filter(line => line.trim() !== "")
179
+ .flatMap(line => {
180
+ const parsed = JSON.parse(line);
181
+ const match = ARTIFACT_NAME.exec(parsed.name ?? "");
182
+ if (!match || parsed.expired === true) return [];
183
+ return [
184
+ {
185
+ name: parsed.name,
186
+ baseSha: match[1],
187
+ runId: String(parsed.runId ?? match[2]),
188
+ createdAt: parsed.createdAt ?? "",
189
+ },
190
+ ];
191
+ });
192
+ }
193
+
194
+ /**
195
+ * Commits from `ancestor` to `sha`, or undefined when `ancestor` is not one.
196
+ * @param {Deps["run"]} run - Command runner
197
+ * @param {string} ancestor - Candidate base
198
+ * @param {string} sha - Requested commit
199
+ * @returns {number | undefined} Distance
200
+ */
201
+ function ancestorDistance(run, ancestor, sha) {
202
+ if (ancestor === sha) return 0;
203
+ try {
204
+ run("git", ["merge-base", "--is-ancestor", ancestor, sha]);
205
+ return Number(
206
+ run("git", ["rev-list", "--count", `${ancestor}..${sha}`]).trim()
207
+ );
208
+ } catch {
209
+ // probe-direction: fail-closed — a base git cannot place below `sha` is
210
+ // dropped as a candidate, so fewer maps qualify and the push runs more.
211
+ return undefined;
212
+ }
213
+ }
214
+
215
+ /**
216
+ * @typedef {{ runId: string, baseSha: string, distance: number, artifacts: ReadonlyArray<MapArtifact> }} RunChoice
217
+ */
218
+
219
+ /**
220
+ * Every candidate run in preference order: base equal to `sha` first, then
221
+ * nearer ancestors, and within one base the newest run first. Each run must
222
+ * still pass {@link runRefusal} and {@link piecesRefusal} before it is used.
223
+ * @param {ReadonlyArray<MapArtifact>} artifacts - Published map artifacts
224
+ * @param {string} sha - Requested commit
225
+ * @param {Deps["run"]} run - Command runner
226
+ * @returns {ReadonlyArray<RunChoice>} Candidates
227
+ */
228
+ export function rankRuns(artifacts, sha, run) {
229
+ const bases = [...new Set(artifacts.map(artifact => artifact.baseSha))]
230
+ .map(baseSha => ({
231
+ baseSha,
232
+ distance: ancestorDistance(run, baseSha, sha),
233
+ }))
234
+ .filter(entry => entry.distance !== undefined)
235
+ .sort((a, b) => a.distance - b.distance);
236
+ return bases.flatMap(({ baseSha, distance }) => {
237
+ const atBase = artifacts.filter(artifact => artifact.baseSha === baseSha);
238
+ const runs = [...atBase]
239
+ .sort(
240
+ (a, b) =>
241
+ b.createdAt.localeCompare(a.createdAt) ||
242
+ Number(b.runId) - Number(a.runId)
243
+ )
244
+ .map(artifact => artifact.runId);
245
+ return [...new Set(runs)].map(runId => ({
246
+ runId,
247
+ baseSha,
248
+ distance,
249
+ artifacts: atBase.filter(artifact => artifact.runId === runId),
250
+ }));
251
+ });
252
+ }
253
+
254
+ /**
255
+ * The preferred candidate run, before any trust check (see {@link rankRuns}).
256
+ * @param {ReadonlyArray<MapArtifact>} artifacts - Published map artifacts
257
+ * @param {string} sha - Requested commit
258
+ * @param {Deps["run"]} run - Command runner
259
+ * @returns {RunChoice | undefined} Choice
260
+ */
261
+ export function selectRun(artifacts, sha, run) {
262
+ return rankRuns(artifacts, sha, run)[0];
263
+ }
264
+
265
+ /**
266
+ * Why a workflow run's map must not be used, or undefined when it may.
267
+ *
268
+ * Only a run of this repository's own code (not a fork pull request's) that
269
+ * concluded `success` qualifies: a fork controls the code that recorded the
270
+ * map, and a failed or cancelled run may have stopped before every test file
271
+ * was traced.
272
+ * @param {{ conclusion?: unknown, headSha?: unknown, headRepository?: unknown } | null | undefined} info - What `gh api repos/<repo>/actions/runs/<id>` reports, through `RUN_JQ`
273
+ * @param {string} repo - owner/name the map is meant for
274
+ * @returns {string | undefined} The reason, or undefined
275
+ */
276
+ export function runRefusal(info, repo) {
277
+ const head =
278
+ typeof info?.headRepository === "string" ? info.headRepository : "";
279
+ if (head.toLowerCase() !== repo.toLowerCase()) {
280
+ return `its code came from ${head || "an unknown repository"}, not ${repo}`;
281
+ }
282
+ if (info?.conclusion !== "success") {
283
+ return `it did not succeed (${typeof info?.conclusion === "string" ? info.conclusion : "still running"})`;
284
+ }
285
+ if (typeof info.headSha !== "string" || !FULL_SHA.test(info.headSha)) {
286
+ return "GitHub reported no head commit for it";
287
+ }
288
+ return undefined;
289
+ }
290
+
291
+ /**
292
+ * Why a run's downloaded map pieces do not form one complete map of that run,
293
+ * or undefined when they do.
294
+ *
295
+ * Each piece names the run, base and head commit it was recorded in, its
296
+ * scope, and how many pieces that scope has (`pieces`, one per shard leg)
297
+ * with its own zero-based index (`piece`). Every scope that uploaded anything
298
+ * must have each of its pieces exactly once; a piece that does not say how
299
+ * many there are (an older recorder) is refused too.
300
+ * @param {ReadonlyArray<Record<string, unknown>>} metas - The pieces' metadata
301
+ * @param {{ runId: string, baseSha: string, headSha: string }} run - The run they must belong to
302
+ * @returns {string | undefined} The reason, or undefined
303
+ */
304
+ export function piecesRefusal(metas, { runId, baseSha, headSha }) {
305
+ if (metas.length === 0) return "its artifacts hold no map";
306
+ const foreign = metas.some(
307
+ meta =>
308
+ String(meta.runId ?? "") !== runId ||
309
+ meta.baseSha !== baseSha ||
310
+ meta.headSha !== headSha
311
+ );
312
+ if (foreign) {
313
+ return `a map piece was not recorded by run ${runId} at its head commit ${headSha.slice(0, 12)}`;
314
+ }
315
+ if (metas.some(meta => typeof meta.scope !== "string" || !meta.scope)) {
316
+ return "a map piece has no scope";
317
+ }
318
+ const scopes = [...new Set(metas.map(meta => String(meta.scope)))].sort();
319
+ for (const scope of scopes) {
320
+ const reason = scopeRefusal(
321
+ scope,
322
+ metas.filter(meta => meta.scope === scope)
323
+ );
324
+ if (reason) return reason;
325
+ }
326
+ return undefined;
327
+ }
328
+
329
+ /**
330
+ * Why one scope's pieces are not a complete set, or undefined.
331
+ * @param {string} scope - The scope
332
+ * @param {ReadonlyArray<Record<string, unknown>>} metas - That scope's pieces
333
+ * @returns {string | undefined} The reason, or undefined
334
+ */
335
+ function scopeRefusal(scope, metas) {
336
+ const declared = [...new Set(metas.map(meta => meta.pieces))];
337
+ if (declared.length !== 1) {
338
+ return `the ${scope} map pieces disagree on how many there are`;
339
+ }
340
+ const [total] = declared;
341
+ if (!Number.isInteger(total) || total < 1) {
342
+ return `the ${scope} map does not say how many pieces it has`;
343
+ }
344
+ const indices = new Set(
345
+ metas
346
+ .map(meta => meta.piece)
347
+ .filter(piece => Number.isInteger(piece) && piece >= 0 && piece < total)
348
+ );
349
+ if (indices.size !== total || metas.length !== total) {
350
+ return `only ${indices.size} of ${total} ${scope} pieces were uploaded`;
351
+ }
352
+ return undefined;
353
+ }
354
+
355
+ /**
356
+ * Every `.json` file under a directory, recursively.
357
+ * @param {string} directory - Directory to walk
358
+ * @returns {ReadonlyArray<string>} File paths
359
+ */
360
+ function walk(directory) {
361
+ return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
362
+ const full = path.join(directory, entry.name);
363
+ if (entry.isDirectory()) return walk(full);
364
+ return entry.name.endsWith(".json") ? [full] : [];
365
+ });
366
+ }
367
+
368
+ /**
369
+ * Merge downloaded `{ meta, map }` files into one map; a test file listed by
370
+ * several jobs gets the union of their entries.
371
+ * @param {ReadonlyArray<{ meta?: Record<string, unknown>, map?: Record<string, ReadonlyArray<string>> }>} documents - Parsed map files
372
+ * @returns {{ map: Readonly<Record<string, ReadonlyArray<string>>>, metas: ReadonlyArray<Record<string, unknown>> }} Merged map and the metadata seen
373
+ */
374
+ export function mergeMaps(documents) {
375
+ const valid = documents.filter(
376
+ document => document && typeof document.map === "object"
377
+ );
378
+ const keys = [
379
+ ...new Set(valid.flatMap(document => Object.keys(document.map))),
380
+ ];
381
+ const map = Object.fromEntries(
382
+ keys
383
+ .sort()
384
+ .map(key => [
385
+ key,
386
+ [...new Set(valid.flatMap(document => document.map[key] ?? []))].sort(),
387
+ ])
388
+ );
389
+ return { map, metas: valid.map(document => document.meta ?? {}) };
390
+ }
391
+
392
+ /**
393
+ * The union of the full-rerun triggers each recorded map carries (the
394
+ * project's Vitest `forceRerunTriggers`, `setupFiles` and `globalSetup`).
395
+ * @param {ReadonlyArray<Record<string, unknown>>} metas - Recorded metadata
396
+ * @returns {ReadonlyArray<string>} Sorted, de-duplicated globs
397
+ */
398
+ export function mergedTriggers(metas) {
399
+ return [
400
+ ...new Set(
401
+ metas.flatMap(meta =>
402
+ Array.isArray(meta.triggers)
403
+ ? meta.triggers.filter(glob => typeof glob === "string")
404
+ : []
405
+ )
406
+ ),
407
+ ].sort();
408
+ }
409
+
410
+ /**
411
+ * A duration as `2d 3h`, `3h 12m` or `5m`.
412
+ * @param {number} milliseconds - Duration
413
+ * @returns {string} Human-readable age
414
+ */
415
+ export function formatAge(milliseconds) {
416
+ const minutes = Math.max(0, Math.floor(milliseconds / 60_000));
417
+ const days = Math.floor(minutes / 1440);
418
+ const hours = Math.floor((minutes % 1440) / 60);
419
+ if (days > 0) return `${days}d ${hours}h`;
420
+ if (hours > 0) return `${hours}h ${minutes % 60}m`;
421
+ return `${minutes}m`;
422
+ }
423
+
424
+ /**
425
+ * @typedef {object} LoadedMap
426
+ * @property {RunChoice} choice - The run, with every artifact it uploaded
427
+ * @property {Readonly<Record<string, ReadonlyArray<string>>>} map - Merged map
428
+ * @property {ReadonlyArray<Record<string, unknown>>} metas - Its pieces' metadata
429
+ */
430
+
431
+ /**
432
+ * Page through the artifact listing, newest first, trying each candidate run
433
+ * in preference order until one passes every trust check.
434
+ * @param {object} input - Inputs
435
+ * @param {string} input.repo - owner/name
436
+ * @param {string} input.sha - Requested commit
437
+ * @param {number} input.maxPages - Page budget
438
+ * @param {number} input.maxAgeDays - Oldest artifact worth reading
439
+ * @param {Deps} input.deps - Injected effects
440
+ * @returns {{ loaded: LoadedMap | undefined, refusals: ReadonlyArray<string> }} The map, or why each candidate was refused
441
+ */
442
+ function findRun({ repo, sha, maxPages, maxAgeDays, deps }) {
443
+ const oldest = deps.now().getTime() - maxAgeDays * 86_400_000;
444
+ const seen = [];
445
+ const tried = new Set();
446
+ const refusals = [];
447
+ for (let page = 1; page <= maxPages; page += 1) {
448
+ const output = deps.run("gh", [
449
+ "api",
450
+ `repos/${repo}/actions/artifacts?per_page=${PAGE_SIZE}&page=${page}`,
451
+ "--jq",
452
+ LISTING_JQ,
453
+ ]);
454
+ const lines = output.split("\n").filter(entry => entry.trim() !== "");
455
+ seen.push(...parseArtifacts(output));
456
+ for (const candidate of rankRuns(seen, sha, deps.run)) {
457
+ if (tried.has(candidate.runId)) continue;
458
+ if (tried.size >= MAX_RUN_CHECKS) return { loaded: undefined, refusals };
459
+ tried.add(candidate.runId);
460
+ const result = loadRun(repo, candidate, deps);
461
+ if ("loaded" in result) return { loaded: result.loaded, refusals };
462
+ refusals.push(`refused run ${candidate.runId} (${result.refusal})`);
463
+ }
464
+ const last = lines.length ? JSON.parse(lines.at(-1)).createdAt : "";
465
+ if (lines.length < PAGE_SIZE || Date.parse(last) < oldest) break;
466
+ }
467
+ return { loaded: undefined, refusals };
468
+ }
469
+
470
+ /**
471
+ * Verify one candidate run with GitHub, download its pieces and check them.
472
+ * @param {string} repo - owner/name
473
+ * @param {RunChoice} candidate - The run
474
+ * @param {Deps} deps - Injected effects
475
+ * @returns {{ loaded: LoadedMap } | { refusal: string }} The map, or why not
476
+ */
477
+ function loadRun(repo, candidate, deps) {
478
+ const info = (() => {
479
+ try {
480
+ return JSON.parse(
481
+ deps.run("gh", [
482
+ "api",
483
+ `repos/${repo}/actions/runs/${candidate.runId}`,
484
+ "--jq",
485
+ RUN_JQ,
486
+ ])
487
+ );
488
+ } catch (error) {
489
+ // probe-direction: fail-closed — a run GitHub cannot describe is not
490
+ // trusted, so its map is skipped and the push runs more tests.
491
+ return {
492
+ unreadable: error instanceof Error ? error.message : String(error),
493
+ };
494
+ }
495
+ })();
496
+ if (info?.unreadable !== undefined) {
497
+ return {
498
+ refusal: `could not read run ${candidate.runId} from GitHub: ${info.unreadable}`,
499
+ };
500
+ }
501
+ const distrust = runRefusal(info, repo);
502
+ if (distrust) return { refusal: distrust };
503
+ const download = fs.mkdtempSync(path.join(os.tmpdir(), "lisa-access-map-"));
504
+ try {
505
+ const choice = completeRun(repo, candidate, deps);
506
+ deps.run("gh", [
507
+ "run",
508
+ "download",
509
+ choice.runId,
510
+ "--repo",
511
+ repo,
512
+ ...choice.artifacts.flatMap(artifact => ["--name", artifact.name]),
513
+ "--dir",
514
+ download,
515
+ ]);
516
+ const { map, metas } = mergeMaps(
517
+ walk(download).map(file => JSON.parse(fs.readFileSync(file, "utf8")))
518
+ );
519
+ const incomplete = piecesRefusal(metas, {
520
+ runId: choice.runId,
521
+ baseSha: choice.baseSha,
522
+ headSha: info.headSha,
523
+ });
524
+ if (incomplete) return { refusal: incomplete };
525
+ return { loaded: { choice, map, metas } };
526
+ } catch (error) {
527
+ // probe-direction: fail-closed — a run whose map cannot be downloaded or
528
+ // parsed is skipped like any other refused run.
529
+ return {
530
+ refusal: `its map could not be downloaded: ${error instanceof Error ? error.message : String(error)}`,
531
+ };
532
+ } finally {
533
+ fs.rmSync(download, { recursive: true, force: true });
534
+ }
535
+ }
536
+
537
+ /**
538
+ * Add the chosen run's other map artifacts (a page boundary can split them).
539
+ * @param {string} repo - owner/name
540
+ * @param {RunChoice} choice - The run
541
+ * @param {Deps} deps - Injected effects
542
+ * @returns {RunChoice} The run with every artifact
543
+ */
544
+ function completeRun(repo, choice, deps) {
545
+ const own = parseArtifacts(
546
+ deps.run("gh", [
547
+ "api",
548
+ `repos/${repo}/actions/runs/${choice.runId}/artifacts?per_page=${PAGE_SIZE}`,
549
+ "--jq",
550
+ LISTING_JQ,
551
+ ])
552
+ ).filter(
553
+ artifact =>
554
+ artifact.runId === choice.runId && artifact.baseSha === choice.baseSha
555
+ );
556
+ const names = new Set(choice.artifacts.map(artifact => artifact.name));
557
+ return {
558
+ ...choice,
559
+ artifacts: [
560
+ ...choice.artifacts,
561
+ ...own.filter(artifact => !names.has(artifact.name)),
562
+ ],
563
+ };
564
+ }
565
+
566
+ /**
567
+ * Write `map.json` and `meta.json` for a trusted run and print its summary.
568
+ * @param {object} input - Inputs
569
+ * @param {LoadedMap} input.loaded - The trusted map
570
+ * @param {string} input.sha - Requested commit
571
+ * @param {string} input.out - Output directory
572
+ * @param {Deps} input.deps - Injected effects
573
+ * @returns {void}
574
+ */
575
+ function saveMap({ loaded, sha, out, deps }) {
576
+ const { choice, map, metas } = loaded;
577
+ const createdAt =
578
+ metas
579
+ .map(meta => String(meta.createdAt ?? ""))
580
+ .filter(Boolean)
581
+ .sort()[0] ??
582
+ choice.artifacts[0]?.createdAt ??
583
+ "";
584
+ fs.mkdirSync(out, { recursive: true });
585
+ fs.writeFileSync(
586
+ path.join(out, "map.json"),
587
+ `${JSON.stringify(map, null, 2)}\n`
588
+ );
589
+ fs.writeFileSync(
590
+ path.join(out, "meta.json"),
591
+ `${JSON.stringify(
592
+ {
593
+ requestedBase: sha,
594
+ baseSha: choice.baseSha,
595
+ commitsBehind: choice.distance,
596
+ runId: choice.runId,
597
+ createdAt,
598
+ artifacts: choice.artifacts.map(artifact => artifact.name),
599
+ testFiles: Object.keys(map).length,
600
+ triggers: mergedTriggers(metas),
601
+ },
602
+ null,
603
+ 2
604
+ )}\n`
605
+ );
606
+ const age = formatAge(deps.now().getTime() - Date.parse(createdAt));
607
+ deps.out(
608
+ `access map: base ${choice.baseSha} (${choice.distance} commits behind ${sha}), run ${choice.runId}, created ${createdAt} (age ${age}), ${Object.keys(map).length} test files → ${path.join(out, "map.json")}`
609
+ );
610
+ }
611
+
612
+ /**
613
+ * Fetch, merge and save the map for `--base`.
614
+ * @param {ReadonlyArray<string>} argv - Arguments after the script
615
+ * @param {Deps} deps - Injected effects
616
+ * @returns {number} Exit code
617
+ */
618
+ export function main(argv, deps) {
619
+ const { base, repo, out, maxPages, maxAgeDays } = parseArgs(argv);
620
+ if (!base) {
621
+ deps.err(
622
+ "usage: fetch-test-access-map.mjs --base <sha> [--repo owner/name] [--out <dir>]"
623
+ );
624
+ return 2;
625
+ }
626
+ if (!repo) {
627
+ deps.err(
628
+ "no access map: could not tell which GitHub repository to read (no --repo, GITHUB_REPOSITORY or GitHub origin remote)"
629
+ );
630
+ return 1;
631
+ }
632
+ const sha = (() => {
633
+ try {
634
+ return deps
635
+ .run("git", ["rev-parse", "--verify", `${base}^{commit}`])
636
+ .trim();
637
+ } catch {
638
+ return base;
639
+ }
640
+ })();
641
+ const found = (() => {
642
+ try {
643
+ return findRun({ repo, sha, maxPages, maxAgeDays, deps });
644
+ } catch (error) {
645
+ deps.err(
646
+ `fetch-test-access-map: could not list artifacts of ${repo}: ${error instanceof Error ? error.message : String(error)}`
647
+ );
648
+ return null;
649
+ }
650
+ })();
651
+ if (found === null) return 1;
652
+ if (found.loaded === undefined) {
653
+ // One line: the push gate reports the last stderr line as the reason.
654
+ const why = found.refusals.length ? `: ${found.refusals.join("; ")}` : "";
655
+ deps.err(`no access map for ${base}${why}`);
656
+ return 1;
657
+ }
658
+ saveMap({ loaded: found.loaded, sha, out, deps });
659
+ return 0;
660
+ }
661
+
662
+ if (invokedAsScript(import.meta.url)) {
663
+ process.exitCode = main(process.argv.slice(2), {
664
+ run: (command, args) =>
665
+ execFileSync(command, args, {
666
+ encoding: "utf8",
667
+ stdio: ["ignore", "pipe", "pipe"],
668
+ maxBuffer: 256 * 1024 * 1024,
669
+ }),
670
+ now: () => new Date(),
671
+ out: line => process.stdout.write(`${line}\n`),
672
+ err: line => process.stderr.write(`${line}\n`),
673
+ });
674
+ }