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

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 (153) hide show
  1. package/README.md +44 -2
  2. package/dist/bridge/bridge.base.d.ts +9 -0
  3. package/dist/bridge/bridge.service.d.ts +75 -2
  4. package/dist/bridge/bridge.service.js +317 -9
  5. package/dist/bridge/bridge.types.d.ts +22 -0
  6. package/dist/bridge/local-yield-flag.d.ts +6 -0
  7. package/dist/bridge/local-yield-flag.js +34 -0
  8. package/dist/bridge/runner-host-capabilities.d.ts +2 -0
  9. package/dist/bridge/runner-host-capabilities.js +4 -0
  10. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  11. package/dist/bridge/test-postgres-capability.js +120 -0
  12. package/dist/cleanup/cleanup.service.d.ts +9 -0
  13. package/dist/cleanup/cleanup.service.js +72 -109
  14. package/dist/cleanup/cleanup.types.d.ts +4 -0
  15. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  16. package/dist/cleanup/forge-owned-paths.js +53 -0
  17. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  18. package/dist/cleanup/host-runtime-ledger.js +109 -0
  19. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  20. package/dist/cleanup/managed-branch-sweep.js +111 -0
  21. package/dist/cli/cli.help.js +18 -0
  22. package/dist/cli/cli.service.d.ts +16 -0
  23. package/dist/cli/cli.service.js +142 -16
  24. package/dist/cli/local-config.d.ts +4 -0
  25. package/dist/cli/local-config.js +26 -4
  26. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  27. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  28. package/dist/runtime/host-database-capability-boundary.js +1 -0
  29. package/dist/runtime/host-facts.d.ts +35 -0
  30. package/dist/runtime/host-facts.js +95 -0
  31. package/dist/runtime/host-load-admission.d.ts +60 -0
  32. package/dist/runtime/host-load-admission.js +99 -0
  33. package/dist/runtime/host-load-child-environment.d.ts +22 -0
  34. package/dist/runtime/host-load-child-environment.js +67 -0
  35. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  36. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  37. package/dist/runtime/host-load-governor-config.d.ts +43 -0
  38. package/dist/runtime/host-load-governor-config.js +76 -0
  39. package/dist/runtime/host-load-governor.d.ts +174 -0
  40. package/dist/runtime/host-load-governor.js +541 -0
  41. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  42. package/dist/runtime/host-load-ledger-lock.js +185 -0
  43. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  44. package/dist/runtime/host-load-runtime-settings.js +78 -0
  45. package/dist/runtime/host-load-sampler.d.ts +126 -0
  46. package/dist/runtime/host-load-sampler.js +232 -0
  47. package/dist/runtime/host-load-step-class.d.ts +68 -0
  48. package/dist/runtime/host-load-step-class.js +106 -0
  49. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  50. package/dist/runtime/host-load-step-reaper.js +95 -0
  51. package/dist/runtime/host-load-step-run.d.ts +73 -0
  52. package/dist/runtime/host-load-step-run.js +102 -0
  53. package/dist/runtime/host-load-token-ledger.d.ts +174 -0
  54. package/dist/runtime/host-load-token-ledger.js +421 -0
  55. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  56. package/dist/runtime/host-pressure-stall.js +168 -0
  57. package/dist/runtime/host-runtime-contract.d.ts +4 -0
  58. package/dist/runtime/host-runtime-contract.js +6 -1
  59. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  60. package/dist/runtime/host-runtime-lease.js +281 -11
  61. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  62. package/dist/runtime/host-runtime-promotion.js +48 -0
  63. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  64. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  65. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  66. package/dist/runtime/host-runtime-requirements.js +117 -0
  67. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  68. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  69. package/dist/runtime/runner-settings.d.ts +100 -0
  70. package/dist/runtime/runner-settings.js +214 -0
  71. package/dist/sandbox/host-capacity-broker.d.ts +107 -0
  72. package/dist/sandbox/host-capacity-broker.js +315 -0
  73. package/dist/sandbox/runtime.d.ts +10 -1
  74. package/dist/sandbox/runtime.js +45 -2
  75. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  76. package/dist/sandbox/sandbox-cgroups.js +42 -0
  77. package/dist/session/managed-attempt-tools.d.ts +2 -0
  78. package/dist/session/managed-attempt-tools.js +156 -37
  79. package/dist/session/managed-command-host-load.d.ts +45 -0
  80. package/dist/session/managed-command-host-load.js +82 -0
  81. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  82. package/dist/session/mcp-argument-coercion.js +121 -0
  83. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  84. package/dist/session/phase-completion.artifacts.js +98 -25
  85. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  86. package/dist/session/phase-completion.command-validation.js +77 -0
  87. package/dist/session/phase-completion.d.ts +4 -0
  88. package/dist/session/phase-completion.helpers.js +13 -12
  89. package/dist/session/phase-completion.js +4 -0
  90. package/dist/session/phase-completion.prompts.js +6 -1
  91. package/dist/session/phase-completion.runtime.d.ts +5 -3
  92. package/dist/session/phase-completion.runtime.js +49 -19
  93. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  94. package/dist/session/phase-completion.schema-parts.js +188 -0
  95. package/dist/session/phase-completion.schemas.d.ts +3 -3
  96. package/dist/session/phase-completion.schemas.js +184 -209
  97. package/dist/session/phase-completion.validation.d.ts +2 -3
  98. package/dist/session/phase-completion.validation.js +46 -92
  99. package/dist/session/pre-publication-host-load.d.ts +27 -0
  100. package/dist/session/pre-publication-host-load.js +111 -0
  101. package/dist/session/pre-publication-pass.d.ts +60 -0
  102. package/dist/session/pre-publication-pass.js +145 -0
  103. package/dist/session/pre-publication-process.d.ts +3 -0
  104. package/dist/session/pre-publication-process.js +25 -12
  105. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  106. package/dist/session/pre-publication-skipped-tests.js +109 -0
  107. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  108. package/dist/session/pre-publication-step-execution.js +49 -0
  109. package/dist/session/pre-publication-validation.d.ts +30 -20
  110. package/dist/session/pre-publication-validation.js +169 -139
  111. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  112. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  113. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  114. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  115. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  116. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  117. package/dist/session/provider-cli/provider-cli.process.d.ts +32 -1
  118. package/dist/session/provider-cli/provider-cli.process.js +122 -30
  119. package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
  120. package/dist/session/provider-cli/provider-cli.prompts.js +20 -2
  121. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  122. package/dist/session/provider-cli/provider-cli.service.js +194 -161
  123. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  124. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  125. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  126. package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
  127. package/dist/session/provider-cli/provider-output-state.js +9 -0
  128. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  129. package/dist/session/publishable-worktree-changes.js +193 -0
  130. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  131. package/dist/session/sandbox-host-capacity-gate.js +229 -0
  132. package/dist/session/session.base.d.ts +9 -1
  133. package/dist/session/session.service.d.ts +9 -2
  134. package/dist/session/session.service.js +120 -5
  135. package/dist/session/session.types.d.ts +3 -0
  136. package/dist/session/session.types.js +15 -3
  137. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  138. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  139. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  140. package/dist/shared/process/host-process-supervisor.js +1 -1
  141. package/dist/shared/process/process-tree.d.ts +52 -0
  142. package/dist/shared/process/process-tree.js +144 -0
  143. package/dist/shared/process/process.d.ts +67 -0
  144. package/dist/shared/process/process.js +213 -11
  145. package/dist/shared/provider-capabilities.js +5 -6
  146. package/dist/version.d.ts +1 -1
  147. package/dist/version.js +1 -1
  148. package/dist/worktree/dependency-warmer.d.ts +25 -0
  149. package/dist/worktree/dependency-warmer.js +46 -10
  150. package/dist/worktree/worktree.service.d.ts +10 -1
  151. package/dist/worktree/worktree.service.js +42 -2
  152. package/dist/worktree/worktree.types.d.ts +7 -0
  153. package/package.json +2 -2
