@loucompanion/forge-bridge 0.1.4-dev.d2d83bc81b6a → 0.1.4-dev.deb7f72e7930

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 (253) hide show
  1. package/README.md +144 -3
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +9 -0
  15. package/dist/bridge/bridge.service.d.ts +92 -15
  16. package/dist/bridge/bridge.service.js +432 -342
  17. package/dist/bridge/bridge.types.d.ts +27 -0
  18. package/dist/bridge/in-flight-registry.d.ts +62 -0
  19. package/dist/bridge/in-flight-registry.js +207 -0
  20. package/dist/bridge/local-yield-flag.d.ts +6 -0
  21. package/dist/bridge/local-yield-flag.js +34 -0
  22. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  23. package/dist/bridge/readiness-result-outbox.js +20 -0
  24. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  25. package/dist/bridge/runner-host-capabilities.js +17 -0
  26. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  27. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  28. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  29. package/dist/bridge/test-postgres-capability.js +120 -0
  30. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  31. package/dist/cleanup/cleanup-wip.js +66 -0
  32. package/dist/cleanup/cleanup.service.d.ts +20 -1
  33. package/dist/cleanup/cleanup.service.js +150 -169
  34. package/dist/cleanup/cleanup.types.d.ts +6 -0
  35. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  36. package/dist/cleanup/forge-owned-paths.js +53 -0
  37. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  38. package/dist/cleanup/host-runtime-ledger.js +130 -0
  39. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  40. package/dist/cleanup/managed-branch-sweep.js +111 -0
  41. package/dist/cli/cli.help.js +74 -12
  42. package/dist/cli/cli.service.d.ts +19 -10
  43. package/dist/cli/cli.service.js +152 -187
  44. package/dist/cli/idle-status.d.ts +84 -0
  45. package/dist/cli/idle-status.js +181 -0
  46. package/dist/cli/local-config.d.ts +6 -0
  47. package/dist/cli/local-config.js +32 -4
  48. package/dist/cli/provider-cli-detection.d.ts +10 -0
  49. package/dist/cli/provider-cli-detection.js +160 -0
  50. package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
  51. package/dist/runtime/aspnet-runtime-prebuild.js +140 -7
  52. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  53. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  54. package/dist/runtime/docker-engine-probe.js +7 -0
  55. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  56. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  57. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  58. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  59. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  60. package/dist/runtime/host-database-capability-boundary.js +1 -0
  61. package/dist/runtime/host-facts.d.ts +36 -0
  62. package/dist/runtime/host-facts.js +95 -0
  63. package/dist/runtime/host-load-admission.d.ts +67 -0
  64. package/dist/runtime/host-load-admission.js +99 -0
  65. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  66. package/dist/runtime/host-load-child-environment.js +76 -0
  67. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  68. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  69. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  70. package/dist/runtime/host-load-governor-config.js +83 -0
  71. package/dist/runtime/host-load-governor.d.ts +186 -0
  72. package/dist/runtime/host-load-governor.js +632 -0
  73. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  74. package/dist/runtime/host-load-ledger-lock.js +187 -0
  75. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  76. package/dist/runtime/host-load-runtime-settings.js +80 -0
  77. package/dist/runtime/host-load-sampler.d.ts +156 -0
  78. package/dist/runtime/host-load-sampler.js +298 -0
  79. package/dist/runtime/host-load-step-class.d.ts +70 -0
  80. package/dist/runtime/host-load-step-class.js +161 -0
  81. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  82. package/dist/runtime/host-load-step-reaper.js +95 -0
  83. package/dist/runtime/host-load-step-run.d.ts +73 -0
  84. package/dist/runtime/host-load-step-run.js +102 -0
  85. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  86. package/dist/runtime/host-load-test-slot.js +81 -0
  87. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  88. package/dist/runtime/host-load-token-ledger.js +453 -0
  89. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  90. package/dist/runtime/host-load-windows-cpu.js +85 -0
  91. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  92. package/dist/runtime/host-pressure-stall.js +168 -0
  93. package/dist/runtime/host-runtime-contract.d.ts +16 -0
  94. package/dist/runtime/host-runtime-contract.js +35 -2
  95. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  96. package/dist/runtime/host-runtime-lease.js +285 -55
  97. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  98. package/dist/runtime/host-runtime-promotion.js +48 -0
  99. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  100. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  101. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  102. package/dist/runtime/host-runtime-requirements.js +117 -0
  103. package/dist/runtime/managed-command-teardown.js +5 -16
  104. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  105. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  106. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  107. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  108. package/dist/runtime/runner-settings.d.ts +104 -0
  109. package/dist/runtime/runner-settings.js +236 -0
  110. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  111. package/dist/sandbox/host-capacity-broker.js +336 -0
  112. package/dist/sandbox/managed-branch.d.ts +13 -0
  113. package/dist/sandbox/managed-branch.js +36 -0
  114. package/dist/sandbox/provider-auth/codex.js +11 -11
  115. package/dist/sandbox/runtime.d.ts +10 -1
  116. package/dist/sandbox/runtime.js +47 -8
  117. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  118. package/dist/sandbox/sandbox-cgroups.js +42 -0
  119. package/dist/session/architect-waits.d.ts +2 -0
  120. package/dist/session/architect-waits.js +138 -0
  121. package/dist/session/managed-attempt-tools.d.ts +2 -7
  122. package/dist/session/managed-attempt-tools.js +202 -116
  123. package/dist/session/managed-build-receipt.d.ts +5 -0
  124. package/dist/session/managed-build-receipt.js +8 -3
  125. package/dist/session/managed-command-host-load.d.ts +47 -0
  126. package/dist/session/managed-command-host-load.js +83 -0
  127. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  128. package/dist/session/mcp-argument-coercion.js +121 -0
  129. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  130. package/dist/session/phase-completion.artifacts.js +100 -26
  131. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  132. package/dist/session/phase-completion.command-validation.js +77 -0
  133. package/dist/session/phase-completion.d.ts +12 -0
  134. package/dist/session/phase-completion.helpers.js +13 -12
  135. package/dist/session/phase-completion.js +5 -0
  136. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  137. package/dist/session/phase-completion.mcp-args.js +156 -0
  138. package/dist/session/phase-completion.prompts.js +6 -1
  139. package/dist/session/phase-completion.runtime.d.ts +5 -11
  140. package/dist/session/phase-completion.runtime.js +91 -215
  141. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  142. package/dist/session/phase-completion.schema-parts.js +188 -0
  143. package/dist/session/phase-completion.schemas.d.ts +3 -3
  144. package/dist/session/phase-completion.schemas.js +208 -231
  145. package/dist/session/phase-completion.validation.d.ts +2 -3
  146. package/dist/session/phase-completion.validation.js +49 -93
  147. package/dist/session/pre-publication-host-load.d.ts +27 -0
  148. package/dist/session/pre-publication-host-load.js +111 -0
  149. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  150. package/dist/session/pre-publication-native-postgres.js +111 -0
  151. package/dist/session/pre-publication-pass.d.ts +61 -0
  152. package/dist/session/pre-publication-pass.js +148 -0
  153. package/dist/session/pre-publication-process.d.ts +3 -0
  154. package/dist/session/pre-publication-process.js +33 -20
  155. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  156. package/dist/session/pre-publication-skipped-tests.js +109 -0
  157. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  158. package/dist/session/pre-publication-step-execution.js +50 -0
  159. package/dist/session/pre-publication-validation.d.ts +37 -21
  160. package/dist/session/pre-publication-validation.js +224 -166
  161. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  162. package/dist/session/provider-cli/claude-background-work.js +181 -0
  163. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  164. package/dist/session/provider-cli/host-build-lock.js +30 -0
  165. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  166. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  167. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  168. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  169. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  170. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  171. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  172. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  173. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  174. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  175. package/dist/session/provider-cli/provider-cli.process.d.ts +41 -31
  176. package/dist/session/provider-cli/provider-cli.process.js +139 -438
  177. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  178. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  179. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  180. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  181. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  182. package/dist/session/provider-cli/provider-cli.service.js +200 -189
  183. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  184. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  185. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  186. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  188. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  189. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  190. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  191. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  192. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  193. package/dist/session/provider-cli/provider-output-state.js +15 -0
  194. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  195. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  196. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  197. package/dist/session/publishable-worktree-changes.js +193 -0
  198. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  199. package/dist/session/qa-sidecar-validation.js +28 -0
  200. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  201. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  202. package/dist/session/session-redaction.js +31 -181
  203. package/dist/session/session.base.d.ts +9 -1
  204. package/dist/session/session.service.d.ts +11 -2
  205. package/dist/session/session.service.js +182 -61
  206. package/dist/session/session.types.d.ts +3 -0
  207. package/dist/session/session.types.js +15 -3
  208. package/dist/session/sidecar-json-shape.d.ts +31 -0
  209. package/dist/session/sidecar-json-shape.js +217 -0
  210. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  211. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  212. package/dist/shared/fs/file-identity.d.ts +10 -0
  213. package/dist/shared/fs/file-identity.js +15 -0
  214. package/dist/shared/fs/replace-file.d.ts +7 -0
  215. package/dist/shared/fs/replace-file.js +33 -0
  216. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  217. package/dist/shared/process/host-process-recovery.js +23 -3
  218. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  219. package/dist/shared/process/host-process-supervisor.js +67 -15
  220. package/dist/shared/process/process-tree.d.ts +52 -0
  221. package/dist/shared/process/process-tree.js +144 -0
  222. package/dist/shared/process/process.d.ts +67 -0
  223. package/dist/shared/process/process.js +213 -11
  224. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  225. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  226. package/dist/shared/process/windows-launch.d.ts +18 -0
  227. package/dist/shared/process/windows-launch.js +68 -0
  228. package/dist/shared/provider-capabilities.js +14 -7
  229. package/dist/version.d.ts +1 -1
  230. package/dist/version.js +1 -1
  231. package/dist/worktree/dependency-warmer.d.ts +25 -0
  232. package/dist/worktree/dependency-warmer.js +46 -10
  233. package/dist/worktree/wip-git.d.ts +33 -0
  234. package/dist/worktree/wip-git.js +122 -0
  235. package/dist/worktree/wip-refs.d.ts +62 -0
  236. package/dist/worktree/wip-refs.js +119 -0
  237. package/dist/worktree/wip-restore.d.ts +38 -0
  238. package/dist/worktree/wip-restore.js +190 -0
  239. package/dist/worktree/wip-snapshot.d.ts +50 -0
  240. package/dist/worktree/wip-snapshot.js +268 -0
  241. package/dist/worktree/worktree-inputs.d.ts +8 -0
  242. package/dist/worktree/worktree-inputs.js +134 -0
  243. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  244. package/dist/worktree/worktree-origin-sync.js +127 -0
  245. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  246. package/dist/worktree/worktree-wip-events.js +98 -0
  247. package/dist/worktree/worktree-wip.d.ts +49 -0
  248. package/dist/worktree/worktree-wip.js +182 -0
  249. package/dist/worktree/worktree.base.d.ts +7 -1
  250. package/dist/worktree/worktree.service.d.ts +36 -5
  251. package/dist/worktree/worktree.service.js +120 -155
  252. package/dist/worktree/worktree.types.d.ts +38 -0
  253. package/package.json +2 -2
