@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b

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 (329) hide show
  1. package/README.md +183 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -0,0 +1,166 @@
1
+ // What a pre-publication pass validates: the paths the attempt changed, which select the CI parity
2
+ // checks, and the revisions the affected .NET tests measure against. When the attempt makes a merge
3
+ // (a conflict repair merging the target branch in) and the merge's other parent is on the target
4
+ // branch, the pass measures the merged head against that parent, as CI measures a pull request
5
+ // against its base: what the target branch brought matches it and was validated by its CI, while the
6
+ // Story's own changes and every conflict resolution that is not the target's version still count.
7
+ // The merged head's integration is CI's job on the pushed head.
8
+ import { randomUUID } from "node:crypto";
9
+ import { validationEvent } from "./pre-publication-pass.js";
10
+ import { ForgeFailureError } from "./session.types.js";
11
+ // The new exports of the same change; the pass checks them alongside the changed paths.
12
+ export { findUnreferencedNewExports } from "./unreferenced-exports.js";
13
+ /**
14
+ * Git reads history as it was committed. The agent could otherwise plant a replace ref
15
+ * (`git replace <target tip> <fake>`) or a graft that rewrites what the merge parent's tree is and
16
+ * whose ancestor it is. The bridge's own git calls in the pass, and the affected .NET run that measures
17
+ * against these revisions, run with it (the sandbox import does the same, sandbox/runtime.ts). Other
18
+ * check steps do not: their suites may make replace refs or grafts of their own in throwaway repos. An empty graft file is no grafts; /dev/null is one on every
19
+ * platform Git runs on (Git for Windows maps it to NUL), and nothing can be written into it.
20
+ */
21
+ export const historyIntegrityEnvironment = {
22
+ GIT_NO_REPLACE_OBJECTS: "1",
23
+ GIT_GRAFT_FILE: "/dev/null",
24
+ };
25
+ const commitSha = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/iu;
26
+ // A branch name the bridge can fetch by refspec; anything else scopes nothing.
27
+ const branchName = /^(?!-)(?!.*\.\.)[A-Za-z0-9._/-]+$/u;
28
+ /**
29
+ * The pass's change set: the verified merge parent it measures against (null when the attempt makes no
30
+ * merge, or merges something its target branch's CI did not validate), and the changed paths that select
31
+ * its checks. Emits whether and how a merge scoped the pass.
32
+ */
33
+ export async function passChangeSet(git, execution, emit) {
34
+ const attempted = await attemptMergeParent(git, execution?.baselineRevision);
35
+ const scope = attempted === null ? null : await verifiedMergeScope(git, attempted, execution?.targetBranch);
36
+ if (scope !== null && scope.mergeParent === null) {
37
+ await emit?.(validationEvent("prepublication_validation_merge_unscoped", "validation-contract", `This attempt merges ${attempted}, but ${scope.unscopedReason}: every path the attempt changed selects checks.`, { mergeParent: attempted, reason: scope.unscopedReason }));
38
+ }
39
+ const mergeParent = scope?.mergeParent ?? null;
40
+ const changedPaths = await changedPathInventory(git, execution?.baselineRevision, mergeParent);
41
+ if (scope !== null && scope.mergeParent !== null) {
42
+ // A merged head that matches the parent selects nothing; say so rather than pass silently.
43
+ await emit?.(changedPaths.length === 0
44
+ ? validationEvent("prepublication_validation_merge_scope_empty", "validation-contract", `This attempt merges ${scope.mergeParent} from ${scope.targetRef}, and its merged head matches it: no check is selected; CI validates the merged head.`, { severity: "warning", mergeParent: scope.mergeParent, targetRef: scope.targetRef })
45
+ : validationEvent("prepublication_validation_merge_scoped", "validation-contract", `This attempt merges ${scope.mergeParent} from ${scope.targetRef}: checks are selected by the ${changedPaths.length} path(s) the merged head changes over it; CI validates the merged head.`, { mergeParent: scope.mergeParent, targetRef: scope.targetRef }));
46
+ }
47
+ return { mergeParent, changedPaths };
48
+ }
49
+ /**
50
+ * The other parent of a merge the attempt makes: MERGE_HEAD while a merge is in progress, or the second
51
+ * parent of a merge commit HEAD made since the dispatch baseline. Null when the attempt makes no merge,
52
+ * including a merge commit that was already HEAD at dispatch.
53
+ */
54
+ export async function attemptMergeParent(git, baselineRevision) {
55
+ const merging = await resolveCommit(git, "MERGE_HEAD");
56
+ if (merging)
57
+ return merging;
58
+ const baseline = baselineRevision?.trim();
59
+ if (!baseline)
60
+ return null;
61
+ const secondParent = await resolveCommit(git, "HEAD^2");
62
+ if (!secondParent)
63
+ return null;
64
+ const head = await resolveCommit(git, "HEAD");
65
+ const base = await resolveCommit(git, baseline);
66
+ return head !== null && base !== null && head !== base ? secondParent : null;
67
+ }
68
+ /**
69
+ * Scopes the pass to a merge parent only when the target branch's CI validated it: the parent is the
70
+ * target's tip on origin, or an ancestor of it. The agent controls the merge and every local ref (it can
71
+ * rewrite refs/remotes/origin/<target>, which a host worktree shares with the main repository), so the
72
+ * bridge fetches the target into a ref of its own for this pass and deletes it afterwards. A parent
73
+ * anywhere else (a scratch branch holding the attempt's own work), or a fetch that fails (a Docker
74
+ * sandbox workspace has no origin), scopes nothing.
75
+ */
76
+ export async function verifiedMergeScope(git, mergeParent, targetBranch, validationRef = `refs/forge/validation-target/${randomUUID()}`) {
77
+ const target = targetBranch?.trim() ?? "";
78
+ if (!target)
79
+ return { mergeParent: null, unscopedReason: "the dispatch names no target branch" };
80
+ if (commitSha.test(target))
81
+ return await scopeToTip(git, mergeParent, target, target);
82
+ const branch = target.replace(/^refs\/heads\//u, "");
83
+ if (!branchName.test(branch))
84
+ return { mergeParent: null, unscopedReason: `target branch ${target} is not a branch name` };
85
+ const targetRef = `origin/${branch}`;
86
+ try {
87
+ // An empty --refmap keeps the fetch from also moving refs/remotes/origin/<target>: it writes only its
88
+ // own ref. The fetch is inside the try, so an aborted fetch that already wrote the ref still deletes it.
89
+ const fetched = await git(["fetch", "--no-tags", "--no-write-fetch-head", "--refmap=", "--quiet", "origin",
90
+ `+refs/heads/${branch}:${validationRef}`]);
91
+ if (fetched.exitCode !== 0)
92
+ return { mergeParent: null, unscopedReason: `the bridge could not fetch ${branch} from origin` };
93
+ return await scopeToTip(git, mergeParent, validationRef, targetRef);
94
+ }
95
+ finally {
96
+ // Forge leaves nothing behind: the ref is this pass's alone.
97
+ await git(["update-ref", "-d", validationRef]);
98
+ }
99
+ }
100
+ async function scopeToTip(git, mergeParent, revision, targetRef) {
101
+ const tip = await resolveCommit(git, revision);
102
+ if (tip === null)
103
+ return { mergeParent: null, unscopedReason: `${targetRef} is not in this checkout` };
104
+ if (tip === mergeParent)
105
+ return { mergeParent, targetRef };
106
+ const ancestor = await git(["merge-base", "--is-ancestor", mergeParent, tip]);
107
+ return ancestor.exitCode === 0
108
+ ? { mergeParent, targetRef }
109
+ : { mergeParent: null, unscopedReason: `${mergeParent} is not on ${targetRef}` };
110
+ }
111
+ /**
112
+ * The paths the attempt changed: uncommitted, committed since the baseline, and untracked. With a
113
+ * verified merge parent, what the merged head changes over that parent, and the untracked paths.
114
+ */
115
+ export async function changedPathInventory(git, baselineRevision, mergeParent) {
116
+ const baseline = mergeParent === null ? baselineRevision?.trim() : undefined;
117
+ const paths = new Set();
118
+ if (mergeParent !== null) {
119
+ // Renames count as a deletion plus an addition, so both sides of one count.
120
+ for (const line of await gitLines(git, ["diff", "--name-only", "--no-renames", mergeParent, "--"]))
121
+ paths.add(normalizedPath(line));
122
+ }
123
+ else {
124
+ for (const line of await gitLines(git, ["diff", "--name-only", "HEAD", "--"]))
125
+ paths.add(normalizedPath(line));
126
+ }
127
+ if (baseline) {
128
+ for (const line of await gitLines(git, ["diff", "--name-only", `${baseline}..HEAD`, "--"]))
129
+ paths.add(normalizedPath(line));
130
+ }
131
+ for (const line of await gitLines(git, ["status", "--porcelain=v1", "--untracked-files=all"])) {
132
+ // Against a merge parent, the tracked paths are already measured; only the untracked ones add.
133
+ if (mergeParent !== null && !line.startsWith("??"))
134
+ continue;
135
+ paths.add(normalizedPath(line.slice(3).split(" -> ").at(-1) ?? ""));
136
+ }
137
+ paths.delete("");
138
+ return [...paths];
139
+ }
140
+ /**
141
+ * The step environment the affected .NET tests read (scripts/run-affected-dotnet-tests.mjs): the dispatch
142
+ * baseline, and the verified merge parent they measure against instead when there is one. The validator
143
+ * adds historyIntegrityEnvironment to that check's steps only.
144
+ */
145
+ export function validationRevisionEnvironment(baselineRevision, mergeParent) {
146
+ const baseline = baselineRevision?.trim();
147
+ return {
148
+ ...(baseline ? { FORGE_VALIDATION_BASE_REVISION: baseline } : {}),
149
+ ...(mergeParent ? { FORGE_VALIDATION_MERGE_PARENT_REVISION: mergeParent } : {}),
150
+ };
151
+ }
152
+ async function resolveCommit(git, revision) {
153
+ const result = await git(["rev-parse", "-q", "--verify", `${revision}^{commit}`]);
154
+ const sha = `${result.stdout ?? ""}`.trim();
155
+ return result.exitCode === 0 && commitSha.test(sha) ? sha.toLowerCase() : null;
156
+ }
157
+ async function gitLines(git, args) {
158
+ const result = await git(args);
159
+ if (result.exitCode !== 0) {
160
+ throw new ForgeFailureError("prepublication_validation_failed", `prepublication_validation_failed: unable to inventory changed paths: ${result.stderr ?? result.stdout ?? "git failed"}`, "bridge");
161
+ }
162
+ return `${result.stdout ?? ""}`.split(/\r?\n/u).filter(Boolean);
163
+ }
164
+ function normalizedPath(raw) {
165
+ return raw.trim().replaceAll("\\", "/");
166
+ }
@@ -0,0 +1,27 @@
1
+ import { type HostLoadStepGate } from "../runtime/host-load-governor.js";
2
+ import { type HostLoadTokenPriority } from "../runtime/host-load-token-ledger.js";
3
+ import type { RunnerDispatchEvent } from "./session.types.js";
4
+ /** Which attempt a governed validation step belongs to, and its queue class. */
5
+ export interface PrePublicationHostLoadOwner {
6
+ readonly dispatchAttemptId: string | null;
7
+ readonly priority: HostLoadTokenPriority;
8
+ }
9
+ export interface GovernedValidationStep {
10
+ readonly checkId: string;
11
+ readonly command: string;
12
+ readonly args: readonly string[];
13
+ readonly owner?: PrePublicationHostLoadOwner;
14
+ readonly signal?: AbortSignal;
15
+ readonly emit?: (event: RunnerDispatchEvent) => Promise<void>;
16
+ }
17
+ /**
18
+ * Runs one pre-publication step behind the host load governor (decision 0013).
19
+ * With the governor off this is a direct call, so behavior is unchanged. With
20
+ * it on, the step waits for admission first; queue time is reported as
21
+ * `host_load_wait_ms` with status `waiting_for_host_capacity`, and the step's
22
+ * own clock (`elapsed_ms`) starts only once it is admitted. `run` gets the
23
+ * signal to launch with: it also aborts when the step's reservation is lost
24
+ * (token fenced, or not renewable for a lease), and the step then fails with
25
+ * that error instead of running on unaccounted.
26
+ */
27
+ export declare function runHostGovernedValidationStep<T>(gate: HostLoadStepGate | undefined, step: GovernedValidationStep, run: (signal: AbortSignal | undefined) => Promise<T>): Promise<T>;
@@ -0,0 +1,112 @@
1
+ import { monotonicNowMs } from "../shared/time/monotonic.js";
2
+ import { HostCapacityTimeoutError } from "../runtime/host-load-governor.js";
3
+ import { HostCapacityLedgerUnavailableError } from "../runtime/host-load-ledger-lock.js";
4
+ import { orderedWaitReports, retentionFor, returnHostLoadToken } from "../runtime/host-load-step-run.js";
5
+ import { classifyValidationStep } from "../runtime/host-load-step-class.js";
6
+ import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
7
+ /**
8
+ * Runs one pre-publication step behind the host load governor (decision 0013).
9
+ * With the governor off this is a direct call, so behavior is unchanged. With
10
+ * it on, the step waits for admission first; queue time is reported as
11
+ * `host_load_wait_ms` with status `waiting_for_host_capacity`, and the step's
12
+ * own clock (`elapsed_ms`) starts only once it is admitted. `run` gets the
13
+ * signal to launch with: it also aborts when the step's reservation is lost
14
+ * (token fenced, or not renewable for a lease), and the step then fails with
15
+ * that error instead of running on unaccounted.
16
+ */
17
+ export async function runHostGovernedValidationStep(gate, step, run) {
18
+ if (!gate?.enabled)
19
+ return await run(step.signal);
20
+ const { stepClass, cost } = classifyValidationStep(step.checkId, step.command, step.args);
21
+ const base = { checkId: step.checkId, contractId: "forge-ci-parity-v1", stepClass };
22
+ const emit = async (eventType, content, data, kind = "checkpoint") => {
23
+ await step.emit?.({ role: "runner", kind, content, eventType, data: JSON.stringify({ ...base, ...data }) })
24
+ .catch(() => undefined);
25
+ };
26
+ // Every waiting event lands before the admitted or failed one that follows it.
27
+ const reports = orderedWaitReports(async (decision) => await emit("prepublication_host_capacity_waiting", `Pre-publication step '${step.checkId}' (${stepClass}) is waiting for host capacity: ${decision.detail}`, { status: "waiting_for_host_capacity", reason: decision.reason, cpuCores: cost.cpuCores, memoryBytes: cost.memoryBytes }));
28
+ let admission;
29
+ try {
30
+ admission = await gate.acquire({
31
+ stepClass,
32
+ label: step.checkId,
33
+ cost,
34
+ dispatchAttemptId: step.owner?.dispatchAttemptId ?? null,
35
+ priority: step.owner?.priority ?? "foreground",
36
+ }, { signal: step.signal, onWaiting: reports.onWaiting });
37
+ await reports.drained();
38
+ }
39
+ catch (error) {
40
+ await reports.drained();
41
+ if (error instanceof HostCapacityTimeoutError) {
42
+ await emit("prepublication_host_capacity_timeout", error.message, { status: "host_capacity_timeout", host_load_wait_ms: Math.round(error.waitMs) }, "error");
43
+ }
44
+ else if (error instanceof HostCapacityLedgerUnavailableError) {
45
+ await emit("prepublication_host_capacity_ledger_unavailable", error.message, { status: "host_capacity_ledger_unavailable" }, "error");
46
+ }
47
+ throw error;
48
+ }
49
+ const waitMs = Math.round(admission.waitMs);
50
+ await emit("prepublication_host_capacity_admitted", `Pre-publication step '${step.checkId}' (${stepClass}) was admitted after ${waitMs}ms waiting for host capacity.`, { status: "running", reason: admission.decision.reason, host_load_wait_ms: waitMs });
51
+ // Step timers start here, after admission: a step can never time out because it waited.
52
+ const startedAtMs = monotonicNowMs();
53
+ const runSignal = step.signal ? AbortSignal.any([step.signal, admission.fenced]) : admission.fenced;
54
+ const reservationLost = async () => {
55
+ const reason = admission.fenced.reason;
56
+ await emit("prepublication_host_capacity_lost", `Pre-publication step '${step.checkId}' (${stepClass}) was stopped because its host capacity reservation was lost: ${reason instanceof Error ? reason.message : String(reason)}`, { status: "host_capacity_lost" }, "error");
57
+ throw reason;
58
+ };
59
+ let unstopped = null;
60
+ try {
61
+ let result;
62
+ try {
63
+ result = await run(runSignal);
64
+ }
65
+ catch (error) {
66
+ // Part of the step may still run: that, not a fence, is what it failed with.
67
+ // Also a supervised runner's failed proof, which arrives sanitized and wrapped.
68
+ const retention = retentionFor(error);
69
+ if (retention) {
70
+ unstopped = retention;
71
+ throw error;
72
+ }
73
+ if (admission.fenced.aborted)
74
+ return await reservationLost();
75
+ throw error;
76
+ }
77
+ // A result produced after the reservation was lost is not trusted either.
78
+ if (admission.fenced.aborted)
79
+ return await reservationLost();
80
+ return result;
81
+ }
82
+ finally {
83
+ const elapsedMs = Math.round(monotonicNowMs() - startedAtMs);
84
+ // Assigned in the catch above; widened, since control-flow narrowing does not see it here.
85
+ const treeLeft = unstopped;
86
+ const returned = {
87
+ failure: treeLeft ? { kind: "retained", message: treeLeft.reason.message } : null,
88
+ };
89
+ // The token is kept, with its cost, while part of the step's tree may still run.
90
+ await returnHostLoadToken(admission, treeLeft, error => {
91
+ returned.failure = {
92
+ kind: error instanceof HostCapacityTokenFencedError ? "fenced" : "ledger_unavailable",
93
+ message: error instanceof Error ? error.message : String(error),
94
+ };
95
+ });
96
+ const failure = returned.failure;
97
+ await emit("prepublication_host_capacity_released", failure?.kind === "retained"
98
+ ? `Pre-publication step '${step.checkId}' ended, but part of its process tree did not stop; its host capacity stays reserved until it is gone: ${failure.message}`
99
+ : failure?.kind === "fenced"
100
+ ? `Pre-publication step '${step.checkId}' finished, but its host capacity token had been reclaimed: ${failure.message}`
101
+ : failure
102
+ ? `Pre-publication step '${step.checkId}' finished, but its host capacity token could not be returned yet (the governor keeps retrying): ${failure.message}`
103
+ : `Pre-publication step '${step.checkId}' (${stepClass}) ran ${elapsedMs}ms after waiting ${waitMs}ms for host capacity.`, {
104
+ status: "completed",
105
+ host_load_wait_ms: waitMs,
106
+ elapsed_ms: elapsedMs,
107
+ tokenFenced: failure?.kind === "fenced",
108
+ releaseFailed: failure?.kind === "ledger_unavailable",
109
+ tokenRetained: failure?.kind === "retained",
110
+ });
111
+ }
112
+ }
@@ -0,0 +1,30 @@
1
+ import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
2
+ import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
3
+ import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
4
+ import type { RunnerDispatchEvent } from "./session.types.js";
5
+ /**
6
+ * A provisioned native test cluster whose file prefers it serves this check's shared
7
+ * test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
8
+ * first). Docker is still probed, never recovered, so the fixtures know whether
9
+ * pinned-engine tests can start their own containers. An unreadable file leaves the
10
+ * check on Docker.
11
+ */
12
+ export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
13
+ /** Whether this check already has its isolated PostgreSQL without Docker. */
14
+ export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
15
+ /**
16
+ * The grant, when it makes its check Docker-free. A native_preferred grant still lets
17
+ * pinned-engine tests start Docker containers, so a Docker loss during its check stays
18
+ * retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
19
+ */
20
+ export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
21
+ /**
22
+ * Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
23
+ * is left disowned for the next start's reap and does not change the check's own result.
24
+ */
25
+ export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
26
+ /** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
27
+ export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
28
+ export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
29
+ /** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
30
+ export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;
@@ -0,0 +1,111 @@
1
+ import path from "node:path";
2
+ import { attemptDatabaseCapabilityEnvironment } from "../runtime/attempt-database-broker.js";
3
+ import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
4
+ import { nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresGrant, } from "../runtime/native-test-postgres-fallback.js";
5
+ import { validationEvent } from "./pre-publication-pass.js";
6
+ import { supportsNativeTestPostgresFallback } from "./pre-publication-step-execution.js";
7
+ // Which PostgreSQL a pre-publication check's isolated_postgres prerequisite is met by,
8
+ // before the validator falls back to waiting for Docker.
9
+ /**
10
+ * A provisioned native test cluster whose file prefers it serves this check's shared
11
+ * test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
12
+ * first). Docker is still probed, never recovered, so the fixtures know whether
13
+ * pinned-engine tests can start their own containers. An unreadable file leaves the
14
+ * check on Docker.
15
+ */
16
+ export async function preferredNativeTestPostgres(checkId, requiredPrerequisite, readCluster, dockerEngineProbe, emit, startEphemeral = startEphemeralTestPostgresGrant) {
17
+ if (requiredPrerequisite !== "isolated_postgres" || !supportsNativeTestPostgresFallback(checkId))
18
+ return undefined;
19
+ let configured;
20
+ try {
21
+ configured = readCluster();
22
+ }
23
+ catch (error) {
24
+ await emit?.(validationEvent("prepublication_prerequisite_native_invalid", checkId, `The native PostgreSQL test cluster configuration was refused, so '${checkId}' uses Docker: ${error instanceof Error ? error.message : String(error)}`));
25
+ return undefined;
26
+ }
27
+ if (configured?.use === "ephemeral") {
28
+ return await ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral);
29
+ }
30
+ if (configured?.use !== "preferred")
31
+ return undefined;
32
+ const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
33
+ const grant = nativeTestPostgresGrant(configured, dockerAvailable);
34
+ if (!grant)
35
+ return undefined;
36
+ await emit?.(validationEvent("prepublication_prerequisite_native_preferred", checkId, `Pre-publication check '${checkId}' is using the dedicated native PostgreSQL test cluster at ${grant.endpoint} with per-run owned databases${dockerAvailable
37
+ ? "; tests that need a pinned engine container still start one in Docker."
38
+ : ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
39
+ return grant;
40
+ }
41
+ /**
42
+ * A throwaway cluster of the check's own, whose superuser it holds (owner policy 2026-11-17).
43
+ * If it cannot start, the check falls back to Docker, and to the provisioned cluster only while
44
+ * Docker is down.
45
+ */
46
+ async function ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral) {
47
+ const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
48
+ let grant;
49
+ try {
50
+ grant = await startEphemeral(configured, dockerAvailable);
51
+ }
52
+ catch (error) {
53
+ await emit?.(validationEvent("prepublication_prerequisite_ephemeral_unavailable", checkId, `An ephemeral PostgreSQL test cluster could not start for '${checkId}', so it uses Docker: ${error instanceof Error ? error.message : String(error)}`));
54
+ return undefined;
55
+ }
56
+ try {
57
+ await emit?.(validationEvent("prepublication_prerequisite_native_ephemeral", checkId, `Pre-publication check '${checkId}' is using its own ephemeral PostgreSQL test cluster at ${grant.endpoint}, deleted when the check ends${dockerAvailable
58
+ ? "; tests that need a pinned engine container still start one in Docker."
59
+ : ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
60
+ }
61
+ catch (error) {
62
+ // The caller releases only a grant it receives, so a failed emit releases it here.
63
+ await grant.release?.().catch(() => undefined);
64
+ throw error;
65
+ }
66
+ return grant;
67
+ }
68
+ function environmentValue(environment, name) {
69
+ return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
70
+ ? environment?.[name]?.trim() ?? ""
71
+ : process.env[name]?.trim() ?? "";
72
+ }
73
+ /** Whether this check already has its isolated PostgreSQL without Docker. */
74
+ export function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
75
+ if (checkId === "playwright-e2e") {
76
+ const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
77
+ return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
78
+ || /^[0-9a-f-]{36}$/iu.test(attemptId))
79
+ && /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
80
+ && path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
81
+ // The attempt owns a database only once the Bridge's broker has issued it one.
82
+ && environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
83
+ }
84
+ return Boolean(postgresAdminConnection);
85
+ }
86
+ /**
87
+ * The grant, when it makes its check Docker-free. A native_preferred grant still lets
88
+ * pinned-engine tests start Docker containers, so a Docker loss during its check stays
89
+ * retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
90
+ */
91
+ export function dockerFreeGrant(grant) {
92
+ return grant?.mode === nativeTestPostgresFallbackDatabaseMode ? grant : undefined;
93
+ }
94
+ /**
95
+ * Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
96
+ * is left disowned for the next start's reap and does not change the check's own result.
97
+ */
98
+ export async function releaseCheckPostgres(checkId, grant, emit) {
99
+ try {
100
+ await grant?.release?.();
101
+ }
102
+ catch (error) {
103
+ await emit?.(validationEvent("prepublication_ephemeral_release_failed", checkId, `The ephemeral PostgreSQL test cluster for '${checkId}' could not be released and will be reaped later: ${error instanceof Error ? error.message : String(error)}`)).catch(() => undefined);
104
+ }
105
+ }
106
+ /** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
107
+ export function dockerUnavailableNativeTestPostgres(checkId, requiredPrerequisite, readCluster) {
108
+ return requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(checkId)
109
+ ? nativeTestPostgresGrant(readCluster(), false)
110
+ : null;
111
+ }
@@ -0,0 +1,61 @@
1
+ import type { ValidationStep } from "./pre-publication-step-execution.js";
2
+ import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
3
+ /** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
4
+ export declare const runtimeRestartCheckId = "host-runtime-restart";
5
+ /** One check that failed in a pass: the step that failed and its clipped diagnostics. */
6
+ export interface PrePublicationCheckFailure {
7
+ readonly checkId: string;
8
+ readonly exitCode: number;
9
+ readonly command: string;
10
+ readonly args: readonly string[];
11
+ readonly detail: string;
12
+ }
13
+ /**
14
+ * A failed validation pass. The single-check fields name the first failure, as they always have;
15
+ * `failures` lists every check that failed in the pass, in the order the checks ran.
16
+ */
17
+ export declare class PrePublicationValidationError extends ForgeFailureError {
18
+ readonly checkId: string;
19
+ readonly exitCode: number;
20
+ readonly command: string;
21
+ readonly args: readonly string[];
22
+ readonly detail: string;
23
+ readonly code = "prepublication_validation_failed";
24
+ readonly failures: readonly PrePublicationCheckFailure[];
25
+ constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string, additionalFailures?: readonly PrePublicationCheckFailure[]);
26
+ /** Every failed check's id, first failure first. */
27
+ get checkIds(): readonly string[];
28
+ }
29
+ export declare class PrePublicationPass {
30
+ private readonly runtimeRestartFailure?;
31
+ private readonly failures;
32
+ /** The check whose .NET build failed to compile in this pass, if any. */
33
+ private dotnetCompileFailedIn;
34
+ /** A failed runtime restart before the pass is its first failure. */
35
+ constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
36
+ record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
37
+ /** The failed checks that keep this check from running meaningfully in this pass. */
38
+ blockers(checkId: string): readonly string[];
39
+ /**
40
+ * Whether an error ends the pass with the failures it already found. Only a classified retryable
41
+ * failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
42
+ * pass has found a failure: the repair turn can fix those failures now, and the next pass meets
43
+ * the condition again. Any other error, or cancellation, still ends the attempt as it did.
44
+ */
45
+ stopsAt(error: unknown, signal?: AbortSignal): error is ForgeFailureError;
46
+ stoppedEvent(checkId: string, error: ForgeFailureError): RunnerDispatchEvent;
47
+ /** Throws every failure the pass found as one validation failure. */
48
+ throwIfFailed(): void;
49
+ }
50
+ export declare function skippedCheckEvent(checkId: string, blockedBy: readonly string[]): RunnerDispatchEvent;
51
+ /** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
52
+ export declare class SkippedTestTally {
53
+ private readonly worktreePath;
54
+ private readonly environment?;
55
+ private summary;
56
+ constructor(worktreePath: string, environment?: Readonly<Record<string, string>> | undefined);
57
+ /** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
58
+ add(args: readonly string[], stepStartedMs: number): Promise<void>;
59
+ passedEvent(checkId: string, secrets: readonly string[]): RunnerDispatchEvent;
60
+ }
61
+ export declare function validationEvent(eventType: string, checkId: string, content: string, detail?: Readonly<Record<string, unknown>>): RunnerDispatchEvent;