@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.0098fdb4e213
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 +232 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- 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 +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -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 +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- 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/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- 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 +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -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 +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -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/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-load-admission.d.ts +67 -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 +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -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 +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- 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 +81 -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 +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- 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.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -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 +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -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 +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -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 +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- 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 +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- 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 +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- 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 +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- 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 +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- 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 +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- 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.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- 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.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -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 +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -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 +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- 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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -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 +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -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/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- 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 +69 -0
- package/dist/shared/process/process.js +223 -16
- 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.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
6
|
+
import { redactText } from "../shared/redaction/redaction.js";
|
|
7
|
+
import { replaceFile } from "../shared/fs/replace-file.js";
|
|
8
|
+
const inFlightPrebuilds = new Map();
|
|
9
|
+
/** Runs one ASP.NET runtime build under the attempt's supervisor, logging only redacted output. */
|
|
10
|
+
export async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal, exactSecrets = [],
|
|
11
|
+
/** Once the build's supervised tree is up: records it on the build's host load token. */
|
|
12
|
+
onStarted) {
|
|
13
|
+
const childName = `runtime-build-${plan.fingerprint.slice(-12)}`;
|
|
14
|
+
const stdoutLogPath = path.join(logDirectory, `${childName}.stdout.log`);
|
|
15
|
+
const stderrLogPath = path.join(logDirectory, `${childName}.stderr.log`);
|
|
16
|
+
let stdoutTail = "";
|
|
17
|
+
let stderrTail = "";
|
|
18
|
+
const append = async (target, line) => {
|
|
19
|
+
await fs.appendFile(target, `${redactText(line, exactSecrets)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
20
|
+
};
|
|
21
|
+
const child = await supervisor.startChildReady(childName, {
|
|
22
|
+
command: plan.command,
|
|
23
|
+
args: plan.args,
|
|
24
|
+
cwd: plan.cwd,
|
|
25
|
+
env: plan.environment,
|
|
26
|
+
captureOutput: false,
|
|
27
|
+
}, {
|
|
28
|
+
onStdoutLine: async (line) => {
|
|
29
|
+
stdoutTail = appendRuntimeBuildTail(stdoutTail, redactText(line, exactSecrets));
|
|
30
|
+
await append(stdoutLogPath, line);
|
|
31
|
+
},
|
|
32
|
+
onStderrLine: async (line) => {
|
|
33
|
+
stderrTail = appendRuntimeBuildTail(stderrTail, redactText(line, exactSecrets));
|
|
34
|
+
await append(stderrLogPath, line);
|
|
35
|
+
},
|
|
36
|
+
}, signal, { maxStartAttempts: 2, retryDelayMs: 250 });
|
|
37
|
+
await onStarted?.(child.metadataPath);
|
|
38
|
+
const result = await child.result;
|
|
39
|
+
return {
|
|
40
|
+
exitCode: result.exitCode,
|
|
41
|
+
stdoutTail: appendRuntimeBuildTail(stdoutTail, redactText(result.stdout, exactSecrets)),
|
|
42
|
+
stderrTail: appendRuntimeBuildTail(stderrTail, redactText(result.stderr, exactSecrets)),
|
|
43
|
+
stdoutLogPath,
|
|
44
|
+
stderrLogPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function appendRuntimeBuildTail(current, value) {
|
|
48
|
+
if (!value)
|
|
49
|
+
return current;
|
|
50
|
+
return `${current}${current ? "\n" : ""}${value}`.slice(-4_000);
|
|
51
|
+
}
|
|
52
|
+
export function createAspNetRuntimePrebuildPlan(options) {
|
|
53
|
+
if (!isDotnetRun(options.command, options.args))
|
|
54
|
+
return null;
|
|
55
|
+
const projectArgument = readOptionValue(options.args, "--project");
|
|
56
|
+
const projectPath = path.resolve(options.cwd, projectArgument ?? ".");
|
|
57
|
+
const normalizedWorktree = path.resolve(options.worktreePath);
|
|
58
|
+
const relativeProject = path.relative(normalizedWorktree, projectPath);
|
|
59
|
+
if (relativeProject.startsWith("..") || path.isAbsolute(relativeProject)) {
|
|
60
|
+
throw new Error("host_runtime_build_invalid: the ASP.NET project must remain inside the managed worktree.");
|
|
61
|
+
}
|
|
62
|
+
const projectDirectory = projectArgument && path.extname(projectPath).toLowerCase() === ".csproj"
|
|
63
|
+
? path.dirname(projectPath)
|
|
64
|
+
: projectPath;
|
|
65
|
+
const buildArgs = [
|
|
66
|
+
"build",
|
|
67
|
+
...(projectArgument ? [projectArgument] : []),
|
|
68
|
+
"--nologo",
|
|
69
|
+
"--no-restore",
|
|
70
|
+
"--disable-build-servers",
|
|
71
|
+
"-p:UseSharedCompilation=false",
|
|
72
|
+
"-p:DefaultItemExcludesInProjectFolder=TestResults/**",
|
|
73
|
+
...forwardBuildOptions(options.args),
|
|
74
|
+
];
|
|
75
|
+
const fingerprint = `sha256:${createHash("sha256").update(JSON.stringify({
|
|
76
|
+
inputCommitSha: options.inputCommitSha,
|
|
77
|
+
runtimeContractFingerprint: options.runtimeContractFingerprint,
|
|
78
|
+
project: relativeProject.replaceAll("\\", "/"),
|
|
79
|
+
args: buildArgs,
|
|
80
|
+
environment: buildEnvironmentContract(options.environment ?? {}),
|
|
81
|
+
})).digest("hex")}`;
|
|
82
|
+
return {
|
|
83
|
+
fingerprint,
|
|
84
|
+
receiptPath: path.join(projectDirectory, "obj", ".forge-runtime-build.json"),
|
|
85
|
+
command: options.command,
|
|
86
|
+
args: buildArgs,
|
|
87
|
+
cwd: options.cwd,
|
|
88
|
+
environment: options.environment ?? {},
|
|
89
|
+
projectPath,
|
|
90
|
+
worktreePath: normalizedWorktree,
|
|
91
|
+
inputCommitSha: options.inputCommitSha,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export async function ensureAspNetRuntimePrebuilt(plan, execute, signal) {
|
|
95
|
+
const pending = inFlightPrebuilds.get(plan.receiptPath);
|
|
96
|
+
if (pending)
|
|
97
|
+
return await pending;
|
|
98
|
+
const started = ensureAspNetRuntimePrebuiltCore(plan, execute, signal);
|
|
99
|
+
inFlightPrebuilds.set(plan.receiptPath, started);
|
|
100
|
+
try {
|
|
101
|
+
return await started;
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
if (inFlightPrebuilds.get(plan.receiptPath) === started)
|
|
105
|
+
inFlightPrebuilds.delete(plan.receiptPath);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function ensureAspNetRuntimePrebuiltCore(plan, execute, signal) {
|
|
109
|
+
const inputs = await aspNetBuildInputs(plan);
|
|
110
|
+
const fingerprint = `sha256:${createHash("sha256").update(JSON.stringify({
|
|
111
|
+
planFingerprint: plan.fingerprint,
|
|
112
|
+
...inputs,
|
|
113
|
+
})).digest("hex")}`;
|
|
114
|
+
const receipt = await readReceipt(plan.receiptPath);
|
|
115
|
+
if (receipt?.fingerprint === fingerprint
|
|
116
|
+
&& receipt.planFingerprint === plan.fingerprint
|
|
117
|
+
&& receipt.inputCommitSha === plan.inputCommitSha
|
|
118
|
+
&& await aspNetOutputsMatch(plan, receipt.outputs)) {
|
|
119
|
+
return { cacheHit: true, receiptPath: plan.receiptPath, fingerprint };
|
|
120
|
+
}
|
|
121
|
+
const result = await execute(plan, signal);
|
|
122
|
+
if (result.exitCode !== 0) {
|
|
123
|
+
const evidence = [
|
|
124
|
+
diagnostic("stderr", result.stderrTail),
|
|
125
|
+
diagnostic("stdout", result.stdoutTail),
|
|
126
|
+
`stdout log: ${result.stdoutLogPath}`,
|
|
127
|
+
`stderr log: ${result.stderrLogPath}`,
|
|
128
|
+
].filter(Boolean).join("; ");
|
|
129
|
+
throw new ForgeFailureError("host_runtime_project_start_failed", `host_runtime_project_start_failed: dotnet build exited with code ${result.exitCode}.${evidence ? ` ${evidence}` : ""}`, "bridge");
|
|
130
|
+
}
|
|
131
|
+
await fs.mkdir(path.dirname(plan.receiptPath), { recursive: true });
|
|
132
|
+
const outputs = await collectAspNetBuildOutputs(plan);
|
|
133
|
+
if (outputs.length === 0) {
|
|
134
|
+
throw new Error("host_runtime_build_output_missing: dotnet build succeeded without producing a verifiable project output.");
|
|
135
|
+
}
|
|
136
|
+
const temporaryReceipt = `${plan.receiptPath}.${randomUUID()}.tmp`;
|
|
137
|
+
const nextReceipt = {
|
|
138
|
+
schemaVersion: 2,
|
|
139
|
+
fingerprint,
|
|
140
|
+
planFingerprint: plan.fingerprint,
|
|
141
|
+
inputCommitSha: plan.inputCommitSha,
|
|
142
|
+
projectPath: plan.projectPath,
|
|
143
|
+
...inputs,
|
|
144
|
+
outputs,
|
|
145
|
+
completedAt: new Date().toISOString(),
|
|
146
|
+
};
|
|
147
|
+
await fs.writeFile(temporaryReceipt, `${JSON.stringify(nextReceipt)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
148
|
+
try {
|
|
149
|
+
await replaceFile(temporaryReceipt, plan.receiptPath);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await fs.rm(temporaryReceipt, { force: true }).catch(() => undefined);
|
|
153
|
+
}
|
|
154
|
+
return { cacheHit: false, receiptPath: plan.receiptPath, fingerprint };
|
|
155
|
+
}
|
|
156
|
+
export function withAspNetPrebuiltRunArguments(command, args) {
|
|
157
|
+
if (!isDotnetRun(command, args)) {
|
|
158
|
+
throw new Error("node_runtime_adapter_invalid: aspnetcore adapter requires a dotnet run command.");
|
|
159
|
+
}
|
|
160
|
+
const applicationArguments = args.indexOf("--");
|
|
161
|
+
const insertionIndex = applicationArguments < 0 ? args.length : applicationArguments;
|
|
162
|
+
const beforeApplication = args.slice(0, insertionIndex);
|
|
163
|
+
return [
|
|
164
|
+
...beforeApplication,
|
|
165
|
+
...(!beforeApplication.includes("--no-build") ? ["--no-build"] : []),
|
|
166
|
+
...(!beforeApplication.includes("--no-restore") ? ["--no-restore"] : []),
|
|
167
|
+
...args.slice(insertionIndex),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
export async function resolveWorktreeCommitSha(worktreePath, supplied) {
|
|
171
|
+
if (supplied && /^[0-9a-f]{40,64}$/iu.test(supplied))
|
|
172
|
+
return supplied.toLowerCase();
|
|
173
|
+
return await new Promise((resolve, reject) => {
|
|
174
|
+
const child = spawn("git", ["rev-parse", "--verify", "HEAD^{commit}"], {
|
|
175
|
+
cwd: worktreePath,
|
|
176
|
+
windowsHide: true,
|
|
177
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
178
|
+
});
|
|
179
|
+
let stdout = "";
|
|
180
|
+
let stderr = "";
|
|
181
|
+
child.stdout.setEncoding("utf8");
|
|
182
|
+
child.stderr.setEncoding("utf8");
|
|
183
|
+
child.stdout.on("data", chunk => { stdout = `${stdout}${String(chunk)}`.slice(-256); });
|
|
184
|
+
child.stderr.on("data", chunk => { stderr = `${stderr}${String(chunk)}`.slice(-1_000); });
|
|
185
|
+
child.once("error", reject);
|
|
186
|
+
child.once("close", code => {
|
|
187
|
+
const commit = stdout.trim();
|
|
188
|
+
if (code === 0 && /^[0-9a-f]{40,64}$/iu.test(commit))
|
|
189
|
+
resolve(commit.toLowerCase());
|
|
190
|
+
else
|
|
191
|
+
reject(new Error(`host_runtime_build_commit_unavailable: git rev-parse failed (${code ?? "unknown"}): ${stderr.trim()}`));
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
function isDotnetRun(command, args) {
|
|
196
|
+
const executable = path.basename(command).toLowerCase();
|
|
197
|
+
return (executable === "dotnet" || executable === "dotnet.exe") && args[0]?.toLowerCase() === "run";
|
|
198
|
+
}
|
|
199
|
+
function readOptionValue(args, option) {
|
|
200
|
+
const index = args.findIndex(argument => argument === option || argument.startsWith(`${option}=`));
|
|
201
|
+
if (index < 0)
|
|
202
|
+
return null;
|
|
203
|
+
const argument = args[index];
|
|
204
|
+
return argument.startsWith(`${option}=`) ? argument.slice(option.length + 1) : args[index + 1] ?? null;
|
|
205
|
+
}
|
|
206
|
+
function forwardBuildOptions(args) {
|
|
207
|
+
const forwarded = [];
|
|
208
|
+
const optionsWithValues = new Set(["-c", "--configuration", "-f", "--framework", "-r", "--runtime", "--arch", "--os"]);
|
|
209
|
+
for (let index = 1; index < args.length; index += 1) {
|
|
210
|
+
const argument = args[index];
|
|
211
|
+
if (argument === "--")
|
|
212
|
+
break;
|
|
213
|
+
if (argument === "--project") {
|
|
214
|
+
index += 1;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (argument.startsWith("--project="))
|
|
218
|
+
continue;
|
|
219
|
+
if (optionsWithValues.has(argument)) {
|
|
220
|
+
const value = args[index + 1];
|
|
221
|
+
if (value !== undefined) {
|
|
222
|
+
forwarded.push(argument, value);
|
|
223
|
+
index += 1;
|
|
224
|
+
}
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if ([...optionsWithValues].some(option => argument.startsWith(`${option}=`))
|
|
228
|
+
|| argument.startsWith("-p:")
|
|
229
|
+
|| argument.startsWith("/p:")) {
|
|
230
|
+
forwarded.push(argument);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return forwarded;
|
|
234
|
+
}
|
|
235
|
+
async function readReceipt(receiptPath) {
|
|
236
|
+
try {
|
|
237
|
+
const parsed = JSON.parse(await fs.readFile(receiptPath, "utf8"));
|
|
238
|
+
return parsed.schemaVersion === 2
|
|
239
|
+
&& typeof parsed.fingerprint === "string"
|
|
240
|
+
&& typeof parsed.planFingerprint === "string"
|
|
241
|
+
&& typeof parsed.inputCommitSha === "string"
|
|
242
|
+
&& typeof parsed.sourceDigest === "string"
|
|
243
|
+
&& typeof parsed.dependencyDigest === "string"
|
|
244
|
+
&& typeof parsed.sdkVersion === "string"
|
|
245
|
+
&& Array.isArray(parsed.outputs)
|
|
246
|
+
? parsed
|
|
247
|
+
: null;
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error.code === "ENOENT" || error instanceof SyntaxError)
|
|
251
|
+
return null;
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function aspNetBuildInputs(plan) {
|
|
256
|
+
const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
|
|
257
|
+
? path.dirname(plan.projectPath)
|
|
258
|
+
: plan.projectPath;
|
|
259
|
+
const sourceDigest = await projectSourceDigest(plan, projectDirectory);
|
|
260
|
+
const dependencyReceipt = path.join(projectDirectory, "obj", ".forge-dependency-preparation.json");
|
|
261
|
+
const dependencyContent = await fs.readFile(dependencyReceipt).catch(() => null);
|
|
262
|
+
const globalJson = await findAncestorFile(projectDirectory, plan.worktreePath, "global.json");
|
|
263
|
+
const globalJsonContent = globalJson ? await fs.readFile(globalJson) : null;
|
|
264
|
+
return {
|
|
265
|
+
sourceDigest,
|
|
266
|
+
dependencyDigest: `sha256:${createHash("sha256")
|
|
267
|
+
.update(dependencyContent ?? Buffer.alloc(0))
|
|
268
|
+
.update(globalJsonContent ?? Buffer.alloc(0))
|
|
269
|
+
.digest("hex")}`,
|
|
270
|
+
sdkVersion: await dotnetSdkVersion(plan.cwd),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Digest of everything the project build compiles from inside the worktree: the
|
|
275
|
+
* project directory, every project it references (transitively, through
|
|
276
|
+
* ProjectReference), and the Directory.Build/Directory.Packages files above them.
|
|
277
|
+
* A change in a referenced project must invalidate the receipt, or the launch
|
|
278
|
+
* reuses a binary built from the previous source.
|
|
279
|
+
*/
|
|
280
|
+
async function projectSourceDigest(plan, projectDirectory) {
|
|
281
|
+
const worktree = path.resolve(plan.worktreePath);
|
|
282
|
+
const directories = await projectSourceDirectories(plan, projectDirectory);
|
|
283
|
+
const files = new Set();
|
|
284
|
+
for (const directory of directories) {
|
|
285
|
+
const collected = [];
|
|
286
|
+
await collectInputFiles(directory, directory, collected);
|
|
287
|
+
for (const file of collected)
|
|
288
|
+
files.add(file);
|
|
289
|
+
for (const buildFile of await ancestorBuildFiles(directory, worktree))
|
|
290
|
+
files.add(buildFile);
|
|
291
|
+
}
|
|
292
|
+
const hash = createHash("sha256");
|
|
293
|
+
for (const file of [...files].sort((left, right) => left.localeCompare(right))) {
|
|
294
|
+
hash.update(path.relative(worktree, file).replaceAll("\\", "/"));
|
|
295
|
+
hash.update("\0");
|
|
296
|
+
hash.update(await fs.readFile(file));
|
|
297
|
+
hash.update("\0");
|
|
298
|
+
}
|
|
299
|
+
return `sha256:${hash.digest("hex")}`;
|
|
300
|
+
}
|
|
301
|
+
const msbuildProjectExtensions = new Set([".csproj", ".fsproj", ".vbproj"]);
|
|
302
|
+
const msbuildDirectoryFiles = ["Directory.Build.props", "Directory.Build.targets", "Directory.Packages.props"];
|
|
303
|
+
/** The project directory and the directories of the projects it references inside the worktree. */
|
|
304
|
+
async function projectSourceDirectories(plan, projectDirectory) {
|
|
305
|
+
const worktree = path.resolve(plan.worktreePath);
|
|
306
|
+
const directories = new Set([path.resolve(projectDirectory)]);
|
|
307
|
+
const queue = msbuildProjectExtensions.has(path.extname(plan.projectPath).toLowerCase())
|
|
308
|
+
? [path.resolve(plan.projectPath)]
|
|
309
|
+
: await projectFilesIn(projectDirectory);
|
|
310
|
+
const visited = new Set();
|
|
311
|
+
while (queue.length > 0) {
|
|
312
|
+
const projectFile = queue.shift();
|
|
313
|
+
if (visited.has(projectFile))
|
|
314
|
+
continue;
|
|
315
|
+
visited.add(projectFile);
|
|
316
|
+
const content = await fs.readFile(projectFile, "utf8").catch(() => null);
|
|
317
|
+
if (content === null)
|
|
318
|
+
continue;
|
|
319
|
+
for (const include of projectReferenceIncludes(content)) {
|
|
320
|
+
// An MSBuild property cannot be resolved here; the referenced source stays outside the digest.
|
|
321
|
+
if (include.includes("$("))
|
|
322
|
+
continue;
|
|
323
|
+
const referenced = path.resolve(path.dirname(projectFile), include.replaceAll("\\", "/"));
|
|
324
|
+
if (!containedIn(worktree, referenced))
|
|
325
|
+
continue;
|
|
326
|
+
directories.add(path.dirname(referenced));
|
|
327
|
+
queue.push(referenced);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return [...directories];
|
|
331
|
+
}
|
|
332
|
+
async function projectFilesIn(directory) {
|
|
333
|
+
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
334
|
+
return entries
|
|
335
|
+
.filter(entry => entry.isFile() && msbuildProjectExtensions.has(path.extname(entry.name).toLowerCase()))
|
|
336
|
+
.map(entry => path.join(directory, entry.name));
|
|
337
|
+
}
|
|
338
|
+
function projectReferenceIncludes(projectXml) {
|
|
339
|
+
const withoutComments = projectXml.replaceAll(/<!--[\s\S]*?-->/gu, "");
|
|
340
|
+
const includes = [];
|
|
341
|
+
for (const match of withoutComments.matchAll(/<ProjectReference\b[^>]*?\bInclude\s*=\s*(?:"([^"]*)"|'([^']*)')/giu)) {
|
|
342
|
+
const value = match[1] ?? match[2] ?? "";
|
|
343
|
+
for (const part of value.split(";")) {
|
|
344
|
+
const trimmed = part.trim();
|
|
345
|
+
if (trimmed)
|
|
346
|
+
includes.push(trimmed);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return includes;
|
|
350
|
+
}
|
|
351
|
+
async function ancestorBuildFiles(directory, worktree) {
|
|
352
|
+
const found = [];
|
|
353
|
+
let current = path.resolve(directory);
|
|
354
|
+
while (containedIn(worktree, current)) {
|
|
355
|
+
for (const name of msbuildDirectoryFiles) {
|
|
356
|
+
const candidate = path.join(current, name);
|
|
357
|
+
if (await fs.stat(candidate).then(stat => stat.isFile()).catch(() => false))
|
|
358
|
+
found.push(candidate);
|
|
359
|
+
}
|
|
360
|
+
if (current === worktree)
|
|
361
|
+
break;
|
|
362
|
+
const parent = path.dirname(current);
|
|
363
|
+
if (parent === current)
|
|
364
|
+
break;
|
|
365
|
+
current = parent;
|
|
366
|
+
}
|
|
367
|
+
return found;
|
|
368
|
+
}
|
|
369
|
+
function containedIn(root, candidate) {
|
|
370
|
+
const relative = path.relative(root, candidate);
|
|
371
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
372
|
+
}
|
|
373
|
+
async function collectInputFiles(root, directory, files) {
|
|
374
|
+
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
375
|
+
for (const entry of entries) {
|
|
376
|
+
const absolute = path.join(directory, entry.name);
|
|
377
|
+
if (entry.isDirectory()) {
|
|
378
|
+
if (!["bin", "obj", "node_modules", ".git", "TestResults"].includes(entry.name)) {
|
|
379
|
+
await collectInputFiles(root, absolute, files);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else if (entry.isFile()) {
|
|
383
|
+
files.push(absolute);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async function collectAspNetBuildOutputs(plan) {
|
|
388
|
+
const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
|
|
389
|
+
? path.dirname(plan.projectPath)
|
|
390
|
+
: plan.projectPath;
|
|
391
|
+
const outputRoot = path.join(projectDirectory, "bin");
|
|
392
|
+
const outputs = [];
|
|
393
|
+
await collectOutputFiles(outputRoot, projectDirectory, outputs);
|
|
394
|
+
return outputs.sort((left, right) => left.path.localeCompare(right.path));
|
|
395
|
+
}
|
|
396
|
+
async function collectOutputFiles(directory, projectDirectory, outputs) {
|
|
397
|
+
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
398
|
+
for (const entry of entries) {
|
|
399
|
+
const absolute = path.join(directory, entry.name);
|
|
400
|
+
if (entry.isDirectory())
|
|
401
|
+
await collectOutputFiles(absolute, projectDirectory, outputs);
|
|
402
|
+
else if (entry.isFile()) {
|
|
403
|
+
const stat = await fs.stat(absolute);
|
|
404
|
+
outputs.push({
|
|
405
|
+
path: path.relative(projectDirectory, absolute).replaceAll("\\", "/"),
|
|
406
|
+
size: stat.size,
|
|
407
|
+
digest: createHash("sha256").update(await fs.readFile(absolute)).digest("hex"),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function aspNetOutputsMatch(plan, outputs) {
|
|
413
|
+
if (outputs.length === 0)
|
|
414
|
+
return false;
|
|
415
|
+
const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
|
|
416
|
+
? path.dirname(plan.projectPath)
|
|
417
|
+
: plan.projectPath;
|
|
418
|
+
for (const output of outputs) {
|
|
419
|
+
const absolute = path.resolve(projectDirectory, output.path);
|
|
420
|
+
const relative = path.relative(projectDirectory, absolute);
|
|
421
|
+
if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
422
|
+
return false;
|
|
423
|
+
const stat = await fs.stat(absolute).catch(() => null);
|
|
424
|
+
if (!stat?.isFile() || stat.size !== output.size)
|
|
425
|
+
return false;
|
|
426
|
+
const digest = createHash("sha256").update(await fs.readFile(absolute)).digest("hex");
|
|
427
|
+
if (digest !== output.digest)
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
async function findAncestorFile(directory, root, name) {
|
|
433
|
+
let current = path.resolve(directory);
|
|
434
|
+
const resolvedRoot = path.resolve(root);
|
|
435
|
+
while (true) {
|
|
436
|
+
const candidate = path.join(current, name);
|
|
437
|
+
if (await fs.stat(candidate).then(stat => stat.isFile()).catch(() => false))
|
|
438
|
+
return candidate;
|
|
439
|
+
if (current === resolvedRoot)
|
|
440
|
+
return null;
|
|
441
|
+
const parent = path.dirname(current);
|
|
442
|
+
if (parent === current || path.relative(resolvedRoot, parent).startsWith(".."))
|
|
443
|
+
return null;
|
|
444
|
+
current = parent;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async function dotnetSdkVersion(cwd) {
|
|
448
|
+
return await new Promise(resolve => {
|
|
449
|
+
const child = spawn("dotnet", ["--version"], { cwd, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
450
|
+
let output = "";
|
|
451
|
+
child.stdout.setEncoding("utf8");
|
|
452
|
+
child.stderr.setEncoding("utf8");
|
|
453
|
+
child.stdout.on("data", chunk => { output += String(chunk); });
|
|
454
|
+
child.stderr.on("data", chunk => { output += String(chunk); });
|
|
455
|
+
child.once("error", () => resolve("unavailable"));
|
|
456
|
+
child.once("close", code => resolve(code === 0 ? output.trim().slice(0, 256) : `unavailable:${code ?? "unknown"}`));
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function buildEnvironmentContract(environment) {
|
|
460
|
+
return {
|
|
461
|
+
DOTNET_ROOT: environment.DOTNET_ROOT ?? process.env.DOTNET_ROOT ?? null,
|
|
462
|
+
DOTNET_ROLL_FORWARD: environment.DOTNET_ROLL_FORWARD ?? process.env.DOTNET_ROLL_FORWARD ?? null,
|
|
463
|
+
DOTNET_MULTILEVEL_LOOKUP: environment.DOTNET_MULTILEVEL_LOOKUP ?? process.env.DOTNET_MULTILEVEL_LOOKUP ?? null,
|
|
464
|
+
MSBuildSDKsPath: environment.MSBuildSDKsPath ?? process.env.MSBuildSDKsPath ?? null,
|
|
465
|
+
NUGET_PACKAGES: environment.NUGET_PACKAGES ?? process.env.NUGET_PACKAGES ?? null,
|
|
466
|
+
FORGE_BUILD_CACHE_EPOCH: createHash("sha256")
|
|
467
|
+
.update(environment.FORGE_BUILD_CACHE_EPOCH ?? process.env.FORGE_BUILD_CACHE_EPOCH ?? "default")
|
|
468
|
+
.digest("hex"),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function diagnostic(label, value) {
|
|
472
|
+
const normalized = value.replaceAll(/[\r\n\t]+/gu, " ").trim();
|
|
473
|
+
return normalized ? `${label} tail: ${normalized.slice(-2_000)}` : "";
|
|
474
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { NativeTestPostgresFallback } from "./native-test-postgres-fallback.js";
|
|
2
|
+
/**
|
|
3
|
+
* The managed host attempt's database capability. The Bridge keeps the test cluster's
|
|
4
|
+
* administrator credential; an attempt (its agent, its application runtime and its tests)
|
|
5
|
+
* receives only a login for one database created for it. Forge.Api checks that login before it
|
|
6
|
+
* migrates (AttemptScopedDatabasePolicy.AssertBrokeredCapabilityAsync), but that check runs in
|
|
7
|
+
* attempt code: the boundary is what this broker issues and the cluster's pg_hba rules, which
|
|
8
|
+
* let an attempt role log in only to its own database.
|
|
9
|
+
*/
|
|
10
|
+
export declare const attemptDatabaseCapabilityEnvironment = "FORGE_ATTEMPT_DATABASE_CAPABILITY";
|
|
11
|
+
export interface AttemptDatabaseCapability {
|
|
12
|
+
readonly databaseName: string;
|
|
13
|
+
readonly connectionString: string;
|
|
14
|
+
}
|
|
15
|
+
export type AttemptDatabaseReleaseOutcome = "dropped" | "missing" | "retained";
|
|
16
|
+
export interface AttemptDatabaseBroker {
|
|
17
|
+
provision(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<AttemptDatabaseCapability>;
|
|
18
|
+
release(dispatchAttemptId: string, fencingToken: string): Promise<AttemptDatabaseReleaseOutcome>;
|
|
19
|
+
/**
|
|
20
|
+
* Drops this broker's databases whose attempt is no longer live, asking `isLive` about each one
|
|
21
|
+
* just before acting on it. Returns the dropped names.
|
|
22
|
+
*/
|
|
23
|
+
reapOrphans(isLive: (dispatchAttemptId: string) => boolean): Promise<readonly string[]>;
|
|
24
|
+
}
|
|
25
|
+
export declare class AttemptDatabaseBrokerError extends Error {
|
|
26
|
+
readonly code: string;
|
|
27
|
+
constructor(code: string, detail: string);
|
|
28
|
+
}
|
|
29
|
+
export interface AttemptDatabaseLogin {
|
|
30
|
+
readonly database: string;
|
|
31
|
+
readonly username: string;
|
|
32
|
+
readonly password: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Runs one psql script and returns its unaligned output: as the cluster administrator against
|
|
36
|
+
* `postgres`, or, given a login, as that login against its database.
|
|
37
|
+
*/
|
|
38
|
+
export type AttemptDatabaseSqlRunner = (sql: string, signal?: AbortSignal, login?: AttemptDatabaseLogin) => Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* The ownership marker on the attempt's role. Only a role with CREATEROLE can change a role's
|
|
41
|
+
* comment, so the attempt cannot forge or erase it (it can rewrite its database's comment, which
|
|
42
|
+
* is therefore informational). Must match AttemptScopedDatabasePolicy.BrokeredRoleMarkerPrefix.
|
|
43
|
+
*/
|
|
44
|
+
export declare function brokeredDatabaseMarker(dispatchAttemptId: string, fencingToken: string, owner: string): string;
|
|
45
|
+
export declare function attemptDatabaseName(dispatchAttemptId: string): string;
|
|
46
|
+
/** Identifies one Bridge's broker on a shared cluster, so it reaps only databases it issued. */
|
|
47
|
+
export declare function attemptDatabaseBrokerOwner(stateRoot: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Brokers attempt databases on the dedicated native test cluster that
|
|
50
|
+
* scripts/setup-native-test-postgres.ps1 provisions. That cluster holds only disposable test
|
|
51
|
+
* databases, so even a leaked attempt capability cannot reach developer data. Each attempt
|
|
52
|
+
* gets a login role and a database it owns, cloned from template1 (which carries pgvector,
|
|
53
|
+
* an extension an unprivileged owner cannot create).
|
|
54
|
+
*/
|
|
55
|
+
export declare class NativeTestClusterDatabaseBroker implements AttemptDatabaseBroker {
|
|
56
|
+
private readonly admin;
|
|
57
|
+
private readonly runSql;
|
|
58
|
+
private readonly owner;
|
|
59
|
+
private readonly delay;
|
|
60
|
+
/** Names being provisioned right now; the reaper leaves them alone. */
|
|
61
|
+
private readonly provisioning;
|
|
62
|
+
constructor(admin: NativeTestClusterAdmin, runSql: AttemptDatabaseSqlRunner, owner: string, delay?: (milliseconds: number) => Promise<void>);
|
|
63
|
+
provision(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<AttemptDatabaseCapability>;
|
|
64
|
+
release(dispatchAttemptId: string, fencingToken: string): Promise<AttemptDatabaseReleaseOutcome>;
|
|
65
|
+
reapOrphans(isLive: (dispatchAttemptId: string) => boolean): Promise<readonly string[]>;
|
|
66
|
+
private state;
|
|
67
|
+
private createDatabase;
|
|
68
|
+
/** Fails closed unless the cluster lets this login reach its own database and nothing else. */
|
|
69
|
+
private assertConfinedToOwnDatabase;
|
|
70
|
+
private drop;
|
|
71
|
+
}
|
|
72
|
+
export interface NativeTestClusterAdmin {
|
|
73
|
+
readonly host: string;
|
|
74
|
+
readonly port: number;
|
|
75
|
+
readonly username: string;
|
|
76
|
+
readonly password: string;
|
|
77
|
+
}
|
|
78
|
+
export declare function nativeTestClusterAdmin(fallback: Pick<NativeTestPostgresFallback, "connectionString" | "endpoint">): NativeTestClusterAdmin;
|
|
79
|
+
/** Runs SQL through the psql that ships with the PostgreSQL install hosting the native test cluster. */
|
|
80
|
+
export declare function psqlSqlRunner(admin: NativeTestClusterAdmin, psqlPath: string, timeoutMs?: number): AttemptDatabaseSqlRunner;
|
|
81
|
+
/** psql beside the cluster's pg_ctl: FORGE_NATIVE_TEST_POSTGRES_PSQL, a Windows install, or PATH. */
|
|
82
|
+
export declare function resolvePsqlPath(): string | null;
|
|
83
|
+
/**
|
|
84
|
+
* The broker for this host, or null when no native test cluster is provisioned. Without a
|
|
85
|
+
* broker, Forge.Api still refuses to start in a managed host attempt; other applications run.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createNativeTestClusterDatabaseBroker(readFallback: () => NativeTestPostgresFallback | null, stateRoot: string): AttemptDatabaseBroker | null;
|
|
88
|
+
/** The exact strings to redact wherever a capability may be printed: the whole value and its password. */
|
|
89
|
+
export declare function attemptDatabaseCapabilitySecrets(capability: string | undefined): readonly string[];
|