@@ -3,10 +3,14 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
5
5
  import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
6
- import { nativeTestPostgresFallbackEnvironment, parseNativeTestPostgresFallback, } from "../runtime/native-test-postgres-fallback.js";
7
- import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "../runtime/host-runtime-contract.js";
6
+ import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
7
+ import { dockerFreeGrant, dockerUnavailableNativeTestPostgres, isolatedPostgresProvided, preferredNativeTestPostgres, releaseCheckPostgres, } from "./pre-publication-native-postgres.js";
8
+ import { managedAttemptInvocation, validationExecutionForStep, } from "./pre-publication-step-execution.js";
9
+ import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
8
10
  import { redactText } from "../shared/redaction/redaction.js";
11
+ import { PrePublicationPass, PrePublicationValidationError, SkippedTestTally, skippedCheckEvent, validationEvent, } from "./pre-publication-pass.js";
9
12
  import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
13
+ import { ProcessTreeTerminationError } from "../shared/process/process.js";
10
14
  import { findUnreferencedNewExports } from "./unreferenced-exports.js";
11
15
  import { ForgeFailureError, sanitizeFailureError, } from "./session.types.js";
12
16
  const contractRelativePath = ".forge/validation/ci-parity.v1.json";
@@ -20,16 +24,21 @@ const requiredCheckIds = new Set([
20
24
  "playwright-e2e",
21
25
  "github-provider-policy",
22
26
  ]);
