@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b
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 +128 -4
- 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 +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- 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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -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.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -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 +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +104 -26
- 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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- 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 +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- 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/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -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 +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- 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 +1 -2
- package/dist/sandbox/runtime.js +9 -19
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- 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 +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.js +6 -5
- 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-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- 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-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 +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -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 +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -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 +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { failureFactsForCode, failureResult, } from "./session.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a Forge PR review may run. A review reads pull request code an author controls, and the only
|
|
4
|
+
* operating-system isolation this bridge enforces is its Docker sandbox: a container with no git
|
|
5
|
+
* credential, no remote and no host home directory. On a plain host the provider runs as the
|
|
6
|
+
* bridge's user, beside that user's git credentials and provider sign-in, and the review guardrails
|
|
7
|
+
* (credential-free git environment, tool deny rules, command shims, the post-run ref and remote-head
|
|
8
|
+
* checks) are defence in depth, not a boundary. So a review placed on the host is refused before any
|
|
9
|
+
* provider starts unless the runner's owner opted in with `allowUnsandboxedPrReview: true` in
|
|
10
|
+
* bridge.json, accepting that risk.
|
|
11
|
+
*/
|
|
12
|
+
export const prReviewUnsandboxedHostCode = "pr_review.unsandboxed_host";
|
|
13
|
+
/**
|
|
14
|
+
* A review placed in this bridge's Docker sandbox for a project whose sandbox contract it cannot read or build:
|
|
15
|
+
* refused before any provider starts, and never retried on this runner (a capacity wait would only expire).
|
|
16
|
+
*/
|
|
17
|
+
export const prReviewSandboxUnavailableCode = "pr_review.sandbox_unavailable";
|
|
18
|
+
/** The execution facility a runner advertises when its owner opted in to host-placed reviews. */
|
|
19
|
+
export const prReviewUnsandboxedHostFacility = "pr_review_unsandboxed_host";
|
|
20
|
+
/** The warning a host-placed review carries when the runner's owner opted in. */
|
|
21
|
+
export const prReviewUnsandboxedHostWarningEvent = "pr_review_unsandboxed_host_warning";
|
|
22
|
+
/** A dispatch for the review-only pr_review session, by role, lane or cycle kind. */
|
|
23
|
+
export function isPrReviewDispatch(dispatch) {
|
|
24
|
+
return [dispatch.execution.role, dispatch.execution.lane, dispatch.cycleRun.kind]
|
|
25
|
+
.some((value) => (value ?? "").trim().toLowerCase() === "pr_review");
|
|
26
|
+
}
|
|
27
|
+
/** The pull request head a review dispatch reads, lowercased, or null for any other dispatch. */
|
|
28
|
+
export function prReviewDispatchHeadSha(dispatch) {
|
|
29
|
+
if (!isPrReviewDispatch(dispatch)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return (dispatch.prReview?.headSha || dispatch.pullRequest?.headSha || "").trim().toLowerCase() || null;
|
|
33
|
+
}
|
|
34
|
+
function placedInDocker(dispatch) {
|
|
35
|
+
return dispatch.sandbox?.executionMode === "docker";
|
|
36
|
+
}
|
|
37
|
+
/** Why this bridge refuses the dispatch, or null: a review placed outside Docker without the opt-in. */
|
|
38
|
+
export function prReviewPlacementRefusal(dispatch, allowUnsandboxedPrReview) {
|
|
39
|
+
if (!isPrReviewDispatch(dispatch) || placedInDocker(dispatch) || allowUnsandboxedPrReview === true) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return `${prReviewUnsandboxedHostCode}: this Forge PR review was placed on the bridge host, where the provider would read `
|
|
43
|
+
+ "author-controlled pull request code with the bridge user's credentials in reach. This bridge runs reviews only in its "
|
|
44
|
+
+ "Docker sandbox. Its owner can accept the risk with \"allowUnsandboxedPrReview\": true in bridge.json.";
|
|
45
|
+
}
|
|
46
|
+
/** The warning for a review that runs on the host because the runner's owner opted in, or null. */
|
|
47
|
+
export function prReviewUnsandboxedHostWarning(dispatch, allowUnsandboxedPrReview) {
|
|
48
|
+
if (!isPrReviewDispatch(dispatch) || placedInDocker(dispatch) || allowUnsandboxedPrReview !== true) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return "Warning: this Forge PR review ran on the bridge host without OS-level isolation, because the runner's owner set "
|
|
52
|
+
+ "\"allowUnsandboxedPrReview\": true in bridge.json. The provider read author-controlled code with the bridge user's "
|
|
53
|
+
+ "credentials in reach; only Forge's review guardrails stood between them.";
|
|
54
|
+
}
|
|
55
|
+
/** The terminal failure for a refused review (see {@link prReviewPlacementRefusal}), or null. */
|
|
56
|
+
export function prReviewPlacementRefusalResult(dispatch, allowUnsandboxedPrReview) {
|
|
57
|
+
const refusal = prReviewPlacementRefusal(dispatch, allowUnsandboxedPrReview);
|
|
58
|
+
return refusal
|
|
59
|
+
? failureResult(refusal, [{ role: "runner", kind: "error", content: refusal, eventType: prReviewUnsandboxedHostCode }], failureFactsForCode(prReviewUnsandboxedHostCode))
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Set by the server-local runner on a run-once whose Forge PR review it admitted on its host (in its container
|
|
64
|
+
* sandbox, or because the runner opted in to host reviews). Nothing else sets it.
|
|
65
|
+
*/
|
|
66
|
+
export const prReviewHostAdmittedEnv = "FORGE_PR_REVIEW_HOST_ADMITTED";
|
|
67
|
+
/**
|
|
68
|
+
* forge-bridge run-once (which the server-local runner launches): a Forge PR review placed outside Docker runs
|
|
69
|
+
* only when the server-local runner admitted it on this host; any other is refused before a provider starts.
|
|
70
|
+
*/
|
|
71
|
+
export async function runOnceWithReviewPlacement(dispatch, run, env = process.env) {
|
|
72
|
+
return prReviewPlacementRefusalResult(dispatch, env[prReviewHostAdmittedEnv] === "1") ?? await run(dispatch);
|
|
73
|
+
}
|
|
74
|
+
/** The execution facilities that tell Forge this runner's owner opted in to host-placed reviews. */
|
|
75
|
+
export function prReviewExecutionFacilities(allowUnsandboxedPrReview) {
|
|
76
|
+
return allowUnsandboxedPrReview === true ? [prReviewUnsandboxedHostFacility] : [];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Runs the dispatch; a review that runs on the host by the owner's opt-in is logged, announced as a
|
|
80
|
+
* session event and reported in the result summary as a warning.
|
|
81
|
+
*/
|
|
82
|
+
export async function runWithUnsandboxedReviewWarning(dispatch, allowUnsandboxedPrReview, sink, log, run) {
|
|
83
|
+
const warning = prReviewUnsandboxedHostWarning(dispatch, allowUnsandboxedPrReview);
|
|
84
|
+
if (!warning) {
|
|
85
|
+
return await run();
|
|
86
|
+
}
|
|
87
|
+
log(warning);
|
|
88
|
+
await sink.emit({ role: "runner", kind: "checkpoint", content: warning, eventType: prReviewUnsandboxedHostWarningEvent });
|
|
89
|
+
const result = await run();
|
|
90
|
+
return { ...result, summary: `${result.summary} ${warning}` };
|
|
91
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type RunnerDispatchEvent } from "./session.types.js";
|
|
2
|
+
export { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
3
|
+
export type ChangeSetGit = (args: readonly string[]) => Promise<{
|
|
4
|
+
exitCode: number;
|
|
5
|
+
stdout?: string;
|
|
6
|
+
stderr?: string;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Git reads history as it was committed. The agent could otherwise plant a replace ref
|
|
10
|
+
* (`git replace <target tip> <fake>`) or a graft that rewrites what the merge parent's tree is and
|
|
11
|
+
* whose ancestor it is. The bridge's own git calls in the pass, and the affected .NET run that measures
|
|
12
|
+
* against these revisions, run with it (the sandbox import does the same, sandbox/runtime.ts). Other
|
|
13
|
+
* check steps do not: their suites may make replace refs or grafts of their own in throwaway repos. An empty graft file is no grafts; /dev/null is one on every
|
|
14
|
+
* platform Git runs on (Git for Windows maps it to NUL), and nothing can be written into it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const historyIntegrityEnvironment: Readonly<Record<string, string>>;
|
|
17
|
+
/**
|
|
18
|
+
* The pass's change set: the verified merge parent it measures against (null when the attempt makes no
|
|
19
|
+
* merge, or merges something its target branch's CI did not validate), and the changed paths that select
|
|
20
|
+
* its checks. Emits whether and how a merge scoped the pass.
|
|
21
|
+
*/
|
|
22
|
+
export declare function passChangeSet(git: ChangeSetGit, execution: {
|
|
23
|
+
readonly baselineRevision?: string;
|
|
24
|
+
readonly targetBranch?: string;
|
|
25
|
+
} | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<{
|
|
26
|
+
readonly mergeParent: string | null;
|
|
27
|
+
readonly changedPaths: readonly string[];
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* The other parent of a merge the attempt makes: MERGE_HEAD while a merge is in progress, or the second
|
|
31
|
+
* parent of a merge commit HEAD made since the dispatch baseline. Null when the attempt makes no merge,
|
|
32
|
+
* including a merge commit that was already HEAD at dispatch.
|
|
33
|
+
*/
|
|
34
|
+
export declare function attemptMergeParent(git: ChangeSetGit, baselineRevision: string | undefined): Promise<string | null>;
|
|
35
|
+
/** A merge parent the pass may scope to, or why it may not. */
|
|
36
|
+
export type MergeScope = {
|
|
37
|
+
readonly mergeParent: string;
|
|
38
|
+
readonly targetRef: string;
|
|
39
|
+
} | {
|
|
40
|
+
readonly mergeParent: null;
|
|
41
|
+
readonly unscopedReason: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Scopes the pass to a merge parent only when the target branch's CI validated it: the parent is the
|
|
45
|
+
* target's tip on origin, or an ancestor of it. The agent controls the merge and every local ref (it can
|
|
46
|
+
* rewrite refs/remotes/origin/<target>, which a host worktree shares with the main repository), so the
|
|
47
|
+
* bridge fetches the target into a ref of its own for this pass and deletes it afterwards. A parent
|
|
48
|
+
* anywhere else (a scratch branch holding the attempt's own work), or a fetch that fails (a Docker
|
|
49
|
+
* sandbox workspace has no origin), scopes nothing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function verifiedMergeScope(git: ChangeSetGit, mergeParent: string, targetBranch: string | undefined, validationRef?: string): Promise<MergeScope>;
|
|
52
|
+
/**
|
|
53
|
+
* The paths the attempt changed: uncommitted, committed since the baseline, and untracked. With a
|
|
54
|
+
* verified merge parent, what the merged head changes over that parent, and the untracked paths.
|
|
55
|
+
*/
|
|
56
|
+
export declare function changedPathInventory(git: ChangeSetGit, baselineRevision: string | undefined, mergeParent: string | null): Promise<readonly string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* The step environment the affected .NET tests read (scripts/run-affected-dotnet-tests.mjs): the dispatch
|
|
59
|
+
* baseline, and the verified merge parent they measure against instead when there is one. The validator
|
|
60
|
+
* adds historyIntegrityEnvironment to that check's steps only.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validationRevisionEnvironment(baselineRevision: string | undefined, mergeParent: string | null): Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// What a pre-publication pass validates: the paths the attempt changed, which select the CI parity
|
|
2
|
+
// checks, and the revisions the affected .NET tests measure against. When the attempt makes a merge
|
|
3
|
+
// (a conflict repair merging the target branch in) and the merge's other parent is on the target
|
|
4
|
+
// branch, the pass measures the merged head against that parent, as CI measures a pull request
|
|
5
|
+
// against its base: what the target branch brought matches it and was validated by its CI, while the
|
|
6
|
+
// Story's own changes and every conflict resolution that is not the target's version still count.
|
|
7
|
+
// The merged head's integration is CI's job on the pushed head.
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { validationEvent } from "./pre-publication-pass.js";
|
|
10
|
+
import { ForgeFailureError } from "./session.types.js";
|
|
11
|
+
// The new exports of the same change; the pass checks them alongside the changed paths.
|
|
12
|
+
export { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
13
|
+
/**
|
|
14
|
+
* Git reads history as it was committed. The agent could otherwise plant a replace ref
|
|
15
|
+
* (`git replace <target tip> <fake>`) or a graft that rewrites what the merge parent's tree is and
|
|
16
|
+
* whose ancestor it is. The bridge's own git calls in the pass, and the affected .NET run that measures
|
|
17
|
+
* against these revisions, run with it (the sandbox import does the same, sandbox/runtime.ts). Other
|
|
18
|
+
* check steps do not: their suites may make replace refs or grafts of their own in throwaway repos. An empty graft file is no grafts; /dev/null is one on every
|
|
19
|
+
* platform Git runs on (Git for Windows maps it to NUL), and nothing can be written into it.
|
|
20
|
+
*/
|
|
21
|
+
export const historyIntegrityEnvironment = {
|
|
22
|
+
GIT_NO_REPLACE_OBJECTS: "1",
|
|
23
|
+
GIT_GRAFT_FILE: "/dev/null",
|
|
24
|
+
};
|
|
25
|
+
const commitSha = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/iu;
|
|
26
|
+
// A branch name the bridge can fetch by refspec; anything else scopes nothing.
|
|
27
|
+
const branchName = /^(?!-)(?!.*\.\.)[A-Za-z0-9._/-]+$/u;
|
|
28
|
+
/**
|
|
29
|
+
* The pass's change set: the verified merge parent it measures against (null when the attempt makes no
|
|
30
|
+
* merge, or merges something its target branch's CI did not validate), and the changed paths that select
|
|
31
|
+
* its checks. Emits whether and how a merge scoped the pass.
|
|
32
|
+
*/
|
|
33
|
+
export async function passChangeSet(git, execution, emit) {
|
|
34
|
+
const attempted = await attemptMergeParent(git, execution?.baselineRevision);
|
|
35
|
+
const scope = attempted === null ? null : await verifiedMergeScope(git, attempted, execution?.targetBranch);
|
|
36
|
+
if (scope !== null && scope.mergeParent === null) {
|
|
37
|
+
await emit?.(validationEvent("prepublication_validation_merge_unscoped", "validation-contract", `This attempt merges ${attempted}, but ${scope.unscopedReason}: every path the attempt changed selects checks.`, { mergeParent: attempted, reason: scope.unscopedReason }));
|
|
38
|
+
}
|
|
39
|
+
const mergeParent = scope?.mergeParent ?? null;
|
|
40
|
+
const changedPaths = await changedPathInventory(git, execution?.baselineRevision, mergeParent);
|
|
41
|
+
if (scope !== null && scope.mergeParent !== null) {
|
|
42
|
+
// A merged head that matches the parent selects nothing; say so rather than pass silently.
|
|
43
|
+
await emit?.(changedPaths.length === 0
|
|
44
|
+
? validationEvent("prepublication_validation_merge_scope_empty", "validation-contract", `This attempt merges ${scope.mergeParent} from ${scope.targetRef}, and its merged head matches it: no check is selected; CI validates the merged head.`, { severity: "warning", mergeParent: scope.mergeParent, targetRef: scope.targetRef })
|
|
45
|
+
: validationEvent("prepublication_validation_merge_scoped", "validation-contract", `This attempt merges ${scope.mergeParent} from ${scope.targetRef}: checks are selected by the ${changedPaths.length} path(s) the merged head changes over it; CI validates the merged head.`, { mergeParent: scope.mergeParent, targetRef: scope.targetRef }));
|
|
46
|
+
}
|
|
47
|
+
return { mergeParent, changedPaths };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The other parent of a merge the attempt makes: MERGE_HEAD while a merge is in progress, or the second
|
|
51
|
+
* parent of a merge commit HEAD made since the dispatch baseline. Null when the attempt makes no merge,
|
|
52
|
+
* including a merge commit that was already HEAD at dispatch.
|
|
53
|
+
*/
|
|
54
|
+
export async function attemptMergeParent(git, baselineRevision) {
|
|
55
|
+
const merging = await resolveCommit(git, "MERGE_HEAD");
|
|
56
|
+
if (merging)
|
|
57
|
+
return merging;
|
|
58
|
+
const baseline = baselineRevision?.trim();
|
|
59
|
+
if (!baseline)
|
|
60
|
+
return null;
|
|
61
|
+
const secondParent = await resolveCommit(git, "HEAD^2");
|
|
62
|
+
if (!secondParent)
|
|
63
|
+
return null;
|
|
64
|
+
const head = await resolveCommit(git, "HEAD");
|
|
65
|
+
const base = await resolveCommit(git, baseline);
|
|
66
|
+
return head !== null && base !== null && head !== base ? secondParent : null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Scopes the pass to a merge parent only when the target branch's CI validated it: the parent is the
|
|
70
|
+
* target's tip on origin, or an ancestor of it. The agent controls the merge and every local ref (it can
|
|
71
|
+
* rewrite refs/remotes/origin/<target>, which a host worktree shares with the main repository), so the
|
|
72
|
+
* bridge fetches the target into a ref of its own for this pass and deletes it afterwards. A parent
|
|
73
|
+
* anywhere else (a scratch branch holding the attempt's own work), or a fetch that fails (a Docker
|
|
74
|
+
* sandbox workspace has no origin), scopes nothing.
|
|
75
|
+
*/
|
|
76
|
+
export async function verifiedMergeScope(git, mergeParent, targetBranch, validationRef = `refs/forge/validation-target/${randomUUID()}`) {
|
|
77
|
+
const target = targetBranch?.trim() ?? "";
|
|
78
|
+
if (!target)
|
|
79
|
+
return { mergeParent: null, unscopedReason: "the dispatch names no target branch" };
|
|
80
|
+
if (commitSha.test(target))
|
|
81
|
+
return await scopeToTip(git, mergeParent, target, target);
|
|
82
|
+
const branch = target.replace(/^refs\/heads\//u, "");
|
|
83
|
+
if (!branchName.test(branch))
|
|
84
|
+
return { mergeParent: null, unscopedReason: `target branch ${target} is not a branch name` };
|
|
85
|
+
const targetRef = `origin/${branch}`;
|
|
86
|
+
try {
|
|
87
|
+
// An empty --refmap keeps the fetch from also moving refs/remotes/origin/<target>: it writes only its
|
|
88
|
+
// own ref. The fetch is inside the try, so an aborted fetch that already wrote the ref still deletes it.
|
|
89
|
+
const fetched = await git(["fetch", "--no-tags", "--no-write-fetch-head", "--refmap=", "--quiet", "origin",
|
|
90
|
+
`+refs/heads/${branch}:${validationRef}`]);
|
|
91
|
+
if (fetched.exitCode !== 0)
|
|
92
|
+
return { mergeParent: null, unscopedReason: `the bridge could not fetch ${branch} from origin` };
|
|
93
|
+
return await scopeToTip(git, mergeParent, validationRef, targetRef);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
// Forge leaves nothing behind: the ref is this pass's alone.
|
|
97
|
+
await git(["update-ref", "-d", validationRef]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function scopeToTip(git, mergeParent, revision, targetRef) {
|
|
101
|
+
const tip = await resolveCommit(git, revision);
|
|
102
|
+
if (tip === null)
|
|
103
|
+
return { mergeParent: null, unscopedReason: `${targetRef} is not in this checkout` };
|
|
104
|
+
if (tip === mergeParent)
|
|
105
|
+
return { mergeParent, targetRef };
|
|
106
|
+
const ancestor = await git(["merge-base", "--is-ancestor", mergeParent, tip]);
|
|
107
|
+
return ancestor.exitCode === 0
|
|
108
|
+
? { mergeParent, targetRef }
|
|
109
|
+
: { mergeParent: null, unscopedReason: `${mergeParent} is not on ${targetRef}` };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The paths the attempt changed: uncommitted, committed since the baseline, and untracked. With a
|
|
113
|
+
* verified merge parent, what the merged head changes over that parent, and the untracked paths.
|
|
114
|
+
*/
|
|
115
|
+
export async function changedPathInventory(git, baselineRevision, mergeParent) {
|
|
116
|
+
const baseline = mergeParent === null ? baselineRevision?.trim() : undefined;
|
|
117
|
+
const paths = new Set();
|
|
118
|
+
if (mergeParent !== null) {
|
|
119
|
+
// Renames count as a deletion plus an addition, so both sides of one count.
|
|
120
|
+
for (const line of await gitLines(git, ["diff", "--name-only", "--no-renames", mergeParent, "--"]))
|
|
121
|
+
paths.add(normalizedPath(line));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (const line of await gitLines(git, ["diff", "--name-only", "HEAD", "--"]))
|
|
125
|
+
paths.add(normalizedPath(line));
|
|
126
|
+
}
|
|
127
|
+
if (baseline) {
|
|
128
|
+
for (const line of await gitLines(git, ["diff", "--name-only", `${baseline}..HEAD`, "--"]))
|
|
129
|
+
paths.add(normalizedPath(line));
|
|
130
|
+
}
|
|
131
|
+
for (const line of await gitLines(git, ["status", "--porcelain=v1", "--untracked-files=all"])) {
|
|
132
|
+
// Against a merge parent, the tracked paths are already measured; only the untracked ones add.
|
|
133
|
+
if (mergeParent !== null && !line.startsWith("??"))
|
|
134
|
+
continue;
|
|
135
|
+
paths.add(normalizedPath(line.slice(3).split(" -> ").at(-1) ?? ""));
|
|
136
|
+
}
|
|
137
|
+
paths.delete("");
|
|
138
|
+
return [...paths];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The step environment the affected .NET tests read (scripts/run-affected-dotnet-tests.mjs): the dispatch
|
|
142
|
+
* baseline, and the verified merge parent they measure against instead when there is one. The validator
|
|
143
|
+
* adds historyIntegrityEnvironment to that check's steps only.
|
|
144
|
+
*/
|
|
145
|
+
export function validationRevisionEnvironment(baselineRevision, mergeParent) {
|
|
146
|
+
const baseline = baselineRevision?.trim();
|
|
147
|
+
return {
|
|
148
|
+
...(baseline ? { FORGE_VALIDATION_BASE_REVISION: baseline } : {}),
|
|
149
|
+
...(mergeParent ? { FORGE_VALIDATION_MERGE_PARENT_REVISION: mergeParent } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async function resolveCommit(git, revision) {
|
|
153
|
+
const result = await git(["rev-parse", "-q", "--verify", `${revision}^{commit}`]);
|
|
154
|
+
const sha = `${result.stdout ?? ""}`.trim();
|
|
155
|
+
return result.exitCode === 0 && commitSha.test(sha) ? sha.toLowerCase() : null;
|
|
156
|
+
}
|
|
157
|
+
async function gitLines(git, args) {
|
|
158
|
+
const result = await git(args);
|
|
159
|
+
if (result.exitCode !== 0) {
|
|
160
|
+
throw new ForgeFailureError("prepublication_validation_failed", `prepublication_validation_failed: unable to inventory changed paths: ${result.stderr ?? result.stdout ?? "git failed"}`, "bridge");
|
|
161
|
+
}
|
|
162
|
+
return `${result.stdout ?? ""}`.split(/\r?\n/u).filter(Boolean);
|
|
163
|
+
}
|
|
164
|
+
function normalizedPath(raw) {
|
|
165
|
+
return raw.trim().replaceAll("\\", "/");
|
|
166
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
2
2
|
import { HostCapacityTimeoutError } from "../runtime/host-load-governor.js";
|
|
3
3
|
import { HostCapacityLedgerUnavailableError } from "../runtime/host-load-ledger-lock.js";
|
|
4
|
-
import { retentionFor, returnHostLoadToken } from "../runtime/host-load-step-run.js";
|
|
4
|
+
import { orderedWaitReports, retentionFor, returnHostLoadToken } from "../runtime/host-load-step-run.js";
|
|
5
5
|
import { classifyValidationStep } from "../runtime/host-load-step-class.js";
|
|
6
6
|
import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
|
|
7
7
|
/**
|
|
@@ -23,6 +23,8 @@ export async function runHostGovernedValidationStep(gate, step, run) {
|
|
|
23
23
|
await step.emit?.({ role: "runner", kind, content, eventType, data: JSON.stringify({ ...base, ...data }) })
|
|
24
24
|
.catch(() => undefined);
|
|
25
25
|
};
|
|
26
|
+
// Every waiting event lands before the admitted or failed one that follows it.
|
|
27
|
+
const reports = orderedWaitReports(async (decision) => await emit("prepublication_host_capacity_waiting", `Pre-publication step '${step.checkId}' (${stepClass}) is waiting for host capacity: ${decision.detail}`, { status: "waiting_for_host_capacity", reason: decision.reason, cpuCores: cost.cpuCores, memoryBytes: cost.memoryBytes }));
|
|
26
28
|
let admission;
|
|
27
29
|
try {
|
|
28
30
|
admission = await gate.acquire({
|
|
@@ -31,12 +33,11 @@ export async function runHostGovernedValidationStep(gate, step, run) {
|
|
|
31
33
|
cost,
|
|
32
34
|
dispatchAttemptId: step.owner?.dispatchAttemptId ?? null,
|
|
33
35
|
priority: step.owner?.priority ?? "foreground",
|
|
34
|
-
}, {
|
|
35
|
-
|
|
36
|
-
onWaiting: async (decision) => await emit("prepublication_host_capacity_waiting", `Pre-publication step '${step.checkId}' (${stepClass}) is waiting for host capacity: ${decision.detail}`, { status: "waiting_for_host_capacity", reason: decision.reason, cpuCores: cost.cpuCores, memoryBytes: cost.memoryBytes }),
|
|
37
|
-
});
|
|
36
|
+
}, { signal: step.signal, onWaiting: reports.onWaiting });
|
|
37
|
+
await reports.drained();
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
+
await reports.drained();
|
|
40
41
|
if (error instanceof HostCapacityTimeoutError) {
|
|
41
42
|
await emit("prepublication_host_capacity_timeout", error.message, { status: "host_capacity_timeout", host_load_wait_ms: Math.round(error.waitMs) }, "error");
|
|
42
43
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
3
|
+
import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
|
|
4
|
+
import type { RunnerDispatchEvent } from "./session.types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
7
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
8
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
9
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
10
|
+
* check on Docker.
|
|
11
|
+
*/
|
|
12
|
+
export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
|
|
13
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
14
|
+
export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
17
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
18
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
19
|
+
*/
|
|
20
|
+
export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
23
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
|
|
26
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
27
|
+
export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
|
|
28
|
+
export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
|
|
29
|
+
/** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
|
|
30
|
+
export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilityEnvironment } from "../runtime/attempt-database-broker.js";
|
|
3
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
4
|
+
import { nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresGrant, } from "../runtime/native-test-postgres-fallback.js";
|
|
5
|
+
import { validationEvent } from "./pre-publication-pass.js";
|
|
6
|
+
import { supportsNativeTestPostgresFallback } from "./pre-publication-step-execution.js";
|
|
7
|
+
// Which PostgreSQL a pre-publication check's isolated_postgres prerequisite is met by,
|
|
8
|
+
// before the validator falls back to waiting for Docker.
|
|
9
|
+
/**
|
|
10
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
11
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
12
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
13
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
14
|
+
* check on Docker.
|
|
15
|
+
*/
|
|
16
|
+
export async function preferredNativeTestPostgres(checkId, requiredPrerequisite, readCluster, dockerEngineProbe, emit, startEphemeral = startEphemeralTestPostgresGrant) {
|
|
17
|
+
if (requiredPrerequisite !== "isolated_postgres" || !supportsNativeTestPostgresFallback(checkId))
|
|
18
|
+
return undefined;
|
|
19
|
+
let configured;
|
|
20
|
+
try {
|
|
21
|
+
configured = readCluster();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_invalid", checkId, `The native PostgreSQL test cluster configuration was refused, so '${checkId}' uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (configured?.use === "ephemeral") {
|
|
28
|
+
return await ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral);
|
|
29
|
+
}
|
|
30
|
+
if (configured?.use !== "preferred")
|
|
31
|
+
return undefined;
|
|
32
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
33
|
+
const grant = nativeTestPostgresGrant(configured, dockerAvailable);
|
|
34
|
+
if (!grant)
|
|
35
|
+
return undefined;
|
|
36
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_preferred", checkId, `Pre-publication check '${checkId}' is using the dedicated native PostgreSQL test cluster at ${grant.endpoint} with per-run owned databases${dockerAvailable
|
|
37
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
38
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
39
|
+
return grant;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A throwaway cluster of the check's own, whose superuser it holds (owner policy 2026-11-17).
|
|
43
|
+
* If it cannot start, the check falls back to Docker, and to the provisioned cluster only while
|
|
44
|
+
* Docker is down.
|
|
45
|
+
*/
|
|
46
|
+
async function ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral) {
|
|
47
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
48
|
+
let grant;
|
|
49
|
+
try {
|
|
50
|
+
grant = await startEphemeral(configured, dockerAvailable);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
await emit?.(validationEvent("prepublication_prerequisite_ephemeral_unavailable", checkId, `An ephemeral PostgreSQL test cluster could not start for '${checkId}', so it uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_ephemeral", checkId, `Pre-publication check '${checkId}' is using its own ephemeral PostgreSQL test cluster at ${grant.endpoint}, deleted when the check ends${dockerAvailable
|
|
58
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
59
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// The caller releases only a grant it receives, so a failed emit releases it here.
|
|
63
|
+
await grant.release?.().catch(() => undefined);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
return grant;
|
|
67
|
+
}
|
|
68
|
+
function environmentValue(environment, name) {
|
|
69
|
+
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
70
|
+
? environment?.[name]?.trim() ?? ""
|
|
71
|
+
: process.env[name]?.trim() ?? "";
|
|
72
|
+
}
|
|
73
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
74
|
+
export function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
75
|
+
if (checkId === "playwright-e2e") {
|
|
76
|
+
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
77
|
+
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
78
|
+
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
79
|
+
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
80
|
+
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
81
|
+
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
82
|
+
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
83
|
+
}
|
|
84
|
+
return Boolean(postgresAdminConnection);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
88
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
89
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
90
|
+
*/
|
|
91
|
+
export function dockerFreeGrant(grant) {
|
|
92
|
+
return grant?.mode === nativeTestPostgresFallbackDatabaseMode ? grant : undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
96
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
97
|
+
*/
|
|
98
|
+
export async function releaseCheckPostgres(checkId, grant, emit) {
|
|
99
|
+
try {
|
|
100
|
+
await grant?.release?.();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await emit?.(validationEvent("prepublication_ephemeral_release_failed", checkId, `The ephemeral PostgreSQL test cluster for '${checkId}' could not be released and will be reaped later: ${error instanceof Error ? error.message : String(error)}`)).catch(() => undefined);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
107
|
+
export function dockerUnavailableNativeTestPostgres(checkId, requiredPrerequisite, readCluster) {
|
|
108
|
+
return requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(checkId)
|
|
109
|
+
? nativeTestPostgresGrant(readCluster(), false)
|
|
110
|
+
: null;
|
|
111
|
+
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
4
|
-
import { withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
|
|
4
|
+
import { withHostTestParallelism, withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
|
|
5
5
|
import { isSubPath } from "../shared/path/path.js";
|
|
6
6
|
import { NodeProcessRunner, ProcessTreeTerminationError } from "../shared/process/process.js";
|
|
7
|
+
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
7
8
|
/** Output kept per stream for one validation step (the tail). */
|
|
8
9
|
export const prePublicationOutputLimitChars = 4 * 1024 * 1024;
|
|
9
10
|
export class ProcessPrePublicationCommandRunner {
|
|
10
11
|
async run(command, args, cwd, signal, environment) {
|
|
11
12
|
try {
|
|
12
13
|
const launch = await pnpmDirectoryLaunch(command, args, cwd);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// npm and pnpm are batch files on Windows, run through cmd.exe. Its command line is
|
|
15
|
+
// passed verbatim: Node's own quoting escapes inner quotes as \", which cmd.exe does
|
|
16
|
+
// not read, so a quoted argument reached the package manager with its quotes.
|
|
17
|
+
const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm")
|
|
18
|
+
? buildWindowsCmdLaunch(`${command}.cmd`, launch.args)
|
|
19
|
+
: null;
|
|
18
20
|
// A process group the runner stops as a whole, settling only once it is gone:
|
|
19
21
|
// a validation step's host capacity is never returned while its test hosts,
|
|
20
22
|
// build nodes or browser workers still run.
|
|
21
23
|
const result = await new NodeProcessRunner().run({
|
|
22
|
-
command:
|
|
23
|
-
args:
|
|
24
|
+
command: windowsBatch?.command ?? command,
|
|
25
|
+
args: windowsBatch?.args ?? [...launch.args],
|
|
26
|
+
windowsVerbatimArguments: windowsBatch !== null,
|
|
24
27
|
cwd: launch.cwd,
|
|
25
28
|
env: prePublicationChildEnvironment(environment),
|
|
26
29
|
rawOutput: true,
|
|
@@ -48,9 +51,6 @@ export class ProcessPrePublicationCommandRunner {
|
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
function quoteWindowsCommandArgument(value) {
|
|
52
|
-
return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `"${value.replaceAll('"', '""')}"`;
|
|
53
|
-
}
|
|
54
54
|
export function prePublicationChildEnvironment(environment) {
|
|
55
55
|
const child = {};
|
|
56
56
|
const privilegedNames = new Set([
|
|
@@ -65,7 +65,8 @@ export function prePublicationChildEnvironment(environment) {
|
|
|
65
65
|
}
|
|
66
66
|
// A validation step must not join the host ledger (it would queue behind its own token)
|
|
67
67
|
// or the sandbox broker, whether the variable is inherited or passed in explicitly.
|
|
68
|
-
|
|
68
|
+
// A heavy step that shares the host with other heavy steps sizes its test parallelism for its share.
|
|
69
|
+
return withHostTestParallelism(withoutHostLoadGovernorVariables({ ...child, ...environment }));
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* Corepack picks the pnpm version from the nearest package.json `packageManager`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
|
|
1
2
|
import type { PrePublicationExecutionContext } from "./pre-publication-validation.js";
|
|
2
3
|
export interface ValidationStep {
|
|
3
4
|
readonly command: string;
|
|
@@ -8,4 +9,4 @@ export interface ValidationStep {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function managedAttemptInvocation(checkId: string, step: ValidationStep, environment?: Readonly<Record<string, string>>): Pick<ValidationStep, "command" | "args">;
|
|
10
11
|
export declare function supportsNativeTestPostgresFallback(checkId: string): boolean;
|
|
11
|
-
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?:
|
|
12
|
+
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: NativeTestPostgresGrant): PrePublicationExecutionContext | undefined;
|
|
@@ -29,21 +29,22 @@ export function supportsNativeTestPostgresFallback(checkId) {
|
|
|
29
29
|
return nativeFallbackCheckIds.has(checkId);
|
|
30
30
|
}
|
|
31
31
|
export function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
32
|
-
// The
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
// Bridge, and E2E steps never do.
|
|
32
|
+
// The grant only exists when the operator provisioned a dedicated native test
|
|
33
|
+
// cluster, and only the runner-authored .NET test tiers and the suite-identity
|
|
34
|
+
// check receive it; build, client, Bridge, and E2E steps never do.
|
|
36
35
|
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
37
36
|
return execution;
|
|
38
37
|
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
39
38
|
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
40
39
|
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
41
40
|
return execution;
|
|
41
|
+
// Re-validate the connection before it reaches attempt code.
|
|
42
|
+
parseNativeTestPostgresFallback(postgresAdminConnection.connectionString);
|
|
42
43
|
return {
|
|
43
44
|
...execution,
|
|
44
45
|
environment: {
|
|
45
46
|
...execution?.environment,
|
|
46
|
-
...nativeTestPostgresFallbackEnvironment(
|
|
47
|
+
...nativeTestPostgresFallbackEnvironment(postgresAdminConnection),
|
|
47
48
|
},
|
|
48
49
|
};
|
|
49
50
|
}
|