@@ -3,10 +3,13 @@ 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 { managedAttemptInvocation, supportsNativeTestPostgresFallback, validationExecutionForStep, } from "./pre-publication-step-execution.js";
8
+ import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
8
9
  import { redactText } from "../shared/redaction/redaction.js";
10
+ import { PrePublicationPass, PrePublicationValidationError, SkippedTestTally, skippedCheckEvent, validationEvent, } from "./pre-publication-pass.js";
9
11
  import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
12
+ import { ProcessTreeTerminationError } from "../shared/process/process.js";
10
13
  import { findUnreferencedNewExports } from "./unreferenced-exports.js";
11
14
  import { ForgeFailureError, sanitizeFailureError, } from "./session.types.js";
12
15
  const contractRelativePath = ".forge/validation/ci-parity.v1.json";
@@ -45,23 +48,31 @@ const approvedContractDigests = new Set([
45
48
  ...compatibleApprovedContractDigests,
46
49
  ]);
47
50
  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
- }
51
+ const timeoutConfirmation = {
52
+ started: [
53
+ "prepublication_validation_timeout_confirmation_started",
54
+ "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment.",
55
+ ],
56
+ passed: [
57
+ "prepublication_validation_timeout_confirmation_passed",
58
+ "The complete client test step passed on its single timeout confirmation run.",
59
+ ],
60
+ failedEvent: "prepublication_validation_timeout_confirmation_failed",
61
+ failedContent: exitCode => `The complete client test step failed on its single timeout confirmation run (exit ${exitCode}).`,
62
+ };
63
+ const cleanupConfirmation = {
64
+ started: [
65
+ "prepublication_validation_cleanup_confirmation_started",
66
+ "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment.",
67
+ ],
68
+ passed: [
69
+ "prepublication_validation_cleanup_confirmation_passed",
70
+ "The complete Bridge test step passed on its single cleanup confirmation run.",
71
+ ],
72
+ failedEvent: "prepublication_validation_cleanup_confirmation_failed",
73
+ failedContent: exitCode => `The complete Bridge test step failed on its single cleanup confirmation run (exit ${exitCode}).`,
74
+ };
75
+ export { PrePublicationValidationError };
65
76
  export class PrePublicationInfrastructureError extends ForgeFailureError {
66
77
  checkId;
67
78
  exitCode;
@@ -83,105 +94,162 @@ export class PrePublicationValidator {
83
94
  commands;
84
95
  dockerEngineProbe;
85
96
  nativeTestPostgresFallback;
86
- constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null) {
97
+ hostLoad;
98
+ constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad) {
87
99
  this.commands = commands;
88
100
  this.dockerEngineProbe = dockerEngineProbe;
89
101
  this.nativeTestPostgresFallback = nativeTestPostgresFallback;
102
+ this.hostLoad = hostLoad;
90
103
  }
104
+ /**
105
+ * Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
106
+ * can still meaningfully run keeps going, and the pass then throws all of its failures as one
107
+ * PrePublicationValidationError.
108
+ */
91
109
  async validate(worktreePath, profile, capabilities, emit, signal, execution) {
92
110
  const checksExports = profile === "implementation" || profile === "comment_repair";
111
+ const pass = new PrePublicationPass(execution?.runtimeRestartFailure);
93
112
  const contract = await loadValidationContract(worktreePath);
94
113
  if (contract === null) {
95
114
  await emit?.(validationEvent("prepublication_validation_legacy_contract", "legacy-provider-validation", `This checkout predates ${contractRelativePath}; Bridge preserved legacy provider validation without source mutation.`));
96
115
  if (checksExports) {
97
116
  const legacy = await prepareValidationExecution(execution);
98
117
  try {
99
- await this.assertNoTestOnlyExports(worktreePath, emit, signal, legacy.execution);
118
+ await this.checkTestOnlyExports(pass, worktreePath, emit, signal, legacy.execution);
100
119
  }
101
120
  finally {
102
121
  await legacy.cleanup();
103
122
  }
104
123
  }
124
+ pass.throwIfFailed();
105
125
  return [];
106
126
  }
107
127
  const scoped = await prepareValidationExecution(execution);
108
128
  try {
109
129
  if (checksExports)
110
- await this.assertNoTestOnlyExports(worktreePath, emit, signal, scoped.execution);
130
+ await this.checkTestOnlyExports(pass, worktreePath, emit, signal, scoped.execution);
111
131
  const contractDigest = validationContractDigest(contract);
112
132
  await this.assertContractMatchesDispatchBaseline(worktreePath, contractDigest, signal, scoped.execution);
113
133
  if (contractDigest !== currentApprovedContractDigest) {
114
134
  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
135
  }
116
136
  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;
137
+ const run = {
138
+ worktreePath,
139
+ capabilities,
140
+ emit,
141
+ signal,
142
+ execution: scoped.execution,
143
+ postgresAdminConnection: scoped.postgresAdminConnection,
144
+ };
145
+ return await this.runChecks(applicableChecks(contract, profile, changedPaths), run, pass);
180
146
  }
181
147
  finally {
182
148
  await scoped.cleanup();
183
149
  }
184
150
  }
151
+ async runChecks(checks, run, pass) {
152
+ const completed = [];
153
+ for (const check of checks) {
154
+ if (check.providerOnly) {
155
+ await run.emit?.(validationEvent("prepublication_validation_provider_only", check.id, `Preserved provider-only validation '${check.id}' for the provider check run.`));
156
+ continue;
157
+ }
158
+ const blockedBy = pass.blockers(check.id);
159
+ if (blockedBy.length > 0) {
160
+ await run.emit?.(skippedCheckEvent(check.id, blockedBy));
161
+ continue;
162
+ }
163
+ try {
164
+ const failed = await this.runCheck(check, run);
165
+ // A cancelled step may settle with an exit code rather than throw; the pass ends either way.
166
+ run.signal?.throwIfAborted();
167
+ if (failed)
168
+ pass.record(failed.failure, failed.step);
169
+ else
170
+ completed.push(check.id);
171
+ }
172
+ catch (error) {
173
+ if (!pass.stopsAt(error, run.signal))
174
+ throw error;
175
+ await run.emit?.(pass.stoppedEvent(check.id, error));
176
+ break;
177
+ }
178
+ }
179
+ pass.throwIfFailed();
180
+ return completed;
181
+ }
182
+ /** Runs one check's steps in order; the first failed step ends the check, since later steps use its output. */
183
+ async runCheck(check, run) {
184
+ if (check.requiredCapability && !run.capabilities.has(check.requiredCapability)) {
185
+ throw new ForgeFailureError("prepublication_capability_unavailable", `prepublication_capability_unavailable: ${check.id} requires ${check.requiredCapability}; publication is holding until a capable runner is available.`, "bridge");
186
+ }
187
+ const postgresAdminConnection = await this.ensurePrerequisite(check, run.execution?.environment, run.postgresAdminConnection, run.emit) ?? run.postgresAdminConnection;
188
+ const stepRun = { ...run, check, postgresAdminConnection };
189
+ await run.emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
190
+ const skipped = new SkippedTestTally(run.worktreePath, run.execution?.environment);
191
+ for (const step of check.steps) {
192
+ const stepStartedMs = Date.now() - 1000;
193
+ const result = await this.runConfirmedStep(stepRun, step);
194
+ if (result.exitCode !== 0) {
195
+ const detail = diagnosticDetail(result);
196
+ await run.emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
197
+ return {
198
+ failure: { checkId: check.id, exitCode: result.exitCode, command: result.command, args: result.args, detail },
199
+ step,
200
+ };
201
+ }
202
+ await skipped.add(result.args, stepStartedMs);
203
+ }
204
+ await run.emit?.(skipped.passedEvent(check.id, validationExactSecrets(run.execution?.environment)));
205
+ return null;
206
+ }
207
+ /** Runs a step, confirming once a failure that matches a known transient pattern. */
208
+ async runConfirmedStep(run, step) {
209
+ let result = await this.runCheckedStep(run, step);
210
+ if (isTimeoutOnlyClientTestFailure(run.check.id, step, result)) {
211
+ result = await this.confirmStep(run, step, timeoutConfirmation);
212
+ }
213
+ if (isTransientBridgeCleanupFailure(run.check.id, step, result)) {
214
+ result = await this.confirmStep(run, step, cleanupConfirmation);
215
+ }
216
+ if (isTransientShellInfrastructureFailure(result)) {
217
+ result = await this.confirmInfrastructure(run, step);
218
+ }
219
+ return result;
220
+ }
221
+ async runCheckedStep(run, step) {
222
+ const { check, worktreePath, signal, execution, postgresAdminConnection, emit } = run;
223
+ const result = await this.runStep(check.id, step, worktreePath, signal, execution, postgresAdminConnection, emit);
224
+ await this.throwIfPrerequisiteWasLost(check, result, execution?.environment, postgresAdminConnection, emit);
225
+ return result;
226
+ }
227
+ async confirmStep(run, step, confirmation) {
228
+ await run.emit?.(validationEvent(confirmation.started[0], run.check.id, confirmation.started[1]));
229
+ const result = await this.runCheckedStep(run, step);
230
+ await run.emit?.(result.exitCode === 0
231
+ ? validationEvent(confirmation.passed[0], run.check.id, confirmation.passed[1])
232
+ : validationEvent(confirmation.failedEvent, run.check.id, confirmation.failedContent(result.exitCode)));
233
+ return result;
234
+ }
235
+ async confirmInfrastructure(run, step) {
236
+ const checkId = run.check.id;
237
+ 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."));
238
+ const result = await this.runCheckedStep(run, step);
239
+ const infrastructureFailed = isTransientShellInfrastructureFailure(result);
240
+ await run.emit?.(validationEvent(infrastructureFailed
241
+ ? "prepublication_infrastructure_confirmation_failed"
242
+ : "prepublication_infrastructure_confirmation_passed", checkId, infrastructureFailed
243
+ ? `The validation shell failed again on its single infrastructure confirmation run (exit ${result.exitCode}).`
244
+ : result.exitCode === 0
245
+ ? "The validation step recovered on its single infrastructure confirmation run."
246
+ : "The host-runtime failure did not recur; continuing with normal validation failure handling."));
247
+ if (!infrastructureFailed)
248
+ return result;
249
+ const detail = diagnosticDetail(result);
250
+ await run.emit?.(validationEvent("prepublication_infrastructure_failed", checkId, `Pre-publication infrastructure for '${checkId}' remained unavailable${detail ? `: ${detail}` : "."}`));
251
+ throw new PrePublicationInfrastructureError(checkId, result.exitCode, result.command, result.args, detail);
252
+ }
185
253
  /** Returns the native fallback connection when this check must use it instead of Docker. */
186
254
  async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
187
255
  if (check.requiredPrerequisite === "isolated_postgres"
@@ -202,7 +270,7 @@ export class PrePublicationValidator {
202
270
  const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
203
271
  if (!snapshot.available) {
204
272
  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)
273
+ const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check.id)
206
274
  ? this.nativeTestPostgresFallback()
207
275
  : null;
208
276
  if (fallback) {
@@ -230,7 +298,8 @@ export class PrePublicationValidator {
230
298
  throw new PrePublicationInfrastructureError(check.id, result.exitCode, result.command, result.args, detail);
231
299
  }
232
300
  // Runs for every target repository, with or without a CI parity contract: it only reads the worktree.
233
- async assertNoTestOnlyExports(worktreePath, emit, signal, execution) {
301
+ // A failure joins the pass's failures; the contract's checks still run.
302
+ async checkTestOnlyExports(pass, worktreePath, emit, signal, execution) {
234
303
  const found = await findUnreferencedNewExports(args => this.runCommand("git", args, worktreePath, signal, execution), worktreePath, execution?.baselineRevision);
235
304
  const unused = found.filter(row => !row.testOnly);
236
305
  if (unused.length > 0) {
@@ -241,7 +310,7 @@ export class PrePublicationValidator {
241
310
  return;
242
311
  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
312
  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);
313
+ pass.record({ checkId: "unreferenced-exports", exitCode: 1, command: "git", args: ["grep"], detail });
245
314
  }
246
315
  async changedPaths(worktreePath, signal, execution) {
247
316
  const baselineRevision = execution?.baselineRevision?.trim();
@@ -288,8 +357,14 @@ export class PrePublicationValidator {
288
357
  throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
289
358
  }
290
359
  }
291
- async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection) {
360
+ async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
292
361
  const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
362
+ // Every launch, including confirmation reruns, is admitted by the host load governor first.
363
+ return await runHostGovernedValidationStep(this.hostLoad, {
364
+ checkId, command: invocation.command, args: invocation.args, owner: execution?.hostLoadOwner, signal, emit,
365
+ }, async (stepSignal) => await this.launchStep(checkId, step, invocation, cwd, stepSignal, execution, postgresAdminConnection));
366
+ }
367
+ async launchStep(checkId, step, invocation, cwd, signal, execution, postgresAdminConnection) {
293
368
  const stepExecution = validationExecutionForStep(checkId, step, execution, postgresAdminConnection);
294
369
  const before = await readValidationFiles(cwd, step.assertUnchangedPaths ?? []);
295
370
  const result = await this.runCommand(invocation.command, invocation.args, cwd, signal, stepExecution);
@@ -334,57 +409,13 @@ export class PrePublicationValidator {
334
409
  };
335
410
  }
336
411
  catch (error) {
412
+ // Carries the check its host capacity token waits on; it names only the executable.
413
+ if (error instanceof ProcessTreeTerminationError)
414
+ throw error;
337
415
  throw sanitizeFailureError(error, exactSecrets);
338
416
  }
339
417
  }
340
418
  }
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
419
  function environmentValue(environment, name) {
389
420
  return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
390
421
  ? environment?.[name]?.trim() ?? ""
@@ -406,6 +437,7 @@ function validationExactSecrets(environment) {
406
437
  return [
407
438
  environment?.[hostRuntimeTestPostgresAdminEnvironment]?.trim() ?? "",
408
439
  environment?.[hostRuntimeLegacyTestPostgresEnvironment]?.trim() ?? "",
440
+ environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
409
441
  ...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
410
442
  ].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
411
443
  }
@@ -538,6 +570,7 @@ function withoutPrivilegedPostgresEnvironment(environment) {
538
570
  const privilegedNames = new Set([
539
571
  hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
540
572
  hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
573
+ hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
541
574
  ]);
542
575
  return Object.fromEntries(Object.entries(environment)
543
576
  .filter(([name]) => !privilegedNames.has(name.toLowerCase())));
@@ -607,6 +640,3 @@ function canonicalizeJson(value) {
607
640
  }
608
641
  return value;
609
642
  }
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,40 @@
1
+ import { PrePublicationValidationError, type PrePublicationProfile, type PrePublicationValidator } from "../pre-publication-validation.js";
2
+ import type { ProviderProcessRunner } from "./provider-cli.process.js";
3
+ import type { ProviderCliRunContext } from "./provider-cli.types.js";
4
+ import { type ProviderOutputState } from "./provider-output-state.js";
5
+ /**
6
+ * The in-place repair budget: FORGE_PREPUBLICATION_REPAIR_TURNS when it is a whole number from 1
7
+ * (capped at 10), otherwise 4.
8
+ */
9
+ export declare function prePublicationRepairTurnsFromEnvironment(environment?: Readonly<Record<string, string | undefined>>): number;
10
+ export interface PrePublicationRepairOptions {
11
+ readonly context: ProviderCliRunContext;
12
+ readonly validationProfile: PrePublicationProfile;
13
+ readonly repairEnvironment: Readonly<Record<string, string>> | undefined;
14
+ readonly outputState: ProviderOutputState;
15
+ readonly preparedHeadSha: string;
16
+ readonly repairScope: "implementation" | "pull_request";
17
+ /**
18
+ * Derives the repair environment from a refreshed runtime environment. CI repair
19
+ * rewrites its readiness manifest so the attempt URLs it records stay current.
20
+ */
21
+ readonly onRuntimeEnvironmentRefreshed?: (runtimeEnvironment: Readonly<Record<string, string>>) => Promise<Readonly<Record<string, string>>>;
22
+ }
23
+ /** One resumed provider turn that repairs a failed pass in place. */
24
+ export interface PrePublicationRepairTurn {
25
+ readonly prompt: string;
26
+ readonly repairTurn: number;
27
+ readonly maxRepairTurns: number;
28
+ readonly providerThreadId: string;
29
+ readonly repairEnvironment: Readonly<Record<string, string>> | undefined;
30
+ readonly environment: Readonly<Record<string, string>>;
31
+ readonly failure: PrePublicationValidationError;
32
+ }
33
+ export interface PrePublicationRepairDependencies {
34
+ readonly validator: PrePublicationValidator;
35
+ readonly defaultProcessRunner: ProviderProcessRunner;
36
+ readonly maxRepairTurns: number;
37
+ readonly runRepairTurn: (turn: PrePublicationRepairTurn) => Promise<void>;
38
+ }
39
+ export declare function validatePrePublicationWithRepair(options: PrePublicationRepairOptions, dependencies: PrePublicationRepairDependencies): Promise<void>;
40
+ export declare function buildPrePublicationRepairPrompt(error: PrePublicationValidationError, repairTurn: number, maxRepairTurns: number, repairScope: "implementation" | "pull_request"): string;