23
- const currentApprovedContractDigest = "378c767c7977c850140ffb19d69db41da62d0187c37a33828d6cda8803a61c83";
27
+ // Every gate profile runs the affected .NET tests; only CI runs the whole tiers (decision 0017).
28
+ const currentApprovedContractDigest = "9cf3a3070de56f3d3bc2c013dfa45b0fd463d257722849087e6743fb9cb1fd0d";
29
+ // Only comment repair ran the affected tests; the other profiles ran Unit, Contract and
30
+ // Infrastructure whole. Story branches cut before decision 0017 still carry it.
31
+ const commentRepairOnlyAffectedContractDigest = "378c767c7977c850140ffb19d69db41da62d0187c37a33828d6cda8803a61c83";
24
32
  // Comment repair ran the whole ApiComponent and Orchestration tiers under this contract.
25
- // Story branches cut before the affected-tests contract still carry it.
26
33
  const wholeTierCommentRepairContractDigest = "024de3648c907db9c0eab13def9a4f91e81148433e0a2ba7f44776446421054a";
27
34
  // Contracts that declare the comment-repair-dotnet-regression check.
28
35
  const commentRepairRegressionContractDigests = new Set([
29
36
  currentApprovedContractDigest,
37
+ commentRepairOnlyAffectedContractDigest,
30
38
  wholeTierCommentRepairContractDigest,
31
39
  ]);
