@codyswann/lisa 5.4.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/README.md +60 -3
  2. package/all/copy-contents/gitignore +16 -0
  3. package/all/copy-contents/scripts/lisa-mutation.sh +4 -6
  4. package/all/copy-overwrite/scripts/fetch-test-access-map.d.mts +71 -0
  5. package/all/copy-overwrite/scripts/fetch-test-access-map.mjs +674 -0
  6. package/all/copy-overwrite/scripts/lib/affected-tests.mjs +818 -0
  7. package/all/copy-overwrite/scripts/lib/automation-provenance-local.mjs +22 -1
  8. package/all/copy-overwrite/scripts/lib/build-marker.mjs +410 -0
  9. package/all/copy-overwrite/scripts/lib/gate-pass-cache.mjs +537 -0
  10. package/all/copy-overwrite/scripts/lib/kill-marks.mjs +1 -2
  11. package/all/copy-overwrite/scripts/lib/lisa-cleanup-sweep-processes.mjs +3 -4
  12. package/all/copy-overwrite/scripts/lib/npm-update-controller-broker.mjs +1 -1
  13. package/all/copy-overwrite/scripts/lib/npm-update-gate-hooks.mjs +2 -1
  14. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +8 -1
  15. package/all/copy-overwrite/scripts/lib/npm-update-hosted-hook.mjs +1 -1
  16. package/all/copy-overwrite/scripts/lib/npm-update-tool-launcher.mjs +1 -1
  17. package/all/copy-overwrite/scripts/lib/push-admission.mjs +158 -0
  18. package/all/copy-overwrite/scripts/lib/push-gate-defaults.d.mts +34 -0
  19. package/all/copy-overwrite/scripts/lib/push-gate-defaults.mjs +147 -0
  20. package/all/copy-overwrite/scripts/lib/push-timing.mjs +323 -0
  21. package/all/copy-overwrite/scripts/lib/rspec-selection.mjs +672 -0
  22. package/all/copy-overwrite/scripts/lisa-affected-tests.mjs +566 -0
  23. package/all/copy-overwrite/scripts/lisa-gates.mjs +29 -0
  24. package/all/copy-overwrite/scripts/lisa-lint-staged-preflight.mjs +10 -1
  25. package/all/copy-overwrite/scripts/lisa-push-timing-report.mjs +153 -0
  26. package/all/copy-overwrite/scripts/lisa-rspec-select.mjs +982 -0
  27. package/all/copy-overwrite/scripts/lisa-run-gates.mjs +231 -6
  28. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +105 -17
  29. package/all/deletions.json +11 -2
  30. package/cdk/create-only/vitest.config.local.ts +1 -7
  31. package/cdk/package-lisa/package.lisa.json +4 -4
  32. package/dist/cli/admit-cmd.d.ts +21 -0
  33. package/dist/cli/admit-cmd.d.ts.map +1 -0
  34. package/dist/cli/admit-cmd.js +142 -0
  35. package/dist/cli/admit-cmd.js.map +1 -0
  36. package/dist/cli/check-cmd.d.ts +72 -0
  37. package/dist/cli/check-cmd.d.ts.map +1 -0
  38. package/dist/cli/check-cmd.js +316 -0
  39. package/dist/cli/check-cmd.js.map +1 -0
  40. package/dist/cli/index.d.ts.map +1 -1
  41. package/dist/cli/index.js +6 -4
  42. package/dist/cli/index.js.map +1 -1
  43. package/dist/cli/lisa-test-run-admission.d.ts +18 -0
  44. package/dist/cli/lisa-test-run-admission.d.ts.map +1 -0
  45. package/dist/cli/lisa-test-run-admission.js +62 -0
  46. package/dist/cli/lisa-test-run-admission.js.map +1 -0
  47. package/dist/cli/lisa-test-run-payload.d.ts +37 -0
  48. package/dist/cli/lisa-test-run-payload.d.ts.map +1 -0
  49. package/dist/cli/lisa-test-run-payload.js +55 -0
  50. package/dist/cli/lisa-test-run-payload.js.map +1 -0
  51. package/dist/cli/lisa-test-run-shard-files.d.ts +89 -0
  52. package/dist/cli/lisa-test-run-shard-files.d.ts.map +1 -0
  53. package/dist/cli/lisa-test-run-shard-files.js +239 -0
  54. package/dist/cli/lisa-test-run-shard-files.js.map +1 -0
  55. package/dist/cli/lisa-test-run-shard.d.ts +6 -2
  56. package/dist/cli/lisa-test-run-shard.d.ts.map +1 -1
  57. package/dist/cli/lisa-test-run-shard.js +25 -13
  58. package/dist/cli/lisa-test-run-shard.js.map +1 -1
  59. package/dist/cli/lisa-test-run.d.ts +1 -1
  60. package/dist/cli/lisa-test-run.d.ts.map +1 -1
  61. package/dist/cli/lisa-test-run.js +47 -10
  62. package/dist/cli/lisa-test-run.js.map +1 -1
  63. package/dist/cli/update-check-hook.d.ts.map +1 -1
  64. package/dist/cli/update-check-hook.js +3 -0
  65. package/dist/cli/update-check-hook.js.map +1 -1
  66. package/dist/configs/vitest/base.d.ts +58 -135
  67. package/dist/configs/vitest/base.d.ts.map +1 -1
  68. package/dist/configs/vitest/base.js +76 -228
  69. package/dist/configs/vitest/base.js.map +1 -1
  70. package/dist/configs/vitest/cdk.d.ts.map +1 -1
  71. package/dist/configs/vitest/cdk.js +3 -2
  72. package/dist/configs/vitest/cdk.js.map +1 -1
  73. package/dist/configs/vitest/coverage-include-global-setup.d.ts.map +1 -1
  74. package/dist/configs/vitest/coverage-include-global-setup.js +3 -4
  75. package/dist/configs/vitest/coverage-include-global-setup.js.map +1 -1
  76. package/dist/configs/vitest/coverage-reports-directory.d.ts +27 -5
  77. package/dist/configs/vitest/coverage-reports-directory.d.ts.map +1 -1
  78. package/dist/configs/vitest/coverage-reports-directory.js +47 -10
  79. package/dist/configs/vitest/coverage-reports-directory.js.map +1 -1
  80. package/dist/configs/vitest/harper-fabric.d.ts.map +1 -1
  81. package/dist/configs/vitest/harper-fabric.js +3 -2
  82. package/dist/configs/vitest/harper-fabric.js.map +1 -1
  83. package/dist/configs/vitest/nestjs.d.ts.map +1 -1
  84. package/dist/configs/vitest/nestjs.js +3 -2
  85. package/dist/configs/vitest/nestjs.js.map +1 -1
  86. package/dist/configs/vitest/phaser.d.ts.map +1 -1
  87. package/dist/configs/vitest/phaser.js +3 -2
  88. package/dist/configs/vitest/phaser.js.map +1 -1
  89. package/dist/configs/vitest/refusal-announcement.d.ts +51 -0
  90. package/dist/configs/vitest/refusal-announcement.d.ts.map +1 -0
  91. package/dist/configs/vitest/refusal-announcement.js +97 -0
  92. package/dist/configs/vitest/refusal-announcement.js.map +1 -0
  93. package/dist/configs/vitest/socket-safe-temp-base.d.ts +3 -4
  94. package/dist/configs/vitest/socket-safe-temp-base.d.ts.map +1 -1
  95. package/dist/configs/vitest/socket-safe-temp-base.js +7 -6
  96. package/dist/configs/vitest/socket-safe-temp-base.js.map +1 -1
  97. package/dist/configs/vitest/typescript.d.ts.map +1 -1
  98. package/dist/configs/vitest/typescript.js +3 -2
  99. package/dist/configs/vitest/typescript.js.map +1 -1
  100. package/dist/core/admission-decision.d.ts +110 -0
  101. package/dist/core/admission-decision.d.ts.map +1 -0
  102. package/dist/core/admission-decision.js +91 -0
  103. package/dist/core/admission-decision.js.map +1 -0
  104. package/dist/core/admission-lock.d.ts +69 -0
  105. package/dist/core/admission-lock.d.ts.map +1 -0
  106. package/dist/core/admission-lock.js +278 -0
  107. package/dist/core/admission-lock.js.map +1 -0
  108. package/dist/core/admission-settings.d.ts +69 -0
  109. package/dist/core/admission-settings.d.ts.map +1 -0
  110. package/dist/core/admission-settings.js +204 -0
  111. package/dist/core/admission-settings.js.map +1 -0
  112. package/dist/core/admission-state.d.ts +50 -0
  113. package/dist/core/admission-state.d.ts.map +1 -0
  114. package/dist/core/admission-state.js +168 -0
  115. package/dist/core/admission-state.js.map +1 -0
  116. package/dist/core/admission.d.ts +70 -0
  117. package/dist/core/admission.d.ts.map +1 -0
  118. package/dist/core/admission.js +205 -0
  119. package/dist/core/admission.js.map +1 -0
  120. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  121. package/dist/core/lisa-owned-hash-ledger.js +318 -0
  122. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  123. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  124. package/dist/core/project-config-push-gate.d.ts +66 -0
  125. package/dist/core/project-config-push-gate.d.ts.map +1 -0
  126. package/dist/core/project-config-push-gate.js +82 -0
  127. package/dist/core/project-config-push-gate.js.map +1 -0
  128. package/dist/core/project-config.d.ts +4 -0
  129. package/dist/core/project-config.d.ts.map +1 -1
  130. package/dist/core/project-config.js +14 -9
  131. package/dist/core/project-config.js.map +1 -1
  132. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  133. package/dist/core/upstream-evidence-manifest.js +197 -123
  134. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  135. package/expo/package-lisa/package.lisa.json +2 -2
  136. package/harper-fabric/package-lisa/package.lisa.json +4 -4
  137. package/nestjs/create-only/vitest.config.local.ts +1 -7
  138. package/nestjs/package-lisa/package.lisa.json +4 -4
  139. package/npm-package/package-lisa/package.lisa.json +4 -4
  140. package/package.json +12 -11
  141. package/phaser/package-lisa/package.lisa.json +4 -4
  142. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  143. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  144. package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  145. package/plugins/lisa/.codex-plugin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  146. package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +1 -1
  147. package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  148. package/plugins/lisa/skills/lisa-git-submit-pr/SKILL.md +1 -1
  149. package/plugins/lisa/skills/lisa-implement/SKILL.md +1 -1
  150. package/plugins/lisa-agy/plugin.json +1 -1
  151. package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  152. package/plugins/lisa-agy/skills/lisa-git-submit-pr/SKILL.md +1 -1
  153. package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +1 -1
  154. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  155. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  156. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  157. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  159. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  160. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  161. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  162. package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  163. package/plugins/lisa-copilot/skills/lisa-git-submit-pr/SKILL.md +1 -1
  164. package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +1 -1
  165. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  166. package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  167. package/plugins/lisa-cursor/skills/lisa-git-submit-pr/SKILL.md +1 -1
  168. package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +1 -1
  169. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  170. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  171. package/plugins/lisa-devin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  172. package/plugins/lisa-devin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  173. package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +1 -1
  174. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  175. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  176. package/plugins/lisa-expo-agy/plugin.json +1 -1
  177. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  178. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  179. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  180. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  181. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  182. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  183. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  184. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  185. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  186. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  187. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  188. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  189. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  190. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  191. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  192. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  193. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  194. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  195. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  196. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  197. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  198. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  199. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  200. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  201. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  202. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  203. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  204. package/plugins/lisa-rails-agy/plugin.json +1 -1
  205. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  206. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  207. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  208. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  209. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  210. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  211. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  212. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  213. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  214. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  215. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  216. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  217. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  218. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  219. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  220. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  221. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  222. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  223. package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  224. package/plugins/src/base/skills/lisa-git-submit-pr/SKILL.md +1 -1
  225. package/plugins/src/base/skills/lisa-implement/SKILL.md +1 -1
  226. package/rails/copy-overwrite/Gemfile.lisa +8 -0
  227. package/rails/copy-overwrite/lefthook.yml +25 -11
  228. package/rails/copy-overwrite/scripts/lisa-rails-gates.mjs +686 -0
  229. package/rails/copy-overwrite/scripts/lisa-rspec-shards.mjs +2 -2
  230. package/rails/copy-overwrite/scripts/lisa_crystalball_recorder.rb +239 -0
  231. package/rails/copy-overwrite/scripts/lisa_rspec_partial_coverage.rb +83 -0
  232. package/scripts/build-unless-marked.mjs +83 -0
  233. package/scripts/check-plugins-sync.sh +22 -5
  234. package/scripts/classify-markdown-assertions.mjs +141 -0
  235. package/scripts/integration-shard-build.mjs +143 -0
  236. package/scripts/lib/history-scanner-suites.mjs +19 -0
  237. package/scripts/lib/markdown-assertions/classify.mjs +289 -0
  238. package/scripts/lib/markdown-assertions/context.mjs +53 -0
  239. package/scripts/lib/markdown-assertions/corpus.mjs +222 -0
  240. package/scripts/lib/markdown-assertions/manifest-cull.mjs +86 -0
  241. package/scripts/lib/markdown-assertions/record-setup.mjs +265 -0
  242. package/scripts/lib/markdown-assertions/record.mjs +115 -0
  243. package/scripts/lib/markdown-assertions/record.vitest.config.mjs +24 -0
  244. package/scripts/lib/markdown-assertions/sites.mjs +273 -0
  245. package/scripts/lib/markdown-assertions/test-cull.mjs +768 -0
  246. package/scripts/lib/markdown-assertions/tokens.mjs +158 -0
  247. package/scripts/lib/shell-guard-trace.mjs +6 -0
  248. package/scripts/lib/test-access-map-setup.mjs +40 -0
  249. package/scripts/lib/test-access-map-tracer.mjs +205 -0
  250. package/scripts/lib/test-access-map.d.mts +72 -0
  251. package/scripts/lib/test-access-map.mjs +395 -0
  252. package/scripts/lib/test-timings-reporter.d.mts +17 -0
  253. package/scripts/lib/test-timings-reporter.mjs +99 -0
  254. package/scripts/plan-integration-shards.mjs +300 -0
  255. package/scripts/test-timing-report.d.mts +41 -0
  256. package/scripts/test-timing-report.mjs +361 -0
  257. package/scripts/two-channel-couplings.json +132 -36
  258. package/scripts/verify-npm-advisories-4333.mjs +3 -12
  259. package/typescript/copy-overwrite/.prettierignore +12 -0
  260. package/typescript/create-only/vitest.config.local.ts +1 -7
  261. package/typescript/package-lisa/package.lisa.json +4 -4
  262. package/all/copy-overwrite/scripts/lisa-scratch-run.sh +0 -1078
  263. package/dist/cli/lisa-test-run-bootstrap.d.ts +0 -3
  264. package/dist/cli/lisa-test-run-bootstrap.d.ts.map +0 -1
  265. package/dist/cli/lisa-test-run-bootstrap.js +0 -229
  266. package/dist/cli/lisa-test-run-bootstrap.js.map +0 -1
  267. package/dist/cli/lisa-test-run-ipc.d.ts +0 -49
  268. package/dist/cli/lisa-test-run-ipc.d.ts.map +0 -1
  269. package/dist/cli/lisa-test-run-ipc.js +0 -226
  270. package/dist/cli/lisa-test-run-ipc.js.map +0 -1
  271. package/dist/cli/lisa-test-run-process-group.d.ts +0 -30
  272. package/dist/cli/lisa-test-run-process-group.d.ts.map +0 -1
  273. package/dist/cli/lisa-test-run-process-group.js +0 -140
  274. package/dist/cli/lisa-test-run-process-group.js.map +0 -1
  275. package/dist/cli/lisa-test-run-reaper.d.ts +0 -3
  276. package/dist/cli/lisa-test-run-reaper.d.ts.map +0 -1
  277. package/dist/cli/lisa-test-run-reaper.js +0 -195
  278. package/dist/cli/lisa-test-run-reaper.js.map +0 -1
  279. package/dist/cli/lisa-test-run-runtime.d.ts +0 -46
  280. package/dist/cli/lisa-test-run-runtime.d.ts.map +0 -1
  281. package/dist/cli/lisa-test-run-runtime.js +0 -123
  282. package/dist/cli/lisa-test-run-runtime.js.map +0 -1
  283. package/dist/cli/lisa-test-run-supervisor.d.ts +0 -13
  284. package/dist/cli/lisa-test-run-supervisor.d.ts.map +0 -1
  285. package/dist/cli/lisa-test-run-supervisor.js +0 -265
  286. package/dist/cli/lisa-test-run-supervisor.js.map +0 -1
  287. package/dist/configs/vitest/fleet-admission-global-setup.d.ts +0 -34
  288. package/dist/configs/vitest/fleet-admission-global-setup.d.ts.map +0 -1
  289. package/dist/configs/vitest/fleet-admission-global-setup.js +0 -123
  290. package/dist/configs/vitest/fleet-admission-global-setup.js.map +0 -1
  291. package/dist/configs/vitest/fleet-admission.d.ts +0 -129
  292. package/dist/configs/vitest/fleet-admission.d.ts.map +0 -1
  293. package/dist/configs/vitest/fleet-admission.js +0 -239
  294. package/dist/configs/vitest/fleet-admission.js.map +0 -1
  295. package/dist/configs/vitest/scratch-authority.d.ts +0 -25
  296. package/dist/configs/vitest/scratch-authority.d.ts.map +0 -1
  297. package/dist/configs/vitest/scratch-authority.js +0 -107
  298. package/dist/configs/vitest/scratch-authority.js.map +0 -1
  299. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts +0 -5
  300. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts.map +0 -1
  301. package/dist/configs/vitest/scratch-bound-cleanup-programs.js +0 -219
  302. package/dist/configs/vitest/scratch-bound-cleanup-programs.js.map +0 -1
  303. package/dist/configs/vitest/scratch-bound-cleanup.d.ts +0 -28
  304. package/dist/configs/vitest/scratch-bound-cleanup.d.ts.map +0 -1
  305. package/dist/configs/vitest/scratch-bound-cleanup.js +0 -155
  306. package/dist/configs/vitest/scratch-bound-cleanup.js.map +0 -1
  307. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts +0 -17
  308. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts.map +0 -1
  309. package/dist/configs/vitest/scratch-bound-root-cleanup.js +0 -149
  310. package/dist/configs/vitest/scratch-bound-root-cleanup.js.map +0 -1
  311. package/dist/configs/vitest/scratch-global-setup.d.ts +0 -258
  312. package/dist/configs/vitest/scratch-global-setup.d.ts.map +0 -1
  313. package/dist/configs/vitest/scratch-global-setup.js +0 -505
  314. package/dist/configs/vitest/scratch-global-setup.js.map +0 -1
  315. package/dist/configs/vitest/scratch-leak-setup.d.ts +0 -2
  316. package/dist/configs/vitest/scratch-leak-setup.d.ts.map +0 -1
  317. package/dist/configs/vitest/scratch-leak-setup.js +0 -108
  318. package/dist/configs/vitest/scratch-leak-setup.js.map +0 -1
  319. package/dist/configs/vitest/scratch-namespace-authority.d.ts +0 -80
  320. package/dist/configs/vitest/scratch-namespace-authority.d.ts.map +0 -1
  321. package/dist/configs/vitest/scratch-namespace-authority.js +0 -291
  322. package/dist/configs/vitest/scratch-namespace-authority.js.map +0 -1
  323. package/dist/configs/vitest/scratch-owner.d.ts +0 -131
  324. package/dist/configs/vitest/scratch-owner.d.ts.map +0 -1
  325. package/dist/configs/vitest/scratch-owner.js +0 -297
  326. package/dist/configs/vitest/scratch-owner.js.map +0 -1
  327. package/dist/configs/vitest/scratch-route-profile.d.ts +0 -46
  328. package/dist/configs/vitest/scratch-route-profile.d.ts.map +0 -1
  329. package/dist/configs/vitest/scratch-route-profile.js +0 -233
  330. package/dist/configs/vitest/scratch-route-profile.js.map +0 -1
  331. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts +0 -33
  332. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts.map +0 -1
  333. package/dist/configs/vitest/scratch-run-root-compatibility.js +0 -137
  334. package/dist/configs/vitest/scratch-run-root-compatibility.js.map +0 -1
  335. package/dist/configs/vitest/scratch-run-root-intent.d.ts +0 -66
  336. package/dist/configs/vitest/scratch-run-root-intent.d.ts.map +0 -1
  337. package/dist/configs/vitest/scratch-run-root-intent.js +0 -183
  338. package/dist/configs/vitest/scratch-run-root-intent.js.map +0 -1
  339. package/dist/configs/vitest/scratch-setup.d.ts +0 -46
  340. package/dist/configs/vitest/scratch-setup.d.ts.map +0 -1
  341. package/dist/configs/vitest/scratch-setup.js +0 -226
  342. package/dist/configs/vitest/scratch-setup.js.map +0 -1
  343. package/dist/configs/vitest/scratch-supervision-intent.d.ts +0 -8
  344. package/dist/configs/vitest/scratch-supervision-intent.d.ts.map +0 -1
  345. package/dist/configs/vitest/scratch-supervision-intent.js +0 -125
  346. package/dist/configs/vitest/scratch-supervision-intent.js.map +0 -1
  347. package/dist/configs/vitest/scratch-supervision-protocol.d.ts +0 -12
  348. package/dist/configs/vitest/scratch-supervision-protocol.d.ts.map +0 -1
  349. package/dist/configs/vitest/scratch-supervision-protocol.js +0 -230
  350. package/dist/configs/vitest/scratch-supervision-protocol.js.map +0 -1
  351. package/dist/configs/vitest/scratch-supervision.d.ts +0 -69
  352. package/dist/configs/vitest/scratch-supervision.d.ts.map +0 -1
  353. package/dist/configs/vitest/scratch-supervision.js +0 -244
  354. package/dist/configs/vitest/scratch-supervision.js.map +0 -1
  355. package/dist/configs/vitest/scratch-sweep.d.ts +0 -66
  356. package/dist/configs/vitest/scratch-sweep.d.ts.map +0 -1
  357. package/dist/configs/vitest/scratch-sweep.js +0 -82
  358. package/dist/configs/vitest/scratch-sweep.js.map +0 -1
  359. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts +0 -48
  360. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts.map +0 -1
  361. package/dist/configs/vitest/scratch-tmpdir-trust.js +0 -194
  362. package/dist/configs/vitest/scratch-tmpdir-trust.js.map +0 -1
  363. package/dist/configs/vitest/scratch.d.ts +0 -19
  364. package/dist/configs/vitest/scratch.d.ts.map +0 -1
  365. package/dist/configs/vitest/scratch.js +0 -34
  366. package/dist/configs/vitest/scratch.js.map +0 -1
  367. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts +0 -86
  368. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts.map +0 -1
  369. package/dist/configs/vitest/synthesis-scratch-reclaim.js +0 -226
  370. package/dist/configs/vitest/synthesis-scratch-reclaim.js.map +0 -1
