@loucompanion/forge-bridge 0.1.4-dev.a5a3a7ab2f02 → 0.1.4-dev.a7b2e9125fed
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.
- package/README.md +22 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.service.d.ts +1 -1
- package/dist/bridge/bridge.service.js +4 -110
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +9 -2
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +19 -10
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +7 -0
- package/dist/runtime/host-load-governor.d.ts +10 -0
- package/dist/runtime/host-load-governor.js +125 -34
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-lease.d.ts +1 -1
- package/dist/runtime/host-runtime-lease.js +1 -1
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/sandbox/host-capacity-broker.d.ts +7 -1
- package/dist/sandbox/host-capacity-broker.js +23 -4
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +51 -62
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +38 -168
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +58 -8
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +5 -5
- package/dist/session/provider-cli/provider-cli.service.js +65 -257
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.js +12 -3
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.types.js +2 -2
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -4,10 +4,11 @@ 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
6
|
import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
|
|
7
|
-
import {
|
|
7
|
+
import { dockerFreeGrant, dockerUnavailableNativeTestPostgres, isolatedPostgresProvided, preferredNativeTestPostgres, releaseCheckPostgres, } from "./pre-publication-native-postgres.js";
|
|
8
|
+
import { managedAttemptInvocation, validationExecutionForStep, } from "./pre-publication-step-execution.js";
|
|
8
9
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
9
10
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
10
|
-
import {
|
|
11
|
+
import { PrePublicationPass, PrePublicationValidationError, SkippedTestTally, skippedCheckEvent, validationEvent, } from "./pre-publication-pass.js";
|
|
11
12
|
import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
|
|
12
13
|
import { ProcessTreeTerminationError } from "../shared/process/process.js";
|
|
13
14
|
import { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
@@ -23,16 +24,21 @@ const requiredCheckIds = new Set([
|
|
|
23
24
|
"playwright-e2e",
|
|
24
25
|
"github-provider-policy",
|
|
25
26
|
]);
|
|
26
|
-
|
|
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";
|
|
27
32
|
// Comment repair ran the whole ApiComponent and Orchestration tiers under this contract.
|
|
28
|
-
// Story branches cut before the affected-tests contract still carry it.
|
|
29
33
|
const wholeTierCommentRepairContractDigest = "024de3648c907db9c0eab13def9a4f91e81148433e0a2ba7f44776446421054a";
|
|
30
34
|
// Contracts that declare the comment-repair-dotnet-regression check.
|
|
31
35
|
const commentRepairRegressionContractDigests = new Set([
|
|
32
36
|
currentApprovedContractDigest,
|
|
37
|
+
commentRepairOnlyAffectedContractDigest,
|
|
33
38
|
wholeTierCommentRepairContractDigest,
|
|
34
39
|
]);
|
|
35
40
|
const compatibleApprovedContractDigests = new Set([
|
|
41
|
+
commentRepairOnlyAffectedContractDigest,
|
|
36
42
|
wholeTierCommentRepairContractDigest,
|
|
37
43
|
// Preserve dispatches pinned before comment repair gained all .NET regression tiers.
|
|
38
44
|
"c0014ce6abc0e0b2e66dd2bcf6cb14c47d28506444c73f87d1b76b3d1c06027b",
|
|
@@ -48,23 +54,31 @@ const approvedContractDigests = new Set([
|
|
|
48
54
|
...compatibleApprovedContractDigests,
|
|
49
55
|
]);
|
|
50
56
|
const ansiColorSequence = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "gu");
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 };
|
|
68
82
|
export class PrePublicationInfrastructureError extends ForgeFailureError {
|
|
69
83
|
checkId;
|
|
70
84
|
exitCode;
|
|
@@ -87,117 +101,176 @@ export class PrePublicationValidator {
|
|
|
87
101
|
dockerEngineProbe;
|
|
88
102
|
nativeTestPostgresFallback;
|
|
89
103
|
hostLoad;
|
|
90
|
-
|
|
104
|
+
startEphemeral;
|
|
105
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad, startEphemeral) {
|
|
91
106
|
this.commands = commands;
|
|
92
107
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
93
108
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
94
109
|
this.hostLoad = hostLoad;
|
|
110
|
+
this.startEphemeral = startEphemeral;
|
|
95
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
|
+
*/
|
|
96
117
|
async validate(worktreePath, profile, capabilities, emit, signal, execution) {
|
|
97
118
|
const checksExports = profile === "implementation" || profile === "comment_repair";
|
|
119
|
+
const pass = new PrePublicationPass(execution?.runtimeRestartFailure);
|
|
98
120
|
const contract = await loadValidationContract(worktreePath);
|
|
99
121
|
if (contract === null) {
|
|
100
122
|
await emit?.(validationEvent("prepublication_validation_legacy_contract", "legacy-provider-validation", `This checkout predates ${contractRelativePath}; Bridge preserved legacy provider validation without source mutation.`));
|
|
101
123
|
if (checksExports) {
|
|
102
124
|
const legacy = await prepareValidationExecution(execution);
|
|
103
125
|
try {
|
|
104
|
-
await this.
|
|
126
|
+
await this.checkTestOnlyExports(pass, worktreePath, emit, signal, legacy.execution);
|
|
105
127
|
}
|
|
106
128
|
finally {
|
|
107
129
|
await legacy.cleanup();
|
|
108
130
|
}
|
|
109
131
|
}
|
|
132
|
+
pass.throwIfFailed();
|
|
110
133
|
return [];
|
|
111
134
|
}
|
|
112
135
|
const scoped = await prepareValidationExecution(execution);
|
|
113
136
|
try {
|
|
114
137
|
if (checksExports)
|
|
115
|
-
await this.
|
|
138
|
+
await this.checkTestOnlyExports(pass, worktreePath, emit, signal, scoped.execution);
|
|
116
139
|
const contractDigest = validationContractDigest(contract);
|
|
117
140
|
await this.assertContractMatchesDispatchBaseline(worktreePath, contractDigest, signal, scoped.execution);
|
|
118
141
|
if (contractDigest !== currentApprovedContractDigest) {
|
|
119
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}.`));
|
|
120
143
|
}
|
|
121
144
|
const changedPaths = await this.changedPaths(worktreePath, signal, scoped.execution);
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
const postgresAdminConnection = await this.ensurePrerequisite(check, scoped.execution?.environment, scoped.postgresAdminConnection, emit) ?? scoped.postgresAdminConnection;
|
|
133
|
-
await emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
|
|
134
|
-
let skipped = { count: 0, reasons: [] };
|
|
135
|
-
for (const step of check.steps) {
|
|
136
|
-
const stepStartedMs = Date.now() - 1000;
|
|
137
|
-
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
138
|
-
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
139
|
-
if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
|
|
140
|
-
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."));
|
|
141
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
142
|
-
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
143
|
-
await emit?.(validationEvent(result.exitCode === 0
|
|
144
|
-
? "prepublication_validation_timeout_confirmation_passed"
|
|
145
|
-
: "prepublication_validation_timeout_confirmation_failed", check.id, result.exitCode === 0
|
|
146
|
-
? "The complete client test step passed on its single timeout confirmation run."
|
|
147
|
-
: `The complete client test step failed on its single timeout confirmation run (exit ${result.exitCode}).`));
|
|
148
|
-
}
|
|
149
|
-
if (isTransientBridgeCleanupFailure(check.id, step, result)) {
|
|
150
|
-
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."));
|
|
151
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
152
|
-
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
153
|
-
await emit?.(validationEvent(result.exitCode === 0
|
|
154
|
-
? "prepublication_validation_cleanup_confirmation_passed"
|
|
155
|
-
: "prepublication_validation_cleanup_confirmation_failed", check.id, result.exitCode === 0
|
|
156
|
-
? "The complete Bridge test step passed on its single cleanup confirmation run."
|
|
157
|
-
: `The complete Bridge test step failed on its single cleanup confirmation run (exit ${result.exitCode}).`));
|
|
158
|
-
}
|
|
159
|
-
if (isTransientShellInfrastructureFailure(result)) {
|
|
160
|
-
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."));
|
|
161
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
162
|
-
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
163
|
-
const infrastructureFailed = isTransientShellInfrastructureFailure(result);
|
|
164
|
-
await emit?.(validationEvent(infrastructureFailed
|
|
165
|
-
? "prepublication_infrastructure_confirmation_failed"
|
|
166
|
-
: "prepublication_infrastructure_confirmation_passed", check.id, infrastructureFailed
|
|
167
|
-
? `The validation shell failed again on its single infrastructure confirmation run (exit ${result.exitCode}).`
|
|
168
|
-
: result.exitCode === 0
|
|
169
|
-
? "The validation step recovered on its single infrastructure confirmation run."
|
|
170
|
-
: "The host-runtime failure did not recur; continuing with normal validation failure handling."));
|
|
171
|
-
if (infrastructureFailed) {
|
|
172
|
-
const detail = diagnosticDetail(result);
|
|
173
|
-
await emit?.(validationEvent("prepublication_infrastructure_failed", check.id, `Pre-publication infrastructure for '${check.id}' remained unavailable${detail ? `: ${detail}` : "."}`));
|
|
174
|
-
throw new PrePublicationInfrastructureError(check.id, result.exitCode, result.command, result.args, detail);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (result.exitCode !== 0) {
|
|
178
|
-
const detail = diagnosticDetail(result);
|
|
179
|
-
await emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
|
|
180
|
-
throw new PrePublicationValidationError(check.id, result.exitCode, result.command, result.args, detail);
|
|
181
|
-
}
|
|
182
|
-
// The invocation's own arguments: a managed attempt may direct results to its test-output root.
|
|
183
|
-
skipped = mergeSkippedTests(skipped, await readSkippedTests(worktreePath, result.args, stepStartedMs, scoped.execution?.environment));
|
|
184
|
-
}
|
|
185
|
-
completed.push(check.id);
|
|
186
|
-
// A pass that skipped tests says so, with each reason, instead of reading as a plain pass.
|
|
187
|
-
const secrets = validationExactSecrets(scoped.execution?.environment);
|
|
188
|
-
skipped = { ...skipped, reasons: skipped.reasons.map(entry => ({ ...entry, reason: redactText(entry.reason, secrets) })) };
|
|
189
|
-
const skippedDetail = skipped.count > 0 ? describeSkippedTests(skipped) : undefined;
|
|
190
|
-
await emit?.(validationEvent("prepublication_validation_passed", check.id, skippedDetail
|
|
191
|
-
? `Pre-publication CI parity check '${check.id}' passed with ${skippedDetail}.`
|
|
192
|
-
: `Pre-publication CI parity check '${check.id}' passed.`, skipped.count > 0 ? { skippedTests: skipped.count, skippedReasons: skipped.reasons } : undefined));
|
|
193
|
-
}
|
|
194
|
-
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);
|
|
195
154
|
}
|
|
196
155
|
finally {
|
|
197
156
|
await scoped.cleanup();
|
|
198
157
|
}
|
|
199
158
|
}
|
|
200
|
-
|
|
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. */
|
|
201
274
|
async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
|
|
202
275
|
if (check.requiredPrerequisite === "isolated_postgres"
|
|
203
276
|
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection)) {
|
|
@@ -206,6 +279,11 @@ export class PrePublicationValidator {
|
|
|
206
279
|
: `Pre-publication check '${check.id}' is using the configured loopback PostgreSQL test server with per-run owned databases. No Docker daemon is required.`));
|
|
207
280
|
return undefined;
|
|
208
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) {
|
|
209
287
|
if (check.requiredPrerequisite === undefined || !this.dockerEngineProbe)
|
|
210
288
|
return undefined;
|
|
211
289
|
const current = this.dockerEngineProbe.current();
|
|
@@ -217,12 +295,10 @@ export class PrePublicationValidator {
|
|
|
217
295
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
218
296
|
if (!snapshot.available) {
|
|
219
297
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
220
|
-
const fallback = check.
|
|
221
|
-
? this.nativeTestPostgresFallback()
|
|
222
|
-
: null;
|
|
298
|
+
const fallback = dockerUnavailableNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback);
|
|
223
299
|
if (fallback) {
|
|
224
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.`));
|
|
225
|
-
return fallback
|
|
301
|
+
return fallback;
|
|
226
302
|
}
|
|
227
303
|
await emit?.(validationEvent("prepublication_prerequisite_unavailable", check.id, `Pre-publication check '${check.id}' is waiting for Docker infrastructure recovery: ${detail}`));
|
|
228
304
|
throw new PrePublicationInfrastructureError(check.id, 75, "docker", ["info"], detail);
|
|
@@ -234,7 +310,7 @@ export class PrePublicationValidator {
|
|
|
234
310
|
if (result.exitCode === 0
|
|
235
311
|
|| check.requiredPrerequisite === undefined
|
|
236
312
|
|| (check.requiredPrerequisite === "isolated_postgres"
|
|
237
|
-
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection))
|
|
313
|
+
&& isolatedPostgresProvided(check.id, environment, dockerFreeGrant(postgresAdminConnection)))
|
|
238
314
|
|| !this.dockerEngineProbe)
|
|
239
315
|
return;
|
|
240
316
|
const snapshot = await this.dockerEngineProbe.refresh(true);
|
|
@@ -245,7 +321,8 @@ export class PrePublicationValidator {
|
|
|
245
321
|
throw new PrePublicationInfrastructureError(check.id, result.exitCode, result.command, result.args, detail);
|
|
246
322
|
}
|
|
247
323
|
// Runs for every target repository, with or without a CI parity contract: it only reads the worktree.
|
|
248
|
-
|
|
324
|
+
// A failure joins the pass's failures; the contract's checks still run.
|
|
325
|
+
async checkTestOnlyExports(pass, worktreePath, emit, signal, execution) {
|
|
249
326
|
const found = await findUnreferencedNewExports(args => this.runCommand("git", args, worktreePath, signal, execution), worktreePath, execution?.baselineRevision);
|
|
250
327
|
const unused = found.filter(row => !row.testOnly);
|
|
251
328
|
if (unused.length > 0) {
|
|
@@ -256,7 +333,7 @@ export class PrePublicationValidator {
|
|
|
256
333
|
return;
|
|
257
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.`;
|
|
258
335
|
await emit?.(validationEvent("prepublication_validation_failed", "unreferenced-exports", `New code is tested but never called: ${detail}`));
|
|
259
|
-
|
|
336
|
+
pass.record({ checkId: "unreferenced-exports", exitCode: 1, command: "git", args: ["grep"], detail });
|
|
260
337
|
}
|
|
261
338
|
async changedPaths(worktreePath, signal, execution) {
|
|
262
339
|
const baselineRevision = execution?.baselineRevision?.trim();
|
|
@@ -299,10 +376,24 @@ export class PrePublicationValidator {
|
|
|
299
376
|
if (!approvedContractDigests.has(baselineDigest)) {
|
|
300
377
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the dispatch baseline uses unapproved CI parity contract ${baselineDigest}.`, "bridge");
|
|
301
378
|
}
|
|
302
|
-
|
|
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) {
|
|
303
381
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
|
|
304
382
|
}
|
|
305
383
|
}
|
|
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
|
+
}
|
|
306
397
|
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
|
|
307
398
|
const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
|
|
308
399
|
// Every launch, including confirmation reruns, is admitted by the host load governor first.
|
|
@@ -362,27 +453,11 @@ export class PrePublicationValidator {
|
|
|
362
453
|
}
|
|
363
454
|
}
|
|
364
455
|
}
|
|
365
|
-
function environmentValue(environment, name) {
|
|
366
|
-
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
367
|
-
? environment?.[name]?.trim() ?? ""
|
|
368
|
-
: process.env[name]?.trim() ?? "";
|
|
369
|
-
}
|
|
370
|
-
function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
371
|
-
if (checkId === "playwright-e2e") {
|
|
372
|
-
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
373
|
-
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
374
|
-
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
375
|
-
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
376
|
-
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
377
|
-
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
378
|
-
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
379
|
-
}
|
|
380
|
-
return Boolean(postgresAdminConnection);
|
|
381
|
-
}
|
|
382
456
|
function validationExactSecrets(environment) {
|
|
383
457
|
return [
|
|
384
|
-
|
|
385
|
-
environment?.[
|
|
458
|
+
// The connection strings and their passwords: a test may print either.
|
|
459
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeTestPostgresAdminEnvironment]),
|
|
460
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeLegacyTestPostgresEnvironment]),
|
|
386
461
|
environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
|
|
387
462
|
...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
|
|
388
463
|
].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
@@ -572,6 +647,13 @@ export async function loadValidationContract(worktreePath) {
|
|
|
572
647
|
}
|
|
573
648
|
return contract;
|
|
574
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
|
+
}
|
|
575
657
|
function validationContractDigest(contract) {
|
|
576
658
|
return createHash("sha256")
|
|
577
659
|
.update(JSON.stringify(canonicalizeJson(contract)))
|
|
@@ -586,12 +668,3 @@ function canonicalizeJson(value) {
|
|
|
586
668
|
}
|
|
587
669
|
return value;
|
|
588
670
|
}
|
|
589
|
-
function validationEvent(eventType, checkId, content, detail) {
|
|
590
|
-
return {
|
|
591
|
-
role: "runner",
|
|
592
|
-
kind: "checkpoint",
|
|
593
|
-
content,
|
|
594
|
-
eventType,
|
|
595
|
-
data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1", ...detail }),
|
|
596
|
-
};
|
|
597
|
-
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.
|
|
23
|
+
*/
|
|
24
|
+
export declare function claudeHeadlessToolArgs(): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* The provider ended its turn while background work it started (a background subagent or
|
|
27
|
+
* shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
|
|
28
|
+
* result for such work, and nothing started in the background reports to Forge, so Forge stops
|
|
29
|
+
* the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
|
|
30
|
+
* task, ended the run.
|
|
31
|
+
*/
|
|
32
|
+
export declare function providerTurnEndedWithBackgroundWorkFailure(message: string): ForgeFailureError;
|
|
33
|
+
/**
|
|
34
|
+
* Fails every provider run Forge stopped because its turn ended with background work still live,
|
|
35
|
+
* whether or not the turn recorded a completion first: the stop cut that work short, so nothing
|
|
36
|
+
* may validate, commit or publish the worktree it left behind.
|
|
37
|
+
*/
|
|
38
|
+
export declare class BackgroundWorkStopFailingRunner implements ProviderProcessRunner {
|
|
39
|
+
private readonly inner;
|
|
40
|
+
constructor(inner: ProviderProcessRunner);
|
|
41
|
+
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Recognizes a main-conversation turn that ended while background tasks it started were still
|
|
45
|
+
* live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
|
|
46
|
+
* Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
|
|
47
|
+
* event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
|
|
48
|
+
* without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
|
|
49
|
+
* once, so the runner can stop the provider instead of waiting on work no one will collect.
|
|
50
|
+
*/
|
|
51
|
+
export declare class ClaudeBackgroundTurnEndWatch {
|
|
52
|
+
private readonly graceMs;
|
|
53
|
+
private readonly onTurnEndedWithBackgroundWork;
|
|
54
|
+
private liveBackgroundTasks;
|
|
55
|
+
private terminalSinceMainActivity;
|
|
56
|
+
private mainTurnEnded;
|
|
57
|
+
private timer;
|
|
58
|
+
private stopped;
|
|
59
|
+
private readonly enabled;
|
|
60
|
+
/** Watches only Claude Code, by its executable `command`; other output is left alone. */
|
|
61
|
+
constructor(command: string, graceMs: number, onTurnEndedWithBackgroundWork: () => void);
|
|
62
|
+
consume(line: string): void;
|
|
63
|
+
stop(): void;
|
|
64
|
+
private armIfTurnEndedWithBackgroundWork;
|
|
65
|
+
private cancel;
|
|
66
|
+
}
|