32
40
  const compatibleApprovedContractDigests = new Set([
41
+ commentRepairOnlyAffectedContractDigest,
33
42
  wholeTierCommentRepairContractDigest,
34
43
  // Preserve dispatches pinned before comment repair gained all .NET regression tiers.
35
44
  "c0014ce6abc0e0b2e66dd2bcf6cb14c47d28506444c73f87d1b76b3d1c06027b",
@@ -45,23 +54,31 @@ const approvedContractDigests = new Set([
45
54
  ...compatibleApprovedContractDigests,
46
55
  ]);
47
56
  const ansiColorSequence = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "gu");
48
- export class PrePublicationValidationError extends ForgeFailureError {
49
- checkId;
50
- exitCode;
51
- command;
52
- args;
53
- detail;
54
- code = "prepublication_validation_failed";
55
- constructor(checkId, exitCode, command, args, detail) {
56
- super("prepublication_validation_failed", `prepublication_validation_failed: ${checkId} exited ${exitCode}${detail ? `: ${detail}` : ""}`, "bridge");
57
- this.checkId = checkId;
58
- this.exitCode = exitCode;
59
- this.command = command;
60
- this.args = args;
61
- this.detail = detail;
62
- this.name = "PrePublicationValidationError";
63
- }
64
- }
57
+ const timeoutConfirmation = {
58
+ started: [
59
+ "prepublication_validation_timeout_confirmation_started",
60
+ "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment.",
61
+ ],
62
+ passed: [
63
+ "prepublication_validation_timeout_confirmation_passed",
64
+ "The complete client test step passed on its single timeout confirmation run.",
65
+ ],
66
+ failedEvent: "prepublication_validation_timeout_confirmation_failed",
67
+ failedContent: exitCode => `The complete client test step failed on its single timeout confirmation run (exit ${exitCode}).`,
68
+ };
69
+ const cleanupConfirmation = {
70
+ started: [
71
+ "prepublication_validation_cleanup_confirmation_started",
72
+ "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment.",
73
+ ],
74
+ passed: [
75
+ "prepublication_validation_cleanup_confirmation_passed",
76
+ "The complete Bridge test step passed on its single cleanup confirmation run.",
77
+ ],
78
+ failedEvent: "prepublication_validation_cleanup_confirmation_failed",
79
+ failedContent: exitCode => `The complete Bridge test step failed on its single cleanup confirmation run (exit ${exitCode}).`,
80
+ };
81
+ export { PrePublicationValidationError };
65
82
  export class PrePublicationInfrastructureError extends ForgeFailureError {
66
83
  checkId;
67
84
  exitCode;
@@ -83,106 +100,177 @@ export class PrePublicationValidator {
83
100
  commands;
84
101
  dockerEngineProbe;
85
102
  nativeTestPostgresFallback;
86
- constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null) {
103
+ hostLoad;
104
+ startEphemeral;
105
+ constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad, startEphemeral) {
87
106
  this.commands = commands;
88
107
  this.dockerEngineProbe = dockerEngineProbe;
89
108
  this.nativeTestPostgresFallback = nativeTestPostgresFallback;
109
+ this.hostLoad = hostLoad;
110
+ this.startEphemeral = startEphemeral;
90
111
  }
112
+ /**
113
+ * Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
114
+ * can still meaningfully run keeps going, and the pass then throws all of its failures as one
115
+ * PrePublicationValidationError.
116
+ */
91
117
  async validate(worktreePath, profile, capabilities, emit, signal, execution) {
92
118
  const checksExports = profile === "implementation" || profile === "comment_repair";
119
+ const pass = new PrePublicationPass(execution?.runtimeRestartFailure);
93
120
  const contract = await loadValidationContract(worktreePath);
94
121
  if (contract === null) {
95
122
  await emit?.(validationEvent("prepublication_validation_legacy_contract", "legacy-provider-validation", `This checkout predates ${contractRelativePath}; Bridge preserved legacy provider validation without source mutation.`));
96
123
  if (checksExports) {
97
124
  const legacy = await prepareValidationExecution(execution);
98
125
  try {
99
- await this.assertNoTestOnlyExports(worktreePath, emit, signal, legacy.execution);
126
+ await this.checkTestOnlyExports(pass, worktreePath, emit, signal, legacy.execution);
100
127
  }
101
128
  finally {
102
129
  await legacy.cleanup();
103
130
  }
104
131
  }
132
+ pass.throwIfFailed();
105
133
  return [];
106
134
  }
107
135
  const scoped = await prepareValidationExecution(execution);
108
136
  try {
109
137
  if (checksExports)
110
- await this.assertNoTestOnlyExports(worktreePath, emit, signal, scoped.execution);
138
+ await this.checkTestOnlyExports(pass, worktreePath, emit, signal, scoped.execution);
111
139
  const contractDigest = validationContractDigest(contract);
112
140
  await this.assertContractMatchesDispatchBaseline(worktreePath, contractDigest, signal, scoped.execution);
113
141
  if (contractDigest !== currentApprovedContractDigest) {
114
142
  await emit?.(validationEvent("prepublication_validation_compatible_contract", "validation-contract", `This checkout is pinned to approved compatible CI parity contract ${contractDigest}; the host's current contract is ${currentApprovedContractDigest}.`));
115
143
  }
116
144
  const changedPaths = await this.changedPaths(worktreePath, signal, scoped.execution);
117
- const selected = applicableChecks(contract, profile, changedPaths);
118
- const completed = [];
119
- for (const check of selected) {
120
- if (check.providerOnly) {
121
- await emit?.(validationEvent("prepublication_validation_provider_only", check.id, `Preserved provider-only validation '${check.id}' for the provider check run.`));
122
- continue;
123
- }
124
- if (check.requiredCapability && !capabilities.has(check.requiredCapability)) {
125
- throw new ForgeFailureError("prepublication_capability_unavailable", `prepublication_capability_unavailable: ${check.id} requires ${check.requiredCapability}; publication is holding until a capable runner is available.`, "bridge");
126
- }
127
- const postgresAdminConnection = await this.ensurePrerequisite(check, scoped.execution?.environment, scoped.postgresAdminConnection, emit) ?? scoped.postgresAdminConnection;
128
- await emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
129
- for (const step of check.steps) {
130
- let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
131
- await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
132
- if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
133
- await emit?.(validationEvent("prepublication_validation_timeout_confirmation_started", check.id, "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment."));
134
- result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
135
- await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
136
- await emit?.(validationEvent(result.exitCode === 0
137
- ? "prepublication_validation_timeout_confirmation_passed"
138
- : "prepublication_validation_timeout_confirmation_failed", check.id, result.exitCode === 0
139
- ? "The complete client test step passed on its single timeout confirmation run."
140
- : `The complete client test step failed on its single timeout confirmation run (exit ${result.exitCode}).`));
141
- }
142
- if (isTransientBridgeCleanupFailure(check.id, step, result)) {
143
- await emit?.(validationEvent("prepublication_validation_cleanup_confirmation_started", check.id, "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment."));
144
- result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
145
- await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
146
- await emit?.(validationEvent(result.exitCode === 0
147
- ? "prepublication_validation_cleanup_confirmation_passed"
148
- : "prepublication_validation_cleanup_confirmation_failed", check.id, result.exitCode === 0
149
- ? "The complete Bridge test step passed on its single cleanup confirmation run."
150
- : `The complete Bridge test step failed on its single cleanup confirmation run (exit ${result.exitCode}).`));
151
- }
152
- if (isTransientShellInfrastructureFailure(result)) {
153
- await emit?.(validationEvent("prepublication_infrastructure_confirmation_started", check.id, "The validation shell reported a known host-runtime failure; confirming once with the same command and attempt environment."));
154
- result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
155
- await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
156
- const infrastructureFailed = isTransientShellInfrastructureFailure(result);
157
- await emit?.(validationEvent(infrastructureFailed
158
- ? "prepublication_infrastructure_confirmation_failed"
159
- : "prepublication_infrastructure_confirmation_passed", check.id, infrastructureFailed
160
- ? `The validation shell failed again on its single infrastructure confirmation run (exit ${result.exitCode}).`
161
- : result.exitCode === 0
162
- ? "The validation step recovered on its single infrastructure confirmation run."
163
- : "The host-runtime failure did not recur; continuing with normal validation failure handling."));
164
- if (infrastructureFailed) {
165
- const detail = diagnosticDetail(result);
166
- await emit?.(validationEvent("prepublication_infrastructure_failed", check.id, `Pre-publication infrastructure for '${check.id}' remained unavailable${detail ? `: ${detail}` : "."}`));
167
- throw new PrePublicationInfrastructureError(check.id, result.exitCode, result.command, result.args, detail);
168
- }
169
- }
170
- if (result.exitCode !== 0) {
171
- const detail = diagnosticDetail(result);
172
- await emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
173
- throw new PrePublicationValidationError(check.id, result.exitCode, result.command, result.args, detail);
174
- }
175
- }
176
- completed.push(check.id);
177
- await emit?.(validationEvent("prepublication_validation_passed", check.id, `Pre-publication CI parity check '${check.id}' passed.`));
178
- }
179
- return completed;
145
+ const run = {
146
+ worktreePath,
147
+ capabilities,
148
+ emit,
149
+ signal,
150
+ execution: withValidationBaseRevision(scoped.execution),
151
+ postgresAdminConnection: scoped.postgresAdminConnection,
152
+ };
153
+ return await this.runChecks(applicableChecks(contract, profile, changedPaths), run, pass);
180
154
  }
181
155
  finally {
182
156
  await scoped.cleanup();
183
157
  }
184
158
  }
185
- /** Returns the native fallback connection when this check must use it instead of Docker. */
159
+ async runChecks(checks, run, pass) {
160
+ const completed = [];
161
+ for (const check of checks) {
162
+ if (check.providerOnly) {
163
+ await run.emit?.(validationEvent("prepublication_validation_provider_only", check.id, `Preserved provider-only validation '${check.id}' for the provider check run.`));
164
+ continue;
165
+ }
166
+ const blockedBy = pass.blockers(check.id);
167
+ if (blockedBy.length > 0) {
168
+ await run.emit?.(skippedCheckEvent(check.id, blockedBy));
169
+ continue;
170
+ }
171
+ try {
172
+ const failed = await this.runCheck(check, run);
173
+ // A cancelled step may settle with an exit code rather than throw; the pass ends either way.
174
+ run.signal?.throwIfAborted();
175
+ if (failed)
176
+ pass.record(failed.failure, failed.step);
177
+ else
178
+ completed.push(check.id);
179
+ }
180
+ catch (error) {
181
+ if (!pass.stopsAt(error, run.signal))
182
+ throw error;
183
+ await run.emit?.(pass.stoppedEvent(check.id, error));
184
+ break;
185
+ }
186
+ }
187
+ pass.throwIfFailed();
188
+ return completed;
189
+ }
190
+ /** Runs one check's steps in order; the first failed step ends the check, since later steps use its output. */
191
+ async runCheck(check, run) {
192
+ if (check.requiredCapability && !run.capabilities.has(check.requiredCapability)) {
193
+ throw new ForgeFailureError("prepublication_capability_unavailable", `prepublication_capability_unavailable: ${check.id} requires ${check.requiredCapability}; publication is holding until a capable runner is available.`, "bridge");
194
+ }
195
+ const granted = await this.ensurePrerequisite(check, run.execution?.environment, run.postgresAdminConnection, run.emit);
196
+ try {
197
+ return await this.runCheckSteps({ ...run, check, postgresAdminConnection: granted ?? run.postgresAdminConnection });
198
+ }
199
+ finally {
200
+ await releaseCheckPostgres(check.id, granted, run.emit);
201
+ }
202
+ }
203
+ async runCheckSteps(stepRun) {
204
+ const { check, ...run } = stepRun;
205
+ await run.emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
206
+ const skipped = new SkippedTestTally(run.worktreePath, run.execution?.environment);
207
+ for (const step of check.steps) {
208
+ const stepStartedMs = Date.now() - 1000;
209
+ const result = await this.runConfirmedStep(stepRun, step);
210
+ if (result.exitCode !== 0) {
211
+ const detail = diagnosticDetail(result);
212
+ await run.emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
213
+ return {
214
+ failure: { checkId: check.id, exitCode: result.exitCode, command: result.command, args: result.args, detail },
215
+ step,
216
+ };
217
+ }
218
+ await skipped.add(result.args, stepStartedMs);
219
+ }
220
+ // The check's own grant reaches only its steps' derived environments, so name its secrets too.
221
+ await run.emit?.(skipped.passedEvent(check.id, [
222
+ ...validationExactSecrets(run.execution?.environment),
223
+ ...attemptDatabaseCapabilitySecrets(run.postgresAdminConnection?.connectionString),
224
+ ]));
225
+ return null;
226
+ }
227
+ /** Runs a step, confirming once a failure that matches a known transient pattern. */
228
+ async runConfirmedStep(run, step) {
229
+ let result = await this.runCheckedStep(run, step);
230
+ if (isTimeoutOnlyClientTestFailure(run.check.id, step, result)) {
231
+ result = await this.confirmStep(run, step, timeoutConfirmation);
232
+ }
233
+ if (isTransientBridgeCleanupFailure(run.check.id, step, result)) {
234
+ result = await this.confirmStep(run, step, cleanupConfirmation);
235
+ }
236
+ if (isTransientShellInfrastructureFailure(result)) {
237
+ result = await this.confirmInfrastructure(run, step);
238
+ }
239
+ return result;
240
+ }
241
+ async runCheckedStep(run, step) {
242
+ const { check, worktreePath, signal, execution, postgresAdminConnection, emit } = run;
243
+ const result = await this.runStep(check.id, step, worktreePath, signal, execution, postgresAdminConnection, emit);
244
+ await this.throwIfPrerequisiteWasLost(check, result, execution?.environment, postgresAdminConnection, emit);
245
+ return result;
246
+ }
247
+ async confirmStep(run, step, confirmation) {
248
+ await run.emit?.(validationEvent(confirmation.started[0], run.check.id, confirmation.started[1]));
249
+ const result = await this.runCheckedStep(run, step);
250
+ await run.emit?.(result.exitCode === 0
251
+ ? validationEvent(confirmation.passed[0], run.check.id, confirmation.passed[1])
252
+ : validationEvent(confirmation.failedEvent, run.check.id, confirmation.failedContent(result.exitCode)));
253
+ return result;
254
+ }
255
+ async confirmInfrastructure(run, step) {
256
+ const checkId = run.check.id;
257
+ await run.emit?.(validationEvent("prepublication_infrastructure_confirmation_started", checkId, "The validation shell reported a known host-runtime failure; confirming once with the same command and attempt environment."));
258
+ const result = await this.runCheckedStep(run, step);
259
+ const infrastructureFailed = isTransientShellInfrastructureFailure(result);
260
+ await run.emit?.(validationEvent(infrastructureFailed
261
+ ? "prepublication_infrastructure_confirmation_failed"
262
+ : "prepublication_infrastructure_confirmation_passed", checkId, infrastructureFailed
263
+ ? `The validation shell failed again on its single infrastructure confirmation run (exit ${result.exitCode}).`
264
+ : result.exitCode === 0
265
+ ? "The validation step recovered on its single infrastructure confirmation run."
266
+ : "The host-runtime failure did not recur; continuing with normal validation failure handling."));
267
+ if (!infrastructureFailed)
268
+ return result;
269
+ const detail = diagnosticDetail(result);
270
+ await run.emit?.(validationEvent("prepublication_infrastructure_failed", checkId, `Pre-publication infrastructure for '${checkId}' remained unavailable${detail ? `: ${detail}` : "."}`));
271
+ throw new PrePublicationInfrastructureError(checkId, result.exitCode, result.command, result.args, detail);
272
+ }
273
+ /** Returns the native cluster grant when this check uses it instead of Docker. */
186
274
  async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
187
275
  if (check.requiredPrerequisite === "isolated_postgres"
188
276
  && isolatedPostgresProvided(check.id, environment, postgresAdminConnection)) {
@@ -191,6 +279,11 @@ export class PrePublicationValidator {
191
279
  : `Pre-publication check '${check.id}' is using the configured loopback PostgreSQL test server with per-run owned databases. No Docker daemon is required.`));
192
280
  return undefined;
193
281
  }