@@ -0,0 +1,300 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Plan Lisa's sharded integration run from recorded timings (CodySwannGT/lisa#4599).
4
+ *
5
+ * `quality.yml`'s `🧮 Plan Integration-Test Shards` job runs this in Lisa's own
6
+ * CI when `integration_test_shards` is above 1. It finds the newest run that
7
+ * uploaded `test-timings-*-integration*` artifacts (#4592) through the Actions
8
+ * API, reads every file's duration, and assigns files to legs
9
+ * longest-processing-time-first: the longest remaining item goes to the leg
10
+ * with the least planned time. It prints each leg's planned seconds and writes
11
+ * the plan every leg applies through `lisa-test-run` (`LISA_TEST_SHARD_PLAN`,
12
+ * `src/cli/lisa-test-run-shard-files.ts`).
13
+ *
14
+ * The history-scanner suites are one item, so they land in one leg and a
15
+ * sharded run downloads the pinned scanner at most once: their project's
16
+ * global setup runs only in an invocation whose selection holds one of them.
17
+ * The planner still writes a plan when no timings can be found (an expired
18
+ * artifact, a token that cannot read the Actions API). Every file then weighs
19
+ * the same and the group still shares one leg, because Vitest's own
20
+ * `--shard` would run that global setup in every leg.
21
+ *
22
+ * Lisa-only: callers have no timings artifacts, and without this script the
23
+ * plan job hands their legs to the runner's own `--shard=<i>/<n>`.
24
+ *
25
+ * Usage:
26
+ * node scripts/plan-integration-shards.mjs --shards <n> [--repo owner/name]
27
+ * [--timings <downloaded artifacts>] [--out <plan.json>] [--github-output <file>]
28
+ * @module plan-integration-shards
29
+ */
30
+ import { execFileSync } from "node:child_process";
31
+ import * as fs from "node:fs";
32
+ import * as os from "node:os";
33
+ import * as path from "node:path";
34
+
35
+ import { HISTORY_SCANNER_SUITES } from "./lib/history-scanner-suites.mjs";
36
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
37
+ import { collectTimings } from "./test-timing-report.mjs";
38
+
39
+ /** The schema token `lisa-test-run` requires of a plan. */
40
+ export const SHARD_PLAN_SCHEMA = "lisa.test-shard-plan/v1";
41
+
42
+ const REPOSITORY = "CodySwannGT/lisa";
43
+ const ARTIFACT_NAME = /^test-timings-(\d+)-\d+-integration(?:-shard-\d+)?$/;
44
+ const LISTING_JQ =
45
+ ".artifacts[] | {name, runId: .workflow_run.id, createdAt: .created_at, expired}";
46
+ const PAGE_SIZE = 100;
47
+ const MAX_PAGES = 10;
48
+
49
+ /**
50
+ * One decimal place, so a plan prints and compares cleanly.
51
+ * @param {number} value - Seconds
52
+ * @returns {number} Rounded seconds
53
+ */
54
+ function round(value) {
55
+ return Math.round(value * 10) / 10;
56
+ }
57
+
58
+ /**
59
+ * The median of a list, or `fallback` when it is empty.
60
+ * @param {ReadonlyArray<number>} values - Values
61
+ * @param {number} fallback - Answer for no values
62
+ * @returns {number} Median
63
+ */
64
+ function median(values, fallback) {
65
+ if (values.length === 0) return fallback;
66
+ const sorted = values.toSorted((a, b) => a - b);
67
+ const middle = Math.floor(sorted.length / 2);
68
+ return sorted.length % 2 === 1
69
+ ? (sorted[middle] ?? fallback)
70
+ : ((sorted[middle - 1] ?? 0) + (sorted[middle] ?? 0)) / 2;
71
+ }
72
+
73
+ /**
74
+ * Assign timed files and groups to shards, longest first.
75
+ * @param {object} input - Inputs
76
+ * @param {number} input.total - Shard count
77
+ * @param {ReadonlyArray<{ file: string, seconds: number }>} input.timings - Per-file seconds
78
+ * @param {ReadonlyArray<ReadonlyArray<string>>} input.groups - Files that share one leg
79
+ * @returns {{ schema: string, total: number, assignments: Record<string, number>, seconds: number[], defaultSeconds: number, groups: Array<{ files: string[], shard: number }> }} Plan
80
+ */
81
+ export function planShards({ total, timings, groups }) {
82
+ const seconds = new Map(timings.map(entry => [entry.file, entry.seconds]));
83
+ const defaultSeconds = round(
84
+ median(
85
+ timings.map(entry => entry.seconds),
86
+ 1
87
+ )
88
+ );
89
+ const grouped = new Set(groups.flat());
90
+ const items = [
91
+ ...groups.map((files, index) => ({
92
+ key: `group ${index}`,
93
+ group: index,
94
+ files: [...files],
95
+ seconds: files.reduce(
96
+ (sum, file) => sum + (seconds.get(file) ?? defaultSeconds),
97
+ 0
98
+ ),
99
+ })),
100
+ ...timings
101
+ .filter(entry => !grouped.has(entry.file))
102
+ .map(entry => ({
103
+ key: entry.file,
104
+ group: -1,
105
+ files: [entry.file],
106
+ seconds: entry.seconds,
107
+ })),
108
+ ].toSorted((a, b) => b.seconds - a.seconds || a.key.localeCompare(b.key));
109
+ const loads = Array.from({ length: total }, () => 0);
110
+ const assignments = {};
111
+ const groupShards = groups.map(() => 1);
112
+ for (const item of items) {
113
+ const index = loads.indexOf(Math.min(...loads));
114
+ loads[index] = (loads[index] ?? 0) + item.seconds;
115
+ if (item.group >= 0) groupShards[item.group] = index + 1;
116
+ for (const file of item.files)
117
+ if (seconds.has(file)) assignments[file] = index + 1;
118
+ }
119
+ return {
120
+ schema: SHARD_PLAN_SCHEMA,
121
+ total,
122
+ assignments,
123
+ seconds: loads.map(round),
124
+ defaultSeconds,
125
+ groups: groups.map((files, index) => ({
126
+ files: [...files],
127
+ shard: groupShards[index] ?? 1,
128
+ })),
129
+ };
130
+ }
131
+
132
+ /**
133
+ * One line per shard: planned files and seconds.
134
+ * @param {ReturnType<typeof planShards>} plan - Plan
135
+ * @returns {string[]} Lines
136
+ */
137
+ export function formatPlan(plan) {
138
+ return plan.seconds.map((seconds, index) => {
139
+ const files = Object.values(plan.assignments).filter(
140
+ shard => shard === index + 1
141
+ ).length;
142
+ return `shard ${index + 1}/${plan.total}: ${files} planned file${files === 1 ? "" : "s"}, ${seconds.toFixed(1)} s planned`;
143
+ });
144
+ }
145
+
146
+ /**
147
+ * The newest run that uploaded unexpired integration timings.
148
+ * @param {string} repo - owner/name
149
+ * @param {{ run: (command: string, args: ReadonlyArray<string>) => string }} deps - Command runner
150
+ * @returns {string | undefined} Run id
151
+ */
152
+ export function findTimingsRun(repo, deps) {
153
+ const found = [];
154
+ for (let page = 1; page <= MAX_PAGES; page += 1) {
155
+ const output = deps.run("gh", [
156
+ "api",
157
+ `repos/${repo}/actions/artifacts?per_page=${PAGE_SIZE}&page=${page}`,
158
+ "--jq",
159
+ LISTING_JQ,
160
+ ]);
161
+ const lines = output.split("\n").filter(line => line.trim() !== "");
162
+ found.push(
163
+ ...lines
164
+ .map(line => JSON.parse(line))
165
+ .filter(
166
+ entry =>
167
+ entry.expired !== true && ARTIFACT_NAME.test(entry.name ?? "")
168
+ )
169
+ );
170
+ if (found.length > 0 || lines.length < PAGE_SIZE) break;
171
+ }
172
+ const newest = found.toSorted((a, b) =>
173
+ String(b.createdAt).localeCompare(String(a.createdAt))
174
+ )[0];
175
+ return newest === undefined ? undefined : String(newest.runId);
176
+ }
177
+
178
+ /**
179
+ * Parse the arguments, or return a usage error.
180
+ * @param {ReadonlyArray<string>} argv - Arguments after the script name
181
+ * @returns {{ shards: number, repo: string, timings?: string, out?: string, githubOutput?: string } | { error: string }} Options
182
+ */
183
+ export function parseArgs(argv) {
184
+ const value = flag => {
185
+ const at = argv.indexOf(flag);
186
+ return at === -1 ? undefined : argv[at + 1];
187
+ };
188
+ const shards = Number(value("--shards"));
189
+ if (!Number.isInteger(shards) || shards < 2 || shards > 20)
190
+ return { error: "--shards needs a whole number from 2 to 20" };
191
+ return {
192
+ shards,
193
+ repo: value("--repo") ?? REPOSITORY,
194
+ timings: value("--timings"),
195
+ out: value("--out"),
196
+ githubOutput: value("--github-output"),
197
+ };
198
+ }
199
+
200
+ /**
201
+ * Read the integration timings: from `--timings`, or downloaded from the
202
+ * newest run that has them. Never throws: no timings is an answer.
203
+ * @param {{ repo: string, timings?: string }} options - Options
204
+ * @param {Deps} deps - Effects
205
+ * @returns {{ timings: ReadonlyArray<{ file: string, seconds: number }>, source: string }} Timings
206
+ */
207
+ function readTimings(options, deps) {
208
+ if (options.timings !== undefined)
209
+ return {
210
+ timings: collectTimings(options.timings).integration,
211
+ source: options.timings,
212
+ };
213
+ const into = fs.mkdtempSync(path.join(os.tmpdir(), "lisa-shard-timings-"));
214
+ try {
215
+ const runId = findTimingsRun(options.repo, deps);
216
+ if (runId === undefined)
217
+ return { timings: [], source: "no run with integration timings" };
218
+ deps.run("gh", [
219
+ "run",
220
+ "download",
221
+ runId,
222
+ "-R",
223
+ options.repo,
224
+ "-p",
225
+ "test-timings-*-integration*",
226
+ "-D",
227
+ into,
228
+ ]);
229
+ return {
230
+ timings: collectTimings(into).integration,
231
+ source: `run ${runId}`,
232
+ };
233
+ } catch (error) {
234
+ return {
235
+ timings: [],
236
+ source: `the Actions API refused: ${error instanceof Error ? error.message : String(error)}`,
237
+ };
238
+ } finally {
239
+ fs.rmSync(into, { recursive: true, force: true });
240
+ }
241
+ }
242
+
243
+ /**
244
+ * @typedef {object} Deps
245
+ * @property {(command: string, args: ReadonlyArray<string>) => string} run - Run a command, return stdout; throws on failure
246
+ * @property {(line: string) => void} out - Standard output
247
+ * @property {(line: string) => void} err - Standard error
248
+ * @property {(file: string) => boolean} exists - Whether a repository file still exists
249
+ */
250
+
251
+ /**
252
+ * CLI entry.
253
+ * @param {ReadonlyArray<string>} argv - Arguments after the script name
254
+ * @param {Deps} deps - Effects
255
+ * @returns {number} Exit code
256
+ */
257
+ export function main(argv, deps) {
258
+ const options = parseArgs(argv);
259
+ if ("error" in options) {
260
+ deps.err(`plan-integration-shards: ${options.error}.`);
261
+ return 2;
262
+ }
263
+ const read = readTimings(options, deps);
264
+ // A file deleted since the timings were recorded would only skew the loads.
265
+ const timings = read.timings.filter(entry => deps.exists(entry.file));
266
+ const plan = planShards({
267
+ total: options.shards,
268
+ timings,
269
+ groups: [[...HISTORY_SCANNER_SUITES]],
270
+ });
271
+ if (timings.length === 0) {
272
+ deps.out(
273
+ `::notice title=No integration timings::Found no integration timings (${read.source}), so every file weighs the same; the history-scanner suites still share one leg.`
274
+ );
275
+ } else {
276
+ deps.out(
277
+ `Assigned ${timings.length} timed files longest-processing-time-first from ${read.source}; untimed files weigh ${plan.defaultSeconds} s each.`
278
+ );
279
+ }
280
+ for (const line of formatPlan(plan)) deps.out(line);
281
+ const json = JSON.stringify(plan);
282
+ if (options.out !== undefined) fs.writeFileSync(options.out, `${json}\n`);
283
+ if (options.githubOutput !== undefined)
284
+ fs.appendFileSync(options.githubOutput, `mode=files\nplan=${json}\n`);
285
+ return 0;
286
+ }
287
+
288
+ if (invokedAsScript(import.meta.url)) {
289
+ process.exitCode = main(process.argv.slice(2), {
290
+ run: (command, args) =>
291
+ execFileSync(command, [...args], {
292
+ encoding: "utf8",
293
+ stdio: ["ignore", "pipe", "pipe"],
294
+ maxBuffer: 64 * 1024 * 1024,
295
+ }),
296
+ out: line => console.log(line),
297
+ err: line => console.error(line),
298
+ exists: file => fs.existsSync(file),
299
+ });
300
+ }
@@ -0,0 +1,41 @@
1
+ export interface FileTiming {
2
+ readonly file: string;
3
+ readonly seconds: number;
4
+ readonly tests: number;
5
+ }
6
+ export interface ScopeSummary {
7
+ readonly files: number;
8
+ readonly tests: number;
9
+ readonly seconds: number;
10
+ readonly top: readonly {
11
+ readonly file: string;
12
+ readonly seconds: number;
13
+ readonly share: number;
14
+ }[];
15
+ readonly concentration: Readonly<Record<string, number>>;
16
+ readonly all: readonly FileTiming[];
17
+ }
18
+ export interface ReportIo {
19
+ readonly stdout: (line: string) => void;
20
+ readonly stderr: (line: string) => void;
21
+ readonly download?: (runId: string, into: string) => void;
22
+ }
23
+ export declare function collectTimings(directory: string): Readonly<
24
+ Record<string, readonly FileTiming[]>
25
+ > & {
26
+ readonly unit: readonly FileTiming[];
27
+ readonly integration: readonly FileTiming[];
28
+ };
29
+ export declare function summarize(
30
+ files: readonly FileTiming[],
31
+ top: number
32
+ ): ScopeSummary;
33
+ export declare function formatReport(
34
+ summaries: Readonly<Record<string, ScopeSummary>>
35
+ ): string;
36
+ export declare function parseArgs(
37
+ argv: readonly string[]
38
+ ):
39
+ | { dir?: string; run?: string; top: number; json: boolean }
40
+ | { error: string };
41
+ export declare function main(argv: readonly string[], io: ReportIo): number;
@@ -0,0 +1,361 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Per-file test timing report for Lisa's own CI (CodySwannGT/lisa#4592).
4
+ *
5
+ * Reads the `test-timings-<run>-<attempt>-<job>` artifacts that
6
+ * `.github/workflows/quality.yml` uploads from the unit job, every unit shard
7
+ * leg and the integration job, and prints per scope: file count, test count,
8
+ * summed file time, the slowest files with their share, and the cumulative
9
+ * share of the top 10, 100 and 200 files. `--json` emits the same data plus
10
+ * every file's timing, for shard balancing and slow-test audits.
11
+ *
12
+ * Usage:
13
+ * node scripts/test-timing-report.mjs --dir <downloaded artifacts> [--top N] [--json]
14
+ * node scripts/test-timing-report.mjs --run <run-id> [--top N] [--json]
15
+ *
16
+ * A scope with no timings exits 1 naming it: a missing file is not a zero.
17
+ *
18
+ * File time is the span Vitest's json reporter records for the file, from its
19
+ * first test's start to its last test's end. It excludes the file's import and
20
+ * collection time, so it can sit below the per-file duration the default
21
+ * reporter prints.
22
+ *
23
+ * The same file can arrive more than once: the unit job's merged report
24
+ * repeats every shard's files, and a failed-jobs rerun uploads under a new
25
+ * attempt beside the first. One record per file is kept — an executed record
26
+ * over a fully skipped one, then the latest attempt.
27
+ * @module test-timing-report
28
+ */
29
+ import { execFileSync } from "node:child_process";
30
+ import * as fs from "node:fs";
31
+ import * as os from "node:os";
32
+ import * as path from "node:path";
33
+
34
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
35
+ import { TEST_TIMINGS_SCOPES } from "./lib/test-timings-reporter.mjs";
36
+
37
+ const REPOSITORY = "CodySwannGT/lisa";
38
+ const DEFAULT_TOP = 20;
39
+ const CUTOFFS = Object.freeze([10, 100, 200]);
40
+ const SKIPPED = new Set(["skipped", "pending", "todo", "disabled"]);
41
+
42
+ /**
43
+ * @typedef {object} FileTiming
44
+ * @property {string} file - Repository-relative test file
45
+ * @property {number} seconds - Time the file's tests spanned
46
+ * @property {number} tests - Test count
47
+ */
48
+
49
+ /**
50
+ * Every file under a directory, recursively.
51
+ * @param {string} directory - Directory to walk
52
+ * @returns {ReadonlyArray<string>} File paths
53
+ */
54
+ function walk(directory) {
55
+ return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
56
+ const full = path.join(directory, entry.name);
57
+ return entry.isDirectory() ? walk(full) : [full];
58
+ });
59
+ }
60
+
61
+ /**
62
+ * The run attempt an artifact directory names, or 0.
63
+ * @param {string} file - Timing file path
64
+ * @returns {number} Attempt number
65
+ */
66
+ function attemptOf(file) {
67
+ const match = /^test-timings-\d+-(\d+)-/.exec(
68
+ path.basename(path.dirname(file))
69
+ );
70
+ return match ? Number(match[1]) : 0;
71
+ }
72
+
73
+ /**
74
+ * Drop the checkout prefix so files read as repository paths: the current
75
+ * directory for a local run, the GitHub runner's workspace for a CI one.
76
+ * @param {string} name - Absolute path Vitest recorded
77
+ * @returns {string} Repository-relative path when the prefix is recognised
78
+ */
79
+ function repositoryPath(name) {
80
+ const local = `${process.cwd()}${path.sep}`;
81
+ if (name.startsWith(local)) return name.slice(local.length);
82
+ return name.replace(/^.*?\/work\/[^/]+\/[^/]+\//, "");
83
+ }
84
+
85
+ /**
86
+ * Parse one Vitest json report, or `undefined` when it is not one.
87
+ * @param {string} file - Report path
88
+ * @returns {ReadonlyArray<{ file: string, seconds: number, tests: number, executed: boolean }> | undefined} Entries
89
+ */
90
+ function readReport(file) {
91
+ const parsed = (() => {
92
+ try {
93
+ return JSON.parse(fs.readFileSync(file, "utf8"));
94
+ } catch {
95
+ return undefined;
96
+ }
97
+ })();
98
+ if (!parsed || !Array.isArray(parsed.testResults)) return undefined;
99
+ return parsed.testResults
100
+ .filter(result => typeof result?.name === "string")
101
+ .map(result => {
102
+ const assertions = Array.isArray(result.assertionResults)
103
+ ? result.assertionResults
104
+ : [];
105
+ const span =
106
+ typeof result.startTime === "number" &&
107
+ typeof result.endTime === "number"
108
+ ? result.endTime - result.startTime
109
+ : assertions.reduce((sum, a) => sum + (a?.duration ?? 0), 0);
110
+ return {
111
+ file: repositoryPath(result.name),
112
+ seconds: Math.max(0, span) / 1000,
113
+ tests: assertions.length,
114
+ executed: assertions.some(a => !SKIPPED.has(a?.status)),
115
+ };
116
+ });
117
+ }
118
+
119
+ /**
120
+ * Whether a candidate record should replace the one already kept.
121
+ * @param {{ executed: boolean, attempt: number }} candidate - New record
122
+ * @param {{ executed: boolean, attempt: number } | undefined} kept - Current record
123
+ * @returns {boolean} True to replace
124
+ */
125
+ function outranks(candidate, kept) {
126
+ if (kept === undefined) return true;
127
+ if (candidate.executed !== kept.executed) return candidate.executed;
128
+ return candidate.attempt > kept.attempt;
129
+ }
130
+
131
+ /**
132
+ * Gather one record per file, per scope, from a directory of artifacts.
133
+ * @param {string} directory - Downloaded artifacts (any depth)
134
+ * @returns {Readonly<Record<string, ReadonlyArray<FileTiming>>>} Timings by scope
135
+ */
136
+ export function collectTimings(directory) {
137
+ const reports = walk(directory).flatMap(file => {
138
+ const scope = path.basename(file, ".json");
139
+ if (!file.endsWith(".json") || !TEST_TIMINGS_SCOPES.includes(scope))
140
+ return [];
141
+ const entries = readReport(file) ?? [];
142
+ const attempt = attemptOf(file);
143
+ return entries.map(entry => ({ ...entry, scope, attempt }));
144
+ });
145
+ const kept = reports.reduce((acc, record) => {
146
+ const key = `${record.scope}\u0000${record.file}`;
147
+ return outranks(record, acc[key]) ? { ...acc, [key]: record } : acc;
148
+ }, /** @type {Record<string, (typeof reports)[number]>} */ ({}));
149
+ return Object.fromEntries(
150
+ TEST_TIMINGS_SCOPES.map(scope => [
151
+ scope,
152
+ Object.values(kept)
153
+ .filter(record => record.scope === scope)
154
+ .map(({ file, seconds, tests }) => ({ file, seconds, tests }))
155
+ .toSorted(
156
+ (a, b) => b.seconds - a.seconds || a.file.localeCompare(b.file)
157
+ ),
158
+ ])
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Summarise one scope.
164
+ * @param {ReadonlyArray<FileTiming>} files - Files, any order
165
+ * @param {number} top - How many slowest files to list
166
+ * @returns {{ files: number, tests: number, seconds: number, top: ReadonlyArray<{ file: string, seconds: number, share: number }>, concentration: Readonly<Record<string, number>>, all: ReadonlyArray<FileTiming> }} Summary
167
+ */
168
+ export function summarize(files, top) {
169
+ const all = files.toSorted(
170
+ (a, b) => b.seconds - a.seconds || a.file.localeCompare(b.file)
171
+ );
172
+ const seconds = all.reduce((sum, file) => sum + file.seconds, 0);
173
+ const share = value => (seconds === 0 ? 0 : value / seconds);
174
+ const sumOf = count =>
175
+ all.slice(0, count).reduce((sum, file) => sum + file.seconds, 0);
176
+ return {
177
+ files: all.length,
178
+ tests: all.reduce((sum, file) => sum + file.tests, 0),
179
+ seconds,
180
+ top: all.slice(0, top).map(file => ({
181
+ file: file.file,
182
+ seconds: file.seconds,
183
+ share: share(file.seconds),
184
+ })),
185
+ concentration: Object.fromEntries(
186
+ CUTOFFS.map(count => [`top${count}`, share(sumOf(count))])
187
+ ),
188
+ all,
189
+ };
190
+ }
191
+
192
+ /**
193
+ * A ratio as a percentage with one decimal.
194
+ * @param {number} ratio - 0..1
195
+ * @returns {string} Percentage text
196
+ */
197
+ function percent(ratio) {
198
+ return (ratio * 100).toFixed(1);
199
+ }
200
+
201
+ /**
202
+ * Render summaries as text.
203
+ * @param {Readonly<Record<string, ReturnType<typeof summarize>>>} summaries - By scope
204
+ * @returns {string} Report text
205
+ */
206
+ export function formatReport(summaries) {
207
+ return Object.entries(summaries)
208
+ .map(([scope, summary]) => {
209
+ const rows = summary.top.map(
210
+ (file, index) =>
211
+ ` ${String(index + 1).padStart(3)}. ${file.seconds.toFixed(2).padStart(8)}s ${percent(file.share).padStart(6)}% ${file.file}`
212
+ );
213
+ const shares = CUTOFFS.map(count => {
214
+ const key = `top${count}`;
215
+ const ratio = summary.concentration[key];
216
+ return `top ${count}: ${percent(ratio)}%`;
217
+ }).join(" ");
218
+ const fewer =
219
+ summary.files < Math.max(...CUTOFFS)
220
+ ? [
221
+ ` (only ${summary.files} file${summary.files === 1 ? "" : "s"}; a larger cutoff covers them all)`,
222
+ ]
223
+ : [];
224
+ return [
225
+ `${scope}: ${summary.files} files, ${summary.tests} tests, ${summary.seconds.toFixed(1)}s summed file time`,
226
+ ` top ${summary.top.length} files by time:`,
227
+ ...rows,
228
+ ` ${shares}`,
229
+ ...fewer,
230
+ ].join("\n");
231
+ })
232
+ .join("\n\n");
233
+ }
234
+
235
+ /**
236
+ * Download a run's timing artifacts with `gh`.
237
+ * @param {string} runId - Workflow run id
238
+ * @param {string} into - Destination directory
239
+ */
240
+ function downloadRun(runId, into) {
241
+ execFileSync(
242
+ "gh",
243
+ [
244
+ "run",
245
+ "download",
246
+ runId,
247
+ "-R",
248
+ REPOSITORY,
249
+ "-p",
250
+ "test-timings-*",
251
+ "-D",
252
+ into,
253
+ ],
254
+ { stdio: ["ignore", "ignore", "inherit"] }
255
+ );
256
+ }
257
+
258
+ /**
259
+ * Parse the arguments, or return a usage error.
260
+ * @param {ReadonlyArray<string>} argv - Arguments after the script name
261
+ * @returns {{ dir?: string, run?: string, top: number, json: boolean } | { error: string }} Options
262
+ */
263
+ export function parseArgs(argv) {
264
+ const value = flag => {
265
+ const at = argv.indexOf(flag);
266
+ return at === -1 ? undefined : (argv[at + 1] ?? "");
267
+ };
268
+ const dir = value("--dir");
269
+ const run = value("--run");
270
+ const topText = value("--top");
271
+ const top = topText === undefined ? DEFAULT_TOP : Number(topText);
272
+ if ((dir === undefined) === (run === undefined))
273
+ return { error: "pass exactly one of --dir <directory> or --run <run-id>" };
274
+ if (dir === "" || run === "" || (run !== undefined && !/^\d+$/.test(run)))
275
+ return { error: "--dir needs a directory and --run a numeric run id" };
276
+ if (!Number.isInteger(top) || top < 1)
277
+ return { error: "--top needs a positive whole number" };
278
+ return { dir, run, top, json: argv.includes("--json") };
279
+ }
280
+
281
+ /**
282
+ * Report on a directory of artifacts.
283
+ * @param {string} directory - Artifacts directory
284
+ * @param {{ top: number, json: boolean, source: string }} options - Output options
285
+ * @param {{ stdout: (line: string) => void, stderr: (line: string) => void }} io - Output sinks
286
+ * @returns {number} Exit code
287
+ */
288
+ function report(directory, options, io) {
289
+ if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) {
290
+ io.stderr(`test-timing-report: ${directory} is not a directory.`);
291
+ return 1;
292
+ }
293
+ const timings = collectTimings(directory);
294
+ const missing = TEST_TIMINGS_SCOPES.filter(
295
+ scope => timings[scope].length === 0
296
+ );
297
+ if (missing.length > 0) {
298
+ io.stderr(
299
+ `test-timing-report: missing timings for scope${missing.length === 1 ? "" : "s"} ${missing.join(", ")} in ${options.source}. ` +
300
+ "Each scope needs a test-timings artifact holding <scope>.json; a missing file is not reported as zero."
301
+ );
302
+ return 1;
303
+ }
304
+ const summaries = Object.fromEntries(
305
+ TEST_TIMINGS_SCOPES.map(scope => [
306
+ scope,
307
+ summarize(timings[scope], options.top),
308
+ ])
309
+ );
310
+ io.stdout(
311
+ options.json
312
+ ? JSON.stringify(
313
+ { schema: 1, source: options.source, scopes: summaries },
314
+ null,
315
+ 2
316
+ )
317
+ : formatReport(summaries)
318
+ );
319
+ return 0;
320
+ }
321
+
322
+ /**
323
+ * CLI entry.
324
+ * @param {ReadonlyArray<string>} argv - Arguments after the script name
325
+ * @param {{ stdout: (line: string) => void, stderr: (line: string) => void, download?: (runId: string, into: string) => void }} io - Output sinks and downloader
326
+ * @returns {number} Exit code
327
+ */
328
+ export function main(argv, io) {
329
+ const options = parseArgs(argv);
330
+ if ("error" in options) {
331
+ io.stderr(`test-timing-report: ${options.error}.`);
332
+ return 2;
333
+ }
334
+ if (options.dir !== undefined)
335
+ return report(
336
+ path.resolve(options.dir),
337
+ { ...options, source: options.dir },
338
+ io
339
+ );
340
+ const into = fs.mkdtempSync(path.join(os.tmpdir(), "lisa-test-timings-"));
341
+ try {
342
+ try {
343
+ (io.download ?? downloadRun)(options.run, into);
344
+ } catch (error) {
345
+ io.stderr(
346
+ `test-timing-report: could not download test-timings-* artifacts of run ${options.run} from ${REPOSITORY}: ${error instanceof Error ? error.message : String(error)}`
347
+ );
348
+ return 1;
349
+ }
350
+ return report(into, { ...options, source: `run ${options.run}` }, io);
351
+ } finally {
352
+ fs.rmSync(into, { recursive: true, force: true });
353
+ }
354
+ }
355
+
356
+ if (invokedAsScript(import.meta.url)) {
357
+ process.exitCode = main(process.argv.slice(2), {
358
+ stdout: line => console.log(line),
359
+ stderr: line => console.error(line),
360
+ });
361
+ }