@loucompanion/forge-bridge 0.1.4-dev.81e48ecc185d → 0.1.4-dev.866b33be3065
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 +3 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +1 -1
- package/dist/bridge/bridge-chat-provider-command.js +16 -4
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- 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 +4 -1
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- 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 +44 -54
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.runtime.js +1 -1
- package/dist/session/phase-completion.schemas.js +3 -11
- 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-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +7 -3
- package/dist/session/pre-publication-validation.js +32 -30
- 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 +8 -30
- package/dist/session/provider-cli/provider-cli.process.js +25 -376
- 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-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.types.js +1 -1
- 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/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
3
|
+
import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
|
|
4
|
+
import type { RunnerDispatchEvent } from "./session.types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
7
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
8
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
9
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
10
|
+
* check on Docker.
|
|
11
|
+
*/
|
|
12
|
+
export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
|
|
13
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
14
|
+
export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
17
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
18
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
19
|
+
*/
|
|
20
|
+
export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
23
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
|
|
26
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
27
|
+
export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
|
|
28
|
+
export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
|
|
29
|
+
/** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
|
|
30
|
+
export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilityEnvironment } from "../runtime/attempt-database-broker.js";
|
|
3
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
4
|
+
import { nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresGrant, } from "../runtime/native-test-postgres-fallback.js";
|
|
5
|
+
import { validationEvent } from "./pre-publication-pass.js";
|
|
6
|
+
import { supportsNativeTestPostgresFallback } from "./pre-publication-step-execution.js";
|
|
7
|
+
// Which PostgreSQL a pre-publication check's isolated_postgres prerequisite is met by,
|
|
8
|
+
// before the validator falls back to waiting for Docker.
|
|
9
|
+
/**
|
|
10
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
11
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
12
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
13
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
14
|
+
* check on Docker.
|
|
15
|
+
*/
|
|
16
|
+
export async function preferredNativeTestPostgres(checkId, requiredPrerequisite, readCluster, dockerEngineProbe, emit, startEphemeral = startEphemeralTestPostgresGrant) {
|
|
17
|
+
if (requiredPrerequisite !== "isolated_postgres" || !supportsNativeTestPostgresFallback(checkId))
|
|
18
|
+
return undefined;
|
|
19
|
+
let configured;
|
|
20
|
+
try {
|
|
21
|
+
configured = readCluster();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_invalid", checkId, `The native PostgreSQL test cluster configuration was refused, so '${checkId}' uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (configured?.use === "ephemeral") {
|
|
28
|
+
return await ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral);
|
|
29
|
+
}
|
|
30
|
+
if (configured?.use !== "preferred")
|
|
31
|
+
return undefined;
|
|
32
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
33
|
+
const grant = nativeTestPostgresGrant(configured, dockerAvailable);
|
|
34
|
+
if (!grant)
|
|
35
|
+
return undefined;
|
|
36
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_preferred", checkId, `Pre-publication check '${checkId}' is using the dedicated native PostgreSQL test cluster at ${grant.endpoint} with per-run owned databases${dockerAvailable
|
|
37
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
38
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
39
|
+
return grant;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A throwaway cluster of the check's own, whose superuser it holds (owner policy 2026-11-17).
|
|
43
|
+
* If it cannot start, the check falls back to Docker, and to the provisioned cluster only while
|
|
44
|
+
* Docker is down.
|
|
45
|
+
*/
|
|
46
|
+
async function ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral) {
|
|
47
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
48
|
+
let grant;
|
|
49
|
+
try {
|
|
50
|
+
grant = await startEphemeral(configured, dockerAvailable);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
await emit?.(validationEvent("prepublication_prerequisite_ephemeral_unavailable", checkId, `An ephemeral PostgreSQL test cluster could not start for '${checkId}', so it uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_ephemeral", checkId, `Pre-publication check '${checkId}' is using its own ephemeral PostgreSQL test cluster at ${grant.endpoint}, deleted when the check ends${dockerAvailable
|
|
58
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
59
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// The caller releases only a grant it receives, so a failed emit releases it here.
|
|
63
|
+
await grant.release?.().catch(() => undefined);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
return grant;
|
|
67
|
+
}
|
|
68
|
+
function environmentValue(environment, name) {
|
|
69
|
+
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
70
|
+
? environment?.[name]?.trim() ?? ""
|
|
71
|
+
: process.env[name]?.trim() ?? "";
|
|
72
|
+
}
|
|
73
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
74
|
+
export function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
75
|
+
if (checkId === "playwright-e2e") {
|
|
76
|
+
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
77
|
+
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
78
|
+
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
79
|
+
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
80
|
+
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
81
|
+
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
82
|
+
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
83
|
+
}
|
|
84
|
+
return Boolean(postgresAdminConnection);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
88
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
89
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
90
|
+
*/
|
|
91
|
+
export function dockerFreeGrant(grant) {
|
|
92
|
+
return grant?.mode === nativeTestPostgresFallbackDatabaseMode ? grant : undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
96
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
97
|
+
*/
|
|
98
|
+
export async function releaseCheckPostgres(checkId, grant, emit) {
|
|
99
|
+
try {
|
|
100
|
+
await grant?.release?.();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await emit?.(validationEvent("prepublication_ephemeral_release_failed", checkId, `The ephemeral PostgreSQL test cluster for '${checkId}' could not be released and will be reaped later: ${error instanceof Error ? error.message : String(error)}`)).catch(() => undefined);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
107
|
+
export function dockerUnavailableNativeTestPostgres(checkId, requiredPrerequisite, readCluster) {
|
|
108
|
+
return requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(checkId)
|
|
109
|
+
? nativeTestPostgresGrant(readCluster(), false)
|
|
110
|
+
: null;
|
|
111
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
|
|
1
2
|
import type { PrePublicationExecutionContext } from "./pre-publication-validation.js";
|
|
2
3
|
export interface ValidationStep {
|
|
3
4
|
readonly command: string;
|
|
@@ -8,4 +9,4 @@ export interface ValidationStep {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function managedAttemptInvocation(checkId: string, step: ValidationStep, environment?: Readonly<Record<string, string>>): Pick<ValidationStep, "command" | "args">;
|
|
10
11
|
export declare function supportsNativeTestPostgresFallback(checkId: string): boolean;
|
|
11
|
-
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?:
|
|
12
|
+
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: NativeTestPostgresGrant): PrePublicationExecutionContext | undefined;
|
|
@@ -29,21 +29,22 @@ export function supportsNativeTestPostgresFallback(checkId) {
|
|
|
29
29
|
return nativeFallbackCheckIds.has(checkId);
|
|
30
30
|
}
|
|
31
31
|
export function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
32
|
-
// The
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
// Bridge, and E2E steps never do.
|
|
32
|
+
// The grant only exists when the operator provisioned a dedicated native test
|
|
33
|
+
// cluster, and only the runner-authored .NET test tiers and the suite-identity
|
|
34
|
+
// check receive it; build, client, Bridge, and E2E steps never do.
|
|
36
35
|
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
37
36
|
return execution;
|
|
38
37
|
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
39
38
|
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
40
39
|
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
41
40
|
return execution;
|
|
41
|
+
// Re-validate the connection before it reaches attempt code.
|
|
42
|
+
parseNativeTestPostgresFallback(postgresAdminConnection.connectionString);
|
|
42
43
|
return {
|
|
43
44
|
...execution,
|
|
44
45
|
environment: {
|
|
45
46
|
...execution?.environment,
|
|
46
|
-
...nativeTestPostgresFallbackEnvironment(
|
|
47
|
+
...nativeTestPostgresFallbackEnvironment(postgresAdminConnection),
|
|
47
48
|
},
|
|
48
49
|
};
|
|
49
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
-
import type { NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
3
2
|
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
4
3
|
import { type PrePublicationHostLoadOwner } from "./pre-publication-host-load.js";
|
|
4
|
+
import { type NativeTestPostgresFallback, type StartEphemeralTestPostgresGrant } from "./pre-publication-native-postgres.js";
|
|
5
5
|
import { type ValidationStep } from "./pre-publication-step-execution.js";
|
|
6
6
|
import { PrePublicationValidationError, type PrePublicationCheckFailure } from "./pre-publication-pass.js";
|
|
7
7
|
import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
@@ -56,7 +56,8 @@ export declare class PrePublicationValidator {
|
|
|
56
56
|
private readonly dockerEngineProbe?;
|
|
57
57
|
private readonly nativeTestPostgresFallback;
|
|
58
58
|
private readonly hostLoad?;
|
|
59
|
-
|
|
59
|
+
private readonly startEphemeral?;
|
|
60
|
+
constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined, startEphemeral?: StartEphemeralTestPostgresGrant | undefined);
|
|
60
61
|
/**
|
|
61
62
|
* Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
|
|
62
63
|
* can still meaningfully run keeps going, and the pass then throws all of its failures as one
|
|
@@ -66,13 +67,16 @@ export declare class PrePublicationValidator {
|
|
|
66
67
|
private runChecks;
|
|
67
68
|
/** Runs one check's steps in order; the first failed step ends the check, since later steps use its output. */
|
|
68
69
|
private runCheck;
|
|
70
|
+
private runCheckSteps;
|
|
69
71
|
/** Runs a step, confirming once a failure that matches a known transient pattern. */
|
|
70
72
|
private runConfirmedStep;
|
|
71
73
|
private runCheckedStep;
|
|
72
74
|
private confirmStep;
|
|
73
75
|
private confirmInfrastructure;
|
|
74
|
-
/** Returns the native
|
|
76
|
+
/** Returns the native cluster grant when this check uses it instead of Docker. */
|
|
75
77
|
private ensurePrerequisite;
|
|
78
|
+
/** Waits for Docker; returns the native cluster grant when Docker stays down and a cluster is provisioned. */
|
|
79
|
+
private ensureDockerPrerequisite;
|
|
76
80
|
private throwIfPrerequisiteWasLost;
|
|
77
81
|
private checkTestOnlyExports;
|
|
78
82
|
private changedPaths;
|
|
@@ -4,7 +4,8 @@ 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
11
|
import { PrePublicationPass, PrePublicationValidationError, SkippedTestTally, skippedCheckEvent, validationEvent, } from "./pre-publication-pass.js";
|
|
@@ -100,11 +101,13 @@ export class PrePublicationValidator {
|
|
|
100
101
|
dockerEngineProbe;
|
|
101
102
|
nativeTestPostgresFallback;
|
|
102
103
|
hostLoad;
|
|
103
|
-
|
|
104
|
+
startEphemeral;
|
|
105
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad, startEphemeral) {
|
|
104
106
|
this.commands = commands;
|
|
105
107
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
106
108
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
107
109
|
this.hostLoad = hostLoad;
|
|
110
|
+
this.startEphemeral = startEphemeral;
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
|
|
@@ -189,8 +192,16 @@ export class PrePublicationValidator {
|
|
|
189
192
|
if (check.requiredCapability && !run.capabilities.has(check.requiredCapability)) {
|
|
190
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");
|
|
191
194
|
}
|
|
192
|
-
const
|
|
193
|
-
|
|
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;
|
|
194
205
|
await run.emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
|
|
195
206
|
const skipped = new SkippedTestTally(run.worktreePath, run.execution?.environment);
|
|
196
207
|
for (const step of check.steps) {
|
|
@@ -206,7 +217,11 @@ export class PrePublicationValidator {
|
|
|
206
217
|
}
|
|
207
218
|
await skipped.add(result.args, stepStartedMs);
|
|
208
219
|
}
|
|
209
|
-
|
|
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
|
+
]));
|
|
210
225
|
return null;
|
|
211
226
|
}
|
|
212
227
|
/** Runs a step, confirming once a failure that matches a known transient pattern. */
|
|
@@ -255,7 +270,7 @@ export class PrePublicationValidator {
|
|
|
255
270
|
await run.emit?.(validationEvent("prepublication_infrastructure_failed", checkId, `Pre-publication infrastructure for '${checkId}' remained unavailable${detail ? `: ${detail}` : "."}`));
|
|
256
271
|
throw new PrePublicationInfrastructureError(checkId, result.exitCode, result.command, result.args, detail);
|
|
257
272
|
}
|
|
258
|
-
/** Returns the native
|
|
273
|
+
/** Returns the native cluster grant when this check uses it instead of Docker. */
|
|
259
274
|
async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
|
|
260
275
|
if (check.requiredPrerequisite === "isolated_postgres"
|
|
261
276
|
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection)) {
|
|
@@ -264,6 +279,11 @@ export class PrePublicationValidator {
|
|
|
264
279
|
: `Pre-publication check '${check.id}' is using the configured loopback PostgreSQL test server with per-run owned databases. No Docker daemon is required.`));
|
|
265
280
|
return undefined;
|
|
266
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) {
|
|
267
287
|
if (check.requiredPrerequisite === undefined || !this.dockerEngineProbe)
|
|
268
288
|
return undefined;
|
|
269
289
|
const current = this.dockerEngineProbe.current();
|
|
@@ -275,12 +295,10 @@ export class PrePublicationValidator {
|
|
|
275
295
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
276
296
|
if (!snapshot.available) {
|
|
277
297
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
278
|
-
const fallback = check.
|
|
279
|
-
? this.nativeTestPostgresFallback()
|
|
280
|
-
: null;
|
|
298
|
+
const fallback = dockerUnavailableNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback);
|
|
281
299
|
if (fallback) {
|
|
282
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.`));
|
|
283
|
-
return fallback
|
|
301
|
+
return fallback;
|
|
284
302
|
}
|
|
285
303
|
await emit?.(validationEvent("prepublication_prerequisite_unavailable", check.id, `Pre-publication check '${check.id}' is waiting for Docker infrastructure recovery: ${detail}`));
|
|
286
304
|
throw new PrePublicationInfrastructureError(check.id, 75, "docker", ["info"], detail);
|
|
@@ -292,7 +310,7 @@ export class PrePublicationValidator {
|
|
|
292
310
|
if (result.exitCode === 0
|
|
293
311
|
|| check.requiredPrerequisite === undefined
|
|
294
312
|
|| (check.requiredPrerequisite === "isolated_postgres"
|
|
295
|
-
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection))
|
|
313
|
+
&& isolatedPostgresProvided(check.id, environment, dockerFreeGrant(postgresAdminConnection)))
|
|
296
314
|
|| !this.dockerEngineProbe)
|
|
297
315
|
return;
|
|
298
316
|
const snapshot = await this.dockerEngineProbe.refresh(true);
|
|
@@ -435,27 +453,11 @@ export class PrePublicationValidator {
|
|
|
435
453
|
}
|
|
436
454
|
}
|
|
437
455
|
}
|
|
438
|
-
function environmentValue(environment, name) {
|
|
439
|
-
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
440
|
-
? environment?.[name]?.trim() ?? ""
|
|
441
|
-
: process.env[name]?.trim() ?? "";
|
|
442
|
-
}
|
|
443
|
-
function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
444
|
-
if (checkId === "playwright-e2e") {
|
|
445
|
-
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
446
|
-
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
447
|
-
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
448
|
-
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
449
|
-
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
450
|
-
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
451
|
-
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
452
|
-
}
|
|
453
|
-
return Boolean(postgresAdminConnection);
|
|
454
|
-
}
|
|
455
456
|
function validationExactSecrets(environment) {
|
|
456
457
|
return [
|
|
457
|
-
|
|
458
|
-
environment?.[
|
|
458
|
+
// The connection strings and their passwords: a test may print either.
|
|
459
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeTestPostgresAdminEnvironment]),
|
|
460
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeLegacyTestPostgresEnvironment]),
|
|
459
461
|
environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
|
|
460
462
|
...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
|
|
461
463
|
].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ProviderChildEnvironmentOptions {
|
|
2
|
+
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
3
|
+
readonly platform?: NodeJS.Platform;
|
|
4
|
+
readonly homeDir?: string;
|
|
5
|
+
readonly arch?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { normalizeWindowsProviderEnvironment, windowsAllowedProviderParentEnvNames } from "./provider-cli.windows-environment.js";
|
|
3
|
+
// The environment a provider child process starts with: an allowlist of the Bridge's own
|
|
4
|
+
// variables, the request's values, the Windows defaults, then the .NET build-server settings.
|
|
5
|
+
const allowedProviderParentEnvNames = [
|
|
6
|
+
"PATH",
|
|
7
|
+
"HOME",
|
|
8
|
+
"USERPROFILE",
|
|
9
|
+
"TMPDIR",
|
|
10
|
+
"TEMP",
|
|
11
|
+
"TMP",
|
|
12
|
+
"LANG",
|
|
13
|
+
"CLAUDE_CONFIG_DIR"
|
|
14
|
+
];
|
|
15
|
+
export function buildProviderChildEnvironment(requestEnv, options = {}) {
|
|
16
|
+
const parentEnv = options.parentEnv ?? process.env;
|
|
17
|
+
const platform = options.platform ?? process.platform;
|
|
18
|
+
const env = {};
|
|
19
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
20
|
+
if (typeof value === "string" && isAllowedProviderParentEnv(key, platform)) {
|
|
21
|
+
env[key] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (requestEnv) {
|
|
25
|
+
for (const [key, value] of Object.entries(requestEnv)) {
|
|
26
|
+
const trimmedKey = key.trim();
|
|
27
|
+
if (trimmedKey.length > 0) {
|
|
28
|
+
env[trimmedKey] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (platform === "win32") {
|
|
33
|
+
normalizeWindowsProviderEnvironment(env, parentEnv, options.homeDir ?? os.homedir(), options.arch ?? os.arch());
|
|
34
|
+
}
|
|
35
|
+
normalizeProviderBuildEnvironment(env);
|
|
36
|
+
return env;
|
|
37
|
+
}
|
|
38
|
+
function normalizeProviderBuildEnvironment(env) {
|
|
39
|
+
// Provider sessions are long lived and commonly run many dotnet builds. Persistent
|
|
40
|
+
// MSBuild and Roslyn compiler servers otherwise survive individual commands and can
|
|
41
|
+
// retain more memory than the active Forge lane. Keep those caches process-scoped by
|
|
42
|
+
// default on every runner OS; an explicitly supplied request value still wins.
|
|
43
|
+
setCanonicalProviderBuildEnvironmentValue(env, "DOTNET_CLI_USE_MSBUILD_SERVER", "0");
|
|
44
|
+
setCanonicalProviderBuildEnvironmentValue(env, "MSBUILDDISABLENODEREUSE", "1");
|
|
45
|
+
setCanonicalProviderBuildEnvironmentValue(env, "UseSharedCompilation", "false");
|
|
46
|
+
}
|
|
47
|
+
function setCanonicalProviderBuildEnvironmentValue(env, name, value) {
|
|
48
|
+
// The dotnet CLI uses case-sensitive environment lookup on POSIX, while MSBuild
|
|
49
|
+
// property names are case-insensitive on every OS. Collapse request aliases to
|
|
50
|
+
// one canonical key so the explicit value wins without producing ambiguity.
|
|
51
|
+
const exact = env[name];
|
|
52
|
+
const alias = Object.entries(env).find(([key, candidate]) => key !== name
|
|
53
|
+
&& key.toLowerCase() === name.toLowerCase()
|
|
54
|
+
&& typeof candidate === "string"
|
|
55
|
+
&& candidate.trim().length > 0)?.[1];
|
|
56
|
+
const resolved = typeof exact === "string" && exact.trim().length > 0
|
|
57
|
+
? exact
|
|
58
|
+
: alias ?? value;
|
|
59
|
+
for (const key of Object.keys(env)) {
|
|
60
|
+
if (key !== name && key.toLowerCase() === name.toLowerCase()) {
|
|
61
|
+
delete env[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
env[name] = resolved;
|
|
65
|
+
}
|
|
66
|
+
function isAllowedProviderParentEnv(key, platform = process.platform) {
|
|
67
|
+
return isAllowedProviderParentEnvName(key, allowedProviderParentEnvNames)
|
|
68
|
+
|| key.toUpperCase().startsWith("LC_")
|
|
69
|
+
|| (platform === "win32" && isAllowedProviderParentEnvName(key, windowsAllowedProviderParentEnvNames));
|
|
70
|
+
}
|
|
71
|
+
function isAllowedProviderParentEnvName(key, allowedNames) {
|
|
72
|
+
return allowedNames.some((allowed) => allowed.toLowerCase() === key.toLowerCase());
|
|
73
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProviderProcessRunResult } from "./provider-cli.process.js";
|
|
2
|
+
export declare function isCodexModelsCacheSchemaFailure(result: ProviderProcessRunResult): boolean;
|
|
3
|
+
export declare function quarantineIncompatibleCodexModelsCache(requestEnv?: Readonly<Record<string, string>>): Promise<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readEnvironmentValue } from "./provider-cli.windows-environment.js";
|
|
6
|
+
const maximumRecoverableCodexModelsCacheBytes = 16 * 1024 * 1024;
|
|
7
|
+
export function isCodexModelsCacheSchemaFailure(result) {
|
|
8
|
+
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
9
|
+
return output.includes("base_instructions")
|
|
10
|
+
&& output.includes("missing field")
|
|
11
|
+
&& (output.includes("models_cache") || output.includes("models cache") || output.includes("model cache"));
|
|
12
|
+
}
|
|
13
|
+
export async function quarantineIncompatibleCodexModelsCache(requestEnv) {
|
|
14
|
+
const configuredHome = readEnvironmentValue(requestEnv ?? {}, "CODEX_HOME")
|
|
15
|
+
?? readEnvironmentValue(process.env, "CODEX_HOME")
|
|
16
|
+
?? readEnvironmentValue(process.env, "FORGE_CODEX_HOME");
|
|
17
|
+
const codexHome = path.resolve(configuredHome ?? path.join(os.homedir(), ".codex"));
|
|
18
|
+
if (!path.isAbsolute(codexHome) || codexHome === path.parse(codexHome).root)
|
|
19
|
+
return false;
|
|
20
|
+
const cachePath = path.join(codexHome, "models_cache.json");
|
|
21
|
+
const cacheStat = await fs.promises.lstat(cachePath).catch(error => {
|
|
22
|
+
if (error.code === "ENOENT")
|
|
23
|
+
return null;
|
|
24
|
+
throw error;
|
|
25
|
+
});
|
|
26
|
+
if (!cacheStat
|
|
27
|
+
|| !cacheStat.isFile()
|
|
28
|
+
|| cacheStat.isSymbolicLink()
|
|
29
|
+
|| cacheStat.nlink !== 1
|
|
30
|
+
|| cacheStat.size <= 0
|
|
31
|
+
|| cacheStat.size > maximumRecoverableCodexModelsCacheBytes) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const quarantinePath = path.join(codexHome, `models_cache.forge-incompatible-${Date.now()}-${randomUUID()}.json`);
|
|
35
|
+
await fs.promises.rename(cachePath, quarantinePath);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LaunchCommand } from "../../shared/process/windows-launch.js";
|
|
2
2
|
import { ForgeFailureError } from "../session.types.js";
|
|
3
|
+
export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
|
|
4
|
+
export { buildProviderChildEnvironment, type ProviderChildEnvironmentOptions } from "./provider-cli.child-environment.js";
|
|
3
5
|
export declare const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS: number;
|
|
4
6
|
export type ProviderCliCommand = LaunchCommand;
|
|
7
|
+
export { resolveClaudeNpmDirectLaunch, resolveCodexNpmDirectLaunch, resolvePackageManagerDirectLaunch } from "./provider-cli.windows-launch.js";
|
|
5
8
|
export interface ProviderProcessRunRequest {
|
|
6
9
|
readonly command: string;
|
|
7
10
|
readonly args: readonly string[];
|
|
@@ -36,6 +39,8 @@ export interface ProviderProcessRunResult {
|
|
|
36
39
|
readonly cancelled?: true;
|
|
37
40
|
/** Present when Forge stopped a provider that stayed resident after its turn ended. */
|
|
38
41
|
readonly terminalStopReason?: ProviderTerminalStopReason;
|
|
42
|
+
/** Present when Forge closed output pipes a descendant still held after the provider exited. */
|
|
43
|
+
readonly outputPipesReleasedAfterExit?: true;
|
|
39
44
|
}
|
|
40
45
|
export interface ProviderProcessRunner {
|
|
41
46
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
@@ -89,17 +94,12 @@ export declare class CodexResumeRecoveringProcessRunner implements ProviderProce
|
|
|
89
94
|
* arbitrary tool/command output and therefore cannot mint retry authority.
|
|
90
95
|
*/
|
|
91
96
|
export declare function isTransientCodexProviderNotFoundFailure(command: string, result: ProviderProcessRunResult): boolean;
|
|
92
|
-
interface ProviderChildEnvironmentOptions {
|
|
93
|
-
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
94
|
-
readonly platform?: NodeJS.Platform;
|
|
95
|
-
readonly homeDir?: string;
|
|
96
|
-
}
|
|
97
|
-
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
98
97
|
export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
|
|
99
98
|
private readonly terminalExitGraceMs;
|
|
100
99
|
private readonly terminalSuccessCeilingMs;
|
|
101
100
|
private readonly terminalWorkPollMs;
|
|
102
|
-
|
|
101
|
+
private readonly outputPipeReleaseGraceMs;
|
|
102
|
+
constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number, outputPipeReleaseGraceMs?: number);
|
|
103
103
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -112,25 +112,3 @@ export declare function providerCompletionToolMissingFailure(message: string, re
|
|
|
112
112
|
export declare function processGroupResidentMemoryBytes(processGroupId: number, platform?: NodeJS.Platform, procRoot?: string): number | null;
|
|
113
113
|
export declare const UNIX_PROVIDER_START_GRANT_LINE = "forge-provider-start-granted\n";
|
|
114
114
|
export declare function buildUnixProviderStartGateLaunch(command: string, args: readonly string[]): LaunchCommand;
|
|
115
|
-
export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
116
|
-
/**
|
|
117
|
-
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|
|
118
|
-
* PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
|
|
119
|
-
* ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
|
|
120
|
-
*/
|
|
121
|
-
export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
122
|
-
/**
|
|
123
|
-
* Avoids cmd.exe's nested-quote handling for package-manager shims. That
|
|
124
|
-
* quoting loses executable paths containing spaces after the command is
|
|
125
|
-
* wrapped by the Windows Job Object supervisor.
|
|
126
|
-
*/
|
|
127
|
-
export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
128
|
-
/**
|
|
129
|
-
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
130
|
-
* happen while the machine is under enough process pressure for where.exe to
|
|
131
|
-
* miss its timeout; returning the unresolved package-manager name in that case
|
|
132
|
-
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
133
|
-
*/
|
|
134
|
-
export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string): string | null;
|
|
135
|
-
export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
|
|
136
|
-
export {};
|