282
+ return await preferredNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback, this.dockerEngineProbe, emit, this.startEphemeral)
283
+ ?? await this.ensureDockerPrerequisite(check, emit);
284
+ }
285
+ /** Waits for Docker; returns the native cluster grant when Docker stays down and a cluster is provisioned. */
286
+ async ensureDockerPrerequisite(check, emit) {
194
287
  if (check.requiredPrerequisite === undefined || !this.dockerEngineProbe)
195
288
  return undefined;
196
289
  const current = this.dockerEngineProbe.current();
@@ -202,12 +295,10 @@ export class PrePublicationValidator {
202
295
  const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
203
296
  if (!snapshot.available) {
204
297
  const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
205
- const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check)
206
- ? this.nativeTestPostgresFallback()
207
- : null;
298
+ const fallback = dockerUnavailableNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback);
208
299
  if (fallback) {
209
300
  await emit?.(validationEvent("prepublication_prerequisite_native_fallback", check.id, `${detail}. Pre-publication check '${check.id}' is using the dedicated native PostgreSQL test cluster at ${fallback.endpoint} with per-run owned databases.`));
210
- return fallback.connectionString;
301
+ return fallback;
211
302
  }
212
303
  await emit?.(validationEvent("prepublication_prerequisite_unavailable", check.id, `Pre-publication check '${check.id}' is waiting for Docker infrastructure recovery: ${detail}`));
213
304
  throw new PrePublicationInfrastructureError(check.id, 75, "docker", ["info"], detail);
@@ -219,7 +310,7 @@ export class PrePublicationValidator {
219
310
  if (result.exitCode === 0
220
311
  || check.requiredPrerequisite === undefined
221
312
  || (check.requiredPrerequisite === "isolated_postgres"
222
- && isolatedPostgresProvided(check.id, environment, postgresAdminConnection))
313
+ && isolatedPostgresProvided(check.id, environment, dockerFreeGrant(postgresAdminConnection)))
223
314
  || !this.dockerEngineProbe)
224
315
  return;
225
316
  const snapshot = await this.dockerEngineProbe.refresh(true);
@@ -230,7 +321,8 @@ export class PrePublicationValidator {
230
321
  throw new PrePublicationInfrastructureError(check.id, result.exitCode, result.command, result.args, detail);
231
322
  }
232
323
  // Runs for every target repository, with or without a CI parity contract: it only reads the worktree.
233
- async assertNoTestOnlyExports(worktreePath, emit, signal, execution) {
324
+ // A failure joins the pass's failures; the contract's checks still run.
325
+ async checkTestOnlyExports(pass, worktreePath, emit, signal, execution) {
234
326
  const found = await findUnreferencedNewExports(args => this.runCommand("git", args, worktreePath, signal, execution), worktreePath, execution?.baselineRevision);
235
327
  const unused = found.filter(row => !row.testOnly);
236
328
  if (unused.length > 0) {
@@ -241,7 +333,7 @@ export class PrePublicationValidator {
241
333
  return;
242
334
  const detail = `only tests use ${testOnly.map(row => `${row.name} (${row.path})`).join(", ")}. Wire each to a real caller in this Story, or move the export and its test to the Story that first uses it. Do not delete assertions to pass.`;
243
335
  await emit?.(validationEvent("prepublication_validation_failed", "unreferenced-exports", `New code is tested but never called: ${detail}`));
244
- throw new PrePublicationValidationError("unreferenced-exports", 1, "git", ["grep"], detail);
336
+ pass.record({ checkId: "unreferenced-exports", exitCode: 1, command: "git", args: ["grep"], detail });
245
337
  }
246
338
  async changedPaths(worktreePath, signal, execution) {
247
339
  const baselineRevision = execution?.baselineRevision?.trim();
@@ -284,12 +376,32 @@ export class PrePublicationValidator {
284
376
  if (!approvedContractDigests.has(baselineDigest)) {
285
377
  throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the dispatch baseline uses unapproved CI parity contract ${baselineDigest}.`, "bridge");
286
378
  }
287
- if (baselineDigest !== contractDigest) {
379
+ // A conflict repair's uncommitted merge brings the target branch's contract with it.
380
+ if (baselineDigest !== contractDigest && await this.mergedInContractDigest(worktreePath, signal, execution) !== contractDigest) {
288
381
  throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
289
382
  }
290
383
  }
291
- async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection) {
384
+ /** The approved contract of the branch an in-progress merge brings in (MERGE_HEAD), else null. */
385
+ async mergedInContractDigest(worktreePath, signal, execution) {
386
+ const merged = await this.runCommand("git", ["show", `MERGE_HEAD:${contractRelativePath}`], worktreePath, signal, execution);
387
+ if (merged.exitCode !== 0)
388
+ return null;
389
+ try {
390
+ const digest = validationContractDigest(JSON.parse(merged.stdout ?? ""));
391
+ return approvedContractDigests.has(digest) ? digest : null;
392
+ }
393
+ catch {
394
+ return null;
395
+ }
396
+ }
397
+ async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
292
398
  const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
399
+ // Every launch, including confirmation reruns, is admitted by the host load governor first.
400
+ return await runHostGovernedValidationStep(this.hostLoad, {
401
+ checkId, command: invocation.command, args: invocation.args, owner: execution?.hostLoadOwner, signal, emit,
402
+ }, async (stepSignal) => await this.launchStep(checkId, step, invocation, cwd, stepSignal, execution, postgresAdminConnection));
403
+ }
404
+ async launchStep(checkId, step, invocation, cwd, signal, execution, postgresAdminConnection) {
293
405
  const stepExecution = validationExecutionForStep(checkId, step, execution, postgresAdminConnection);
294
406
  const before = await readValidationFiles(cwd, step.assertUnchangedPaths ?? []);
295
407
  const result = await this.runCommand(invocation.command, invocation.args, cwd, signal, stepExecution);
@@ -334,78 +446,19 @@ export class PrePublicationValidator {
334
446
  };
335
447
  }
336
448
  catch (error) {
449
+ // Carries the check its host capacity token waits on; it names only the executable.
450
+ if (error instanceof ProcessTreeTerminationError)
451
+ throw error;
337
452
  throw sanitizeFailureError(error, exactSecrets);
338
453
  }
339
454
  }
340
455
  }
341
- function managedAttemptInvocation(checkId, step, environment) {
342
- const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
343
- const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
344
- || Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
345
- if (checkId !== "playwright-e2e" || !attemptOwned) {
346
- return step;
347
- }
348
- if (!playwrightConfig) {
349
- throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
350
- }
351
- return {
352
- command: "pnpm",
353
- args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
354
- };
355
- }
356
- const nativeFallbackCheckIds = new Set([
357
- "owned-suite-registration",
358
- "dotnet-build-and-unit",
359
- "comment-repair-dotnet-regression",
360
- ]);
361
- const nativeFallbackDotnetTierScripts = [
362
- "scripts/run-dotnet-test-tier.ps1",
363
- "scripts/run-dotnet-test-tier-set.ps1",
364
- "scripts/run-affected-dotnet-tests.mjs",
365
- ];
366
- function supportsNativeTestPostgresFallback(check) {
367
- return nativeFallbackCheckIds.has(check.id);
368
- }
369
- function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
370
- // The connection only exists when Docker is unavailable and the operator
371
- // provisioned a dedicated native test cluster. Only the runner-authored
372
- // .NET test tiers and the suite-identity check receive it; build, client,
373
- // Bridge, and E2E steps never do.
374
- if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
375
- return execution;
376
- const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
377
- .some(script => argument.replaceAll("\\", "/").endsWith(script)));
378
- if (checkId !== "owned-suite-registration" && !runsDotnetTier)
379
- return execution;
380
- return {
381
- ...execution,
382
- environment: {
383
- ...execution?.environment,
384
- ...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
385
- },
386
- };
387
- }
388
- function environmentValue(environment, name) {
389
- return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
390
- ? environment?.[name]?.trim() ?? ""
391
- : process.env[name]?.trim() ?? "";
392
- }
393
- function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
394
- if (checkId === "playwright-e2e") {
395
- const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
396
- return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
397
- || /^[0-9a-f-]{36}$/iu.test(attemptId))
398
- && /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
399
- && path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
400
- // The attempt owns a database only once the Bridge's broker has issued it one.
401
- && environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
402
- }
403
- return Boolean(postgresAdminConnection);
404
- }
405
456
  function validationExactSecrets(environment) {
406
457
  return [
407
- environment?.[hostRuntimeTestPostgresAdminEnvironment]?.trim() ?? "",
408
- environment?.[hostRuntimeLegacyTestPostgresEnvironment]?.trim() ?? "",
458
+ // The connection strings and their passwords: a test may print either.
459
+ ...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeTestPostgresAdminEnvironment]),
460
+ ...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeLegacyTestPostgresEnvironment]),
461
+ environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
409
462
  ...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
410
463
  ].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
411
464
  }
@@ -538,6 +591,7 @@ function withoutPrivilegedPostgresEnvironment(environment) {
538
591
  const privilegedNames = new Set([
539
592
  hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
540
593
  hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
594
+ hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
541
595
  ]);
542
596
  return Object.fromEntries(Object.entries(environment)
543
597
  .filter(([name]) => !privilegedNames.has(name.toLowerCase())));
@@ -593,6 +647,13 @@ export async function loadValidationContract(worktreePath) {
593
647
  }
594
648
  return contract;
595
649
  }
650
+ /** The affected .NET tests measure the attempt's change against its dispatch baseline (run-affected-dotnet-tests.mjs). */
651
+ function withValidationBaseRevision(execution) {
652
+ const baseline = execution?.baselineRevision?.trim();
653
+ if (!baseline)
654
+ return execution;
655
+ return { ...execution, environment: { ...execution?.environment, FORGE_VALIDATION_BASE_REVISION: baseline } };
656
+ }
596
657
  function validationContractDigest(contract) {
597
658
  return createHash("sha256")
598
659
  .update(JSON.stringify(canonicalizeJson(contract)))
@@ -607,6 +668,3 @@ function canonicalizeJson(value) {
607
668
  }
608
669
  return value;
609
670
  }
610
- function validationEvent(eventType, checkId, content) {
611
- return { role: "runner", kind: "checkpoint", content, eventType, data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1" }) };
612
- }
@@ -0,0 +1,67 @@
1
+ import { ForgeFailureError } from "../session.types.js";
2
+ import type { ProviderProcessHandlers, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "./provider-cli.process.js";
3
+ /**
4
+ * Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
5
+ * forked subagents and forked skills in the foreground, and stops Claude Code from moving long
6
+ * shell commands, subagents and MCP calls to the background on its own. Cron disables the
7
+ * session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
8
+ * environment cannot turn them back on.
9
+ */
10
+ export declare const claudeHeadlessEnvironment: Readonly<Record<string, string>>;
11
+ /**
12
+ * Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
13
+ * leaves Monitor running in the background, so it is removed here, together with self-paced
14
+ * wakeups, workflows (which run their agents in the background), cloud routines, cron
15
+ * (also disabled by environment), SendMessage, which resumes an earlier subagent in the
16
+ * background, and agent teams, whose teammates run alongside the turn. Foreground subagents
17
+ * stay available: they block the turn until they finish.
18
+ */
19
+ export declare const claudeHeadlessDisallowedTools: readonly string[];
20
+ /**
21
+ * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
22
+ * again as flag settings, which outrank a user's or repository's settings `env` block. Other flag
23
+ * settings (`provider-user-config-isolation.ts`) share the one `--settings` value.
24
+ */
25
+ export declare function claudeHeadlessToolArgs(additionalSettings?: Readonly<Record<string, unknown>>): readonly string[];
26
+ /**
27
+ * The provider ended its turn while background work it started (a background subagent or
28
+ * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
29
+ * result for such work, and nothing started in the background reports to Forge, so Forge stops
30
+ * the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
31
+ * task, ended the run.
32
+ */
33
+ export declare function providerTurnEndedWithBackgroundWorkFailure(message: string): ForgeFailureError;
34
+ /**
35
+ * Fails every provider run Forge stopped because its turn ended with background work still live,
36
+ * whether or not the turn recorded a completion first: the stop cut that work short, so nothing
37
+ * may validate, commit or publish the worktree it left behind.
38
+ */
39
+ export declare class BackgroundWorkStopFailingRunner implements ProviderProcessRunner {
40
+ private readonly inner;
41
+ constructor(inner: ProviderProcessRunner);
42
+ run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
43
+ }
44
+ /**
45
+ * Recognizes a main-conversation turn that ended while background tasks it started were still
46
+ * live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
47
+ * Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
48
+ * event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
49
+ * without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
50
+ * once, so the runner can stop the provider instead of waiting on work no one will collect.
51
+ */
52
+ export declare class ClaudeBackgroundTurnEndWatch {
53
+ private readonly graceMs;
54
+ private readonly onTurnEndedWithBackgroundWork;
55
+ private liveBackgroundTasks;
56
+ private terminalSinceMainActivity;
57
+ private mainTurnEnded;
58
+ private timer;
59
+ private stopped;
60
+ private readonly enabled;
61
+ /** Watches only Claude Code, by its executable `command`; other output is left alone. */
62
+ constructor(command: string, graceMs: number, onTurnEndedWithBackgroundWork: () => void);
63
+ consume(line: string): void;
64
+ stop(): void;
65
+ private armIfTurnEndedWithBackgroundWork;
66
+ private cancel;
67
+ }