@loucompanion/forge-bridge 0.1.4-dev.c1ae24134918 → 0.1.4-dev.cabe9c22da46
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 +142 -1
- 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 +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +87 -14
- package/dist/bridge/bridge.service.js +394 -338
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +76 -115
- 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 +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +149 -186
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +140 -7
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +12 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- 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 +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +59 -3
- package/dist/runtime/host-runtime-lease.js +209 -58
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/sandbox/host-capacity-broker.d.ts +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +89 -99
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +10 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +4 -10
- package/dist/session/phase-completion.runtime.js +77 -209
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-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.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +72 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +78 -171
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +7 -2
- package/dist/session/session.service.js +100 -2
- package/dist/session/session.types.js +4 -4
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/worktree.service.d.ts +5 -1
- package/dist/worktree/worktree.service.js +29 -1
- package/package.json +2 -2
|
@@ -3,7 +3,52 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
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";
|
|
6
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
|
+
}
|
|
7
52
|
export function createAspNetRuntimePrebuildPlan(options) {
|
|
8
53
|
if (!isDotnetRun(options.command, options.args))
|
|
9
54
|
return null;
|
|
@@ -101,7 +146,7 @@ async function ensureAspNetRuntimePrebuiltCore(plan, execute, signal) {
|
|
|
101
146
|
};
|
|
102
147
|
await fs.writeFile(temporaryReceipt, `${JSON.stringify(nextReceipt)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
103
148
|
try {
|
|
104
|
-
await
|
|
149
|
+
await replaceFile(temporaryReceipt, plan.receiptPath);
|
|
105
150
|
}
|
|
106
151
|
finally {
|
|
107
152
|
await fs.rm(temporaryReceipt, { force: true }).catch(() => undefined);
|
|
@@ -211,7 +256,7 @@ async function aspNetBuildInputs(plan) {
|
|
|
211
256
|
const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
|
|
212
257
|
? path.dirname(plan.projectPath)
|
|
213
258
|
: plan.projectPath;
|
|
214
|
-
const sourceDigest = await
|
|
259
|
+
const sourceDigest = await projectSourceDigest(plan, projectDirectory);
|
|
215
260
|
const dependencyReceipt = path.join(projectDirectory, "obj", ".forge-dependency-preparation.json");
|
|
216
261
|
const dependencyContent = await fs.readFile(dependencyReceipt).catch(() => null);
|
|
217
262
|
const globalJson = await findAncestorFile(projectDirectory, plan.worktreePath, "global.json");
|
|
@@ -225,18 +270,106 @@ async function aspNetBuildInputs(plan) {
|
|
|
225
270
|
sdkVersion: await dotnetSdkVersion(plan.cwd),
|
|
226
271
|
};
|
|
227
272
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
+
}
|
|
231
292
|
const hash = createHash("sha256");
|
|
232
|
-
for (const file of files.sort((left, right) => left.localeCompare(right))) {
|
|
233
|
-
hash.update(path.relative(
|
|
293
|
+
for (const file of [...files].sort((left, right) => left.localeCompare(right))) {
|
|
294
|
+
hash.update(path.relative(worktree, file).replaceAll("\\", "/"));
|
|
234
295
|
hash.update("\0");
|
|
235
296
|
hash.update(await fs.readFile(file));
|
|
236
297
|
hash.update("\0");
|
|
237
298
|
}
|
|
238
299
|
return `sha256:${hash.digest("hex")}`;
|
|
239
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
|
+
}
|
|
240
373
|
async function collectInputFiles(root, directory, files) {
|
|
241
374
|
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
242
375
|
for (const entry of entries) {
|
|
@@ -75,7 +75,7 @@ export interface NativeTestClusterAdmin {
|
|
|
75
75
|
readonly username: string;
|
|
76
76
|
readonly password: string;
|
|
77
77
|
}
|
|
78
|
-
export declare function nativeTestClusterAdmin(fallback: NativeTestPostgresFallback): NativeTestClusterAdmin;
|
|
78
|
+
export declare function nativeTestClusterAdmin(fallback: Pick<NativeTestPostgresFallback, "connectionString" | "endpoint">): NativeTestClusterAdmin;
|
|
79
79
|
/** Runs SQL through the psql that ships with the PostgreSQL install hosting the native test cluster. */
|
|
80
80
|
export declare function psqlSqlRunner(admin: NativeTestClusterAdmin, psqlPath: string, timeoutMs?: number): AttemptDatabaseSqlRunner;
|
|
81
81
|
/** psql beside the cluster's pg_ctl: FORGE_NATIVE_TEST_POSTGRES_PSQL, a Windows install, or PATH. */
|
|
@@ -62,6 +62,11 @@ export declare class DockerEngineProbe {
|
|
|
62
62
|
constructor(options?: DockerEngineProbeOptions, commands?: CommandRunner, cacheMs?: number);
|
|
63
63
|
current(): DockerEngineCapabilitySnapshot | null;
|
|
64
64
|
refresh(force?: boolean): Promise<DockerEngineCapabilitySnapshot>;
|
|
65
|
+
/**
|
|
66
|
+
* One fresh daemon reading that never starts recovery and leaves the cache and the
|
|
67
|
+
* failure streak alone, for callers that only need to know whether Docker is up.
|
|
68
|
+
*/
|
|
69
|
+
probeWithoutRecovery(): Promise<DockerEngineCapabilitySnapshot>;
|
|
65
70
|
/**
|
|
66
71
|
* Establishes a fresh daemon fence for work that declares Docker as a hard
|
|
67
72
|
* prerequisite. This remains bounded, cooldown protected and single-flight;
|
|
@@ -69,6 +69,13 @@ export class DockerEngineProbe {
|
|
|
69
69
|
this.inFlight = operation;
|
|
70
70
|
return await operation;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* One fresh daemon reading that never starts recovery and leaves the cache and the
|
|
74
|
+
* failure streak alone, for callers that only need to know whether Docker is up.
|
|
75
|
+
*/
|
|
76
|
+
async probeWithoutRecovery() {
|
|
77
|
+
return await this.inspectSafely();
|
|
78
|
+
}
|
|
72
79
|
/**
|
|
73
80
|
* Establishes a fresh daemon fence for work that declares Docker as a hard
|
|
74
81
|
* prerequisite. This remains bounded, cooldown protected and single-flight;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type EphemeralTestPostgresCluster, type EphemeralTestPostgresOptions } from "./ephemeral-test-postgres.js";
|
|
2
|
+
import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "./native-test-postgres-fallback.js";
|
|
3
|
+
export type StartEphemeralTestPostgres = (options: EphemeralTestPostgresOptions) => Promise<EphemeralTestPostgresCluster>;
|
|
4
|
+
/** The bin directory an ephemeral cluster runs from: the file's `postgresBin`, else the one holding psql. */
|
|
5
|
+
export declare function ephemeralTestPostgresBinDirectory(fallback: Pick<NativeTestPostgresFallback, "postgresBin">, psqlPath?: () => string | null): string;
|
|
6
|
+
/**
|
|
7
|
+
* Starts a throwaway cluster for one check and returns its grant. The grant's mode keeps the
|
|
8
|
+
* Docker semantics of the shared cluster: with Docker up, pinned-engine tests still start their
|
|
9
|
+
* own containers; with Docker down, they are skipped. The caller must call `release`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function startEphemeralTestPostgresGrant(fallback: Pick<NativeTestPostgresFallback, "postgresBin">, dockerAvailable: boolean, start?: StartEphemeralTestPostgres): Promise<NativeTestPostgresGrant>;
|
|
12
|
+
/** A managed verification command's database environment, and what to release when the command ends. */
|
|
13
|
+
export interface ManagedVerificationDatabase {
|
|
14
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
15
|
+
/** The connection strings and their passwords, for redaction; never the mode or the cluster id. */
|
|
16
|
+
readonly secrets: readonly string[];
|
|
17
|
+
readonly release: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/** A command that runs no verification profile gets no database. */
|
|
20
|
+
export declare const noManagedVerificationDatabase: ManagedVerificationDatabase;
|
|
21
|
+
/**
|
|
22
|
+
* Builds a command's setup from its database. If the setup throws, the command never starts and
|
|
23
|
+
* no caller holds the database, so it is released here before the error is rethrown.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setUpWithManagedVerificationDatabase<T>(database: Pick<ManagedVerificationDatabase, "release">, setUp: () => T): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Releases a command's database once the command has ended. A cluster that would not stop is left
|
|
28
|
+
* disowned for the next start's reap; the failure goes to `report` instead of being dropped.
|
|
29
|
+
*/
|
|
30
|
+
export declare function releaseManagedVerificationDatabase(database: Pick<ManagedVerificationDatabase, "release">, report: (message: string) => Promise<void>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Managed verification on an `ephemeral` host gets a throwaway cluster for the command's
|
|
33
|
+
* lifetime; every other host keeps managedVerificationDatabaseEnvironment's rules. A cluster
|
|
34
|
+
* that cannot start fails the command rather than silently handing it Docker or the shared
|
|
35
|
+
* cluster's narrower login.
|
|
36
|
+
*/
|
|
37
|
+
export declare function managedVerificationDatabase(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null, start?: StartEphemeralTestPostgres): Promise<ManagedVerificationDatabase>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilitySecrets, resolvePsqlPath } from "./attempt-database-broker.js";
|
|
3
|
+
import { EphemeralTestPostgresError, ephemeralTestPostgresClusterEnvironment, startEphemeralTestPostgres, } from "./ephemeral-test-postgres.js";
|
|
4
|
+
import { DockerEngineProbe } from "./docker-engine-probe.js";
|
|
5
|
+
import { managedVerificationDatabaseEnvironment, nativeTestPostgresFallbackConfigEnvironment, nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresFallbackEnvironment, nativeTestPostgresPreferredDatabaseMode, readNativeTestPostgresFallback, } from "./native-test-postgres-fallback.js";
|
|
6
|
+
/** The bin directory an ephemeral cluster runs from: the file's `postgresBin`, else the one holding psql. */
|
|
7
|
+
export function ephemeralTestPostgresBinDirectory(fallback, psqlPath = resolvePsqlPath) {
|
|
8
|
+
if (fallback.postgresBin)
|
|
9
|
+
return fallback.postgresBin;
|
|
10
|
+
const psql = psqlPath();
|
|
11
|
+
if (!psql) {
|
|
12
|
+
throw new EphemeralTestPostgresError("no PostgreSQL install was found; set 'postgresBin' in native-test-postgres.json or FORGE_NATIVE_TEST_POSTGRES_PSQL.");
|
|
13
|
+
}
|
|
14
|
+
return path.dirname(psql);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Starts a throwaway cluster for one check and returns its grant. The grant's mode keeps the
|
|
18
|
+
* Docker semantics of the shared cluster: with Docker up, pinned-engine tests still start their
|
|
19
|
+
* own containers; with Docker down, they are skipped. The caller must call `release`.
|
|
20
|
+
*/
|
|
21
|
+
export async function startEphemeralTestPostgresGrant(fallback, dockerAvailable, start = startEphemeralTestPostgres) {
|
|
22
|
+
const cluster = await start({ binDirectory: ephemeralTestPostgresBinDirectory(fallback) });
|
|
23
|
+
return {
|
|
24
|
+
connectionString: cluster.connectionString,
|
|
25
|
+
endpoint: cluster.endpoint,
|
|
26
|
+
mode: dockerAvailable ? nativeTestPostgresPreferredDatabaseMode : nativeTestPostgresFallbackDatabaseMode,
|
|
27
|
+
ephemeralClusterId: cluster.id,
|
|
28
|
+
release: cluster.release,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** A command that runs no verification profile gets no database. */
|
|
32
|
+
export const noManagedVerificationDatabase = {
|
|
33
|
+
environment: {},
|
|
34
|
+
secrets: [],
|
|
35
|
+
release: async () => undefined,
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds a command's setup from its database. If the setup throws, the command never starts and
|
|
39
|
+
* no caller holds the database, so it is released here before the error is rethrown.
|
|
40
|
+
*/
|
|
41
|
+
export async function setUpWithManagedVerificationDatabase(database, setUp) {
|
|
42
|
+
try {
|
|
43
|
+
return setUp();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
await database.release().catch(() => undefined);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Releases a command's database once the command has ended. A cluster that would not stop is left
|
|
52
|
+
* disowned for the next start's reap; the failure goes to `report` instead of being dropped.
|
|
53
|
+
*/
|
|
54
|
+
export async function releaseManagedVerificationDatabase(database, report) {
|
|
55
|
+
try {
|
|
56
|
+
await database.release();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
await report(error instanceof Error ? error.message : String(error)).catch(() => undefined);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function databaseSecrets(environment) {
|
|
63
|
+
return Object.entries(environment)
|
|
64
|
+
.filter(([name]) => name !== "FORGE_MANAGED_VERIFICATION_DATABASE_MODE" && name !== ephemeralTestPostgresClusterEnvironment)
|
|
65
|
+
.flatMap(([, value]) => attemptDatabaseCapabilitySecrets(value));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Managed verification on an `ephemeral` host gets a throwaway cluster for the command's
|
|
69
|
+
* lifetime; every other host keeps managedVerificationDatabaseEnvironment's rules. A cluster
|
|
70
|
+
* that cannot start fails the command rather than silently handing it Docker or the shared
|
|
71
|
+
* cluster's narrower login.
|
|
72
|
+
*/
|
|
73
|
+
export async function managedVerificationDatabase(dockerAvailable = async () => (await new DockerEngineProbe().probeWithoutRecovery()).available, readFallback = () => {
|
|
74
|
+
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
75
|
+
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
76
|
+
}, start = startEphemeralTestPostgres) {
|
|
77
|
+
const fallback = readFallback();
|
|
78
|
+
if (fallback?.use !== "ephemeral") {
|
|
79
|
+
const environment = await managedVerificationDatabaseEnvironment(dockerAvailable, () => fallback);
|
|
80
|
+
return { environment, secrets: databaseSecrets(environment), release: async () => undefined };
|
|
81
|
+
}
|
|
82
|
+
const grant = await startEphemeralTestPostgresGrant(fallback, await dockerAvailable(), start);
|
|
83
|
+
const environment = nativeTestPostgresFallbackEnvironment(grant);
|
|
84
|
+
return { environment, secrets: databaseSecrets(environment), release: grant.release ?? (async () => undefined) };
|
|
85
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Set for a test run on an ephemeral cluster: its id, which the server reports as `forge.ephemeral_cluster`. */
|
|
2
|
+
export declare const ephemeralTestPostgresClusterEnvironment = "FORGE_TEST_POSTGRES_EPHEMERAL_CLUSTER";
|
|
3
|
+
export declare const ephemeralTestPostgresMarkerSetting = "forge.ephemeral_cluster";
|
|
4
|
+
export declare class EphemeralTestPostgresError extends Error {
|
|
5
|
+
readonly code = "ephemeral_test_postgres_unavailable";
|
|
6
|
+
constructor(detail: string);
|
|
7
|
+
}
|
|
8
|
+
export interface EphemeralTestPostgresCluster {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly connectionString: string;
|
|
11
|
+
readonly endpoint: string;
|
|
12
|
+
readonly password: string;
|
|
13
|
+
/**
|
|
14
|
+
* Stops the server and deletes its directory. Safe to call more than once. Rejects, keeping the
|
|
15
|
+
* directory, when the server is still running after the stop.
|
|
16
|
+
*/
|
|
17
|
+
release(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface ToolResult {
|
|
20
|
+
readonly code: number | null;
|
|
21
|
+
readonly output: string;
|
|
22
|
+
}
|
|
23
|
+
/** Runs one PostgreSQL program. `detached` programs (pg_ctl start) leave a server running, so their output goes to its log. */
|
|
24
|
+
export type EphemeralToolRunner = (file: string, args: readonly string[], options: {
|
|
25
|
+
readonly env: Readonly<Record<string, string>>;
|
|
26
|
+
readonly timeoutMs: number;
|
|
27
|
+
readonly detached?: boolean;
|
|
28
|
+
}) => Promise<ToolResult>;
|
|
29
|
+
export interface EphemeralTestPostgresOptions {
|
|
30
|
+
/** The directory holding initdb, pg_ctl and psql of the PostgreSQL install to run. */
|
|
31
|
+
readonly binDirectory: string;
|
|
32
|
+
readonly root?: string;
|
|
33
|
+
readonly ownerPid?: number;
|
|
34
|
+
readonly runTool?: EphemeralToolRunner;
|
|
35
|
+
readonly isProcessAlive?: (pid: number) => boolean;
|
|
36
|
+
readonly freePort?: () => Promise<number>;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
}
|
|
39
|
+
export declare function defaultEphemeralTestPostgresRoot(): string;
|
|
40
|
+
/**
|
|
41
|
+
* A superuser of a cluster run by the `postgres` OS user can read every cluster that user runs,
|
|
42
|
+
* including live ones (Debian and Ubuntu packages run them all as `postgres`). An ephemeral
|
|
43
|
+
* cluster therefore runs only as an ordinary user, the same one that already runs the attempt.
|
|
44
|
+
*/
|
|
45
|
+
export declare function assertEphemeralClusterOsUser(userName?: string, uid?: number | undefined): void;
|
|
46
|
+
/** Creates, starts and prepares one cluster. On any failure nothing of it is left behind. */
|
|
47
|
+
export declare function startEphemeralTestPostgres(options: EphemeralTestPostgresOptions): Promise<EphemeralTestPostgresCluster>;
|
|
48
|
+
/**
|
|
49
|
+
* Removes clusters whose owning Bridge process is gone. Only directories named like a cluster
|
|
50
|
+
* id inside the root are considered, and a live owner's clusters are never touched.
|
|
51
|
+
*/
|
|
52
|
+
export declare function reapEphemeralTestPostgres(options: EphemeralTestPostgresOptions): Promise<readonly string[]>;
|
|
53
|
+
/**
|
|
54
|
+
* On Windows a started postgres inherits pg_ctl's standard handles, so a pipe would stay open for
|
|
55
|
+
* the server's lifetime; a detached program gets no pipes and settles when it exits.
|
|
56
|
+
*/
|
|
57
|
+
export declare const runPostgresTool: EphemeralToolRunner;
|