@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.81e48ecc185d
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 +54 -2
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +125 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +85 -3
- package/dist/bridge/bridge.service.js +361 -122
- package/dist/bridge/bridge.types.d.ts +22 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -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 +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
- package/dist/runtime/attempt-process-supervisor.js +50 -0
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +64 -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 +184 -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 +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -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-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +4 -0
- package/dist/runtime/host-runtime-contract.js +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +336 -20
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- 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 +607 -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 +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +27 -0
- package/dist/session/managed-attempt-tools.js +356 -41
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +98 -25
- 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 +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +70 -35
- 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 +206 -221
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- 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-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 +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +32 -20
- package/dist/session/pre-publication-validation.js +202 -195
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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 +39 -2
- package/dist/session/provider-cli/provider-cli.process.js +276 -42
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +203 -172
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -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-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
|
|
2
|
+
import type { BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
1
3
|
import type { ApiKeySecretGrant, DispatchSandboxResourceRequest, RunOnceResultPacket, RunnerDispatchEvent } from "../session/session.types.js";
|
|
2
4
|
import type { SandboxFeatureMatrix } from "../sandbox/sandbox.types.js";
|
|
3
5
|
import type { HostRuntimeCapacitySnapshot } from "../runtime/host-runtime-lease.js";
|
|
4
6
|
import type { MemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
|
|
5
7
|
import type { DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
8
|
+
import type { HostFacts } from "../runtime/host-facts.js";
|
|
9
|
+
import type { HostLoadSnapshot } from "../runtime/host-load-sampler.js";
|
|
10
|
+
import type { RunnerSettingsReport } from "../runtime/runner-settings.js";
|
|
6
11
|
import type { BridgeChatCapability, ChatTurnCancelPacket } from "./bridge-chat.types.js";
|
|
7
12
|
export interface BridgeServiceConfig {
|
|
8
13
|
readonly serverUrl: string;
|
|
@@ -61,6 +66,11 @@ export interface BridgeServiceConfig {
|
|
|
61
66
|
readonly callbackAckTimeoutMs?: number;
|
|
62
67
|
readonly heartbeatDockerProbeWaitMs?: number;
|
|
63
68
|
readonly reconnectBackoffMs: readonly number[];
|
|
69
|
+
/**
|
|
70
|
+
* Decision 0014: the `forge-bridge yield` flag file next to the bridge config,
|
|
71
|
+
* polled while running. Null or absent: no local yield flag.
|
|
72
|
+
*/
|
|
73
|
+
readonly localYieldFlagPath?: string | null;
|
|
64
74
|
}
|
|
65
75
|
export interface BridgeRepoMapping {
|
|
66
76
|
readonly repoId?: string | null;
|
|
@@ -142,6 +152,17 @@ export interface BridgeCapabilities {
|
|
|
142
152
|
readonly playwrightProjects?: readonly string[] | null;
|
|
143
153
|
readonly browserLaunch?: boolean | null;
|
|
144
154
|
readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
|
|
155
|
+
/** Native test PostgreSQL and whether its role is a superuser (decision 0013 placement). */
|
|
156
|
+
readonly testPostgres?: BridgeTestPostgresCapability | null;
|
|
157
|
+
/** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
|
|
158
|
+
readonly host?: HostFacts | null;
|
|
159
|
+
/** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
|
|
160
|
+
readonly load?: HostLoadSnapshot | null;
|
|
161
|
+
/** Decision 0014 (schema 8): server settings support and the last `SettingsApplied` report. Material. */
|
|
162
|
+
readonly settings?: BridgeSettingsCapability | null;
|
|
163
|
+
}
|
|
164
|
+
export interface BridgeSettingsCapability extends RunnerSettingsReport {
|
|
165
|
+
readonly supportsServerSettings: true;
|
|
145
166
|
}
|
|
146
167
|
export interface SandboxMemoryCapacityDiagnostics {
|
|
147
168
|
readonly defaultWorkerMemoryLimitBytes: number;
|
|
@@ -292,6 +313,7 @@ export interface BridgeRuntimeReadinessResult {
|
|
|
292
313
|
readonly status: "parallel_ready" | "serialized" | "failed";
|
|
293
314
|
readonly runtimeContractFingerprint?: string | null;
|
|
294
315
|
readonly runtimeContractSource?: string | null;
|
|
316
|
+
readonly runtimeRequirements?: HostRuntimeRequirements | null;
|
|
295
317
|
readonly reasonCode?: string | null;
|
|
296
318
|
readonly reasonMessage?: string | null;
|
|
297
319
|
readonly qaAppLaunchTarget?: BridgeRuntimeReadinessQaLaunchTarget | null;
|
|
@@ -8,7 +8,14 @@ export interface DispatchResultOutbox {
|
|
|
8
8
|
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
9
9
|
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
10
10
|
acknowledge(leaseId: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Moves an undeliverable record out of the replay set. The redacted result
|
|
13
|
+
* is kept, with its original persistedAt, so preserved work can be reconciled.
|
|
14
|
+
*/
|
|
15
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
11
16
|
}
|
|
17
|
+
export declare const dispatchResultOutboxDirectory = "dispatch-results";
|
|
18
|
+
export declare const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
12
19
|
/**
|
|
13
20
|
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
14
21
|
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
@@ -16,10 +23,13 @@ export interface DispatchResultOutbox {
|
|
|
16
23
|
*/
|
|
17
24
|
export declare class FileDispatchResultOutbox implements DispatchResultOutbox {
|
|
18
25
|
private readonly stateRoot;
|
|
26
|
+
private readonly directory;
|
|
19
27
|
private readonly writes;
|
|
20
|
-
constructor(stateRoot: string);
|
|
28
|
+
constructor(stateRoot: string, directory?: string);
|
|
21
29
|
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
30
|
+
private persistRecord;
|
|
22
31
|
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
23
32
|
acknowledge(leaseId: string): Promise<void>;
|
|
33
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
24
34
|
private operate;
|
|
25
35
|
}
|
|
@@ -3,6 +3,8 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
3
3
|
import { assertCanonicalDirectory, createCanonicalDirectory } from "../runtime/attempt-private-directory.js";
|
|
4
4
|
import { runPinnedDirectoryProcess } from "../runtime/pinned-directory-process.js";
|
|
5
5
|
import { dispatchResultReceiptWorker } from "./dispatch-result-worker.js";
|
|
6
|
+
export const dispatchResultOutboxDirectory = "dispatch-results";
|
|
7
|
+
export const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
6
8
|
/**
|
|
7
9
|
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
8
10
|
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
@@ -10,11 +12,16 @@ import { dispatchResultReceiptWorker } from "./dispatch-result-worker.js";
|
|
|
10
12
|
*/
|
|
11
13
|
export class FileDispatchResultOutbox {
|
|
12
14
|
stateRoot;
|
|
15
|
+
directory;
|
|
13
16
|
writes = new Map();
|
|
14
|
-
constructor(stateRoot) {
|
|
17
|
+
constructor(stateRoot, directory = dispatchResultOutboxDirectory) {
|
|
15
18
|
this.stateRoot = stateRoot;
|
|
19
|
+
this.directory = directory;
|
|
16
20
|
}
|
|
17
21
|
async persist(payload) {
|
|
22
|
+
await this.persistRecord(payload, new Date().toISOString());
|
|
23
|
+
}
|
|
24
|
+
async persistRecord(payload, persistedAt) {
|
|
18
25
|
const name = recordName(payload.leaseId);
|
|
19
26
|
const value = JSON.parse(JSON.stringify({ payload }));
|
|
20
27
|
const pending = this.writes.get(name);
|
|
@@ -27,7 +34,7 @@ export class FileDispatchResultOutbox {
|
|
|
27
34
|
const write = this.operate({
|
|
28
35
|
kind: "persist",
|
|
29
36
|
name,
|
|
30
|
-
record: { schemaVersion: 1, persistedAt
|
|
37
|
+
record: { schemaVersion: 1, persistedAt, ...value },
|
|
31
38
|
}).then(() => undefined);
|
|
32
39
|
this.writes.set(name, { value, write });
|
|
33
40
|
try {
|
|
@@ -44,8 +51,23 @@ export class FileDispatchResultOutbox {
|
|
|
44
51
|
async acknowledge(leaseId) {
|
|
45
52
|
await this.operate({ kind: "acknowledge", name: recordName(leaseId) });
|
|
46
53
|
}
|
|
54
|
+
async quarantine(record) {
|
|
55
|
+
// One execution lease can carry several dispatch attempts, so quarantine
|
|
56
|
+
// files are grouped per attempt: <quarantine>/<attempt>/<lease>.json.
|
|
57
|
+
// Copy before removal: a crash in between leaves an identical record in
|
|
58
|
+
// both places, and the next replay quarantines it again idempotently.
|
|
59
|
+
// A record without an attempt id has no per-attempt bucket; the caller
|
|
60
|
+
// keeps it deferred rather than grouping unrelated attempts together.
|
|
61
|
+
const { payload } = record;
|
|
62
|
+
if (!payload.dispatchAttemptId) {
|
|
63
|
+
throw new Error("dispatch_result_invalid: only attempt-bound results can be quarantined.");
|
|
64
|
+
}
|
|
65
|
+
const bucket = path.join(dispatchResultQuarantineDirectory, compactUuid(payload.dispatchAttemptId));
|
|
66
|
+
await new FileDispatchResultOutbox(this.stateRoot, bucket).persistRecord(payload, record.persistedAt);
|
|
67
|
+
await this.acknowledge(payload.leaseId);
|
|
68
|
+
}
|
|
47
69
|
async operate(operation) {
|
|
48
|
-
const root = path.resolve(this.stateRoot,
|
|
70
|
+
const root = path.resolve(this.stateRoot, this.directory);
|
|
49
71
|
await createCanonicalDirectory(root);
|
|
50
72
|
const identity = await assertCanonicalDirectory(root);
|
|
51
73
|
if (!identity)
|
|
@@ -54,9 +76,12 @@ export class FileDispatchResultOutbox {
|
|
|
54
76
|
}
|
|
55
77
|
}
|
|
56
78
|
function recordName(leaseId) {
|
|
57
|
-
|
|
79
|
+
return `${compactUuid(leaseId)}.json`;
|
|
80
|
+
}
|
|
81
|
+
function compactUuid(id) {
|
|
82
|
+
const value = id.replaceAll("-", "").toLowerCase();
|
|
58
83
|
if (!/^[0-9a-f]{32}$/u.test(value)) {
|
|
59
|
-
throw new Error("dispatch_result_invalid:
|
|
84
|
+
throw new Error("dispatch_result_invalid: identifiers must be UUIDs.");
|
|
60
85
|
}
|
|
61
|
-
return
|
|
86
|
+
return value;
|
|
62
87
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** `<config dir>/<config name>.yield.json`, e.g. `~/.config/forge/bridge.yield.json` beside `bridge.json`. */
|
|
2
|
+
export declare function localYieldFlagPathFor(configPath: string): string;
|
|
3
|
+
/** The local flag; a missing or unreadable file means off. */
|
|
4
|
+
export declare function readLocalYieldFlag(flagPath: string): Promise<boolean>;
|
|
5
|
+
/** Writes the flag atomically with mode 0600. */
|
|
6
|
+
export declare function writeLocalYieldFlag(flagPath: string, yieldToForeground: boolean): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
/** `<config dir>/<config name>.yield.json`, e.g. `~/.config/forge/bridge.yield.json` beside `bridge.json`. */
|
|
5
|
+
export function localYieldFlagPathFor(configPath) {
|
|
6
|
+
const parsed = path.parse(path.resolve(configPath));
|
|
7
|
+
return path.join(parsed.dir, `${parsed.name}.yield.json`);
|
|
8
|
+
}
|
|
9
|
+
/** The local flag; a missing or unreadable file means off. */
|
|
10
|
+
export async function readLocalYieldFlag(flagPath) {
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(await fs.readFile(flagPath, "utf8"));
|
|
13
|
+
return parsed?.schemaVersion === 1 && parsed.yieldToForeground === true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Writes the flag atomically with mode 0600. */
|
|
20
|
+
export async function writeLocalYieldFlag(flagPath, yieldToForeground) {
|
|
21
|
+
const content = { schemaVersion: 1, yieldToForeground, updatedAt: new Date().toISOString() };
|
|
22
|
+
await fs.mkdir(path.dirname(flagPath), { recursive: true, mode: 0o700 });
|
|
23
|
+
const temporary = `${flagPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
24
|
+
try {
|
|
25
|
+
await fs.writeFile(temporary, `${JSON.stringify(content, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
26
|
+
// The umask can narrow the create mode but never widen it; set it exactly.
|
|
27
|
+
await fs.chmod(temporary, 0o600);
|
|
28
|
+
await fs.rename(temporary, flagPath);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
await fs.rm(temporary, { force: true }).catch(() => undefined);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { BridgeServiceConfig, BridgeToolchainCapabilities } from "./bridge.types.js";
|
|
2
|
+
import { type BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
2
3
|
export interface RunnerHostCapabilitySnapshot {
|
|
3
4
|
readonly toolchains: BridgeToolchainCapabilities;
|
|
4
5
|
readonly playwrightProjects: readonly string[];
|
|
5
6
|
readonly browserLaunch: boolean;
|
|
6
7
|
readonly providerConnectivity: Readonly<Record<string, boolean>>;
|
|
8
|
+
readonly testPostgres: BridgeTestPostgresCapability;
|
|
7
9
|
}
|
|
8
10
|
export interface RunnerHostCapabilityProbe {
|
|
9
11
|
detect(config: BridgeServiceConfig): Promise<RunnerHostCapabilitySnapshot>;
|
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { probeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
5
6
|
const execFileAsync = promisify(execFile);
|
|
6
7
|
export class ProcessRunnerHostCapabilityProbe {
|
|
7
8
|
async detect(config) {
|
|
@@ -16,6 +17,7 @@ export class ProcessRunnerHostCapabilityProbe {
|
|
|
16
17
|
: Promise.resolve(unavailable("powershell.exe")),
|
|
17
18
|
]);
|
|
18
19
|
const playwrightProjects = await detectPlaywrightProjects(config.repoMappings);
|
|
20
|
+
const testPostgres = await probeTestPostgresCapability();
|
|
19
21
|
const browserLaunch = playwrightProjects.length > 0
|
|
20
22
|
|| config.repoMappings.some(mapping => Boolean(mapping.qaAppLaunchTarget?.url
|
|
21
23
|
|| mapping.qaAppLaunchTarget?.command
|
|
@@ -33,6 +35,7 @@ export class ProcessRunnerHostCapabilityProbe {
|
|
|
33
35
|
browserLaunch,
|
|
34
36
|
providerConnectivity: Object.fromEntries(Object.entries(config.providerStatuses)
|
|
35
37
|
.map(([provider, status]) => [provider, status.signedIn === true])),
|
|
38
|
+
testPostgres,
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -89,5 +92,6 @@ export function emptyRunnerHostCapabilitySnapshot() {
|
|
|
89
92
|
playwrightProjects: [],
|
|
90
93
|
browserLaunch: false,
|
|
91
94
|
providerConnectivity: {},
|
|
95
|
+
testPostgres: { available: false, superuser: null },
|
|
92
96
|
};
|
|
93
97
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this host offers a native test PostgreSQL and whether its role is a superuser
|
|
3
|
+
* (decision 0013 placement). Suites that need `session_replication_role`, `CREATE ROLE` or
|
|
4
|
+
* similar can only run on a superuser test database or on Docker-backed Testcontainers.
|
|
5
|
+
*/
|
|
6
|
+
export interface BridgeTestPostgresCapability {
|
|
7
|
+
readonly available: boolean;
|
|
8
|
+
/** Null when the cluster is configured but the role could not be checked. */
|
|
9
|
+
readonly superuser: boolean | null;
|
|
10
|
+
}
|
|
11
|
+
export type PsqlRunner = (args: readonly string[], env: NodeJS.ProcessEnv) => Promise<string>;
|
|
12
|
+
export declare function probeTestPostgresCapability(environment?: NodeJS.ProcessEnv, runPsql?: PsqlRunner, readFallback?: () => string | null): Promise<BridgeTestPostgresCapability>;
|
|
13
|
+
/** Maps an Npgsql-style connection string or a postgres:// URI to libpq environment. */
|
|
14
|
+
export declare function psqlTarget(connection: string): Record<string, string> | null;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { hostRuntimeTestPostgresAdminEnvironment } from "../runtime/host-runtime-contract.js";
|
|
4
|
+
import { readNativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
6
|
+
const superuserQuery = "select rolsuper from pg_roles where rolname = current_user";
|
|
7
|
+
export async function probeTestPostgresCapability(environment = process.env, runPsql = defaultPsql, readFallback = configuredFallbackConnection) {
|
|
8
|
+
// Same sources pre-publication validation uses: the environment, else the operator's
|
|
9
|
+
// native test cluster file.
|
|
10
|
+
const connection = environment[hostRuntimeTestPostgresAdminEnvironment]?.trim() || readFallback()?.trim();
|
|
11
|
+
if (!connection)
|
|
12
|
+
return { available: false, superuser: null };
|
|
13
|
+
const target = psqlTarget(connection);
|
|
14
|
+
if (!target)
|
|
15
|
+
return { available: true, superuser: null };
|
|
16
|
+
try {
|
|
17
|
+
// The secret travels only in the child's environment, never in argv or logs.
|
|
18
|
+
const output = await runPsql(["-X", "-A", "-t", "-w", "-c", superuserQuery], { ...process.env, ...target, PGCONNECT_TIMEOUT: "5" });
|
|
19
|
+
const value = output.trim().toLowerCase();
|
|
20
|
+
return { available: true, superuser: value === "t" ? true : value === "f" ? false : null };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { available: true, superuser: null };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Maps an Npgsql-style connection string or a postgres:// URI to libpq environment. */
|
|
27
|
+
export function psqlTarget(connection) {
|
|
28
|
+
// libpq reads PGDATABASE as a database name only, so a URI is split into PG* variables
|
|
29
|
+
// rather than passed whole (and not as psql's argument, which would put the secret in argv).
|
|
30
|
+
if (/^postgres(?:ql)?:\/\//iu.test(connection))
|
|
31
|
+
return uriTarget(connection);
|
|
32
|
+
const keys = {
|
|
33
|
+
host: "PGHOST", server: "PGHOST", port: "PGPORT", database: "PGDATABASE",
|
|
34
|
+
username: "PGUSER", "user id": "PGUSER", userid: "PGUSER", user: "PGUSER", password: "PGPASSWORD",
|
|
35
|
+
};
|
|
36
|
+
const target = {};
|
|
37
|
+
for (const part of connection.split(";")) {
|
|
38
|
+
const separator = part.indexOf("=");
|
|
39
|
+
if (separator <= 0)
|
|
40
|
+
continue;
|
|
41
|
+
const name = keys[part.slice(0, separator).trim().toLowerCase()];
|
|
42
|
+
const value = part.slice(separator + 1).trim();
|
|
43
|
+
if (name && value)
|
|
44
|
+
target[name] = value;
|
|
45
|
+
}
|
|
46
|
+
return target.PGHOST || target.PGUSER ? target : null;
|
|
47
|
+
}
|
|
48
|
+
/** libpq URI query parameters that have a PG* environment equivalent. */
|
|
49
|
+
const uriParameterEnvironment = {
|
|
50
|
+
host: "PGHOST", hostaddr: "PGHOSTADDR", port: "PGPORT", dbname: "PGDATABASE", user: "PGUSER",
|
|
51
|
+
password: "PGPASSWORD", passfile: "PGPASSFILE", options: "PGOPTIONS", application_name: "PGAPPNAME",
|
|
52
|
+
sslmode: "PGSSLMODE", sslrootcert: "PGSSLROOTCERT", sslcert: "PGSSLCERT", sslkey: "PGSSLKEY",
|
|
53
|
+
sslcrl: "PGSSLCRL", gssencmode: "PGGSSENCMODE", target_session_attrs: "PGTARGETSESSIONATTRS",
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Parses `postgres[ql]://[user[:password]@][host[:port][,...]][/dbname][?param=value&...]`
|
|
57
|
+
* (libpq's URI form, including comma-separated hosts, bracketed IPv6 and percent-encoding).
|
|
58
|
+
*/
|
|
59
|
+
function uriTarget(connection) {
|
|
60
|
+
const match = /^postgres(?:ql)?:\/\/([^/?#]*)(?:\/([^?#]*))?(?:\?([^#]*))?/iu.exec(connection);
|
|
61
|
+
if (!match)
|
|
62
|
+
return null;
|
|
63
|
+
try {
|
|
64
|
+
const [, authority = "", path, query] = match;
|
|
65
|
+
const target = {};
|
|
66
|
+
const at = authority.lastIndexOf("@");
|
|
67
|
+
if (at >= 0) {
|
|
68
|
+
const userInfo = authority.slice(0, at);
|
|
69
|
+
const colon = userInfo.indexOf(":");
|
|
70
|
+
const user = decodeURIComponent(colon >= 0 ? userInfo.slice(0, colon) : userInfo);
|
|
71
|
+
if (user)
|
|
72
|
+
target.PGUSER = user;
|
|
73
|
+
if (colon >= 0)
|
|
74
|
+
target.PGPASSWORD = decodeURIComponent(userInfo.slice(colon + 1));
|
|
75
|
+
}
|
|
76
|
+
const hosts = [];
|
|
77
|
+
const ports = [];
|
|
78
|
+
for (const entry of authority.slice(at + 1).split(",")) {
|
|
79
|
+
const ipv6 = /^\[([^\]]*)\](?::(.*))?$/u.exec(entry);
|
|
80
|
+
const colon = entry.lastIndexOf(":");
|
|
81
|
+
const host = ipv6 ? ipv6[1] ?? "" : colon >= 0 ? entry.slice(0, colon) : entry;
|
|
82
|
+
const port = ipv6 ? ipv6[2] ?? "" : colon >= 0 ? entry.slice(colon + 1) : "";
|
|
83
|
+
hosts.push(decodeURIComponent(host));
|
|
84
|
+
ports.push(port);
|
|
85
|
+
}
|
|
86
|
+
if (hosts.some(Boolean))
|
|
87
|
+
target.PGHOST = hosts.join(",");
|
|
88
|
+
if (ports.some(Boolean))
|
|
89
|
+
target.PGPORT = ports.join(",");
|
|
90
|
+
const database = path ? decodeURIComponent(path) : "";
|
|
91
|
+
if (database)
|
|
92
|
+
target.PGDATABASE = database;
|
|
93
|
+
for (const parameter of (query ?? "").split("&")) {
|
|
94
|
+
const separator = parameter.indexOf("=");
|
|
95
|
+
if (separator <= 0)
|
|
96
|
+
continue;
|
|
97
|
+
const name = uriParameterEnvironment[decodeURIComponent(parameter.slice(0, separator))];
|
|
98
|
+
const value = decodeURIComponent(parameter.slice(separator + 1));
|
|
99
|
+
if (name && value)
|
|
100
|
+
target[name] = value;
|
|
101
|
+
}
|
|
102
|
+
return target;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Malformed percent-encoding: the role cannot be checked.
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function configuredFallbackConnection() {
|
|
110
|
+
try {
|
|
111
|
+
return readNativeTestPostgresFallback()?.connectionString ?? null;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function defaultPsql(args, env) {
|
|
118
|
+
const result = await execFileAsync("psql", [...args], { encoding: "utf8", timeout: 10_000, env });
|
|
119
|
+
return result.stdout;
|
|
120
|
+
}
|
|
@@ -9,6 +9,15 @@ export declare class ManagedWorktreeCleanupService implements CleanupService {
|
|
|
9
9
|
constructor(stateRoot?: string, git?: GitClient, coordinator?: WorktreeLifecycleCoordinator);
|
|
10
10
|
run(request: CleanupRequest): Promise<CleanupResult>;
|
|
11
11
|
private runLocked;
|
|
12
|
+
private sweepReadinessBranches;
|
|
13
|
+
/**
|
|
14
|
+
* The branch merged work lands on: origin/HEAD when it points at a remote-tracking ref that
|
|
15
|
+
* exists, otherwise the only one of origin/develop, origin/main and origin/master that exists.
|
|
16
|
+
* Null when that's ambiguous or none exist, so the merged sweep is skipped (and reported)
|
|
17
|
+
* rather than measured against the wrong base.
|
|
18
|
+
*/
|
|
19
|
+
private remoteBaseBranch;
|
|
20
|
+
private remoteBranchExists;
|
|
12
21
|
private listWorktrees;
|
|
13
22
|
private staleRuntimeReadinessPaths;
|
|
14
23
|
private scanManagedCandidates;
|