@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c2f22d1dd395
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 +1 -1
- package/dist/bridge/bridge.service.d.ts +12 -1
- package/dist/bridge/bridge.service.js +53 -6
- package/dist/bridge/bridge.types.d.ts +6 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/cli/cli.help.js +2 -2
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
- package/dist/runtime/attempt-process-supervisor.js +77 -3
- 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-diagnostics.js +4 -3
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-sampler.d.ts +83 -0
- package/dist/runtime/host-load-sampler.js +164 -0
- package/dist/runtime/host-pressure-stall.d.ts +41 -0
- package/dist/runtime/host-pressure-stall.js +121 -0
- package/dist/runtime/host-runtime-contract.d.ts +1 -0
- package/dist/runtime/host-runtime-contract.js +71 -10
- package/dist/runtime/host-runtime-lease.d.ts +4 -2
- package/dist/runtime/host-runtime-lease.js +108 -24
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/node-host-runtime-adapter.js +5 -4
- 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 +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/sandbox/repository-lock.js +3 -2
- package/dist/sandbox/runtime.js +5 -4
- package/dist/session/managed-attempt-tools.d.ts +25 -0
- package/dist/session/managed-attempt-tools.js +222 -20
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +8 -4
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.runtime.js +30 -18
- package/dist/session/pre-publication-process.d.ts +20 -0
- package/dist/session/pre-publication-process.js +97 -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-validation.js +32 -58
- package/dist/session/provider-cli/provider-cli.artifacts.js +2 -9
- package/dist/session/provider-cli/provider-cli.process.d.ts +6 -1
- package/dist/session/provider-cli/provider-cli.process.js +198 -16
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
- package/dist/session/provider-cli/provider-cli.service.js +64 -12
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- package/dist/session/publishable-worktree-changes.d.ts +45 -0
- package/dist/session/publishable-worktree-changes.js +177 -0
- package/dist/session/session.types.js +3 -0
- package/dist/shared/process/host-process-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.js +5 -4
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.js +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
6
|
+
import { isSubPath } from "../shared/path/path.js";
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
export class ProcessPrePublicationCommandRunner {
|
|
9
|
+
async run(command, args, cwd, signal, environment) {
|
|
10
|
+
try {
|
|
11
|
+
const launch = await pnpmDirectoryLaunch(command, args, cwd);
|
|
12
|
+
const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm");
|
|
13
|
+
const executable = windowsBatch ? (process.env.ComSpec ?? "cmd.exe") : command;
|
|
14
|
+
const commandArgs = windowsBatch
|
|
15
|
+
? ["/d", "/s", "/c", [`${command}.cmd`, ...launch.args].map(quoteWindowsCommandArgument).join(" ")]
|
|
16
|
+
: [...launch.args];
|
|
17
|
+
const result = await execFileAsync(executable, commandArgs, {
|
|
18
|
+
cwd: launch.cwd,
|
|
19
|
+
encoding: "utf8",
|
|
20
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
21
|
+
signal,
|
|
22
|
+
env: prePublicationChildEnvironment(environment),
|
|
23
|
+
});
|
|
24
|
+
return { exitCode: 0, stdout: result.stdout, stderr: result.stderr };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const failure = error;
|
|
28
|
+
if (failure.name === "AbortError")
|
|
29
|
+
throw error;
|
|
30
|
+
if (failure.code === "ENOENT") {
|
|
31
|
+
return { exitCode: 127, stderr: `executable_not_found: ${command}` };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
exitCode: typeof failure.code === "number" ? failure.code : 1,
|
|
35
|
+
stdout: failure.stdout,
|
|
36
|
+
stderr: failure.stderr ?? failure.message,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function quoteWindowsCommandArgument(value) {
|
|
42
|
+
return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `"${value.replaceAll('"', '""')}"`;
|
|
43
|
+
}
|
|
44
|
+
function prePublicationChildEnvironment(environment) {
|
|
45
|
+
const child = {};
|
|
46
|
+
const privilegedNames = new Set([
|
|
47
|
+
hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
|
|
48
|
+
hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
|
|
49
|
+
hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
|
|
50
|
+
]);
|
|
51
|
+
for (const [name, value] of Object.entries(process.env)) {
|
|
52
|
+
if (typeof value === "string" && !privilegedNames.has(name.toLowerCase())) {
|
|
53
|
+
child[name] = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { ...child, ...environment };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Corepack picks the pnpm version from the nearest package.json `packageManager`
|
|
60
|
+
* pin at or above the process working directory; pnpm's own `--dir` is not
|
|
61
|
+
* consulted. The repository root carries no pin, so `pnpm --dir client ...`
|
|
62
|
+
* launched from the root would run Corepack's host-global default, and pnpm
|
|
63
|
+
* then refuses client's pin (ERR_PNPM_BAD_PM_VERSION). `pnpm --dir X cmd` is
|
|
64
|
+
* `pnpm cmd` run from X, so launch from X and let Corepack walk up from there
|
|
65
|
+
* to the nearest pin. Targets that are absolute, leave the worktree, or do not
|
|
66
|
+
* exist stay unchanged so pnpm reports them itself.
|
|
67
|
+
*/
|
|
68
|
+
export async function pnpmDirectoryLaunch(command, args, cwd) {
|
|
69
|
+
const unchanged = { args, cwd };
|
|
70
|
+
if (command !== "pnpm")
|
|
71
|
+
return unchanged;
|
|
72
|
+
const target = pnpmDirectoryArgument(args);
|
|
73
|
+
if (!target || path.isAbsolute(target.directory))
|
|
74
|
+
return unchanged;
|
|
75
|
+
if (!isSubPath(cwd, path.resolve(cwd, target.directory)))
|
|
76
|
+
return unchanged;
|
|
77
|
+
// The lexical check alone would let a symlink (or junction) inside the worktree
|
|
78
|
+
// move the child's cwd outside it, so compare and launch from real paths.
|
|
79
|
+
const realCwd = await fs.realpath(cwd).catch(() => null);
|
|
80
|
+
const packageDirectory = await fs.realpath(path.resolve(cwd, target.directory)).catch(() => null);
|
|
81
|
+
if (!realCwd || !packageDirectory || !isSubPath(realCwd, packageDirectory))
|
|
82
|
+
return unchanged;
|
|
83
|
+
const stat = await fs.stat(packageDirectory).catch(() => null);
|
|
84
|
+
if (!stat?.isDirectory())
|
|
85
|
+
return unchanged;
|
|
86
|
+
return { args: args.slice(target.consumed), cwd: packageDirectory };
|
|
87
|
+
}
|
|
88
|
+
/** Reads a leading `--dir X`, `--dir=X`, `-C X`, `-CX` or `-C=X`. */
|
|
89
|
+
function pnpmDirectoryArgument(args) {
|
|
90
|
+
const first = args[0] ?? "";
|
|
91
|
+
if (first === "--dir" || first === "-C")
|
|
92
|
+
return args[1] ? { directory: args[1], consumed: 2 } : null;
|
|
93
|
+
const inline = first.startsWith("--dir=") ? first.slice("--dir=".length)
|
|
94
|
+
: first.startsWith("-C") ? first.slice(2).replace(/^=/u, "")
|
|
95
|
+
: "";
|
|
96
|
+
return inline ? { directory: inline, consumed: 1 } : null;
|
|
97
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skipped .NET tests from the TRX files a validation step wrote, so a run that skipped tests reads as
|
|
3
|
+
* "passed with N skipped (reasons)" rather than a plain pass. Only files under the step's declared results
|
|
4
|
+
* directory and written since the step started count, and that directory must resolve (through symlinks) inside
|
|
5
|
+
* the worktree or the attempt's own test-output root; nothing here can fail a passing step.
|
|
6
|
+
*/
|
|
7
|
+
export interface SkippedTestSummary {
|
|
8
|
+
readonly count: number;
|
|
9
|
+
readonly reasons: readonly {
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
readonly count: number;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
/** The attempt-owned output root a managed attempt's tests write under, outside the worktree. */
|
|
15
|
+
export declare const attemptTestOutputEnvironment = "FORGE_TEST_OUTPUT_DIR";
|
|
16
|
+
export declare function resultsDirectoryArgument(args: readonly string[]): string | undefined;
|
|
17
|
+
export declare function readSkippedTests(cwd: string, args: readonly string[], sinceMs: number, environment?: Readonly<Record<string, string>>): Promise<SkippedTestSummary>;
|
|
18
|
+
export declare function mergeSkippedTests(left: SkippedTestSummary, right: SkippedTestSummary): SkippedTestSummary;
|
|
19
|
+
export declare function describeSkippedTests(summary: SkippedTestSummary): string;
|
|
20
|
+
/** Each NotExecuted result's skip reason, from its ErrorInfo message (VSTest's TRX shape). */
|
|
21
|
+
export declare function skippedReasons(trx: string): string[];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isSubPath } from "../shared/path/path.js";
|
|
4
|
+
const emptySummary = { count: 0, reasons: [] };
|
|
5
|
+
/** The attempt-owned output root a managed attempt's tests write under, outside the worktree. */
|
|
6
|
+
export const attemptTestOutputEnvironment = "FORGE_TEST_OUTPUT_DIR";
|
|
7
|
+
const resultsDirectoryFlags = new Set(["-resultsdirectory", "--results-directory"]);
|
|
8
|
+
const maxTrxBytes = 64 * 1024 * 1024;
|
|
9
|
+
const maxTrxFiles = 64;
|
|
10
|
+
const maxReasonLength = 400;
|
|
11
|
+
const maxReasons = 10;
|
|
12
|
+
export function resultsDirectoryArgument(args) {
|
|
13
|
+
const index = args.findIndex(arg => resultsDirectoryFlags.has(arg.toLowerCase()));
|
|
14
|
+
const value = index >= 0 ? args[index + 1] : undefined;
|
|
15
|
+
return value && !value.startsWith("-") ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
export async function readSkippedTests(cwd, args, sinceMs, environment) {
|
|
18
|
+
const declared = resultsDirectoryArgument(args);
|
|
19
|
+
if (!declared)
|
|
20
|
+
return emptySummary;
|
|
21
|
+
const root = await realDirectory(path.resolve(cwd, declared));
|
|
22
|
+
if (!root)
|
|
23
|
+
return emptySummary;
|
|
24
|
+
const attemptOutput = environment?.[attemptTestOutputEnvironment]?.trim();
|
|
25
|
+
const allowedRoots = (await Promise.all([cwd, ...(attemptOutput && path.isAbsolute(attemptOutput) ? [attemptOutput] : [])]
|
|
26
|
+
.map(realDirectory))).filter((allowed) => allowed !== undefined);
|
|
27
|
+
if (!allowedRoots.some(allowed => isSubPath(allowed, root)))
|
|
28
|
+
return emptySummary;
|
|
29
|
+
const files = await recentTrxFiles(root, sinceMs);
|
|
30
|
+
const counts = new Map();
|
|
31
|
+
let count = 0;
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
for (const reason of skippedReasons(await fs.readFile(file, "utf8"))) {
|
|
34
|
+
count += 1;
|
|
35
|
+
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { count, reasons: [...counts].map(([reason, n]) => ({ reason, count: n })) };
|
|
39
|
+
}
|
|
40
|
+
export function mergeSkippedTests(left, right) {
|
|
41
|
+
const counts = new Map(left.reasons.map(entry => [entry.reason, entry.count]));
|
|
42
|
+
for (const entry of right.reasons)
|
|
43
|
+
counts.set(entry.reason, (counts.get(entry.reason) ?? 0) + entry.count);
|
|
44
|
+
return { count: left.count + right.count, reasons: [...counts].map(([reason, count]) => ({ reason, count })) };
|
|
45
|
+
}
|
|
46
|
+
export function describeSkippedTests(summary) {
|
|
47
|
+
const shown = [...summary.reasons].sort((a, b) => b.count - a.count).slice(0, maxReasons);
|
|
48
|
+
const more = summary.reasons.length - shown.length;
|
|
49
|
+
return `${summary.count} skipped test${summary.count === 1 ? "" : "s"} (${shown
|
|
50
|
+
.map(entry => `${entry.count}x ${entry.reason}`).join("; ")}${more > 0 ? `; ${more} more reasons` : ""})`;
|
|
51
|
+
}
|
|
52
|
+
/** Each NotExecuted result's skip reason, from its ErrorInfo message (VSTest's TRX shape). */
|
|
53
|
+
export function skippedReasons(trx) {
|
|
54
|
+
const reasons = [];
|
|
55
|
+
const result = /<UnitTestResult\b([^>]*?)(?:\/>|>([\s\S]*?)<\/UnitTestResult>)/gu;
|
|
56
|
+
for (const match of trx.matchAll(result)) {
|
|
57
|
+
if (!/\boutcome="NotExecuted"/u.test(match[1] ?? ""))
|
|
58
|
+
continue;
|
|
59
|
+
const message = /<Message>([\s\S]*?)<\/Message>/u.exec(match[2] ?? "")?.[1];
|
|
60
|
+
const reason = message ? decodeXml(message).replace(/\s+/gu, " ").trim() : "";
|
|
61
|
+
reasons.push(reason.length === 0 ? "no reason recorded"
|
|
62
|
+
: reason.length > maxReasonLength ? `${reason.slice(0, maxReasonLength)}...` : reason);
|
|
63
|
+
}
|
|
64
|
+
return reasons;
|
|
65
|
+
}
|
|
66
|
+
async function realDirectory(candidate) {
|
|
67
|
+
try {
|
|
68
|
+
const real = await fs.realpath(candidate);
|
|
69
|
+
return (await fs.stat(real)).isDirectory() ? real : undefined;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function recentTrxFiles(root, sinceMs) {
|
|
76
|
+
const found = [];
|
|
77
|
+
const pending = [root];
|
|
78
|
+
while (pending.length > 0 && found.length < maxTrxFiles) {
|
|
79
|
+
const directory = pending.pop();
|
|
80
|
+
let entries;
|
|
81
|
+
try {
|
|
82
|
+
entries = await fs.readdir(directory, { withFileTypes: true });
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
const full = path.join(directory, entry.name);
|
|
89
|
+
if (entry.isDirectory())
|
|
90
|
+
pending.push(full);
|
|
91
|
+
else if (entry.isFile() && entry.name.toLowerCase().endsWith(".trx")) {
|
|
92
|
+
const stat = await fs.stat(full).catch(() => null);
|
|
93
|
+
if (stat && stat.mtimeMs >= sinceMs && stat.size <= maxTrxBytes)
|
|
94
|
+
found.push(full);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return found.sort();
|
|
99
|
+
}
|
|
100
|
+
function decodeXml(value) {
|
|
101
|
+
return value.replace(/&(#x[0-9a-f]+|#[0-9]+|lt|gt|amp|quot|apos);/giu, (entity, name) => {
|
|
102
|
+
const lower = name.toLowerCase();
|
|
103
|
+
if (lower.startsWith("#x"))
|
|
104
|
+
return String.fromCodePoint(Number.parseInt(lower.slice(2), 16));
|
|
105
|
+
if (lower.startsWith("#"))
|
|
106
|
+
return String.fromCodePoint(Number.parseInt(lower.slice(1), 10));
|
|
107
|
+
return { lt: "<", gt: ">", amp: "&", quot: "\"", apos: "'" }[lower] ?? entity;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
2
|
import fs from "node:fs/promises";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import {
|
|
4
|
+
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
6
5
|
import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
|
|
7
6
|
import { nativeTestPostgresFallbackEnvironment, parseNativeTestPostgresFallback, } from "../runtime/native-test-postgres-fallback.js";
|
|
8
|
-
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
7
|
+
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
9
8
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
9
|
+
import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
|
|
10
|
+
import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
|
|
10
11
|
import { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
11
12
|
import { ForgeFailureError, sanitizeFailureError, } from "./session.types.js";
|
|
12
|
-
const execFileAsync = promisify(execFile);
|
|
13
13
|
const contractRelativePath = ".forge/validation/ci-parity.v1.json";
|
|
14
14
|
const requiredCheckIds = new Set([
|
|
15
15
|
"file-size-inventory",
|
|
@@ -80,54 +80,6 @@ export class PrePublicationInfrastructureError extends ForgeFailureError {
|
|
|
80
80
|
this.name = "PrePublicationInfrastructureError";
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
class ProcessPrePublicationCommandRunner {
|
|
84
|
-
async run(command, args, cwd, signal, environment) {
|
|
85
|
-
try {
|
|
86
|
-
const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm");
|
|
87
|
-
const executable = windowsBatch ? (process.env.ComSpec ?? "cmd.exe") : command;
|
|
88
|
-
const commandArgs = windowsBatch
|
|
89
|
-
? ["/d", "/s", "/c", [`${command}.cmd`, ...args].map(quoteWindowsCommandArgument).join(" ")]
|
|
90
|
-
: [...args];
|
|
91
|
-
const result = await execFileAsync(executable, commandArgs, {
|
|
92
|
-
cwd,
|
|
93
|
-
encoding: "utf8",
|
|
94
|
-
maxBuffer: 4 * 1024 * 1024,
|
|
95
|
-
signal,
|
|
96
|
-
env: prePublicationChildEnvironment(environment),
|
|
97
|
-
});
|
|
98
|
-
return { exitCode: 0, stdout: result.stdout, stderr: result.stderr };
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
const failure = error;
|
|
102
|
-
if (failure.name === "AbortError")
|
|
103
|
-
throw error;
|
|
104
|
-
if (failure.code === "ENOENT") {
|
|
105
|
-
return { exitCode: 127, stderr: `executable_not_found: ${command}` };
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
exitCode: typeof failure.code === "number" ? failure.code : 1,
|
|
109
|
-
stdout: failure.stdout,
|
|
110
|
-
stderr: failure.stderr ?? failure.message,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function quoteWindowsCommandArgument(value) {
|
|
116
|
-
return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `"${value.replaceAll('"', '""')}"`;
|
|
117
|
-
}
|
|
118
|
-
function prePublicationChildEnvironment(environment) {
|
|
119
|
-
const child = {};
|
|
120
|
-
const privilegedNames = new Set([
|
|
121
|
-
hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
|
|
122
|
-
hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
|
|
123
|
-
]);
|
|
124
|
-
for (const [name, value] of Object.entries(process.env)) {
|
|
125
|
-
if (typeof value === "string" && !privilegedNames.has(name.toLowerCase())) {
|
|
126
|
-
child[name] = value;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return { ...child, ...environment };
|
|
130
|
-
}
|
|
131
83
|
export class PrePublicationValidator {
|
|
132
84
|
commands;
|
|
133
85
|
dockerEngineProbe;
|
|
@@ -175,7 +127,9 @@ export class PrePublicationValidator {
|
|
|
175
127
|
}
|
|
176
128
|
const postgresAdminConnection = await this.ensurePrerequisite(check, scoped.execution?.environment, scoped.postgresAdminConnection, emit) ?? scoped.postgresAdminConnection;
|
|
177
129
|
await emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
|
|
130
|
+
let skipped = { count: 0, reasons: [] };
|
|
178
131
|
for (const step of check.steps) {
|
|
132
|
+
const stepStartedMs = Date.now() - 1000;
|
|
179
133
|
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
180
134
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
181
135
|
if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
|
|
@@ -221,9 +175,17 @@ export class PrePublicationValidator {
|
|
|
221
175
|
await emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
|
|
222
176
|
throw new PrePublicationValidationError(check.id, result.exitCode, result.command, result.args, detail);
|
|
223
177
|
}
|
|
178
|
+
// The invocation's own arguments: a managed attempt may direct results to its test-output root.
|
|
179
|
+
skipped = mergeSkippedTests(skipped, await readSkippedTests(worktreePath, result.args, stepStartedMs, scoped.execution?.environment));
|
|
224
180
|
}
|
|
225
181
|
completed.push(check.id);
|
|
226
|
-
|
|
182
|
+
// A pass that skipped tests says so, with each reason, instead of reading as a plain pass.
|
|
183
|
+
const secrets = validationExactSecrets(scoped.execution?.environment);
|
|
184
|
+
skipped = { ...skipped, reasons: skipped.reasons.map(entry => ({ ...entry, reason: redactText(entry.reason, secrets) })) };
|
|
185
|
+
const skippedDetail = skipped.count > 0 ? describeSkippedTests(skipped) : undefined;
|
|
186
|
+
await emit?.(validationEvent("prepublication_validation_passed", check.id, skippedDetail
|
|
187
|
+
? `Pre-publication CI parity check '${check.id}' passed with ${skippedDetail}.`
|
|
188
|
+
: `Pre-publication CI parity check '${check.id}' passed.`, skipped.count > 0 ? { skippedTests: skipped.count, skippedReasons: skipped.reasons } : undefined));
|
|
227
189
|
}
|
|
228
190
|
return completed;
|
|
229
191
|
}
|
|
@@ -360,10 +322,11 @@ export class PrePublicationValidator {
|
|
|
360
322
|
const exactSecrets = validationExactSecrets(execution?.environment);
|
|
361
323
|
try {
|
|
362
324
|
if (execution?.processRunner) {
|
|
325
|
+
const launch = await pnpmDirectoryLaunch(command, args, cwd);
|
|
363
326
|
const result = await execution.processRunner.run({
|
|
364
327
|
command,
|
|
365
|
-
args,
|
|
366
|
-
cwd,
|
|
328
|
+
args: launch.args,
|
|
329
|
+
cwd: launch.cwd,
|
|
367
330
|
env: execution.environment,
|
|
368
331
|
captureOutput: true,
|
|
369
332
|
failureRedactionValues: exactSecrets,
|
|
@@ -444,7 +407,9 @@ function isolatedPostgresProvided(checkId, environment, postgresAdminConnection)
|
|
|
444
407
|
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
445
408
|
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
446
409
|
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
447
|
-
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
410
|
+
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
411
|
+
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
412
|
+
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
448
413
|
}
|
|
449
414
|
return Boolean(postgresAdminConnection);
|
|
450
415
|
}
|
|
@@ -452,6 +417,8 @@ function validationExactSecrets(environment) {
|
|
|
452
417
|
return [
|
|
453
418
|
environment?.[hostRuntimeTestPostgresAdminEnvironment]?.trim() ?? "",
|
|
454
419
|
environment?.[hostRuntimeLegacyTestPostgresEnvironment]?.trim() ?? "",
|
|
420
|
+
environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
|
|
421
|
+
...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
|
|
455
422
|
].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
456
423
|
}
|
|
457
424
|
function diagnosticDetail(result) {
|
|
@@ -583,6 +550,7 @@ function withoutPrivilegedPostgresEnvironment(environment) {
|
|
|
583
550
|
const privilegedNames = new Set([
|
|
584
551
|
hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
|
|
585
552
|
hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
|
|
553
|
+
hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
|
|
586
554
|
]);
|
|
587
555
|
return Object.fromEntries(Object.entries(environment)
|
|
588
556
|
.filter(([name]) => !privilegedNames.has(name.toLowerCase())));
|
|
@@ -652,6 +620,12 @@ function canonicalizeJson(value) {
|
|
|
652
620
|
}
|
|
653
621
|
return value;
|
|
654
622
|
}
|
|
655
|
-
function validationEvent(eventType, checkId, content) {
|
|
656
|
-
return {
|
|
623
|
+
function validationEvent(eventType, checkId, content, detail) {
|
|
624
|
+
return {
|
|
625
|
+
role: "runner",
|
|
626
|
+
kind: "checkpoint",
|
|
627
|
+
content,
|
|
628
|
+
eventType,
|
|
629
|
+
data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1", ...detail }),
|
|
630
|
+
};
|
|
657
631
|
}
|
|
@@ -2,12 +2,12 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { artifactRootFor, artifactRootForOwner, debugCompletionPhaseOrder, draftCompletionGateOrder, qaCompletionGateOrder, readCompletionArtifact } from "../phase-completion.js";
|
|
4
4
|
import { ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "../qa-sidecar-validation.js";
|
|
5
|
+
import { stagePublishableWorktreeChangeSet } from "../publishable-worktree-changes.js";
|
|
5
6
|
import { hasLaunchTarget } from "./provider-cli.qa-sidecars.js";
|
|
6
7
|
import { clip, isNodeError, messageFromError, normalizedString, parseJsonLine, stringField } from "./provider-output-state.js";
|
|
7
8
|
const maxTransportedQaSidecarBytes = 8 * 1024 * 1024;
|
|
8
9
|
const maxTransportedQaSidecarsTotalBytes = 16 * 1024 * 1024;
|
|
9
10
|
const developCyclePhaseOrder = ["implementation", "self_review", "validation"];
|
|
10
|
-
const nonPublishableWorktreePaths = [".forge", ".local"];
|
|
11
11
|
export async function emitDraftGateArtifacts(emit, worktreePath, workItemId) {
|
|
12
12
|
const draftArtifactFiles = {
|
|
13
13
|
draft_intent: "draft.intent.json",
|
|
@@ -157,14 +157,7 @@ export async function commitWorktreeChanges(git, worktreePath, workItemId, alrea
|
|
|
157
157
|
return { commitSha, changedFiles };
|
|
158
158
|
}
|
|
159
159
|
export async function stagePublishableWorktreeChanges(git, worktreePath) {
|
|
160
|
-
await git
|
|
161
|
-
for (const reservedPath of nonPublishableWorktreePaths) {
|
|
162
|
-
await git.run(worktreePath, ["reset", "--", reservedPath]).catch(() => "");
|
|
163
|
-
}
|
|
164
|
-
return (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
|
|
165
|
-
.split(/\r?\n/)
|
|
166
|
-
.map((line) => line.trim())
|
|
167
|
-
.filter(Boolean);
|
|
160
|
+
return (await stagePublishableWorktreeChangeSet(git, worktreePath)).publishable;
|
|
168
161
|
}
|
|
169
162
|
export function phaseCompleteEventType(phase) {
|
|
170
163
|
return phase === "implementation" ? "implementation_complete" : `${phase}_complete`;
|
|
@@ -23,6 +23,8 @@ export interface ProviderProcessRunResult {
|
|
|
23
23
|
readonly memorySampleCount?: number;
|
|
24
24
|
readonly memorySource?: string;
|
|
25
25
|
readonly memoryObservedAt?: string;
|
|
26
|
+
/** Present when the caller's cancellation stopped the process before it exited on its own. */
|
|
27
|
+
readonly cancelled?: true;
|
|
26
28
|
}
|
|
27
29
|
export interface ProviderProcessRunner {
|
|
28
30
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
@@ -70,11 +72,14 @@ interface ProviderChildEnvironmentOptions {
|
|
|
70
72
|
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
71
73
|
export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
|
|
72
74
|
private readonly terminalExitGraceMs;
|
|
73
|
-
|
|
75
|
+
private readonly terminalSuccessCeilingMs;
|
|
76
|
+
constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number);
|
|
74
77
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
75
78
|
}
|
|
76
79
|
/** Returns aggregate resident bytes for the exact supervised Unix process group. */
|
|
77
80
|
export declare function processGroupResidentMemoryBytes(processGroupId: number, platform?: NodeJS.Platform, procRoot?: string): number | null;
|
|
81
|
+
export declare const UNIX_PROVIDER_START_GRANT_LINE = "forge-provider-start-granted\n";
|
|
82
|
+
export declare function buildUnixProviderStartGateLaunch(command: string, args: readonly string[]): LaunchCommand;
|
|
78
83
|
export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
79
84
|
/**
|
|
80
85
|
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|