@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0fedbc5c9ef7
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 +146 -3
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +92 -14
- package/dist/bridge/bridge.service.js +446 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +31 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +61 -0
- package/dist/runtime/host-load-governor-config.js +86 -0
- package/dist/runtime/host-load-governor.d.ts +193 -0
- package/dist/runtime/host-load-governor.js +662 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +75 -2
- package/dist/runtime/host-load-sampler.js +142 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +88 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- 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-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +33 -2
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
- package/dist/runtime/prepared-runtime-readiness.js +63 -16
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- 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 +2 -7
- package/dist/session/managed-attempt-tools.js +207 -121
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +91 -215
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- 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-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +31 -19
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +221 -182
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -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.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +72 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +98 -173
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- 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/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -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.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +15 -2
- package/dist/session/session.service.js +246 -88
- package/dist/session/session.types.d.ts +4 -0
- package/dist/session/session.types.js +7 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- 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 +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +42 -0
- package/dist/worktree/wip-git.js +139 -0
- package/dist/worktree/wip-refs.d.ts +77 -0
- package/dist/worktree/wip-refs.js +146 -0
- package/dist/worktree/wip-restore.d.ts +46 -0
- package/dist/worktree/wip-restore.js +280 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +115 -0
- package/dist/worktree/worktree-wip.d.ts +51 -0
- package/dist/worktree/worktree-wip.js +190 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +126 -155
- package/dist/worktree/worktree.types.d.ts +42 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { readCanonicalSourceFile } from "./canonical-source-file.js";
|
|
5
5
|
import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
|
|
6
|
+
import { replaceFile } from "../shared/fs/replace-file.js";
|
|
6
7
|
import { ExactHostProcessRecovery } from "../shared/process/host-process-recovery.js";
|
|
7
8
|
import { captureHostProcessIdentity, } from "../shared/process/host-process-supervisor.js";
|
|
8
9
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
@@ -14,8 +15,7 @@ const maximumReceiptBytes = 16 * 1024 * 1024;
|
|
|
14
15
|
const maximumCapturedCharacters = 200_000;
|
|
15
16
|
const defaultGraceMs = 2_000;
|
|
16
17
|
const receiptReadAttempts = 5;
|
|
17
|
-
const
|
|
18
|
-
const receiptReplaceRetryMs = 25;
|
|
18
|
+
const receiptReadRetryMs = 25;
|
|
19
19
|
const invalidMetadata = Symbol("invalid managed-command metadata");
|
|
20
20
|
let procRoot = "/proc";
|
|
21
21
|
/** Test support: points the Linux process inventory at another directory (null restores /proc). */
|
|
@@ -363,7 +363,7 @@ async function readReceipt(store, name) {
|
|
|
363
363
|
}
|
|
364
364
|
catch {
|
|
365
365
|
if (attempt < receiptReadAttempts)
|
|
366
|
-
await delay(
|
|
366
|
+
await delay(receiptReadRetryMs);
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
return null;
|
|
@@ -462,19 +462,8 @@ async function persistReceipt(receiptPath, receipt) {
|
|
|
462
462
|
const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
|
|
463
463
|
try {
|
|
464
464
|
await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
await fs.rename(temporaryPath, receiptPath);
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
catch (error) {
|
|
471
|
-
const code = error.code;
|
|
472
|
-
// Windows refuses to replace a file another process briefly holds open.
|
|
473
|
-
if (attempt >= receiptReplaceAttempts || (code !== "EPERM" && code !== "EBUSY" && code !== "EACCES"))
|
|
474
|
-
throw error;
|
|
475
|
-
await delay(receiptReplaceRetryMs);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
465
|
+
// Windows refuses to replace a file another process briefly holds open.
|
|
466
|
+
await replaceFile(temporaryPath, receiptPath);
|
|
478
467
|
}
|
|
479
468
|
finally {
|
|
480
469
|
await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
|
|
@@ -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
|
+
}
|
|
@@ -28,5 +28,12 @@ export declare class PlaywrightHostRuntimeAdapter {
|
|
|
28
28
|
*/
|
|
29
29
|
assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
|
|
30
30
|
private readyBrowserCache;
|
|
31
|
+
/**
|
|
32
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
33
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
34
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
35
|
+
* The next `prepare` writes a fresh one.
|
|
36
|
+
*/
|
|
37
|
+
discardOverlay(temporaryDirectory: string): Promise<void>;
|
|
31
38
|
prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
|
|
32
39
|
}
|
|
@@ -35,6 +35,17 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
35
35
|
}
|
|
36
36
|
return { cache: resolution.cache, installCommand };
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
40
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
41
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
42
|
+
* The next `prepare` writes a fresh one.
|
|
43
|
+
*/
|
|
44
|
+
async discardOverlay(temporaryDirectory) {
|
|
45
|
+
if (!await assertCanonicalDirectory(temporaryDirectory, true))
|
|
46
|
+
return;
|
|
47
|
+
await fs.rm(path.join(path.resolve(temporaryDirectory), playwrightOverlayFileName), { force: true });
|
|
48
|
+
}
|
|
38
49
|
async prepare(config, context) {
|
|
39
50
|
const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
|
|
40
51
|
const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
|
|
@@ -62,7 +73,7 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
62
73
|
if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
|
|
63
74
|
throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
|
|
64
75
|
}
|
|
65
|
-
const overlayPath = path.join(temporaryDirectory,
|
|
76
|
+
const overlayPath = path.join(temporaryDirectory, playwrightOverlayFileName);
|
|
66
77
|
const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
|
|
67
78
|
const browserCache = readyCache
|
|
68
79
|
? { path: readyCache, ready: true }
|
|
@@ -135,6 +146,7 @@ async function ensureAttemptWritableDirectories(targets, realWorktree) {
|
|
|
135
146
|
for (const target of resolvedTargets)
|
|
136
147
|
await createPrivateCanonicalDirectory(target);
|
|
137
148
|
}
|
|
149
|
+
const playwrightOverlayFileName = "forge.playwright.config.mjs";
|
|
138
150
|
async function writeAttemptOverlay(target, content) {
|
|
139
151
|
const parent = path.dirname(target);
|
|
140
152
|
const identity = await assertCanonicalDirectory(parent);
|
|
@@ -4,3 +4,7 @@ export interface PreparedRuntimeIdentityDiagnostics {
|
|
|
4
4
|
}
|
|
5
5
|
/** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
|
|
6
6
|
export declare function preparedRuntimeIdentity(worktreePath: string, signal?: AbortSignal, diagnostics?: PreparedRuntimeIdentityDiagnostics): Promise<HostParallelProofIdentity>;
|
|
7
|
+
/** Total bytes of git-ignored launch inputs one identity pass may read. */
|
|
8
|
+
export declare const ignoredLaunchInputByteBudget: number;
|
|
9
|
+
/** Whether a worktree-relative path is an isolation input (see isolationInputBasenames). */
|
|
10
|
+
export declare function isIsolationInputPath(name: string): boolean;
|
|
@@ -10,7 +10,7 @@ import { generatedOutputRootForPath } from "./generated-output-reset.js";
|
|
|
10
10
|
import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
|
|
11
11
|
/** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
|
|
12
12
|
export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics) {
|
|
13
|
-
diagnostics
|
|
13
|
+
const inputs = new CapturedRuntimeInputs(diagnostics);
|
|
14
14
|
const root = await fs.realpath(worktreePath);
|
|
15
15
|
const rootIdentity = (await assertCanonicalDirectory(root));
|
|
16
16
|
const sourceKey = (target) => process.platform === "win32" ? target.toLowerCase() : target;
|
|
@@ -131,7 +131,7 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
131
131
|
bytes += sourceBytes.length;
|
|
132
132
|
const digest = createHash("sha256").update(sourceBytes).digest();
|
|
133
133
|
hash.update(digest);
|
|
134
|
-
|
|
134
|
+
inputs.set(name, digest.toString("hex"));
|
|
135
135
|
snapshot.set(sourceKey(target), Promise.resolve(sourceBytes));
|
|
136
136
|
}
|
|
137
137
|
catch (error) {
|
|
@@ -139,11 +139,12 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
139
139
|
throw error;
|
|
140
140
|
const disposition = deleted.has(name) ? "deleted" : "absent";
|
|
141
141
|
hash.update(disposition);
|
|
142
|
-
|
|
142
|
+
inputs.set(name, disposition);
|
|
143
143
|
snapshot.set(sourceKey(target), Promise.resolve(null));
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
const contract = await loadHostRuntimeContract(root, target => {
|
|
147
|
+
inputs.discovered(path.relative(root, path.resolve(target)));
|
|
147
148
|
const key = sourceKey(path.resolve(target));
|
|
148
149
|
const captured = snapshot.get(key);
|
|
149
150
|
if (captured)
|
|
@@ -192,7 +193,7 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
192
193
|
? null
|
|
193
194
|
: createHash("sha256").update(sourceBytes).digest();
|
|
194
195
|
hash.update(digest ?? "absent");
|
|
195
|
-
|
|
196
|
+
inputs.set(`runtime-discovery:${name}`, digest?.toString("hex") ?? "absent");
|
|
196
197
|
}
|
|
197
198
|
if (head !== (await git.run(root, ["rev-parse", "HEAD"])).trim()
|
|
198
199
|
|| JSON.stringify(source) !== JSON.stringify(await inventory())) {
|
|
@@ -204,11 +205,131 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
204
205
|
throw new Error("host_runtime_source_changed: runtime discovery inventory changed during verification.");
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
|
-
return {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
return await inputs.identity(root, git, signal, head, hostRuntimeContractFingerprint(contract), `sha256:${hash.digest("hex")}`);
|
|
209
|
+
}
|
|
210
|
+
/** Total bytes of git-ignored launch inputs one identity pass may read. */
|
|
211
|
+
export const ignoredLaunchInputByteBudget = 32 * 1024 * 1024;
|
|
212
|
+
/**
|
|
213
|
+
* Per-path digests captured while hashing the prepared source (forwarded to the diagnostics
|
|
214
|
+
* sink when one is supplied), plus every path runtime discovery asked for. The isolation
|
|
215
|
+
* fingerprint is computed from a subset of them.
|
|
216
|
+
*/
|
|
217
|
+
class CapturedRuntimeInputs {
|
|
218
|
+
diagnostics;
|
|
219
|
+
digests = new Map();
|
|
220
|
+
discoveryInputs = new Set();
|
|
221
|
+
constructor(diagnostics) {
|
|
222
|
+
this.diagnostics = diagnostics;
|
|
223
|
+
diagnostics?.entries.clear();
|
|
224
|
+
}
|
|
225
|
+
set(name, digest) {
|
|
226
|
+
this.digests.set(name, digest);
|
|
227
|
+
this.diagnostics?.entries.set(name, digest);
|
|
228
|
+
}
|
|
229
|
+
/** Records a worktree-relative path runtime discovery read (or probed for existence). */
|
|
230
|
+
discovered(relative) {
|
|
231
|
+
const portable = relative.replaceAll("\\", "/");
|
|
232
|
+
if (!portable.startsWith("..") && !path.isAbsolute(portable))
|
|
233
|
+
this.discoveryInputs.add(portable);
|
|
234
|
+
}
|
|
235
|
+
async identity(root, git, signal, inputCommitSha, runtimeContractFingerprint, sourceFingerprint) {
|
|
236
|
+
await this.captureIgnoredLaunchInputs(root, git, signal);
|
|
237
|
+
return {
|
|
238
|
+
inputCommitSha,
|
|
239
|
+
runtimeContractFingerprint,
|
|
240
|
+
sourceFingerprint,
|
|
241
|
+
isolationFingerprint: isolationFingerprint(runtimeContractFingerprint, this.digests, this.discoveryInputs),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Launch inputs Git ignores still shape the runtime: an ignored appsettings.Local.json can set
|
|
246
|
+
* Kestrel endpoints that override ASPNETCORE_URLS. The source inventory omits ignored files, so
|
|
247
|
+
* hash every individually ignored isolation input here. Ignored directories (node_modules, bin,
|
|
248
|
+
* obj and other build output) are collapsed by --directory and not walked. These digests feed
|
|
249
|
+
* only the isolation fingerprint, not the source fingerprint.
|
|
250
|
+
*/
|
|
251
|
+
async captureIgnoredLaunchInputs(root, git, signal) {
|
|
252
|
+
const names = (await git.run(root, ["ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"]))
|
|
253
|
+
.split("\0")
|
|
254
|
+
.filter(name => name && !name.endsWith("/") && !name.startsWith(".forge/") && isIsolationInputPath(name))
|
|
255
|
+
.sort();
|
|
256
|
+
if (names.length > 4096)
|
|
257
|
+
throw new Error("host_runtime_source_invalid: too many ignored launch inputs to verify.");
|
|
258
|
+
// One aggregate budget for every ignored input in the pass. Each read is bounded by what is
|
|
259
|
+
// left, and the size is checked before any bytes are read, so the pass fails closed instead
|
|
260
|
+
// of reading up to 4096 large files.
|
|
261
|
+
let remaining = ignoredLaunchInputByteBudget;
|
|
262
|
+
for (const name of names) {
|
|
263
|
+
signal?.throwIfAborted();
|
|
264
|
+
let digest;
|
|
265
|
+
try {
|
|
266
|
+
const bytes = await readCanonicalSourceFile(path.join(root, name), remaining);
|
|
267
|
+
remaining -= bytes.length;
|
|
268
|
+
digest = createHash("sha256").update(bytes).digest("hex");
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (error.code !== "ENOENT")
|
|
272
|
+
throw error;
|
|
273
|
+
digest = "absent";
|
|
274
|
+
}
|
|
275
|
+
this.set(`ignored-launch-input:${name}`, digest);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Basenames whose content can change how a launched runtime binds ports, resolves
|
|
281
|
+
* dependencies or picks its launch profile beyond what the runtime contract states. A
|
|
282
|
+
* derived contract already fingerprints the manifest and project file it chose; these
|
|
283
|
+
* cover the rest: lockfiles and package-manager config, .NET SDK and package props,
|
|
284
|
+
* launch profiles, Kestrel endpoint config (appsettings) and dev-server/Playwright config.
|
|
285
|
+
*/
|
|
286
|
+
const isolationInputBasenames = new Set([
|
|
287
|
+
"package.json",
|
|
288
|
+
"package-lock.json",
|
|
289
|
+
"npm-shrinkwrap.json",
|
|
290
|
+
"pnpm-lock.yaml",
|
|
291
|
+
"pnpm-workspace.yaml",
|
|
292
|
+
"yarn.lock",
|
|
293
|
+
".npmrc",
|
|
294
|
+
".yarnrc",
|
|
295
|
+
".yarnrc.yml",
|
|
296
|
+
"packages.lock.json",
|
|
297
|
+
"global.json",
|
|
298
|
+
"nuget.config",
|
|
299
|
+
"directory.build.props",
|
|
300
|
+
"directory.build.targets",
|
|
301
|
+
"directory.packages.props",
|
|
302
|
+
"launchsettings.json",
|
|
303
|
+
]);
|
|
304
|
+
/** Whether a worktree-relative path is an isolation input (see isolationInputBasenames). */
|
|
305
|
+
export function isIsolationInputPath(name) {
|
|
306
|
+
if (name === ".forge/forge.runtime.yml")
|
|
307
|
+
return true;
|
|
308
|
+
const basename = name.slice(name.lastIndexOf("/") + 1).toLowerCase();
|
|
309
|
+
return isolationInputBasenames.has(basename)
|
|
310
|
+
|| /\.(?:cs|fs|vb)proj$/u.test(basename)
|
|
311
|
+
|| /^appsettings(?:\.[^/]+)?\.json$/u.test(basename)
|
|
312
|
+
|| /^(?:vite|vitest|next|playwright)\.config\.(?:ts|mts|cts|js|mjs|cjs)$/u.test(basename);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Identity of the inputs that control runtime isolation: the runtime contract plus every
|
|
316
|
+
* launch-relevant source file and every file runtime discovery read. Ordinary source edits
|
|
317
|
+
* leave it unchanged, so a proof observed for one branch head can admit another head whose
|
|
318
|
+
* isolation inputs are byte-identical; any change to them requires a fresh probe.
|
|
319
|
+
*/
|
|
320
|
+
function isolationFingerprint(runtimeContractFingerprint, digests, discoveryInputs) {
|
|
321
|
+
const hash = createHash("sha256");
|
|
322
|
+
hash.update(JSON.stringify(["isolation-v1", runtimeContractFingerprint]));
|
|
323
|
+
const selected = [...digests]
|
|
324
|
+
.filter(([name]) => {
|
|
325
|
+
if (name.startsWith("runtime-discovery:") || name.startsWith("ignored-launch-input:"))
|
|
326
|
+
return true;
|
|
327
|
+
return discoveryInputs.has(name) || isIsolationInputPath(name);
|
|
328
|
+
})
|
|
329
|
+
.sort(([left], [right]) => left.localeCompare(right));
|
|
330
|
+
for (const [name, digest] of selected)
|
|
331
|
+
hash.update(JSON.stringify([name, digest]));
|
|
332
|
+
return `sha256:${hash.digest("hex")}`;
|
|
212
333
|
}
|
|
213
334
|
function directoryInventory(entries) {
|
|
214
335
|
return JSON.stringify(entries.map(entry => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RunOnceDispatchPacket } from "../session/session.types.js";
|
|
2
2
|
import type { HostRuntimeAdmissionCheckpointHandler, HostRuntimeLeaseRuntime } from "./host-runtime-lease.js";
|
|
3
3
|
import { HostParallelPromotionStore, type HostParallelProofIdentity } from "./host-runtime-promotion.js";
|
|
4
4
|
export interface PreparedRuntimePendingSnapshot {
|
|
@@ -19,6 +19,12 @@ export declare class PreparedRuntimeReadiness {
|
|
|
19
19
|
constructor(runtime: HostRuntimeLeaseRuntime, store: HostParallelPromotionStore, releasePreparation: (id: string, fence: string) => Promise<unknown>, admissionExpired: () => Error);
|
|
20
20
|
acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
21
21
|
has(id: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
|
|
24
|
+
* check() found the prepared contract parallel-eligible, so the lease manager may admit it
|
|
25
|
+
* beside other shared-admission runs of the same repository instead of exclusively.
|
|
26
|
+
*/
|
|
27
|
+
isParallelEligibleProbe(id: string, fence: string): boolean;
|
|
22
28
|
hasPending(): boolean;
|
|
23
29
|
pendingSnapshots(): readonly PreparedRuntimePendingSnapshot[];
|
|
24
30
|
verify(dispatch: RunOnceDispatchPacket, worktree: string, checkpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostParallelProofIdentity | undefined>;
|
|
@@ -27,4 +33,10 @@ export declare class PreparedRuntimeReadiness {
|
|
|
27
33
|
private drain;
|
|
28
34
|
private scheduleDeadline;
|
|
29
35
|
private check;
|
|
36
|
+
/**
|
|
37
|
+
* A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
|
|
38
|
+
* contract is quarantined, records no proof. The agent's admission then finds none and runs under
|
|
39
|
+
* exclusive admission.
|
|
40
|
+
*/
|
|
41
|
+
private unproven;
|
|
30
42
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { GitClient } from "../shared/git/git.js";
|
|
3
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
3
4
|
import { loadHostRuntimeContract } from "./host-runtime-contract.js";
|
|
4
5
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible } from "./host-runtime-promotion.js";
|
|
5
6
|
import { preparedRuntimeIdentity } from "./prepared-runtime-identity.js";
|
|
@@ -43,6 +44,15 @@ export class PreparedRuntimeReadiness {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
has(id) { return this.preparations.has(id); }
|
|
47
|
+
/**
|
|
48
|
+
* Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
|
|
49
|
+
* check() found the prepared contract parallel-eligible, so the lease manager may admit it
|
|
50
|
+
* beside other shared-admission runs of the same repository instead of exclusively.
|
|
51
|
+
*/
|
|
52
|
+
isParallelEligibleProbe(id, fence) {
|
|
53
|
+
return [...this.preparations.values()].some(entry => entry.probe?.sandbox.dispatchAttemptId === id
|
|
54
|
+
&& entry.probe.lease.fencingToken === fence);
|
|
55
|
+
}
|
|
46
56
|
hasPending() { return this.preparations.size > 0; }
|
|
47
57
|
pendingSnapshots() {
|
|
48
58
|
return [...this.preparations.values()].map(entry => ({
|
|
@@ -162,6 +172,9 @@ export class PreparedRuntimeReadiness {
|
|
|
162
172
|
}
|
|
163
173
|
if (await this.store.load(dispatch.repo.id, identity))
|
|
164
174
|
return identity;
|
|
175
|
+
// A quarantined contract cannot record proof: skip the exclusive admission and the stack launch.
|
|
176
|
+
if (await this.store.quarantined(dispatch.repo.id, identity.runtimeContractFingerprint))
|
|
177
|
+
return await this.unproven(entry, identity, checkpoint, true);
|
|
165
178
|
await checkpoint?.({ code: "host_runtime_prepared_probe_started", expiresAt: entry.expiresAt,
|
|
166
179
|
message: `Verifying prepared runtime ${identity.inputCommitSha.slice(0, 12)} before agent admission; project-default readiness is not a substitute.` });
|
|
167
180
|
const probeId = randomUUID();
|
|
@@ -172,11 +185,14 @@ export class PreparedRuntimeReadiness {
|
|
|
172
185
|
inputCommitSha: identity.inputCommitSha },
|
|
173
186
|
};
|
|
174
187
|
entry.probe = probe;
|
|
188
|
+
// Any revocation from here on (this probe's own violation or a sibling's) voids its proof.
|
|
189
|
+
const revocationGeneration = await this.store.revocationGeneration(dispatch.repo.id);
|
|
175
190
|
const stopPreparedHeadMonitor = new AbortController();
|
|
176
191
|
const preparedHeadMonitor = monitorPreparedHead(worktree, identity.inputCommitSha, controller, stopPreparedHeadMonitor.signal);
|
|
177
192
|
let cleanupConfirmed;
|
|
178
193
|
let verifiedRuntimeContractFingerprint;
|
|
179
|
-
let verifiedPorts;
|
|
194
|
+
let verifiedPorts = [];
|
|
195
|
+
let isolationViolated = false;
|
|
180
196
|
try {
|
|
181
197
|
controller.signal.throwIfAborted();
|
|
182
198
|
await this.runtime.acquire(probe, controller.signal);
|
|
@@ -189,6 +205,12 @@ export class PreparedRuntimeReadiness {
|
|
|
189
205
|
verifiedRuntimeContractFingerprint = hostRuntimeContractFingerprint(started.runtimeContract);
|
|
190
206
|
verifiedPorts = started.lease.resources.ports.map(port => port.name).sort();
|
|
191
207
|
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
// A shared probe's stray listener: the lease stopped it and revoked the repository (see unproven).
|
|
210
|
+
if (!(error instanceof ForgeFailureError && error.failureCode === "host_runtime_isolation_violation"))
|
|
211
|
+
throw error;
|
|
212
|
+
isolationViolated = true;
|
|
213
|
+
}
|
|
192
214
|
finally {
|
|
193
215
|
stopPreparedHeadMonitor.abort();
|
|
194
216
|
await preparedHeadMonitor;
|
|
@@ -199,25 +221,15 @@ export class PreparedRuntimeReadiness {
|
|
|
199
221
|
if (!cleanupConfirmed) {
|
|
200
222
|
throw new Error("host_runtime_prepared_probe_cleanup_unconfirmed: matching probe teardown was not confirmed.");
|
|
201
223
|
}
|
|
224
|
+
if (isolationViolated)
|
|
225
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
202
226
|
// Probe-owned processes may create transient, untracked files while they
|
|
203
227
|
// are alive. Verify the prepared source only after matching teardown is
|
|
204
228
|
// confirmed: persistent source edits still fail closed, while files that
|
|
205
229
|
// belong to the probe lifecycle cannot create a false source-change loop.
|
|
206
230
|
const currentDiagnostics = { entries: new Map() };
|
|
207
231
|
const currentIdentity = await preparedRuntimeIdentity(worktree, controller.signal, currentDiagnostics);
|
|
208
|
-
const changed =
|
|
209
|
-
if (verifiedRuntimeContractFingerprint !== identity.runtimeContractFingerprint
|
|
210
|
-
|| currentIdentity.runtimeContractFingerprint !== identity.runtimeContractFingerprint) {
|
|
211
|
-
changed.push("runtime contract");
|
|
212
|
-
}
|
|
213
|
-
if (currentIdentity.inputCommitSha !== identity.inputCommitSha)
|
|
214
|
-
changed.push("HEAD");
|
|
215
|
-
if (currentIdentity.sourceFingerprint !== identity.sourceFingerprint) {
|
|
216
|
-
const paths = changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries);
|
|
217
|
-
changed.push(paths.length > 0
|
|
218
|
-
? `source fingerprint (${paths.join(", ")})`
|
|
219
|
-
: "source fingerprint");
|
|
220
|
-
}
|
|
232
|
+
const changed = identityChanges(identity, currentIdentity, verifiedRuntimeContractFingerprint, changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries));
|
|
221
233
|
if (changed.length > 0) {
|
|
222
234
|
throw new Error(`host_runtime_prepared_source_changed: ${changed.join(", ")} changed during isolation verification.`);
|
|
223
235
|
}
|
|
@@ -225,9 +237,26 @@ export class PreparedRuntimeReadiness {
|
|
|
225
237
|
throw new Error("host_runtime_prepared_probe_incomplete: assigned-port verification did not confirm every configured launch port.");
|
|
226
238
|
}
|
|
227
239
|
controller.signal.throwIfAborted();
|
|
228
|
-
await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint)
|
|
240
|
+
const recorded = await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint, identity.isolationFingerprint, revocationGeneration)
|
|
241
|
+
.then(() => true, (error) => errorMessage(error).startsWith("host_parallel_promotion_revoked:")
|
|
242
|
+
? false : Promise.reject(error));
|
|
243
|
+
if (!recorded)
|
|
244
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
229
245
|
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
230
|
-
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its
|
|
246
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its proof is retained for every head with the same isolation inputs.` });
|
|
247
|
+
return identity;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
|
|
251
|
+
* contract is quarantined, records no proof. The agent's admission then finds none and runs under
|
|
252
|
+
* exclusive admission.
|
|
253
|
+
*/
|
|
254
|
+
async unproven(entry, identity, checkpoint, quarantined = false) {
|
|
255
|
+
const reason = quarantined
|
|
256
|
+
? "its runtime contract is quarantined after a recent isolation violation, so it was not probed"
|
|
257
|
+
: "the repository's promotion was revoked during the probe";
|
|
258
|
+
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
259
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} did not prove isolation (${reason}); its runs are serialized.` });
|
|
231
260
|
return identity;
|
|
232
261
|
}
|
|
233
262
|
}
|
|
@@ -274,6 +303,24 @@ async function waitForPreparedHeadPoll(signal) {
|
|
|
274
303
|
function errorMessage(error) {
|
|
275
304
|
return error instanceof Error ? error.message : String(error);
|
|
276
305
|
}
|
|
306
|
+
/** What changed between the identity a probe started from and the one after its teardown. */
|
|
307
|
+
function identityChanges(prepared, current, verifiedRuntimeContractFingerprint, changedPaths) {
|
|
308
|
+
const changed = [];
|
|
309
|
+
if (verifiedRuntimeContractFingerprint !== prepared.runtimeContractFingerprint
|
|
310
|
+
|| current.runtimeContractFingerprint !== prepared.runtimeContractFingerprint) {
|
|
311
|
+
changed.push("runtime contract");
|
|
312
|
+
}
|
|
313
|
+
if (current.inputCommitSha !== prepared.inputCommitSha)
|
|
314
|
+
changed.push("HEAD");
|
|
315
|
+
// Ignored launch inputs change only the isolation fingerprint; either change voids the proof.
|
|
316
|
+
if (current.sourceFingerprint !== prepared.sourceFingerprint
|
|
317
|
+
|| current.isolationFingerprint !== prepared.isolationFingerprint) {
|
|
318
|
+
changed.push(changedPaths.length > 0
|
|
319
|
+
? `source or isolation inputs (${changedPaths.join(", ")})`
|
|
320
|
+
: "source or isolation inputs");
|
|
321
|
+
}
|
|
322
|
+
return changed;
|
|
323
|
+
}
|
|
277
324
|
function changedIdentityPaths(before, after) {
|
|
278
325
|
const paths = new Set([...before.keys(), ...after.keys()]);
|
|
279
326
|
const changed = [...paths]
|