@loucompanion/forge-bridge 0.1.4-dev.b1c678efffd2 → 0.1.4-dev.bb5355d0d83f
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 +13 -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 +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.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-pass.d.ts +2 -1
- package/dist/session/pre-publication-pass.js +8 -5
- 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 +9 -3
- package/dist/session/pre-publication-validation.js +62 -34
- 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 +6 -16
- package/dist/session/provider-cli/provider-cli.process.js +22 -283
- 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-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/sandbox-host-capacity-gate.js +12 -3
- 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
|
+
}
|
|
@@ -29,7 +29,8 @@ export declare class PrePublicationValidationError extends ForgeFailureError {
|
|
|
29
29
|
export declare class PrePublicationPass {
|
|
30
30
|
private readonly runtimeRestartFailure?;
|
|
31
31
|
private readonly failures;
|
|
32
|
-
|
|
32
|
+
/** The check whose .NET build failed to compile in this pass, if any. */
|
|
33
|
+
private dotnetCompileFailedIn;
|
|
33
34
|
/** A failed runtime restart before the pass is its first failure. */
|
|
34
35
|
constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
|
|
35
36
|
record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
|
|
@@ -7,7 +7,9 @@ import { ForgeFailureError, failureFactsFromError } from "./session.types.js";
|
|
|
7
7
|
// could not run because a check they depend on failed, and reports them all as one failure.
|
|
8
8
|
/** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
|
|
9
9
|
export const runtimeRestartCheckId = "host-runtime-restart";
|
|
10
|
-
|
|
10
|
+
// The checks whose first step builds the .NET solution: CI's whole-tier check and the affected
|
|
11
|
+
// tests every gate profile runs (decision 0017).
|
|
12
|
+
const dotnetBuildCheckIds = new Set(["dotnet-build-and-unit", "comment-repair-dotnet-regression"]);
|
|
11
13
|
// Checks that build the .NET solution themselves and would only repeat the compiler errors once its
|
|
12
14
|
// compile step fails: the OpenAPI export builds Forge.Api and the E2E suite publishes it.
|
|
13
15
|
const dotnetBuildConsumers = new Set(["openapi-and-generated-types", "playwright-e2e"]);
|
|
@@ -62,7 +64,8 @@ function clipDetail(detail) {
|
|
|
62
64
|
export class PrePublicationPass {
|
|
63
65
|
runtimeRestartFailure;
|
|
64
66
|
failures = [];
|
|
65
|
-
|
|
67
|
+
/** The check whose .NET build failed to compile in this pass, if any. */
|
|
68
|
+
dotnetCompileFailedIn = null;
|
|
66
69
|
/** A failed runtime restart before the pass is its first failure. */
|
|
67
70
|
constructor(runtimeRestartFailure) {
|
|
68
71
|
this.runtimeRestartFailure = runtimeRestartFailure;
|
|
@@ -70,14 +73,14 @@ export class PrePublicationPass {
|
|
|
70
73
|
}
|
|
71
74
|
record(failure, failedStep) {
|
|
72
75
|
this.failures.push(failure);
|
|
73
|
-
if (failure.checkId
|
|
74
|
-
this.
|
|
76
|
+
if (dotnetBuildCheckIds.has(failure.checkId) && failedStep?.command === "dotnet" && failedStep.args[0] === "build") {
|
|
77
|
+
this.dotnetCompileFailedIn ??= failure.checkId;
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
/** The failed checks that keep this check from running meaningfully in this pass. */
|
|
78
81
|
blockers(checkId) {
|
|
79
82
|
return [
|
|
80
|
-
...(this.
|
|
83
|
+
...(this.dotnetCompileFailedIn && dotnetBuildConsumers.has(checkId) ? [this.dotnetCompileFailedIn] : []),
|
|
81
84
|
...(this.runtimeRestartFailure && runtimeStackConsumers.has(checkId) ? [runtimeRestartCheckId] : []),
|
|
82
85
|
];
|
|
83
86
|
}
|
|
@@ -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,17 +67,22 @@ 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;
|
|
79
83
|
private assertContractMatchesDispatchBaseline;
|
|
84
|
+
/** The approved contract of the branch an in-progress merge brings in (MERGE_HEAD), else null. */
|
|
85
|
+
private mergedInContractDigest;
|
|
80
86
|
private runStep;
|
|
81
87
|
private launchStep;
|
|
82
88
|
private runCommand;
|
|
@@ -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";
|
|
@@ -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",
|
|
@@ -95,11 +101,13 @@ export class PrePublicationValidator {
|
|
|
95
101
|
dockerEngineProbe;
|
|
96
102
|
nativeTestPostgresFallback;
|
|
97
103
|
hostLoad;
|
|
98
|
-
|
|
104
|
+
startEphemeral;
|
|
105
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad, startEphemeral) {
|
|
99
106
|
this.commands = commands;
|
|
100
107
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
101
108
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
102
109
|
this.hostLoad = hostLoad;
|
|
110
|
+
this.startEphemeral = startEphemeral;
|
|
103
111
|
}
|
|
104
112
|
/**
|
|
105
113
|
* Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
|
|
@@ -139,7 +147,7 @@ export class PrePublicationValidator {
|
|
|
139
147
|
capabilities,
|
|
140
148
|
emit,
|
|
141
149
|
signal,
|
|
142
|
-
execution: scoped.execution,
|
|
150
|
+
execution: withValidationBaseRevision(scoped.execution),
|
|
143
151
|
postgresAdminConnection: scoped.postgresAdminConnection,
|
|
144
152
|
};
|
|
145
153
|
return await this.runChecks(applicableChecks(contract, profile, changedPaths), run, pass);
|
|
@@ -184,8 +192,16 @@ export class PrePublicationValidator {
|
|
|
184
192
|
if (check.requiredCapability && !run.capabilities.has(check.requiredCapability)) {
|
|
185
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");
|
|
186
194
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
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;
|
|
189
205
|
await run.emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
|
|
190
206
|
const skipped = new SkippedTestTally(run.worktreePath, run.execution?.environment);
|
|
191
207
|
for (const step of check.steps) {
|
|
@@ -201,7 +217,11 @@ export class PrePublicationValidator {
|
|
|
201
217
|
}
|
|
202
218
|
await skipped.add(result.args, stepStartedMs);
|
|
203
219
|
}
|
|
204
|
-
|
|
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
|
+
]));
|
|
205
225
|
return null;
|
|
206
226
|
}
|
|
207
227
|
/** Runs a step, confirming once a failure that matches a known transient pattern. */
|
|
@@ -250,7 +270,7 @@ export class PrePublicationValidator {
|
|
|
250
270
|
await run.emit?.(validationEvent("prepublication_infrastructure_failed", checkId, `Pre-publication infrastructure for '${checkId}' remained unavailable${detail ? `: ${detail}` : "."}`));
|
|
251
271
|
throw new PrePublicationInfrastructureError(checkId, result.exitCode, result.command, result.args, detail);
|
|
252
272
|
}
|
|
253
|
-
/** Returns the native
|
|
273
|
+
/** Returns the native cluster grant when this check uses it instead of Docker. */
|
|
254
274
|
async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
|
|
255
275
|
if (check.requiredPrerequisite === "isolated_postgres"
|
|
256
276
|
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection)) {
|
|
@@ -259,6 +279,11 @@ export class PrePublicationValidator {
|
|
|
259
279
|
: `Pre-publication check '${check.id}' is using the configured loopback PostgreSQL test server with per-run owned databases. No Docker daemon is required.`));
|
|
260
280
|
return undefined;
|
|
261
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) {
|
|
262
287
|
if (check.requiredPrerequisite === undefined || !this.dockerEngineProbe)
|
|
263
288
|
return undefined;
|
|
264
289
|
const current = this.dockerEngineProbe.current();
|
|
@@ -270,12 +295,10 @@ export class PrePublicationValidator {
|
|
|
270
295
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
271
296
|
if (!snapshot.available) {
|
|
272
297
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
273
|
-
const fallback = check.
|
|
274
|
-
? this.nativeTestPostgresFallback()
|
|
275
|
-
: null;
|
|
298
|
+
const fallback = dockerUnavailableNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback);
|
|
276
299
|
if (fallback) {
|
|
277
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.`));
|
|
278
|
-
return fallback
|
|
301
|
+
return fallback;
|
|
279
302
|
}
|
|
280
303
|
await emit?.(validationEvent("prepublication_prerequisite_unavailable", check.id, `Pre-publication check '${check.id}' is waiting for Docker infrastructure recovery: ${detail}`));
|
|
281
304
|
throw new PrePublicationInfrastructureError(check.id, 75, "docker", ["info"], detail);
|
|
@@ -287,7 +310,7 @@ export class PrePublicationValidator {
|
|
|
287
310
|
if (result.exitCode === 0
|
|
288
311
|
|| check.requiredPrerequisite === undefined
|
|
289
312
|
|| (check.requiredPrerequisite === "isolated_postgres"
|
|
290
|
-
&& isolatedPostgresProvided(check.id, environment, postgresAdminConnection))
|
|
313
|
+
&& isolatedPostgresProvided(check.id, environment, dockerFreeGrant(postgresAdminConnection)))
|
|
291
314
|
|| !this.dockerEngineProbe)
|
|
292
315
|
return;
|
|
293
316
|
const snapshot = await this.dockerEngineProbe.refresh(true);
|
|
@@ -353,10 +376,24 @@ export class PrePublicationValidator {
|
|
|
353
376
|
if (!approvedContractDigests.has(baselineDigest)) {
|
|
354
377
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the dispatch baseline uses unapproved CI parity contract ${baselineDigest}.`, "bridge");
|
|
355
378
|
}
|
|
356
|
-
|
|
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) {
|
|
357
381
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
|
|
358
382
|
}
|
|
359
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
|
+
}
|
|
360
397
|
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
|
|
361
398
|
const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
|
|
362
399
|
// Every launch, including confirmation reruns, is admitted by the host load governor first.
|
|
@@ -416,27 +453,11 @@ export class PrePublicationValidator {
|
|
|
416
453
|
}
|
|
417
454
|
}
|
|
418
455
|
}
|
|
419
|
-
function environmentValue(environment, name) {
|
|
420
|
-
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
421
|
-
? environment?.[name]?.trim() ?? ""
|
|
422
|
-
: process.env[name]?.trim() ?? "";
|
|
423
|
-
}
|
|
424
|
-
function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
425
|
-
if (checkId === "playwright-e2e") {
|
|
426
|
-
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
427
|
-
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
428
|
-
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
429
|
-
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
430
|
-
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
431
|
-
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
432
|
-
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
433
|
-
}
|
|
434
|
-
return Boolean(postgresAdminConnection);
|
|
435
|
-
}
|
|
436
456
|
function validationExactSecrets(environment) {
|
|
437
457
|
return [
|
|
438
|
-
|
|
439
|
-
environment?.[
|
|
458
|
+
// The connection strings and their passwords: a test may print either.
|
|
459
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeTestPostgresAdminEnvironment]),
|
|
460
|
+
...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeLegacyTestPostgresEnvironment]),
|
|
440
461
|
environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
|
|
441
462
|
...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
|
|
442
463
|
].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
@@ -626,6 +647,13 @@ export async function loadValidationContract(worktreePath) {
|
|
|
626
647
|
}
|
|
627
648
|
return contract;
|
|
628
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
|
+
}
|
|
629
657
|
function validationContractDigest(contract) {
|
|
630
658
|
return createHash("sha256")
|
|
631
659
|
.update(JSON.stringify(canonicalizeJson(contract)))
|
|
@@ -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
|
+
}
|