@loucompanion/forge-bridge 0.1.4-dev.83728c550770 → 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 +32 -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/cli/cli.service.d.ts +11 -0
- package/dist/cli/cli.service.js +80 -12
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +19 -3
- 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 +2 -2
- package/dist/runtime/host-runtime-lease.js +9 -8
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- 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.runtime.js +1 -1
- 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 +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -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 +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +45 -8
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -7
- package/dist/session/provider-cli/provider-cli.service.js +66 -243
- 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 +3 -3
- 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 +2 -2
|
@@ -23,7 +23,7 @@ import { AttemptNodeRuntimeLauncher } from "./attempt-node-runtime-launcher.js";
|
|
|
23
23
|
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
24
24
|
import { RecoveryStabilizedMemory, buildMemoryAdmissionDiagnostics, resolveAdaptiveMemoryReserveBytes, } from "./memory-capacity.js";
|
|
25
25
|
import { PlaywrightHostRuntimeAdapter } from "./playwright-host-runtime-adapter.js";
|
|
26
|
-
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "./host-runtime-promotion.js";
|
|
26
|
+
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, readmitHostRuntimeContract, } from "./host-runtime-promotion.js";
|
|
27
27
|
import { ExactHostProcessRecovery, } from "../shared/process/host-process-recovery.js";
|
|
28
28
|
import { resetGeneratedOutputs } from "./generated-output-reset.js";
|
|
29
29
|
import { assertCanonicalDirectory, createCanonicalDirectory } from "./attempt-private-directory.js";
|
|
@@ -71,7 +71,7 @@ export class HostRuntimeLeaseManager {
|
|
|
71
71
|
capacityConfiguration;
|
|
72
72
|
memoryAvailability;
|
|
73
73
|
executionRoot;
|
|
74
|
-
/** Host-wide admission for heavy steps (
|
|
74
|
+
/** Host-wide admission for heavy steps (decisions 0013, 0018): the host test slot, and the budget when on. */
|
|
75
75
|
hostLoadGovernor;
|
|
76
76
|
requirementsCheck = null;
|
|
77
77
|
/** Installs the decision 0013 accept-time requirements recheck for host attempts. */
|
|
@@ -1418,12 +1418,13 @@ export class HostRuntimeLeaseManager {
|
|
|
1418
1418
|
}
|
|
1419
1419
|
}
|
|
1420
1420
|
async runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
|
|
1421
|
-
// The relaunch
|
|
1422
|
-
//
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1421
|
+
// The relaunch keeps the admission granted at start. A workspace contract that changed only its
|
|
1422
|
+
// launch environment is adopted; any other change throws host_runtime_contract_changed.
|
|
1423
|
+
const readmitted = readmitHostRuntimeContract(active, await loadHostRuntimeContract(active.lease.worktreePath));
|
|
1424
|
+
active.runtimeContract = readmitted.runtimeContract;
|
|
1425
|
+
active.runtimeContractFingerprint = readmitted.runtimeContractFingerprint;
|
|
1426
|
+
if (readmitted.changed) {
|
|
1427
|
+
await onProjectCheckpoint?.({ code: "host_runtime_contract_readmitted", message: "The workspace's runtime contract changed only its launch environment; the restart runs it under the admission granted at start." });
|
|
1427
1428
|
}
|
|
1428
1429
|
const portNames = active.executionClass === "analysis_only" ? [] : configuredLaunchPortNames(active.runtimeContract);
|
|
1429
1430
|
const pendingPort = portNames.find(name => active.pendingAdapterLaunches.has(name));
|
|
@@ -28,5 +28,28 @@ export declare class HostParallelPromotionStore {
|
|
|
28
28
|
private recordPath;
|
|
29
29
|
}
|
|
30
30
|
export declare function hostRuntimeContractFingerprint(runtimeContract: LoadedHostRuntimeContract): string;
|
|
31
|
+
export interface ReadmittedHostRuntimeContract {
|
|
32
|
+
readonly runtimeContract: LoadedHostRuntimeContract;
|
|
33
|
+
readonly runtimeContractFingerprint: string;
|
|
34
|
+
readonly changed: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decides whether a restart may run the workspace's current runtime contract under the admission
|
|
38
|
+
* granted at start. A restart relaunches from the workspace in any case, so a contract whose only
|
|
39
|
+
* change is the values its ports launch with (launch environment, or discovery inputs that leave
|
|
40
|
+
* the contract itself unchanged) is adopted. This is how a conflict repair survives its own merge:
|
|
41
|
+
* merging the target branch can rename a variable in a derived launch profile, or change a
|
|
42
|
+
* manifest or project file, without changing anything admission granted. Every other part of the
|
|
43
|
+
* contract is admission: source, concurrency, ports (names, adapters, environment names, URL
|
|
44
|
+
* formats, and the command, arguments and working directory that launch them), Playwright, browser
|
|
45
|
+
* profile, singleton resources and declared requirements. Changing any of those throws the
|
|
46
|
+
* retryable host_runtime_contract_changed, so only a fresh attempt runs that contract. An attempt
|
|
47
|
+
* admitted to run in parallel keeps that admission, as it does when a merge changes only source;
|
|
48
|
+
* a restart never promotes, so the adopted contract earns no parallel-safety proof of its own here.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readmitHostRuntimeContract(admitted: {
|
|
51
|
+
readonly runtimeContract: LoadedHostRuntimeContract;
|
|
52
|
+
readonly runtimeContractFingerprint: string;
|
|
53
|
+
}, current: LoadedHostRuntimeContract): ReadmittedHostRuntimeContract;
|
|
31
54
|
export declare function hostRuntimeParallelEligible(runtimeContract: LoadedHostRuntimeContract): boolean;
|
|
32
55
|
export declare function configuredLaunchPortNames(runtimeContract: LoadedHostRuntimeContract): readonly string[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
4
5
|
/** Persists only observed, contract-bound host parallel-safety evidence. */
|
|
5
6
|
export class HostParallelPromotionStore {
|
|
6
7
|
stateRoot;
|
|
@@ -154,6 +155,41 @@ export function hostRuntimeContractFingerprint(runtimeContract) {
|
|
|
154
155
|
});
|
|
155
156
|
return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
|
|
156
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Decides whether a restart may run the workspace's current runtime contract under the admission
|
|
160
|
+
* granted at start. A restart relaunches from the workspace in any case, so a contract whose only
|
|
161
|
+
* change is the values its ports launch with (launch environment, or discovery inputs that leave
|
|
162
|
+
* the contract itself unchanged) is adopted. This is how a conflict repair survives its own merge:
|
|
163
|
+
* merging the target branch can rename a variable in a derived launch profile, or change a
|
|
164
|
+
* manifest or project file, without changing anything admission granted. Every other part of the
|
|
165
|
+
* contract is admission: source, concurrency, ports (names, adapters, environment names, URL
|
|
166
|
+
* formats, and the command, arguments and working directory that launch them), Playwright, browser
|
|
167
|
+
* profile, singleton resources and declared requirements. Changing any of those throws the
|
|
168
|
+
* retryable host_runtime_contract_changed, so only a fresh attempt runs that contract. An attempt
|
|
169
|
+
* admitted to run in parallel keeps that admission, as it does when a merge changes only source;
|
|
170
|
+
* a restart never promotes, so the adopted contract earns no parallel-safety proof of its own here.
|
|
171
|
+
*/
|
|
172
|
+
export function readmitHostRuntimeContract(admitted, current) {
|
|
173
|
+
const runtimeContractFingerprint = hostRuntimeContractFingerprint(current);
|
|
174
|
+
// The fingerprint leaves out the source of a project or default contract, but parallel
|
|
175
|
+
// eligibility depends on it, so an unchanged fingerprint alone does not prove the same admission.
|
|
176
|
+
if (runtimeContractFingerprint === admitted.runtimeContractFingerprint && current.source === admitted.runtimeContract.source) {
|
|
177
|
+
return { runtimeContract: admitted.runtimeContract, runtimeContractFingerprint, changed: false };
|
|
178
|
+
}
|
|
179
|
+
if (hostRuntimeAdmissionShape(current) !== hostRuntimeAdmissionShape(admitted.runtimeContract)) {
|
|
180
|
+
throw new ForgeFailureError("host_runtime_contract_changed", "host_runtime_contract_changed: the workspace's runtime contract changed after this attempt's runtime was admitted; a fresh attempt is needed to run it.");
|
|
181
|
+
}
|
|
182
|
+
return { runtimeContract: current, runtimeContractFingerprint, changed: true };
|
|
183
|
+
}
|
|
184
|
+
function hostRuntimeAdmissionShape(runtimeContract) {
|
|
185
|
+
const runtime = runtimeContract.contract.runtime;
|
|
186
|
+
return JSON.stringify({
|
|
187
|
+
source: runtimeContract.source,
|
|
188
|
+
schemaVersion: runtimeContract.contract.schemaVersion,
|
|
189
|
+
runtime: { ...runtime, ports: runtime.ports.map(port => ({ ...port, launch: port.launch && { ...port.launch, environment: undefined } })) },
|
|
190
|
+
...requirementsFingerprintPart(runtimeContract.contract.requires),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
157
193
|
// Cost hints are estimates, not placement constraints: they never change the fingerprint.
|
|
158
194
|
function requirementsFingerprintPart(requires) {
|
|
159
195
|
if (!requires)
|
|
@@ -2,15 +2,51 @@ export declare const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE
|
|
|
2
2
|
export declare const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
|
|
3
3
|
export declare const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
5
|
+
* The cluster serves the shared test server while Docker is up, so tests that need a
|
|
6
|
+
* pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
|
|
7
|
+
* first, which keeps test databases out of the Docker VM and saves RAM.
|
|
8
|
+
*/
|
|
9
|
+
export declare const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
|
|
10
|
+
export type NativeTestPostgresDatabaseMode = typeof nativeTestPostgresFallbackDatabaseMode | typeof nativeTestPostgresPreferredDatabaseMode;
|
|
11
|
+
/**
|
|
12
|
+
* What runner-authored .NET test tiers get: `preferred` (the default) the provisioned
|
|
13
|
+
* cluster whenever it is configured; `docker_unavailable` that cluster only after a
|
|
14
|
+
* Docker probe fails; `ephemeral` a throwaway cluster of their own for each check, whose
|
|
15
|
+
* bootstrap superuser they hold (owner policy 2026-11-17). The provisioned cluster still
|
|
16
|
+
* hosts the attempt database broker in every mode.
|
|
17
|
+
*/
|
|
18
|
+
export type NativeTestPostgresUse = "preferred" | "docker_unavailable" | "ephemeral";
|
|
19
|
+
/**
|
|
20
|
+
* A dedicated, operator-provisioned PostgreSQL cluster for runner-authored .NET
|
|
21
|
+
* test tiers, preferred over Docker unless its file says `docker_unavailable`.
|
|
22
|
+
* The cluster must hold nothing but disposable test databases, so its capability
|
|
23
|
+
* carries no more authority than the attempt-private container it replaces.
|
|
9
24
|
*/
|
|
10
25
|
export interface NativeTestPostgresFallback {
|
|
11
26
|
readonly connectionString: string;
|
|
12
27
|
readonly endpoint: string;
|
|
28
|
+
readonly use: NativeTestPostgresUse;
|
|
29
|
+
/** The PostgreSQL bin directory an ephemeral cluster runs from; defaults to the one beside psql. */
|
|
30
|
+
readonly postgresBin?: string;
|
|
13
31
|
}
|
|
32
|
+
/** The cluster as handed to one test process, with the mode its fixtures run in. */
|
|
33
|
+
export interface NativeTestPostgresGrant {
|
|
34
|
+
readonly connectionString: string;
|
|
35
|
+
readonly endpoint: string;
|
|
36
|
+
readonly mode: NativeTestPostgresDatabaseMode;
|
|
37
|
+
/** Set when the grant is a throwaway cluster of its own; the server reports it as `forge.ephemeral_cluster`. */
|
|
38
|
+
readonly ephemeralClusterId?: string;
|
|
39
|
+
/** Stops and deletes an ephemeral cluster once its check has finished. */
|
|
40
|
+
readonly release?: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The provisioned cluster's grant for a check that can use it, or null to use Docker. A
|
|
44
|
+
* preferred cluster is granted whether or not Docker is up; the mode says which, because
|
|
45
|
+
* only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
|
|
46
|
+
* normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
|
|
47
|
+
* start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function nativeTestPostgresGrant(fallback: NativeTestPostgresFallback | null, dockerAvailable: boolean): NativeTestPostgresGrant | null;
|
|
14
50
|
export declare class NativeTestPostgresFallbackError extends Error {
|
|
15
51
|
readonly code = "native_test_postgres_fallback_invalid";
|
|
16
52
|
constructor(detail: string);
|
|
@@ -20,6 +56,14 @@ export declare function resolveNativeTestPostgresFallbackPath(): string;
|
|
|
20
56
|
export declare function configuredNativeTestPostgresFallbackPath(): string | null;
|
|
21
57
|
/** Returns null when no fallback is configured; throws when one is configured unsafely. */
|
|
22
58
|
export declare function readNativeTestPostgresFallback(configPath?: string): NativeTestPostgresFallback | null;
|
|
23
|
-
export declare function parseNativeTestPostgresFallback(connectionString: string): NativeTestPostgresFallback;
|
|
24
|
-
/** Environment for one runner-authored .NET test process using the
|
|
25
|
-
export declare function nativeTestPostgresFallbackEnvironment(
|
|
59
|
+
export declare function parseNativeTestPostgresFallback(connectionString: string, use?: NativeTestPostgresUse): NativeTestPostgresFallback;
|
|
60
|
+
/** Environment for one runner-authored .NET test process using the cluster. */
|
|
61
|
+
export declare function nativeTestPostgresFallbackEnvironment(grant: Pick<NativeTestPostgresGrant, "connectionString" | "mode" | "ephemeralClusterId">): Readonly<Record<string, string>>;
|
|
62
|
+
/**
|
|
63
|
+
* Runner-authored verification uses the operator-provisioned native test cluster,
|
|
64
|
+
* which holds no real data, whenever its file prefers it (the default); Docker then
|
|
65
|
+
* only starts pinned-engine containers. A `docker_unavailable` cluster is used only
|
|
66
|
+
* when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
|
|
67
|
+
* database serves.
|
|
68
|
+
*/
|
|
69
|
+
export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
|
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { resolveLocalConfigPath } from "../cli/local-config.js";
|
|
4
|
+
import { DockerEngineProbe } from "./docker-engine-probe.js";
|
|
5
|
+
import { ephemeralTestPostgresClusterEnvironment } from "./ephemeral-test-postgres.js";
|
|
4
6
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "./host-runtime-contract.js";
|
|
5
7
|
export const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE_TEST_POSTGRES_CONFIG";
|
|
6
8
|
export const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
|
|
7
9
|
export const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
|
|
10
|
+
/**
|
|
11
|
+
* The cluster serves the shared test server while Docker is up, so tests that need a
|
|
12
|
+
* pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
|
|
13
|
+
* first, which keeps test databases out of the Docker VM and saves RAM.
|
|
14
|
+
*/
|
|
15
|
+
export const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
|
|
16
|
+
const nativeTestPostgresUses = ["preferred", "docker_unavailable", "ephemeral"];
|
|
8
17
|
const defaultPostgresPort = 5432;
|
|
9
18
|
const loopbackHosts = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
19
|
+
/**
|
|
20
|
+
* The provisioned cluster's grant for a check that can use it, or null to use Docker. A
|
|
21
|
+
* preferred cluster is granted whether or not Docker is up; the mode says which, because
|
|
22
|
+
* only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
|
|
23
|
+
* normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
|
|
24
|
+
* start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
|
|
25
|
+
*/
|
|
26
|
+
export function nativeTestPostgresGrant(fallback, dockerAvailable) {
|
|
27
|
+
if (!fallback || (dockerAvailable && fallback.use !== "preferred"))
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
connectionString: fallback.connectionString,
|
|
31
|
+
endpoint: fallback.endpoint,
|
|
32
|
+
mode: dockerAvailable ? nativeTestPostgresPreferredDatabaseMode : nativeTestPostgresFallbackDatabaseMode,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
10
35
|
export class NativeTestPostgresFallbackError extends Error {
|
|
11
36
|
code = "native_test_postgres_fallback_invalid";
|
|
12
37
|
constructor(detail) {
|
|
@@ -46,9 +71,17 @@ export function readNativeTestPostgresFallback(configPath = resolveNativeTestPos
|
|
|
46
71
|
if (document.schemaVersion !== 1 || typeof document.connectionString !== "string") {
|
|
47
72
|
throw new NativeTestPostgresFallbackError(`${configPath} must contain schemaVersion 1 and a connectionString.`);
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
if (document.use !== undefined && !nativeTestPostgresUses.includes(document.use)) {
|
|
75
|
+
throw new NativeTestPostgresFallbackError(`${configPath} 'use' must be 'preferred', 'docker_unavailable' or 'ephemeral'.`);
|
|
76
|
+
}
|
|
77
|
+
if (document.postgresBin !== undefined
|
|
78
|
+
&& (typeof document.postgresBin !== "string" || !path.isAbsolute(document.postgresBin))) {
|
|
79
|
+
throw new NativeTestPostgresFallbackError(`${configPath} 'postgresBin' must be an absolute path.`);
|
|
80
|
+
}
|
|
81
|
+
const fallback = parseNativeTestPostgresFallback(document.connectionString, document.use ?? "preferred");
|
|
82
|
+
return typeof document.postgresBin === "string" ? { ...fallback, postgresBin: document.postgresBin } : fallback;
|
|
50
83
|
}
|
|
51
|
-
export function parseNativeTestPostgresFallback(connectionString) {
|
|
84
|
+
export function parseNativeTestPostgresFallback(connectionString, use = "preferred") {
|
|
52
85
|
const fields = new Map();
|
|
53
86
|
for (const segment of connectionString.split(";")) {
|
|
54
87
|
const separator = segment.indexOf("=");
|
|
@@ -79,13 +112,32 @@ export function parseNativeTestPostgresFallback(connectionString) {
|
|
|
79
112
|
if (!(fields.get("username") ?? fields.get("userid") ?? fields.get("user"))) {
|
|
80
113
|
throw new NativeTestPostgresFallbackError("the fallback must name a dedicated test role.");
|
|
81
114
|
}
|
|
82
|
-
return { connectionString: connectionString.trim(), endpoint: `${host}:${port}
|
|
115
|
+
return { connectionString: connectionString.trim(), endpoint: `${host}:${port}`, use };
|
|
83
116
|
}
|
|
84
|
-
/** Environment for one runner-authored .NET test process using the
|
|
85
|
-
export function nativeTestPostgresFallbackEnvironment(
|
|
117
|
+
/** Environment for one runner-authored .NET test process using the cluster. */
|
|
118
|
+
export function nativeTestPostgresFallbackEnvironment(grant) {
|
|
86
119
|
return {
|
|
87
|
-
[hostRuntimeTestPostgresAdminEnvironment]:
|
|
88
|
-
[hostRuntimeLegacyTestPostgresEnvironment]:
|
|
89
|
-
FORGE_MANAGED_VERIFICATION_DATABASE_MODE:
|
|
120
|
+
[hostRuntimeTestPostgresAdminEnvironment]: grant.connectionString,
|
|
121
|
+
[hostRuntimeLegacyTestPostgresEnvironment]: grant.connectionString,
|
|
122
|
+
FORGE_MANAGED_VERIFICATION_DATABASE_MODE: grant.mode,
|
|
123
|
+
// The fixtures accept a superuser login only on the cluster that reports this id.
|
|
124
|
+
...(grant.ephemeralClusterId ? { [ephemeralTestPostgresClusterEnvironment]: grant.ephemeralClusterId } : {}),
|
|
90
125
|
};
|
|
91
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Runner-authored verification uses the operator-provisioned native test cluster,
|
|
129
|
+
* which holds no real data, whenever its file prefers it (the default); Docker then
|
|
130
|
+
* only starts pinned-engine containers. A `docker_unavailable` cluster is used only
|
|
131
|
+
* when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
|
|
132
|
+
* database serves.
|
|
133
|
+
*/
|
|
134
|
+
export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().probeWithoutRecovery()).available, readFallback = () => {
|
|
135
|
+
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
136
|
+
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
137
|
+
}) {
|
|
138
|
+
const fallback = readFallback();
|
|
139
|
+
if (!fallback)
|
|
140
|
+
return {};
|
|
141
|
+
const grant = nativeTestPostgresGrant(fallback, await dockerAvailable());
|
|
142
|
+
return grant ? nativeTestPostgresFallbackEnvironment(grant) : {};
|
|
143
|
+
}
|
|
@@ -9,7 +9,7 @@ export declare const sandboxHostCapacityResponseRoot = "/run/forge/host-capacity
|
|
|
9
9
|
export declare const sandboxHostCapacityResponseOwnerUid = 0;
|
|
10
10
|
export declare const sandboxHostCapacityMaxWaitEnvironment = "FORGE_HOST_LOAD_BROKER_MAX_WAIT_MS";
|
|
11
11
|
export interface SandboxHostCapacityRequest {
|
|
12
|
-
readonly action: "acquire" | "release";
|
|
12
|
+
readonly action: "acquire" | "release" | "retain";
|
|
13
13
|
readonly requestId: string;
|
|
14
14
|
readonly stepClass: string;
|
|
15
15
|
readonly label: string;
|
|
@@ -82,6 +82,12 @@ export declare class SandboxHostCapacityBroker {
|
|
|
82
82
|
private takeAllowance;
|
|
83
83
|
private track;
|
|
84
84
|
private acquire;
|
|
85
|
+
/**
|
|
86
|
+
* The sandbox's step ended but part of its tree may still run: the host token is
|
|
87
|
+
* kept, marked retained (so the attempt's own next step does not wait for it),
|
|
88
|
+
* until the sandbox releases the request or exits.
|
|
89
|
+
*/
|
|
90
|
+
private retain;
|
|
85
91
|
private release;
|
|
86
92
|
/** Queues the newest state for a request; at most one delivery per request is in flight. */
|
|
87
93
|
private respond;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hostLoadStepCostForClass } from "../runtime/host-load-step-class.js";
|
|
2
|
+
import { takesHostTestSlot } from "../runtime/host-load-test-slot.js";
|
|
2
3
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
3
4
|
// Host side of Docker-sandbox admission (decision 0013). The validator inside a
|
|
4
5
|
// container cannot reach the host ledger, so it asks the bridge over the
|
|
@@ -50,11 +51,13 @@ export function parseSandboxHostCapacityRequest(line) {
|
|
|
50
51
|
}
|
|
51
52
|
if (!value || value.type !== sandboxHostCapacityLineType || value.version !== 1)
|
|
52
53
|
return null;
|
|
53
|
-
if (value.action !== "acquire" && value.action !== "release")
|
|
54
|
+
if (value.action !== "acquire" && value.action !== "release" && value.action !== "retain")
|
|
54
55
|
return null;
|
|
55
56
|
if (typeof value.requestId !== "string" || !requestIdPattern.test(value.requestId))
|
|
56
57
|
return null;
|
|
57
|
-
const
|
|
58
|
+
const claimed = typeof value.stepClass === "string" && stepClassPattern.test(value.stepClass) ? value.stepClass : "generic";
|
|
59
|
+
// A sandbox brokers only validation steps; it cannot claim a class that skips the host test slot.
|
|
60
|
+
const stepClass = takesHostTestSlot(claimed) ? claimed : "generic";
|
|
58
61
|
// Diagnostics only, but never control characters or markup from the sandbox.
|
|
59
62
|
const label = typeof value.label === "string" ? value.label.replace(/[^\w .:/@+-]/gu, "_").slice(0, 128) : "";
|
|
60
63
|
return { action: value.action, requestId: value.requestId, stepClass, label };
|
|
@@ -117,7 +120,8 @@ export class SandboxHostCapacityBroker {
|
|
|
117
120
|
if (request.action === "acquire" && !this.tokens.has(request.requestId) && this.tokens.size >= this.maximumOutstanding) {
|
|
118
121
|
this.stop(`more than ${this.maximumOutstanding} host capacity requests outstanding at once`);
|
|
119
122
|
}
|
|
120
|
-
this.track(request.action === "acquire" ? this.acquire(request)
|
|
123
|
+
this.track(request.action === "acquire" ? this.acquire(request)
|
|
124
|
+
: request.action === "retain" ? Promise.resolve(this.retain(request.requestId)) : this.release(request.requestId));
|
|
121
125
|
return true;
|
|
122
126
|
}
|
|
123
127
|
/** The sandbox exited: cancel its waits and return every token it holds. */
|
|
@@ -152,7 +156,7 @@ export class SandboxHostCapacityBroker {
|
|
|
152
156
|
async acquire(request) {
|
|
153
157
|
if (this.closed || this.tokens.has(request.requestId))
|
|
154
158
|
return;
|
|
155
|
-
const entry = { controller: new AbortController(), admission: null, released: false };
|
|
159
|
+
const entry = { controller: new AbortController(), admission: null, released: false, retained: false };
|
|
156
160
|
this.tokens.set(request.requestId, entry);
|
|
157
161
|
let admission;
|
|
158
162
|
try {
|
|
@@ -219,6 +223,9 @@ export class SandboxHostCapacityBroker {
|
|
|
219
223
|
}
|
|
220
224
|
// Registered synchronously after the check above, so no fence can slip between them.
|
|
221
225
|
admission.fenced.addEventListener("abort", () => {
|
|
226
|
+
// Retention stops the step's reservation on purpose; the sandbox already knows.
|
|
227
|
+
if (entry.retained)
|
|
228
|
+
return;
|
|
222
229
|
void this.respond({
|
|
223
230
|
requestId: request.requestId,
|
|
224
231
|
status: "fenced",
|
|
@@ -230,6 +237,18 @@ export class SandboxHostCapacityBroker {
|
|
|
230
237
|
requestId: request.requestId, status: "admitted", waitMs: Math.round(admission.waitMs), reason: admission.decision.reason,
|
|
231
238
|
});
|
|
232
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* The sandbox's step ended but part of its tree may still run: the host token is
|
|
242
|
+
* kept, marked retained (so the attempt's own next step does not wait for it),
|
|
243
|
+
* until the sandbox releases the request or exits.
|
|
244
|
+
*/
|
|
245
|
+
retain(requestId) {
|
|
246
|
+
const entry = this.tokens.get(requestId);
|
|
247
|
+
if (!entry?.admission || entry.released || entry.retained)
|
|
248
|
+
return;
|
|
249
|
+
entry.retained = true;
|
|
250
|
+
entry.admission.retainUntilStopped(async () => entry.released, new Error("The sandbox step's processes could not be proven stopped; its host capacity is kept until the sandbox releases it."));
|
|
251
|
+
}
|
|
233
252
|
async release(requestId) {
|
|
234
253
|
const entry = this.tokens.get(requestId);
|
|
235
254
|
if (!entry || entry.released)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Decision 0022: a blocked Architect verdict may say what it waits on (a sibling Story, a pull
|
|
2
|
+
// request, or something outside Forge) and which choice it needs from the owner. Forge records
|
|
3
|
+
// Story and pull request waits as dependency edges and re-plans the Story when they merge.
|
|
4
|
+
const architectWaitKinds = ["story", "pull_request", "external"];
|
|
5
|
+
const architectWaitUntil = ["merged"];
|
|
6
|
+
const storyIdPattern = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{8,32})$/i;
|
|
7
|
+
// Architect tool properties for non-pass verdicts: revision prose plus the structured waits.
|
|
8
|
+
export function architectNonPassProperties() {
|
|
9
|
+
return {
|
|
10
|
+
revision_questions: {
|
|
11
|
+
type: "array",
|
|
12
|
+
description: "Required for needs_revision when blockers are not used.",
|
|
13
|
+
items: { type: "string" }
|
|
14
|
+
},
|
|
15
|
+
revision_reasons: {
|
|
16
|
+
type: "array",
|
|
17
|
+
description: "Concrete reasons that prevent pass status.",
|
|
18
|
+
items: { type: "string" }
|
|
19
|
+
},
|
|
20
|
+
waits_on: {
|
|
21
|
+
type: "array",
|
|
22
|
+
description: "Only with status blocked. What must merge before this Story can be planned: a sibling Story (kind story, story_id as the full id or its first 8+ hex digits), a pull request (kind pull_request, pr_number), or something outside Forge (kind external). Forge records Story and sibling pull request waits and plans the Story again when they merge; external waits hold for the owner.",
|
|
23
|
+
items: {
|
|
24
|
+
type: "object",
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
required: ["kind", "until", "reason"],
|
|
27
|
+
properties: {
|
|
28
|
+
kind: { type: "string", enum: [...architectWaitKinds] },
|
|
29
|
+
story_id: { type: "string", description: "Required for kind story." },
|
|
30
|
+
pr_number: { type: "integer", minimum: 1, description: "Required for kind pull_request." },
|
|
31
|
+
until: { type: "string", enum: [...architectWaitUntil] },
|
|
32
|
+
reason: { type: "string", description: "What this Story needs from the blocker." }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
owner_decision: {
|
|
37
|
+
type: "object",
|
|
38
|
+
description: "Only with status blocked. A choice only the owner can make before the Story can be planned. Forge holds the Story for the owner and never picks an option.",
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
required: ["question", "options"],
|
|
41
|
+
properties: {
|
|
42
|
+
question: { type: "string" },
|
|
43
|
+
options: {
|
|
44
|
+
type: "array",
|
|
45
|
+
minItems: 2,
|
|
46
|
+
items: {
|
|
47
|
+
type: "object",
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
required: ["label", "summary"],
|
|
50
|
+
properties: {
|
|
51
|
+
label: { type: "string" },
|
|
52
|
+
summary: { type: "string" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
recommended: { type: "string", description: "Label of the recommended option." }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// An explicit null is absent, as the API reads it.
|
|
62
|
+
function isPresent(value) {
|
|
63
|
+
return value !== undefined && value !== null;
|
|
64
|
+
}
|
|
65
|
+
function hasArchitectWaitDeclarations(payload) {
|
|
66
|
+
return isPresent(payload.waits_on) || isPresent(payload.owner_decision);
|
|
67
|
+
}
|
|
68
|
+
// Throws an actionable error for a malformed waits_on or owner_decision. Absent (or null) fields are valid.
|
|
69
|
+
export function validateArchitectWaits(payload, status) {
|
|
70
|
+
if (!hasArchitectWaitDeclarations(payload)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (status !== "blocked") {
|
|
74
|
+
throw new Error("waits_on/owner_decision: allowed only with status blocked; correction: remove them, or return status blocked when the plan cannot pass until they are resolved.");
|
|
75
|
+
}
|
|
76
|
+
if (isPresent(payload.waits_on)) {
|
|
77
|
+
validateWaitsOn(payload.waits_on);
|
|
78
|
+
}
|
|
79
|
+
if (isPresent(payload.owner_decision)) {
|
|
80
|
+
validateOwnerDecision(payload.owner_decision);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateWaitsOn(value) {
|
|
84
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
85
|
+
throw new Error("waits_on: expected a non-empty array; correction: list each Story, pull request or external dependency, or omit waits_on.");
|
|
86
|
+
}
|
|
87
|
+
value.forEach((entry, index) => validateWait(entry, `waits_on[${index}]`));
|
|
88
|
+
}
|
|
89
|
+
function validateWait(entry, label) {
|
|
90
|
+
const wait = requireRecord(entry, label);
|
|
91
|
+
const kind = wait.kind;
|
|
92
|
+
if (typeof kind !== "string" || !architectWaitKinds.includes(kind)) {
|
|
93
|
+
throw new Error(`${label}.kind: expected one of story, pull_request, external.`);
|
|
94
|
+
}
|
|
95
|
+
if (wait.until !== "merged") {
|
|
96
|
+
throw new Error(`${label}.until: expected "merged".`);
|
|
97
|
+
}
|
|
98
|
+
requireText(wait.reason, `${label}.reason`);
|
|
99
|
+
if (kind === "story") {
|
|
100
|
+
const storyId = requireText(wait.story_id, `${label}.story_id`);
|
|
101
|
+
if (!storyIdPattern.test(storyId)) {
|
|
102
|
+
throw new Error(`${label}.story_id: expected the Story's full id or its first 8+ hex digits; got '${storyId}'.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (kind === "pull_request" && !(typeof wait.pr_number === "number" && Number.isInteger(wait.pr_number) && wait.pr_number > 0)) {
|
|
106
|
+
throw new Error(`${label}.pr_number: expected a positive integer pull request number.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function validateOwnerDecision(value) {
|
|
110
|
+
const decision = requireRecord(value, "owner_decision");
|
|
111
|
+
requireText(decision.question, "owner_decision.question");
|
|
112
|
+
if (!Array.isArray(decision.options) || decision.options.length < 2) {
|
|
113
|
+
throw new Error("owner_decision.options: expected at least two options, each with a distinct label and a summary.");
|
|
114
|
+
}
|
|
115
|
+
const labels = decision.options.map((option, index) => {
|
|
116
|
+
const record = requireRecord(option, `owner_decision.options[${index}]`);
|
|
117
|
+
requireText(record.summary, `owner_decision.options[${index}].summary`);
|
|
118
|
+
return requireText(record.label, `owner_decision.options[${index}].label`);
|
|
119
|
+
});
|
|
120
|
+
if (new Set(labels).size !== labels.length) {
|
|
121
|
+
throw new Error("owner_decision.options: expected at least two options, each with a distinct label and a summary.");
|
|
122
|
+
}
|
|
123
|
+
if (isPresent(decision.recommended) && !labels.includes(requireText(decision.recommended, "owner_decision.recommended"))) {
|
|
124
|
+
throw new Error("owner_decision.recommended: expected the label of one of the options.");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function requireRecord(value, label) {
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
129
|
+
throw new Error(`${label}: expected an object.`);
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
function requireText(value, label) {
|
|
134
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
135
|
+
throw new Error(`${label}: expected a non-empty string.`);
|
|
136
|
+
}
|
|
137
|
+
return value.trim();
|
|
138
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
2
1
|
export declare const managedAttemptToolNames: readonly ["forge.run_managed_command", "run_managed_command", "forge.start_managed_command", "start_managed_command", "forge.get_managed_command", "get_managed_command", "forge.wait_managed_command", "wait_managed_command", "forge.start_managed_verification", "start_managed_verification", "forge.reset_generated_outputs", "reset_generated_outputs"];
|
|
3
2
|
/**
|
|
4
3
|
* Stops every managed command this MCP server started, proves each process tree stopped,
|
|
@@ -45,11 +44,5 @@ export declare function buildManagedVerificationCommand(profile: string, outputD
|
|
|
45
44
|
export declare function preferredPowerShellExecutable(platform?: NodeJS.Platform, pathValue?: string): string;
|
|
46
45
|
export declare function validatePlaywrightProjectName(project: string, availableProjects: readonly string[]): void;
|
|
47
46
|
export declare function playwrightProjectNamesFromConfigSource(source: string): readonly string[];
|
|
48
|
-
/**
|
|
49
|
-
* Runner-authored verification normally uses its attempt-owned Testcontainers
|
|
50
|
-
* database. Only when the Docker engine is unavailable does it switch to the
|
|
51
|
-
* operator-provisioned native test cluster, which holds no real data.
|
|
52
|
-
*/
|
|
53
|
-
export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
|
|
54
47
|
export declare function isBuildProducingManagedCommand(command: string, args: readonly string[]): boolean;
|
|
55
48
|
export {};
|