@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
@@ -1,1078 +0,0 @@
1
- #!/bin/sh
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
- # Rails scratch supervisor — run-scoped scratch ownership with an outside
6
- # cleanup authority that survives the tested process.
7
- # -----------------------------------------------------------------------------
8
- # WHY THIS IS SHELL AND NOT NODE
9
- #
10
- # A Rails repository is not required to have Node, npm, Bun, Yarn, a populated
11
- # `node_modules`, or a network at test runtime. The Node-managed scratch
12
- # supervisor cannot be reused here for exactly that reason. This file assumes
13
- # only what the routes it wraps already assume: a POSIX shell, coreutils/BSD
14
- # userland (`ps`, `mkdir`, `rm`, `date`, `od`), and Ruby/Bundler for the payload
15
- # itself. It never fetches anything.
16
- #
17
- # USAGE
18
- #
19
- # sh scripts/lisa-scratch-run.sh --suite <label> -- <command> [args...]
20
- #
21
- # WHAT IT GUARANTEES
22
- #
23
- # 1. Authority precedes allocation. Before the payload can allocate one byte
24
- # of scratch, a separate cleanup authority process — outside the payload's
25
- # process group, and outside this shell's — has read and acknowledged the
26
- # exact run token, the canonical run root, the run root's filesystem
27
- # identity (device + inode), the suite label, the payload's process-group
28
- # identity, and the payload's process-birth identity. The payload is held
29
- # at a gate until that acknowledgement lands. An arming or acknowledgement
30
- # failure REFUSES: the payload never executes.
31
- # 2. Cleanup survives the payload. Pass, fail, timeout, SIGTERM, SIGINT,
32
- # SIGHUP, payload SIGKILL, and foreground-supervisor SIGKILL all end with
33
- # the owned process group boundedly drained and the owned run root absent,
34
- # done by this invocation's own already-armed authority. No successor run
35
- # is started and no global sweep is performed.
36
- # 3. Only what this invocation owns is touched. The authority signals exactly
37
- # one process group — the one it acknowledged, re-verified by birth
38
- # identity so PID reuse cannot broaden it — and deletes exactly one root,
39
- # re-verified by token and by device+inode so a swap cannot broaden it. An
40
- # external database service is never signalled, stopped, reset, or deleted.
41
- # 4. Ambiguity fails closed. Traversal, symlinked roots, inode swaps, owner
42
- # token changes, malformed or oversized markers, PID reuse, birth
43
- # mismatch, and foreign quarantine names all exit nonzero with a reason.
44
- # 5. A fixture leak fails the suite. Unregistered direct children left under
45
- # the payload's temp root are reported with the suite label, the leaked
46
- # count, and the sorted leaked basenames, and make the route exit nonzero.
47
- # A red payload verdict is never overwritten by the leak verdict, and a
48
- # green payload never masks a leaking child.
49
- #
50
- # ENVIRONMENT
51
- #
52
- # LISA_SCRATCH_BASE Temp base. Default: $TMPDIR, else /tmp.
53
- # LISA_SCRATCH_REGISTERED_PREFIXES
54
- # Comma-separated basename prefixes that are
55
- # batch-cleaned instead of reported as leaks.
56
- # Default: "lisa-".
57
- # LISA_SCRATCH_LEAK_GATE enforce (default) | report | off.
58
- # LISA_SCRATCH_ARM_TIMEOUT_MS Arming handshake budget, in ms. Default 15000.
59
- # LISA_SCRATCH_GATE_TIMEOUT_MS How long the held payload waits for the gate
60
- # to open before refusing. Default 300000.
61
- # LISA_SCRATCH_AUTHORITY_REFUSE Conformance control. When 1, the cleanup
62
- # authority declines to acknowledge. The run
63
- # must then REFUSE before the payload executes.
64
- # It can only turn a run into a refusal; it can
65
- # never let one through unsupervised.
66
- # LISA_SCRATCH_DRAIN_MS SIGTERM→SIGKILL drain budget. Default 5000.
67
- # LISA_SCRATCH_TRACE Append lifecycle events to this file. The
68
- # file order IS the ordering proof.
69
- # LISA_SCRATCH_INHERIT_STDIN 1 to give the payload this shell's stdin.
70
- # Default: /dev/null (avoids SIGTTIN on a
71
- # background process group).
72
- # -----------------------------------------------------------------------------
73
-
74
- set -eu
75
-
76
- LISA_SCRATCH_NAMESPACE="lisa-rails-scratch"
77
- LISA_SCRATCH_MARKER_MAX_BYTES=4096
78
- LISA_SCRATCH_MARKER_MAX_LINES=64
79
- LISA_SCRATCH_VERSION=1
80
-
81
- # Exit codes. Distinct so a caller can tell refusal from payload failure.
82
- EX_USAGE=64
83
- EX_LEAK=65
84
- EX_ARM=70
85
- EX_AMBIGUOUS=78
86
-
87
- lisa_die() {
88
- _code="$1"
89
- shift
90
- printf '%s\n' "lisa-scratch-run: $*" >&2
91
- exit "$_code"
92
- }
93
-
94
- lisa_trace() {
95
- [ -n "${LISA_SCRATCH_TRACE:-}" ] || return 0
96
- printf '%s %s %s\n' "$(date +%s 2>/dev/null || echo 0)" "$LISA_SCRATCH_ROLE" "$*" \
97
- >>"$LISA_SCRATCH_TRACE" 2>/dev/null || true
98
- }
99
-
100
- # --- portability probes ------------------------------------------------------
101
-
102
- # Stat device and inode of a path, portably.
103
- # $1 path -> "<dev> <ino>" on stdout, nonzero when it cannot be determined.
104
- lisa_dev_ino() {
105
- _p="$1"
106
- if _v="$(stat -f '%d %i' "$_p" 2>/dev/null)" && [ -n "$_v" ]; then
107
- printf '%s\n' "$_v"
108
- return 0
109
- fi
110
- if _v="$(stat -c '%d %i' "$_p" 2>/dev/null)" && [ -n "$_v" ]; then
111
- printf '%s\n' "$_v"
112
- return 0
113
- fi
114
- # Last-resort fallback: inode from `ls -di`, device stood in for by the
115
- # mount point reported by `df -P`. Both are POSIX.
116
- _ino="$(ls -di "$_p" 2>/dev/null | awk '{print $1}')" || return 1
117
- [ -n "$_ino" ] || return 1
118
- _dev="$(df -P "$_p" 2>/dev/null | awk 'NR==2 {print $NF}')" || return 1
119
- [ -n "$_dev" ] || return 1
120
- printf '%s %s\n' "$_dev" "$_ino"
121
- }
122
-
123
- # Process-birth identity for a pid: something that changes when the PID is
124
- # reused. `lstart` where available, `etime`+`ppid` otherwise.
125
- # $1 pid -> birth string on stdout, nonzero when the process is gone.
126
- lisa_birth() {
127
- _pid="$1"
128
- if _v="$(ps -o lstart= -p "$_pid" 2>/dev/null)" && [ -n "$_v" ]; then
129
- printf '%s\n' "$(printf '%s' "$_v" | tr -s ' ' ' ' | sed 's/^ *//;s/ *$//')"
130
- return 0
131
- fi
132
- if _v="$(ps -o ppid=,etime= -p "$_pid" 2>/dev/null)" && [ -n "$_v" ]; then
133
- printf '%s\n' "$(printf '%s' "$_v" | tr -s ' ' ' ' | sed 's/^ *//;s/ *$//')"
134
- return 0
135
- fi
136
- return 1
137
- }
138
-
139
- lisa_pgid_of() {
140
- ps -o pgid= -p "$1" 2>/dev/null | tr -d ' \t' || return 1
141
- }
142
-
143
- # Whether this process leads its own process group.
144
- #
145
- # Only ever called from a REAL process, never from a `&` subshell: POSIX `$$`
146
- # is the parent shell's pid inside a subshell, so a subshell asking this
147
- # question would be told about its parent. That is why the launcher and the
148
- # authority are spawned as separate `sh` processes rather than as functions in
149
- # the background.
150
- lisa_leads_own_group() {
151
- _self_pgid="$(lisa_pgid_of "$$" || true)"
152
- [ -n "$_self_pgid" ] && [ "$_self_pgid" = "$$" ]
153
- }
154
-
155
- # Put this process in a process group of its own, without a controlling
156
- # terminal, and WITHOUT changing its pid.
157
- #
158
- # Two mechanisms, because neither is portable alone:
159
- #
160
- # `set -m` in the PARENT. Works on Darwin, where /bin/sh is bash. It does
161
- # not work under dash, whose job control initialisation opens /dev/tty — so
162
- # on a Linux CI runner, which has no controlling terminal, every background
163
- # job stays in the parent's group. Measured: the whole Rails supervisor
164
- # suite refused with "payload did not get an isolated process group" on
165
- # hosted Linux while passing on Darwin.
166
- #
167
- # `setsid`. Always present on Linux, absent from stock Darwin. It forks
168
- # ONLY when the caller already leads a group, and the caller here provably
169
- # does not — that is the condition we are in. So it execs in place, the pid
170
- # is preserved, and the parent's `$!` and `wait` stay valid, which a forking
171
- # setsid would silently break by returning its own status instead.
172
- #
173
- # $1 re-entry guard variable name, $2.. the argv to re-exec.
174
- lisa_isolate_group() {
175
- lisa_leads_own_group && return 0
176
- _guard="$1"
177
- shift
178
- eval "_seen=\${$_guard:-0}"
179
- if [ "$_seen" != "1" ] && command -v setsid >/dev/null 2>&1; then
180
- export "$_guard=1"
181
- exec setsid "$@"
182
- fi
183
- return 1
184
- }
185
-
186
- lisa_alive() {
187
- kill -0 "$1" 2>/dev/null
188
- }
189
-
190
- # Short sleep, degrading to a whole second where fractional sleep is absent.
191
- #
192
- # It publishes how long it actually slept, in `LISA_SCRATCH_NAP_MS`, and every
193
- # wait loop advances its counter by THAT rather than by an assumed 50 ms.
194
- # POSIX does not require `sleep` to accept a fractional operand — it is a
195
- # widespread extension, not a guarantee — so on a shell where it is missing a
196
- # loop that assumed 50 ms would run twenty times its stated budget: the 15 s
197
- # arming handshake would wait 300 s, and the 5 s drain 100 s, before escalating
198
- # to SIGKILL. A budget that is only a budget on some machines is not one.
199
- LISA_SCRATCH_NAP_MS=50
200
- lisa_nap() {
201
- if [ "${LISA_SCRATCH_FRACTIONAL_SLEEP:-unknown}" = "unknown" ]; then
202
- if sleep 0.05 2>/dev/null; then
203
- LISA_SCRATCH_FRACTIONAL_SLEEP=yes
204
- LISA_SCRATCH_NAP_MS=50
205
- else
206
- LISA_SCRATCH_FRACTIONAL_SLEEP=no
207
- LISA_SCRATCH_NAP_MS=1000
208
- fi
209
- fi
210
- if [ "$LISA_SCRATCH_FRACTIONAL_SLEEP" = yes ]; then
211
- sleep 0.05
212
- else
213
- sleep 1
214
- fi
215
- }
216
-
217
- # --- marker (arming record) --------------------------------------------------
218
-
219
- # Read one key out of a marker file, fail-closed on malformed or oversized
220
- # input. $1 marker path, $2 key.
221
- lisa_marker_get() {
222
- _file="$1"
223
- _key="$2"
224
- [ -f "$_file" ] || return 1
225
- if [ -L "$_file" ]; then return 1; fi
226
- # Cleanup may remove this invocation's marker between native reads. A
227
- # failed open remains a refusal, without leaking shell pathname diagnostics.
228
- _bytes="$(wc -c 2>/dev/null <"$_file" | tr -d ' ')" || return 1
229
- case "$_bytes" in "" | *[!0-9]*) return 1 ;; esac
230
- [ "$_bytes" -le "$LISA_SCRATCH_MARKER_MAX_BYTES" ] || return 1
231
- _lines="$(wc -l 2>/dev/null <"$_file" | tr -d ' ')" || return 1
232
- case "$_lines" in "" | *[!0-9]*) return 1 ;; esac
233
- [ "$_lines" -le "$LISA_SCRATCH_MARKER_MAX_LINES" ] || return 1
234
- _hits="$(grep -c "^${_key}=" "$_file" 2>/dev/null || true)"
235
- [ "$_hits" = "1" ] || return 1
236
- sed -n "s/^${_key}=//p" "$_file" 2>/dev/null
237
- }
238
-
239
- # --- path safety -------------------------------------------------------------
240
-
241
- # Canonicalize a directory that must already exist, without readlink -f (absent
242
- # on stock macOS). Refuses a symlinked leaf outright.
243
- lisa_canonical_dir() {
244
- _p="$1"
245
- [ -d "$_p" ] || return 1
246
- [ -L "$_p" ] && return 1
247
- (cd -P -- "$_p" 2>/dev/null && pwd -P) || return 1
248
- }
249
-
250
- # A run root must be an absolute, traversal-free path directly beneath the
251
- # namespace directory of the declared base.
252
- lisa_root_is_well_formed() {
253
- _root="$1"
254
- _base="$2"
255
- case "$_root" in
256
- /*) : ;;
257
- *) return 1 ;;
258
- esac
259
- case "$_root" in
260
- *..*) return 1 ;;
261
- esac
262
- case "$_root" in
263
- "${_base}/${LISA_SCRATCH_NAMESPACE}/"*) : ;;
264
- *) return 1 ;;
265
- esac
266
- _leaf="${_root#"${_base}/${LISA_SCRATCH_NAMESPACE}/"}"
267
- case "$_leaf" in
268
- */*) return 1 ;;
269
- "") return 1 ;;
270
- esac
271
- return 0
272
- }
273
-
274
- lisa_token_is_well_formed() {
275
- case "$1" in
276
- "" | *[!0-9a-f]*) return 1 ;;
277
- esac
278
- [ "${#1}" -eq 64 ]
279
- }
280
-
281
- # The basename is a 96-bit locator, never the run's 256-bit authority. Keeping
282
- # it independent of suite length leaves Chrome's six-character temp suffix and
283
- # SingletonSocket within 104 bytes including NUL under canonical /private/tmp.
284
- # The complete token still binds the marker, acknowledgement and quarantine.
285
- lisa_root_matches_token() {
286
- lisa_token_is_well_formed "$2" || return 1
287
- [ "${1##*/}" = "$(printf 'r.%.24s' "$2")" ]
288
- }
289
-
290
- lisa_suite_is_well_formed() {
291
- case "$1" in
292
- "" | *[!A-Za-z0-9._-]*) return 1 ;;
293
- esac
294
- [ "${#1}" -le 64 ]
295
- }
296
-
297
- # =============================================================================
298
- # AUTHORITY MODE — the outside cleanup authority.
299
- #
300
- # Started by the supervisor BEFORE the payload's gate is opened, in its own
301
- # process group, so that killing either the payload group or the supervisor
302
- # group leaves it running. It is the same file and the same invocation: no
303
- # successor Lisa run is ever started to do cleanup.
304
- # =============================================================================
305
-
306
- lisa_authority_main() {
307
- LISA_SCRATCH_ROLE=authority
308
- _root="$1"
309
-
310
- # The authority's whole job is to outlive a kill aimed at the payload group
311
- # or at the supervisor, so it must not share either. Best effort rather than
312
- # fatal: it is the safety net, and a net that refuses to exist is worse than
313
- # one that is merely in the wrong group. The launcher applies the same test
314
- # and DOES refuse, so a platform that cannot isolate never gets this far.
315
- lisa_isolate_group LISA_SCRATCH_AUTHORITY_REENTRY \
316
- "$LISA_SCRATCH_SH" "$LISA_SCRATCH_SELF" --authority "$_root" || true
317
-
318
- # Every field is re-derived from the marker and independently verified. A
319
- # marker this cannot fully validate is never acted on.
320
- _base="${LISA_SCRATCH_BASE:-${TMPDIR:-/tmp}}"
321
- _base="${_base%/}"
322
- _base="$(lisa_canonical_dir "$_base")" ||
323
- lisa_die "$EX_AMBIGUOUS" "authority: temp base is not a canonical directory"
324
-
325
- lisa_root_is_well_formed "$_root" "$_base" ||
326
- lisa_die "$EX_AMBIGUOUS" "authority: refusing malformed run root: $_root"
327
- if [ -L "$_root" ]; then
328
- lisa_die "$EX_AMBIGUOUS" "authority: refusing symlinked run root: $_root"
329
- fi
330
- _canon="$(lisa_canonical_dir "$_root")" ||
331
- lisa_die "$EX_AMBIGUOUS" "authority: run root is not a canonical directory: $_root"
332
- [ "$_canon" = "$_root" ] ||
333
- lisa_die "$EX_AMBIGUOUS" "authority: run root resolves elsewhere: $_root -> $_canon"
334
-
335
- _marker="$_root/.lisa-scratch-arm"
336
- _token="$(lisa_marker_get "$_marker" token)" ||
337
- lisa_die "$EX_AMBIGUOUS" "authority: unreadable or malformed arming marker"
338
- lisa_token_is_well_formed "$_token" ||
339
- lisa_die "$EX_AMBIGUOUS" "authority: malformed run token"
340
- [ "$_token" = "${LISA_SCRATCH_TOKEN:-}" ] ||
341
- lisa_die "$EX_AMBIGUOUS" "authority: run token differs from supervisor authority"
342
- lisa_root_matches_token "$_root" "$_token" ||
343
- lisa_die "$EX_AMBIGUOUS" "authority: run locator differs from full token"
344
- _version="$(lisa_marker_get "$_marker" version)" ||
345
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no version"
346
- [ "$_version" = "$LISA_SCRATCH_VERSION" ] ||
347
- lisa_die "$EX_AMBIGUOUS" "authority: unsupported arming marker version: $_version"
348
- _mroot="$(lisa_marker_get "$_marker" root)" ||
349
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no root"
350
- [ "$_mroot" = "$_root" ] ||
351
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker root disagrees: $_mroot"
352
- _suite="$(lisa_marker_get "$_marker" suite)" ||
353
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no suite"
354
- lisa_suite_is_well_formed "$_suite" ||
355
- lisa_die "$EX_AMBIGUOUS" "authority: malformed suite label"
356
- _dev_ino="$(lisa_marker_get "$_marker" devino)" ||
357
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no filesystem identity"
358
- _live_dev_ino="$(lisa_dev_ino "$_root")" ||
359
- lisa_die "$EX_AMBIGUOUS" "authority: cannot read run root filesystem identity"
360
- [ "$_dev_ino" = "$_live_dev_ino" ] ||
361
- lisa_die "$EX_AMBIGUOUS" "authority: run root filesystem identity changed"
362
- _pgid="$(lisa_marker_get "$_marker" pgid)" ||
363
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no process group"
364
- case "$_pgid" in
365
- "" | 0 | 1 | *[!0-9]*)
366
- lisa_die "$EX_AMBIGUOUS" "authority: refusing process group '$_pgid'"
367
- ;;
368
- esac
369
- _birth="$(lisa_marker_get "$_marker" birth)" ||
370
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no process-birth identity"
371
- [ -n "$_birth" ] ||
372
- lisa_die "$EX_AMBIGUOUS" "authority: empty process-birth identity"
373
- _sup_pid="$(lisa_marker_get "$_marker" suppid)" ||
374
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no supervisor pid"
375
- case "$_sup_pid" in
376
- "" | *[!0-9]*)
377
- lisa_die "$EX_AMBIGUOUS" "authority: refusing supervisor pid '$_sup_pid'"
378
- ;;
379
- esac
380
- _sup_birth="$(lisa_marker_get "$_marker" supbirth)" ||
381
- lisa_die "$EX_AMBIGUOUS" "authority: arming marker has no supervisor birth"
382
-
383
- # The payload group must still be the one that was armed. Verifying birth
384
- # here — not only later — is what makes PID reuse unable to broaden the kill.
385
- _live_birth="$(lisa_birth "$_pgid" || true)"
386
- if [ -n "$_live_birth" ] && [ "$_live_birth" != "$_birth" ]; then
387
- lisa_die "$EX_AMBIGUOUS" "authority: payload process-birth identity mismatch"
388
- fi
389
-
390
- if [ "${LISA_SCRATCH_AUTHORITY_REFUSE:-0}" = "1" ]; then
391
- lisa_trace "ack-declined"
392
- lisa_die "$EX_ARM" "authority: declining to acknowledge (LISA_SCRATCH_AUTHORITY_REFUSE=1)"
393
- fi
394
-
395
- # Acknowledge. Only now may the supervisor open the payload gate.
396
- printf 'version=%s\ntoken=%s\nroot=%s\ndevino=%s\nsuite=%s\npgid=%s\nbirth=%s\nauthority=%s\n' \
397
- "$LISA_SCRATCH_VERSION" "$_token" "$_root" "$_dev_ino" "$_suite" "$_pgid" \
398
- "$_birth" "$$" >"$_root/.lisa-scratch-ack.tmp"
399
- mv -f "$_root/.lisa-scratch-ack.tmp" "$_root/.lisa-scratch-ack"
400
- lisa_trace "ack token=$_token pgid=$_pgid suite=$_suite"
401
-
402
- # Wait for the run to end, by any exit path. The root vanishing means the
403
- # supervisor completed its own cleanup first; the supervisor's process
404
- # disappearing means it was killed and cleanup falls to this process.
405
- while :; do
406
- [ -d "$_root" ] || break
407
- if [ -f "$_root/.lisa-scratch-done" ]; then
408
- break
409
- fi
410
- if ! lisa_alive "$_sup_pid"; then
411
- break
412
- fi
413
- _now_birth="$(lisa_birth "$_sup_pid" || true)"
414
- if [ -n "$_now_birth" ] && [ "$_now_birth" != "$_sup_birth" ]; then
415
- break
416
- fi
417
- lisa_nap
418
- done
419
-
420
- lisa_trace "reap-begin"
421
- lisa_drain_group "$_pgid" "$_birth"
422
- lisa_remove_root "$_root" "$_token" "$_dev_ino" "$_base"
423
- if [ -d "$_root" ]; then
424
- lisa_trace "reap-end root-absent=no"
425
- else
426
- lisa_trace "reap-end root-absent=yes"
427
- fi
428
- exit 0
429
- }
430
-
431
- # =============================================================================
432
- # Bounded process-group drain.
433
- #
434
- # Signals exactly the acknowledged process group, and only while its birth
435
- # identity still matches. Never signals pid 1, never signals this process's own
436
- # group, and therefore never reaches a database service running outside it.
437
- # =============================================================================
438
-
439
- lisa_drain_group() {
440
- _pgid="$1"
441
- _birth="$2"
442
-
443
- case "$_pgid" in
444
- "" | 0 | 1 | *[!0-9]*) return 0 ;;
445
- esac
446
-
447
- _own_pgid="$(lisa_pgid_of "$$" || true)"
448
- if [ -n "$_own_pgid" ] && [ "$_own_pgid" = "$_pgid" ]; then
449
- # Refusing to signal our own group is what keeps a misconfigured run from
450
- # taking down the shell, the runner, or a sibling service.
451
- printf '%s\n' "lisa-scratch-run: refusing to drain our own process group" >&2
452
- return 0
453
- fi
454
-
455
- _live_birth="$(lisa_birth "$_pgid" || true)"
456
- if [ -n "$_live_birth" ] && [ "$_live_birth" != "$_birth" ]; then
457
- # A live process wearing our group's pid, born at a different moment: PID
458
- # reuse. Draining it would signal someone else's work.
459
- printf '%s\n' "lisa-scratch-run: process-birth identity mismatch; not draining $_pgid" >&2
460
- return 0
461
- fi
462
- if [ -z "$_live_birth" ]; then
463
- # The group LEADER is gone — which is precisely what happens when the
464
- # payload is SIGKILLed — but a process group outlives its leader, so the
465
- # survivors are the payload's own children and they are still ours.
466
- #
467
- # Returning here instead was a real leak: the orphaned children kept
468
- # running, and because they still held the run's inherited stdout and
469
- # stderr, the managed invocation could not report its outcome until they
470
- # finished on their own. Measured as a 60-second hang on a run that had
471
- # already been killed.
472
- #
473
- # Nothing else can be wearing this group id: a group id is its leader's
474
- # pid, and no process holds that pid at all.
475
- if ! kill -0 -"$_pgid" 2>/dev/null; then
476
- return 0
477
- fi
478
- fi
479
-
480
- kill -TERM -"$_pgid" 2>/dev/null || true
481
-
482
- _budget="${LISA_SCRATCH_DRAIN_MS:-5000}"
483
- case "$_budget" in
484
- "" | *[!0-9]*) _budget=5000 ;;
485
- esac
486
- _waited=0
487
- while [ "$_waited" -lt "$_budget" ]; do
488
- kill -0 -"$_pgid" 2>/dev/null || return 0
489
- lisa_nap
490
- _waited=$((_waited + LISA_SCRATCH_NAP_MS))
491
- done
492
-
493
- kill -0 -"$_pgid" 2>/dev/null || return 0
494
- kill -KILL -"$_pgid" 2>/dev/null || true
495
- return 0
496
- }
497
-
498
- # =============================================================================
499
- # Token-and-identity-bound root removal.
500
- #
501
- # Re-verifies token and device+inode immediately before the rename, renames the
502
- # root into a quarantine name derived from THIS run's token, and deletes only
503
- # that name. A quarantine directory whose suffix is not our token is left
504
- # alone, so a foreign quarantine cannot be swept.
505
- # =============================================================================
506
-
507
- lisa_remove_root() {
508
- _root="$1"
509
- _token="$2"
510
- _dev_ino="$3"
511
- _base="$4"
512
-
513
- [ -d "$_root" ] || return 0
514
- if [ -L "$_root" ]; then
515
- printf '%s\n' "lisa-scratch-run: run root became a symlink; refusing to delete" >&2
516
- return 1
517
- fi
518
- lisa_root_is_well_formed "$_root" "$_base" || {
519
- printf '%s\n' "lisa-scratch-run: run root no longer well-formed; refusing to delete" >&2
520
- return 1
521
- }
522
- lisa_root_matches_token "$_root" "$_token" || {
523
- printf '%s\n' "lisa-scratch-run: run locator differs from full token; refusing to delete" >&2
524
- return 1
525
- }
526
- _now="$(lisa_dev_ino "$_root")" || return 1
527
- if [ "$_now" != "$_dev_ino" ]; then
528
- printf '%s\n' "lisa-scratch-run: run root filesystem identity changed; refusing to delete" >&2
529
- return 1
530
- fi
531
- _marker_token="$(lisa_marker_get "$_root/.lisa-scratch-arm" token || true)"
532
- if [ -n "$_marker_token" ] && [ "$_marker_token" != "$_token" ]; then
533
- printf '%s\n' "lisa-scratch-run: run root owner token changed; refusing to delete" >&2
534
- return 1
535
- fi
536
-
537
- _quarantine="${_base}/${LISA_SCRATCH_NAMESPACE}/.quarantine.${_token}"
538
- case "$_quarantine" in
539
- "${_base}/${LISA_SCRATCH_NAMESPACE}/.quarantine.${_token}") : ;;
540
- *) return 1 ;;
541
- esac
542
- if mv -f "$_root" "$_quarantine" 2>/dev/null; then
543
- rm -rf "$_quarantine" 2>/dev/null || true
544
- else
545
- # Another participant of this same invocation may have taken it already.
546
- [ -d "$_root" ] || return 0
547
- rm -rf "$_root" 2>/dev/null || true
548
- fi
549
- if [ -d "$_root" ]; then return 1; fi
550
- return 0
551
- }
552
-
553
- # =============================================================================
554
- # GATED PAYLOAD LAUNCHER.
555
- #
556
- # Runs as the leader of its own process group, so the group identity exists —
557
- # and can therefore be acknowledged — before the payload runs. It refuses to
558
- # exec the payload unless the authority's acknowledgement for this exact token
559
- # is on disk. That refusal is the enforcement of authority-before-allocation:
560
- # even if the supervisor were wrong, the payload would not start.
561
- # =============================================================================
562
-
563
- lisa_launcher_main() {
564
- LISA_SCRATCH_ROLE=launcher
565
- _root="$1"
566
- _token="$2"
567
- shift 2
568
-
569
- lisa_root_matches_token "$_root" "$_token" ||
570
- lisa_die "$EX_ARM" "payload run locator differs from full token; refusing"
571
-
572
- if ! lisa_isolate_group LISA_SCRATCH_LAUNCH_REENTRY \
573
- "$LISA_SCRATCH_SH" "$LISA_SCRATCH_SELF" --launch "$_root" "$_token" "$@"; then
574
- lisa_die "$EX_ARM" "cannot isolate the payload process group; refusing"
575
- fi
576
-
577
- # Report the group identity the authority has to acknowledge. This happens
578
- # before the gate is even waited on, and long before any scratch exists, so
579
- # the identity being acknowledged is a fact rather than a prediction.
580
- _own_birth="$(lisa_birth "$$" || true)"
581
- [ -n "$_own_birth" ] ||
582
- lisa_die "$EX_ARM" "cannot read the payload process-birth identity"
583
- printf 'version=%s\npgid=%s\nbirth=%s\n' \
584
- "$LISA_SCRATCH_VERSION" "$$" "$_own_birth" \
585
- >"$_root/.lisa-scratch-pg.tmp" ||
586
- lisa_die "$EX_ARM" "cannot report the payload process group"
587
- mv -f "$_root/.lisa-scratch-pg.tmp" "$_root/.lisa-scratch-pg"
588
- lisa_trace "group-reported pgid=$$"
589
-
590
- # Deliberately NOT the arming budget: shrinking the arming budget must
591
- # produce a refusal that is observable as 'the payload never ran', which it
592
- # cannot be if the held payload has already given up on its own.
593
- _deadline="${LISA_SCRATCH_GATE_TIMEOUT_MS:-300000}"
594
- case "$_deadline" in
595
- "" | *[!0-9]*) _deadline=300000 ;;
596
- esac
597
- _waited=0
598
- while [ ! -f "$_root/.lisa-scratch-go" ]; do
599
- if [ "$_waited" -ge "$_deadline" ]; then
600
- lisa_die "$EX_ARM" "payload gate never opened; refusing to run the payload"
601
- fi
602
- lisa_nap
603
- _waited=$((_waited + LISA_SCRATCH_NAP_MS))
604
- done
605
-
606
- _ack_token="$(lisa_marker_get "$_root/.lisa-scratch-ack" token || true)"
607
- [ "$_ack_token" = "$_token" ] ||
608
- lisa_die "$EX_ARM" "no valid cleanup-authority acknowledgement; refusing to run the payload"
609
-
610
- [ -d "$_root/tmp" ] ||
611
- lisa_die "$EX_ARM" "payload scratch root missing; refusing to run the payload"
612
-
613
- TMPDIR="$_root/tmp"
614
- TMP="$TMPDIR"
615
- TEMP="$TMPDIR"
616
- export TMPDIR TMP TEMP
617
- lisa_trace "payload-exec"
618
- if [ "${LISA_SCRATCH_INHERIT_STDIN:-0}" = "1" ]; then
619
- exec "$@"
620
- else
621
- exec "$@" </dev/null
622
- fi
623
- }
624
-
625
- # =============================================================================
626
- # Leak scan.
627
- # =============================================================================
628
-
629
- # Emits the leak report on stderr. Returns 0 clean, 1 leaked.
630
- lisa_leak_scan() {
631
- _tmp="$1"
632
- _suite="$2"
633
-
634
- [ -d "$_tmp" ] || return 0
635
-
636
- _registered="${LISA_SCRATCH_REGISTERED_PREFIXES:-lisa-}"
637
-
638
- _leaked=""
639
- _count=0
640
- for _entry in "$_tmp"/* "$_tmp"/.[!.]*; do
641
- [ -e "$_entry" ] || continue
642
- _name="${_entry##*/}"
643
- _is_registered=no
644
- _rest="$_registered"
645
- while [ -n "$_rest" ]; do
646
- case "$_rest" in
647
- *,*)
648
- _prefix="${_rest%%,*}"
649
- _rest="${_rest#*,}"
650
- ;;
651
- *)
652
- _prefix="$_rest"
653
- _rest=""
654
- ;;
655
- esac
656
- [ -n "$_prefix" ] || continue
657
- case "$_name" in
658
- "$_prefix"*) _is_registered=yes ;;
659
- esac
660
- done
661
- if [ "$_is_registered" = yes ]; then
662
- # Registered prefixes are batch-cleaned, never reported.
663
- rm -rf "$_entry" 2>/dev/null || true
664
- continue
665
- fi
666
- _count=$((_count + 1))
667
- _leaked="$_leaked$_name
668
- "
669
- done
670
-
671
- if [ "$_count" -eq 0 ]; then return 0; fi
672
-
673
- _sorted="$(printf '%s' "$_leaked" | LC_ALL=C sort | tr '\n' ' ' | sed 's/ *$//')"
674
- printf '%s\n' "lisa-scratch-run: scratch leak in suite '$_suite': $_count unregistered direct child(ren): $_sorted" >&2
675
- printf '%s\n' "lisa-scratch-run: register benign prefixes via LISA_SCRATCH_REGISTERED_PREFIXES (comma-separated) or fix the fixture that leaked." >&2
676
- return 1
677
- }
678
-
679
- # =============================================================================
680
- # SUPERVISOR (default mode).
681
- # =============================================================================
682
-
683
- # Terminal path for a signal that arrives while the run is still arming, i.e.
684
- # before the payload has been allowed to allocate anything. Nothing is owned
685
- # yet beyond the run root and, at most, a payload held at the gate.
686
- lisa_abort_arming() {
687
- _sig="$1"
688
- trap - TERM INT HUP
689
- lisa_trace "arm-aborted signal=$_sig"
690
- [ -n "${LISA_SCRATCH_PAYLOAD_PID:-}" ] && kill -TERM "$LISA_SCRATCH_PAYLOAD_PID" 2>/dev/null
691
- [ -n "${LISA_SCRATCH_AUTHORITY_PID:-}" ] && kill -TERM "$LISA_SCRATCH_AUTHORITY_PID" 2>/dev/null
692
- if [ -n "${LISA_SCRATCH_ROOT:-}" ] &&
693
- [ -n "${LISA_SCRATCH_ROOT_DEVINO:-}" ] &&
694
- lisa_root_is_well_formed "$LISA_SCRATCH_ROOT" "${LISA_SCRATCH_BASE_CANONICAL:-}" &&
695
- lisa_root_matches_token "$LISA_SCRATCH_ROOT" "${LISA_SCRATCH_TOKEN:-}" &&
696
- [ "$(lisa_canonical_dir "$LISA_SCRATCH_ROOT")" = "$LISA_SCRATCH_ROOT" ] &&
697
- [ "$(lisa_dev_ino "$LISA_SCRATCH_ROOT")" = "$LISA_SCRATCH_ROOT_DEVINO" ]; then
698
- rm -rf "$LISA_SCRATCH_ROOT" 2>/dev/null || true
699
- fi
700
- kill -"$_sig" $$
701
- }
702
-
703
- lisa_supervisor_main() {
704
- LISA_SCRATCH_ROLE=supervisor
705
-
706
- _suite=""
707
- while [ "$#" -gt 0 ]; do
708
- case "$1" in
709
- --suite)
710
- [ "$#" -ge 2 ] || lisa_die "$EX_USAGE" "--suite requires a value"
711
- _suite="$2"
712
- shift 2
713
- ;;
714
- --suite=*)
715
- _suite="${1#--suite=}"
716
- shift
717
- ;;
718
- --)
719
- shift
720
- break
721
- ;;
722
- *)
723
- lisa_die "$EX_USAGE" "unexpected argument '$1'; usage: --suite <label> -- <command>"
724
- ;;
725
- esac
726
- done
727
-
728
- lisa_suite_is_well_formed "$_suite" ||
729
- lisa_die "$EX_USAGE" "--suite must be 1-64 chars of [A-Za-z0-9._-]"
730
- [ "$#" -ge 1 ] ||
731
- lisa_die "$EX_USAGE" "no payload command after --"
732
-
733
- # A supervised payload may not be another supervisor: exactly one boundary
734
- # per route, no recursive alias.
735
- case "${LISA_SCRATCH_TOKEN:-}" in
736
- ?*) lisa_die "$EX_USAGE" "refusing to nest inside an existing supervised run (suite ${LISA_SCRATCH_SUITE:-unknown})" ;;
737
- esac
738
- case "$1" in
739
- *lisa-scratch-run.sh) lisa_die "$EX_USAGE" "refusing to supervise the supervisor" ;;
740
- esac
741
-
742
- # --- terminal paths, armed before anything can exist to leak ------------
743
- # Installed as the very first thing the run does. A handler installed one
744
- # statement after the directory it protects is a handler with a window, and
745
- # the window is exactly where an interrupted run leaves its root behind
746
- # forever. Installing it here means there is no ordering to get wrong: the
747
- # handler is older than every resource it can be asked to release, and it
748
- # simply does nothing while there is nothing to release.
749
- LISA_SCRATCH_ROOT=""
750
- LISA_SCRATCH_ROOT_DEVINO=""
751
- LISA_SCRATCH_BASE_CANONICAL=""
752
- LISA_SCRATCH_PAYLOAD_PID=""
753
- LISA_SCRATCH_AUTHORITY_PID=""
754
- for _sig in TERM INT HUP; do
755
- # shellcheck disable=SC2064
756
- trap "lisa_abort_arming $_sig" "$_sig"
757
- done
758
-
759
- # --- base + token -------------------------------------------------------
760
- _base="${LISA_SCRATCH_BASE:-${TMPDIR:-/tmp}}"
761
- _base="${_base%/}"
762
- _base="$(lisa_canonical_dir "$_base")" ||
763
- lisa_die "$EX_ARM" "temp base is not a canonical directory: ${LISA_SCRATCH_BASE:-${TMPDIR:-/tmp}}"
764
-
765
- _token="$(od -An -tx1 -N32 /dev/urandom 2>/dev/null | tr -d ' \n')" || _token=""
766
- lisa_token_is_well_formed "$_token" ||
767
- lisa_die "$EX_ARM" "cannot obtain a 256-bit run token from /dev/urandom"
768
-
769
- mkdir -p "$_base/$LISA_SCRATCH_NAMESPACE" ||
770
- lisa_die "$EX_ARM" "cannot create scratch namespace under $_base"
771
- chmod 700 "$_base/$LISA_SCRATCH_NAMESPACE" 2>/dev/null || true
772
-
773
- _locator="$(printf 'r.%.24s' "$_token")"
774
- _root="$_base/$LISA_SCRATCH_NAMESPACE/$_locator"
775
- lisa_root_is_well_formed "$_root" "$_base" ||
776
- lisa_die "$EX_ARM" "computed run root is not well-formed: $_root"
777
-
778
- # Naming a root does not authorize deletion: exclusive creation and its
779
- # captured filesystem identity must also succeed before the handler can act.
780
- LISA_SCRATCH_ROOT="$_root"
781
- LISA_SCRATCH_TOKEN="$_token"
782
- LISA_SCRATCH_SUITE="$_suite"
783
- LISA_SCRATCH_BASE_CANONICAL="$_base"
784
- export LISA_SCRATCH_ROOT LISA_SCRATCH_TOKEN LISA_SCRATCH_SUITE
785
-
786
- # Latch signals across exclusive creation and identity capture. Otherwise a
787
- # signal between mkdir's success and the next assignment could either leak
788
- # our newly created root or mistake a collision for something we own.
789
- LISA_SCRATCH_ARM_SIGNAL=""
790
- for _sig in TERM INT HUP; do
791
- # shellcheck disable=SC2064
792
- trap "LISA_SCRATCH_ARM_SIGNAL=$_sig" "$_sig"
793
- done
794
- _created=no
795
- if mkdir "$_root"; then
796
- _created=yes
797
- LISA_SCRATCH_ROOT_DEVINO="$(lisa_dev_ino "$_root")" || LISA_SCRATCH_ROOT_DEVINO=""
798
- fi
799
- for _sig in TERM INT HUP; do
800
- # shellcheck disable=SC2064
801
- trap "lisa_abort_arming $_sig" "$_sig"
802
- done
803
- [ -z "$LISA_SCRATCH_ARM_SIGNAL" ] || lisa_abort_arming "$LISA_SCRATCH_ARM_SIGNAL"
804
- [ "$_created" = yes ] || lisa_die "$EX_ARM" "cannot exclusively create run root"
805
- [ -n "$LISA_SCRATCH_ROOT_DEVINO" ] ||
806
- lisa_die "$EX_ARM" "cannot read run root filesystem identity"
807
- chmod 700 "$_root" 2>/dev/null || true
808
- _canon="$(lisa_canonical_dir "$_root")" ||
809
- lisa_die "$EX_ARM" "run root is not a canonical directory"
810
- [ "$_canon" = "$_root" ] ||
811
- lisa_die "$EX_ARM" "run root resolves elsewhere: $_root -> $_canon"
812
- _dev_ino="$LISA_SCRATCH_ROOT_DEVINO"
813
- [ "$(lisa_dev_ino "$_root")" = "$_dev_ino" ] ||
814
- lisa_die "$EX_ARM" "run root filesystem identity changed during creation"
815
-
816
- lisa_trace "arm-begin suite=$_suite root=$_root"
817
-
818
- # --- process group exists before it is acknowledged ---------------------
819
- # The payload's group identity has to be knowable BEFORE the payload runs, so
820
- # the launcher is started held at a gate, isolates itself into its own
821
- # process group, and reports that group back. It cannot allocate scratch
822
- # until the gate opens.
823
- #
824
- # `set -m` is a best-effort assist for the Darwin path, where it is what
825
- # gives the background child its own group; the launcher verifies the result
826
- # itself and reaches for setsid when it did not happen, so a shell without
827
- # working job control is a fallback rather than a failure.
828
- set -m 2>/dev/null || true
829
-
830
- # Turning job control on resets the shell's SIGINT disposition — a terminal
831
- # normally delivers SIGINT to the foreground job's group, so the shell steps
832
- # out of the way. That silently drops the handler installed above, and a
833
- # Ctrl-C landing in the handshake window would be discarded rather than
834
- # honoured: measured as a run that continued to completion 15 seconds after
835
- # being told to stop. Re-arming here is what closes it.
836
- for _sig in TERM INT HUP; do
837
- # shellcheck disable=SC2064
838
- trap "lisa_abort_arming $_sig" "$_sig"
839
- done
840
-
841
- # A real process, not a `&` subshell: a subshell cannot learn its own pid
842
- # portably, and "am I my own group leader?" is the question the whole
843
- # handshake rests on.
844
- "$LISA_SCRATCH_SH" "$LISA_SCRATCH_SELF" --launch "$_root" "$_token" "$@" &
845
- _payload_pid="$!"
846
- LISA_SCRATCH_PAYLOAD_PID="$_payload_pid"
847
-
848
- _pg_deadline="${LISA_SCRATCH_ARM_TIMEOUT_MS:-15000}"
849
- case "$_pg_deadline" in
850
- "" | *[!0-9]*) _pg_deadline=15000 ;;
851
- esac
852
- _waited=0
853
- _pgid=""
854
- while [ "$_waited" -lt "$_pg_deadline" ]; do
855
- _pgid="$(lisa_marker_get "$_root/.lisa-scratch-pg" pgid || true)"
856
- [ -n "$_pgid" ] && break
857
- lisa_alive "$_payload_pid" || break
858
- lisa_nap
859
- _waited=$((_waited + LISA_SCRATCH_NAP_MS))
860
- done
861
- _birth="$(lisa_marker_get "$_root/.lisa-scratch-pg" birth || true)"
862
-
863
- _own_pgid="$(lisa_pgid_of "$$" || true)"
864
- lisa_abort_launch() {
865
- kill -TERM "$_payload_pid" 2>/dev/null || true
866
- rm -rf "$_root" 2>/dev/null || true
867
- lisa_die "$EX_ARM" "$1"
868
- }
869
- case "$_pgid" in
870
- "" | 0 | 1 | *[!0-9]*)
871
- lisa_abort_launch "payload did not report an isolated process group; refusing"
872
- ;;
873
- esac
874
- # The reported group must be the payload's own pid. Anything else means the
875
- # launcher was replaced by a forking wrapper, and `wait` would then report
876
- # the wrapper's status instead of the payload's.
877
- [ "$_pgid" = "$_payload_pid" ] ||
878
- lisa_abort_launch "payload process group $_pgid is not the payload pid $_payload_pid; refusing"
879
- [ "$(lisa_pgid_of "$_pgid" || true)" = "$_pgid" ] ||
880
- lisa_abort_launch "payload does not lead the group it reported; refusing"
881
- if [ -n "$_own_pgid" ] && [ "$_pgid" = "$_own_pgid" ]; then
882
- lisa_abort_launch "payload did not get an isolated process group; refusing"
883
- fi
884
- [ -n "$_birth" ] ||
885
- lisa_abort_launch "cannot read the payload process-birth identity"
886
- _sup_birth="$(lisa_birth "$$" || true)"
887
-
888
- # --- write the arming record -------------------------------------------
889
- {
890
- printf 'version=%s\n' "$LISA_SCRATCH_VERSION"
891
- printf 'token=%s\n' "$_token"
892
- printf 'root=%s\n' "$_root"
893
- printf 'devino=%s\n' "$_dev_ino"
894
- printf 'suite=%s\n' "$_suite"
895
- printf 'pgid=%s\n' "$_pgid"
896
- printf 'birth=%s\n' "$_birth"
897
- printf 'suppid=%s\n' "$$"
898
- printf 'supbirth=%s\n' "$_sup_birth"
899
- } >"$_root/.lisa-scratch-arm.tmp" || {
900
- kill -TERM "$_payload_pid" 2>/dev/null || true
901
- rm -rf "$_root" 2>/dev/null || true
902
- lisa_die "$EX_ARM" "cannot write the arming record"
903
- }
904
- mv -f "$_root/.lisa-scratch-arm.tmp" "$_root/.lisa-scratch-arm"
905
- lisa_trace "arm-written pgid=$_pgid"
906
-
907
- # --- start the outside authority and wait for its acknowledgement -------
908
- # Forked from THIS invocation, before the payload gate opens, into its own
909
- # process group. It therefore survives both a payload-group kill and a
910
- # supervisor kill, and no successor Lisa run is ever needed to clean up.
911
- "$LISA_SCRATCH_SH" "$LISA_SCRATCH_SELF" --authority "$_root" &
912
- _authority_pid="$!"
913
- LISA_SCRATCH_AUTHORITY_PID="$_authority_pid"
914
- lisa_trace "authority-started pid=$_authority_pid"
915
-
916
- # Both process groups are assigned at fork time, so job control has done
917
- # its job. Turning it back off keeps the shell's asynchronous 'Terminated'
918
- # notices out of the payload's own stderr.
919
- set +m 2>/dev/null || true
920
-
921
- # Same reason as after `set -m`: the disposition change cuts both ways.
922
- for _sig in TERM INT HUP; do
923
- # shellcheck disable=SC2064
924
- trap "lisa_abort_arming $_sig" "$_sig"
925
- done
926
-
927
- _deadline="${LISA_SCRATCH_ARM_TIMEOUT_MS:-15000}"
928
- case "$_deadline" in
929
- "" | *[!0-9]*) _deadline=15000 ;;
930
- esac
931
- _waited=0
932
- _acked=no
933
- while :; do
934
- _ack_token="$(lisa_marker_get "$_root/.lisa-scratch-ack" token || true)"
935
- if [ "$_ack_token" = "$_token" ]; then
936
- _acked=yes
937
- break
938
- fi
939
- if ! lisa_alive "$_authority_pid"; then
940
- break
941
- fi
942
- if [ "$_waited" -ge "$_deadline" ]; then
943
- break
944
- fi
945
- lisa_nap
946
- _waited=$((_waited + LISA_SCRATCH_NAP_MS))
947
- done
948
-
949
- if [ "$_acked" != yes ]; then
950
- # REFUSE. The payload has not run and never will on this invocation.
951
- kill -TERM "$_payload_pid" 2>/dev/null || true
952
- kill -TERM "$_authority_pid" 2>/dev/null || true
953
- rm -rf "$_root" 2>/dev/null || true
954
- lisa_trace "arm-refused"
955
- lisa_die "$EX_ARM" "cleanup authority did not acknowledge the run; refusing to execute the payload"
956
- fi
957
- lisa_trace "arm-acked"
958
-
959
- # --- terminal paths, installed BEFORE the gate opens --------------------
960
- # A signal arriving in the window between allocation and trap installation
961
- # would otherwise leave the root behind on the foreground path.
962
- LISA_SCRATCH_SIGNAL=""
963
- for _sig in TERM:143 INT:130 HUP:129; do
964
- _signame="${_sig%%:*}"
965
- _sigstatus="${_sig##*:}"
966
- # shellcheck disable=SC2064
967
- trap "LISA_SCRATCH_SIGNAL=$_signame; lisa_supervisor_finish $_payload_pid $_authority_pid \"\$LISA_SCRATCH_ROOT\" \"\$LISA_SCRATCH_TOKEN\" \"$_dev_ino\" \"$_base\" \"$_pgid\" \"$_birth\" $_sigstatus" "$_signame"
968
- done
969
-
970
- # --- allocation may begin -----------------------------------------------
971
- mkdir "$_root/tmp" || {
972
- kill -TERM "$_payload_pid" 2>/dev/null || true
973
- lisa_die "$EX_ARM" "cannot create the payload scratch root"
974
- }
975
- chmod 700 "$_root/tmp" 2>/dev/null || true
976
- : >"$_root/.lisa-scratch-go"
977
- lisa_trace "gate-open"
978
-
979
- _status=0
980
- wait "$_payload_pid" || _status="$?"
981
- lisa_trace "payload-exit status=$_status"
982
- trap - TERM INT HUP
983
- lisa_supervisor_finish "$_payload_pid" "$_authority_pid" "$_root" "$_token" \
984
- "$_dev_ino" "$_base" "$_pgid" "$_birth" "$_status"
985
- }
986
-
987
- # Drain, scan, delete, verify, then exit preserving the payload's verdict.
988
- lisa_supervisor_finish() {
989
- _payload_pid="$1"
990
- _authority_pid="$2"
991
- _root="$3"
992
- _token="$4"
993
- _dev_ino="$5"
994
- _base="$6"
995
- _pgid="$7"
996
- _birth="$8"
997
- _status="$9"
998
-
999
- lisa_trace "finish-begin status=$_status"
1000
-
1001
- # Drain first: a survivor in the owned group could still be creating
1002
- # scratch, which would make the leak verdict a race rather than a fact.
1003
- lisa_drain_group "$_pgid" "$_birth"
1004
-
1005
- _leak=0
1006
- if [ "${LISA_SCRATCH_LEAK_GATE:-enforce}" != "off" ]; then
1007
- lisa_leak_scan "$_root/tmp" "$LISA_SCRATCH_SUITE" || _leak=1
1008
- fi
1009
-
1010
- : >"$_root/.lisa-scratch-done" 2>/dev/null || true
1011
- lisa_remove_root "$_root" "$_token" "$_dev_ino" "$_base" || true
1012
-
1013
- if [ -d "$_root" ]; then
1014
- # The authority still owns this root. Do not kill it — it is the safety
1015
- # net, and it is already armed.
1016
- printf '%s\n' "lisa-scratch-run: run root still present after cleanup: $_root" >&2
1017
- lisa_trace "finish-root-present"
1018
- if [ "$_status" -eq 0 ]; then _status="$EX_AMBIGUOUS"; fi
1019
- else
1020
- lisa_trace "finish-root-absent"
1021
- # The owned group is drained and the owned root is gone, so the authority
1022
- # has nothing left to own. Retire it and reap it here rather than leaving
1023
- # an orphan behind.
1024
- #
1025
- # Polling `kill -0` instead would not work: a background child that has
1026
- # already exited is a zombie until it is waited for, and signal 0 succeeds
1027
- # against a zombie. That reads as "still working" for the whole budget, and
1028
- # cost a flat two seconds on every single supervised run.
1029
- kill -TERM "$_authority_pid" 2>/dev/null || true
1030
- wait "$_authority_pid" 2>/dev/null || true
1031
- fi
1032
-
1033
- if [ "$_leak" -eq 1 ] && [ "${LISA_SCRATCH_LEAK_GATE:-enforce}" = "enforce" ]; then
1034
- # A red payload keeps its own verdict; a green payload does not get to
1035
- # mask a leaking child.
1036
- if [ "$_status" -eq 0 ]; then _status="$EX_LEAK"; fi
1037
- fi
1038
-
1039
- if [ -n "${LISA_SCRATCH_SIGNAL:-}" ]; then
1040
- # Re-raise the original terminal signal so the caller sees what really
1041
- # happened, after cleanup has completed.
1042
- trap - "$LISA_SCRATCH_SIGNAL"
1043
- kill -"$LISA_SCRATCH_SIGNAL" $$
1044
- fi
1045
-
1046
- exit "$_status"
1047
- }
1048
-
1049
- # =============================================================================
1050
- # Entry point.
1051
- # =============================================================================
1052
-
1053
- LISA_SCRATCH_ROLE=supervisor
1054
-
1055
- case "${0}" in
1056
- /*) LISA_SCRATCH_SELF="$0" ;;
1057
- *) LISA_SCRATCH_SELF="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" ;;
1058
- esac
1059
- # The file is POSIX shell throughout, so re-entering it under /bin/sh is exact
1060
- # regardless of which interpreter the route used to start it.
1061
- LISA_SCRATCH_SH="/bin/sh"
1062
- export LISA_SCRATCH_SELF LISA_SCRATCH_SH
1063
-
1064
- if [ "${1:-}" = "--authority" ]; then
1065
- [ "$#" -eq 2 ] || lisa_die "$EX_USAGE" "--authority takes exactly one run root"
1066
- lisa_authority_main "$2"
1067
- fi
1068
-
1069
- # Internal: the held payload launcher. Not a user-facing entry point — the
1070
- # supervisor re-enters here, and so does setsid when it has to build the
1071
- # process group the handshake acknowledges.
1072
- if [ "${1:-}" = "--launch" ]; then
1073
- [ "$#" -ge 4 ] || lisa_die "$EX_USAGE" "--launch takes a run root, a token and a command"
1074
- shift
1075
- lisa_launcher_main "$@"
1076
- fi
1077
-
1078
- lisa_supervisor_main "$@"