@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c1ae24134918
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 +3 -3
- package/dist/bridge/bridge.service.d.ts +14 -1
- package/dist/bridge/bridge.service.js +81 -9
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- 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/cli/cli.help.js +2 -2
- package/dist/cli/cli.service.js +3 -1
- 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-admission.d.ts +52 -0
- package/dist/runtime/host-load-admission.js +84 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +65 -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 +34 -0
- package/dist/runtime/host-load-governor-config.js +46 -0
- package/dist/runtime/host-load-governor.d.ts +172 -0
- package/dist/runtime/host-load-governor.js +519 -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-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -0
- package/dist/runtime/host-load-step-class.d.ts +68 -0
- package/dist/runtime/host-load-step-class.js +106 -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-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -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 +75 -11
- package/dist/runtime/host-runtime-lease.d.ts +19 -3
- package/dist/runtime/host-runtime-lease.js +188 -25
- package/dist/runtime/host-runtime-promotion.js +12 -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/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/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/repository-lock.js +3 -2
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +50 -6
- 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 +25 -0
- package/dist/session/managed-attempt-tools.js +330 -32
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +8 -4
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -0
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.d.ts +2 -0
- package/dist/session/phase-completion.runtime.d.ts +1 -1
- package/dist/session/phase-completion.runtime.js +44 -24
- 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-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 +9 -9
- package/dist/session/pre-publication-validation.js +53 -113
- 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 +37 -1
- package/dist/session/provider-cli/provider-cli.process.js +299 -25
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +15 -0
- 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 +144 -35
- package/dist/session/provider-cli/provider-cli.types.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- 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 +229 -0
- package/dist/session/session.base.d.ts +3 -0
- package/dist/session/session.service.d.ts +2 -0
- package/dist/session/session.service.js +21 -4
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +14 -2
- package/dist/shared/process/host-process-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +6 -5
- 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/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +120 -10
- package/dist/worktree/worktree.service.d.ts +6 -1
- package/dist/worktree/worktree.service.js +14 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PrePublicationExecutionContext } from "./pre-publication-validation.js";
|
|
2
|
+
export interface ValidationStep {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly fallbackCommand?: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly fallbackArgs?: readonly string[];
|
|
7
|
+
readonly assertUnchangedPaths?: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function managedAttemptInvocation(checkId: string, step: ValidationStep, environment?: Readonly<Record<string, string>>): Pick<ValidationStep, "command" | "args">;
|
|
10
|
+
export declare function supportsNativeTestPostgresFallback(checkId: string): boolean;
|
|
11
|
+
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: string): PrePublicationExecutionContext | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { nativeTestPostgresFallbackEnvironment, parseNativeTestPostgresFallback, } from "../runtime/native-test-postgres-fallback.js";
|
|
2
|
+
import { ForgeFailureError } from "./session.types.js";
|
|
3
|
+
export function managedAttemptInvocation(checkId, step, environment) {
|
|
4
|
+
const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
|
|
5
|
+
const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
|
|
6
|
+
|| Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
|
|
7
|
+
if (checkId !== "playwright-e2e" || !attemptOwned) {
|
|
8
|
+
return step;
|
|
9
|
+
}
|
|
10
|
+
if (!playwrightConfig) {
|
|
11
|
+
throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
command: "pnpm",
|
|
15
|
+
args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const nativeFallbackCheckIds = new Set([
|
|
19
|
+
"owned-suite-registration",
|
|
20
|
+
"dotnet-build-and-unit",
|
|
21
|
+
"comment-repair-dotnet-regression",
|
|
22
|
+
]);
|
|
23
|
+
const nativeFallbackDotnetTierScripts = [
|
|
24
|
+
"scripts/run-dotnet-test-tier.ps1",
|
|
25
|
+
"scripts/run-dotnet-test-tier-set.ps1",
|
|
26
|
+
"scripts/run-affected-dotnet-tests.mjs",
|
|
27
|
+
];
|
|
28
|
+
export function supportsNativeTestPostgresFallback(checkId) {
|
|
29
|
+
return nativeFallbackCheckIds.has(checkId);
|
|
30
|
+
}
|
|
31
|
+
export function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
32
|
+
// The connection only exists when Docker is unavailable and the operator
|
|
33
|
+
// provisioned a dedicated native test cluster. Only the runner-authored
|
|
34
|
+
// .NET test tiers and the suite-identity check receive it; build, client,
|
|
35
|
+
// Bridge, and E2E steps never do.
|
|
36
|
+
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
37
|
+
return execution;
|
|
38
|
+
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
39
|
+
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
40
|
+
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
41
|
+
return execution;
|
|
42
|
+
return {
|
|
43
|
+
...execution,
|
|
44
|
+
environment: {
|
|
45
|
+
...execution?.environment,
|
|
46
|
+
...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
3
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
4
|
+
import { type PrePublicationHostLoadOwner } from "./pre-publication-host-load.js";
|
|
5
|
+
import { type ValidationStep } from "./pre-publication-step-execution.js";
|
|
3
6
|
import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
4
7
|
import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
|
|
5
8
|
export type PrePublicationProfile = "implementation" | "comment_repair" | "ci_repair" | "conflict_repair";
|
|
6
|
-
interface ValidationStep {
|
|
7
|
-
readonly command: string;
|
|
8
|
-
readonly fallbackCommand?: string;
|
|
9
|
-
readonly args: readonly string[];
|
|
10
|
-
readonly fallbackArgs?: readonly string[];
|
|
11
|
-
readonly assertUnchangedPaths?: readonly string[];
|
|
12
|
-
}
|
|
13
9
|
interface ValidationCheck {
|
|
14
10
|
readonly id: string;
|
|
15
11
|
readonly profiles: readonly string[];
|
|
@@ -36,6 +32,8 @@ export interface PrePublicationExecutionContext {
|
|
|
36
32
|
readonly baselineRevision?: string;
|
|
37
33
|
readonly environment?: Readonly<Record<string, string>>;
|
|
38
34
|
readonly processRunner?: ProviderProcessRunner;
|
|
35
|
+
/** The attempt governed steps reserve host capacity for (decision 0013). */
|
|
36
|
+
readonly hostLoadOwner?: PrePublicationHostLoadOwner;
|
|
39
37
|
}
|
|
40
38
|
export declare class PrePublicationValidationError extends ForgeFailureError {
|
|
41
39
|
readonly checkId: string;
|
|
@@ -59,7 +57,8 @@ export declare class PrePublicationValidator {
|
|
|
59
57
|
private readonly commands;
|
|
60
58
|
private readonly dockerEngineProbe?;
|
|
61
59
|
private readonly nativeTestPostgresFallback;
|
|
62
|
-
|
|
60
|
+
private readonly hostLoad?;
|
|
61
|
+
constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined);
|
|
63
62
|
validate(worktreePath: string, profile: PrePublicationProfile, capabilities: ReadonlySet<string>, emit?: (event: RunnerDispatchEvent) => Promise<void>, signal?: AbortSignal, execution?: PrePublicationExecutionContext): Promise<readonly string[]>;
|
|
64
63
|
/** Returns the native fallback connection when this check must use it instead of Docker. */
|
|
65
64
|
private ensurePrerequisite;
|
|
@@ -68,6 +67,7 @@ export declare class PrePublicationValidator {
|
|
|
68
67
|
private changedPaths;
|
|
69
68
|
private assertContractMatchesDispatchBaseline;
|
|
70
69
|
private runStep;
|
|
70
|
+
private launchStep;
|
|
71
71
|
private runCommand;
|
|
72
72
|
}
|
|
73
73
|
export declare function applicableChecks(contract: ValidationContract, profile: PrePublicationProfile | "github_actions", changedPaths: readonly string[]): readonly ValidationCheck[];
|
|
@@ -1,15 +1,17 @@
|
|
|
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
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
|
|
7
|
+
import { managedAttemptInvocation, supportsNativeTestPostgresFallback, validationExecutionForStep, } from "./pre-publication-step-execution.js";
|
|
8
|
+
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
9
9
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
10
|
+
import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
|
|
11
|
+
import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
|
|
12
|
+
import { ProcessTreeTerminationError } from "../shared/process/process.js";
|
|
10
13
|
import { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
11
14
|
import { ForgeFailureError, sanitizeFailureError, } from "./session.types.js";
|
|
12
|
-
const execFileAsync = promisify(execFile);
|
|
13
15
|
const contractRelativePath = ".forge/validation/ci-parity.v1.json";
|
|
14
16
|
const requiredCheckIds = new Set([
|
|
15
17
|
"file-size-inventory",
|
|
@@ -80,62 +82,16 @@ export class PrePublicationInfrastructureError extends ForgeFailureError {
|
|
|
80
82
|
this.name = "PrePublicationInfrastructureError";
|
|
81
83
|
}
|
|
82
84
|
}
|
|
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
85
|
export class PrePublicationValidator {
|
|
132
86
|
commands;
|
|
133
87
|
dockerEngineProbe;
|
|
134
88
|
nativeTestPostgresFallback;
|
|
135
|
-
|
|
89
|
+
hostLoad;
|
|
90
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad) {
|
|
136
91
|
this.commands = commands;
|
|
137
92
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
138
93
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
94
|
+
this.hostLoad = hostLoad;
|
|
139
95
|
}
|
|
140
96
|
async validate(worktreePath, profile, capabilities, emit, signal, execution) {
|
|
141
97
|
const checksExports = profile === "implementation" || profile === "comment_repair";
|
|
@@ -175,12 +131,14 @@ export class PrePublicationValidator {
|
|
|
175
131
|
}
|
|
176
132
|
const postgresAdminConnection = await this.ensurePrerequisite(check, scoped.execution?.environment, scoped.postgresAdminConnection, emit) ?? scoped.postgresAdminConnection;
|
|
177
133
|
await emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
|
|
134
|
+
let skipped = { count: 0, reasons: [] };
|
|
178
135
|
for (const step of check.steps) {
|
|
179
|
-
|
|
136
|
+
const stepStartedMs = Date.now() - 1000;
|
|
137
|
+
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
180
138
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
181
139
|
if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
|
|
182
140
|
await emit?.(validationEvent("prepublication_validation_timeout_confirmation_started", check.id, "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment."));
|
|
183
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
141
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
184
142
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
185
143
|
await emit?.(validationEvent(result.exitCode === 0
|
|
186
144
|
? "prepublication_validation_timeout_confirmation_passed"
|
|
@@ -190,7 +148,7 @@ export class PrePublicationValidator {
|
|
|
190
148
|
}
|
|
191
149
|
if (isTransientBridgeCleanupFailure(check.id, step, result)) {
|
|
192
150
|
await emit?.(validationEvent("prepublication_validation_cleanup_confirmation_started", check.id, "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment."));
|
|
193
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
151
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
194
152
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
195
153
|
await emit?.(validationEvent(result.exitCode === 0
|
|
196
154
|
? "prepublication_validation_cleanup_confirmation_passed"
|
|
@@ -200,7 +158,7 @@ export class PrePublicationValidator {
|
|
|
200
158
|
}
|
|
201
159
|
if (isTransientShellInfrastructureFailure(result)) {
|
|
202
160
|
await emit?.(validationEvent("prepublication_infrastructure_confirmation_started", check.id, "The validation shell reported a known host-runtime failure; confirming once with the same command and attempt environment."));
|
|
203
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
161
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
204
162
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
205
163
|
const infrastructureFailed = isTransientShellInfrastructureFailure(result);
|
|
206
164
|
await emit?.(validationEvent(infrastructureFailed
|
|
@@ -221,9 +179,17 @@ export class PrePublicationValidator {
|
|
|
221
179
|
await emit?.(validationEvent("prepublication_validation_failed", check.id, `Pre-publication CI parity check '${check.id}' exited ${result.exitCode}${detail ? `: ${detail}` : "."}`));
|
|
222
180
|
throw new PrePublicationValidationError(check.id, result.exitCode, result.command, result.args, detail);
|
|
223
181
|
}
|
|
182
|
+
// The invocation's own arguments: a managed attempt may direct results to its test-output root.
|
|
183
|
+
skipped = mergeSkippedTests(skipped, await readSkippedTests(worktreePath, result.args, stepStartedMs, scoped.execution?.environment));
|
|
224
184
|
}
|
|
225
185
|
completed.push(check.id);
|
|
226
|
-
|
|
186
|
+
// A pass that skipped tests says so, with each reason, instead of reading as a plain pass.
|
|
187
|
+
const secrets = validationExactSecrets(scoped.execution?.environment);
|
|
188
|
+
skipped = { ...skipped, reasons: skipped.reasons.map(entry => ({ ...entry, reason: redactText(entry.reason, secrets) })) };
|
|
189
|
+
const skippedDetail = skipped.count > 0 ? describeSkippedTests(skipped) : undefined;
|
|
190
|
+
await emit?.(validationEvent("prepublication_validation_passed", check.id, skippedDetail
|
|
191
|
+
? `Pre-publication CI parity check '${check.id}' passed with ${skippedDetail}.`
|
|
192
|
+
: `Pre-publication CI parity check '${check.id}' passed.`, skipped.count > 0 ? { skippedTests: skipped.count, skippedReasons: skipped.reasons } : undefined));
|
|
227
193
|
}
|
|
228
194
|
return completed;
|
|
229
195
|
}
|
|
@@ -251,7 +217,7 @@ export class PrePublicationValidator {
|
|
|
251
217
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
252
218
|
if (!snapshot.available) {
|
|
253
219
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
254
|
-
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check)
|
|
220
|
+
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check.id)
|
|
255
221
|
? this.nativeTestPostgresFallback()
|
|
256
222
|
: null;
|
|
257
223
|
if (fallback) {
|
|
@@ -337,8 +303,14 @@ export class PrePublicationValidator {
|
|
|
337
303
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
|
|
338
304
|
}
|
|
339
305
|
}
|
|
340
|
-
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection) {
|
|
306
|
+
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
|
|
341
307
|
const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
|
|
308
|
+
// Every launch, including confirmation reruns, is admitted by the host load governor first.
|
|
309
|
+
return await runHostGovernedValidationStep(this.hostLoad, {
|
|
310
|
+
checkId, command: invocation.command, args: invocation.args, owner: execution?.hostLoadOwner, signal, emit,
|
|
311
|
+
}, async (stepSignal) => await this.launchStep(checkId, step, invocation, cwd, stepSignal, execution, postgresAdminConnection));
|
|
312
|
+
}
|
|
313
|
+
async launchStep(checkId, step, invocation, cwd, signal, execution, postgresAdminConnection) {
|
|
342
314
|
const stepExecution = validationExecutionForStep(checkId, step, execution, postgresAdminConnection);
|
|
343
315
|
const before = await readValidationFiles(cwd, step.assertUnchangedPaths ?? []);
|
|
344
316
|
const result = await this.runCommand(invocation.command, invocation.args, cwd, signal, stepExecution);
|
|
@@ -360,10 +332,11 @@ export class PrePublicationValidator {
|
|
|
360
332
|
const exactSecrets = validationExactSecrets(execution?.environment);
|
|
361
333
|
try {
|
|
362
334
|
if (execution?.processRunner) {
|
|
335
|
+
const launch = await pnpmDirectoryLaunch(command, args, cwd);
|
|
363
336
|
const result = await execution.processRunner.run({
|
|
364
337
|
command,
|
|
365
|
-
args,
|
|
366
|
-
cwd,
|
|
338
|
+
args: launch.args,
|
|
339
|
+
cwd: launch.cwd,
|
|
367
340
|
env: execution.environment,
|
|
368
341
|
captureOutput: true,
|
|
369
342
|
failureRedactionValues: exactSecrets,
|
|
@@ -382,57 +355,13 @@ export class PrePublicationValidator {
|
|
|
382
355
|
};
|
|
383
356
|
}
|
|
384
357
|
catch (error) {
|
|
358
|
+
// Carries the check its host capacity token waits on; it names only the executable.
|
|
359
|
+
if (error instanceof ProcessTreeTerminationError)
|
|
360
|
+
throw error;
|
|
385
361
|
throw sanitizeFailureError(error, exactSecrets);
|
|
386
362
|
}
|
|
387
363
|
}
|
|
388
364
|
}
|
|
389
|
-
function managedAttemptInvocation(checkId, step, environment) {
|
|
390
|
-
const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
|
|
391
|
-
const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
|
|
392
|
-
|| Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
|
|
393
|
-
if (checkId !== "playwright-e2e" || !attemptOwned) {
|
|
394
|
-
return step;
|
|
395
|
-
}
|
|
396
|
-
if (!playwrightConfig) {
|
|
397
|
-
throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
|
|
398
|
-
}
|
|
399
|
-
return {
|
|
400
|
-
command: "pnpm",
|
|
401
|
-
args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
const nativeFallbackCheckIds = new Set([
|
|
405
|
-
"owned-suite-registration",
|
|
406
|
-
"dotnet-build-and-unit",
|
|
407
|
-
"comment-repair-dotnet-regression",
|
|
408
|
-
]);
|
|
409
|
-
const nativeFallbackDotnetTierScripts = [
|
|
410
|
-
"scripts/run-dotnet-test-tier.ps1",
|
|
411
|
-
"scripts/run-dotnet-test-tier-set.ps1",
|
|
412
|
-
"scripts/run-affected-dotnet-tests.mjs",
|
|
413
|
-
];
|
|
414
|
-
function supportsNativeTestPostgresFallback(check) {
|
|
415
|
-
return nativeFallbackCheckIds.has(check.id);
|
|
416
|
-
}
|
|
417
|
-
function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
418
|
-
// The connection only exists when Docker is unavailable and the operator
|
|
419
|
-
// provisioned a dedicated native test cluster. Only the runner-authored
|
|
420
|
-
// .NET test tiers and the suite-identity check receive it; build, client,
|
|
421
|
-
// Bridge, and E2E steps never do.
|
|
422
|
-
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
423
|
-
return execution;
|
|
424
|
-
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
425
|
-
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
426
|
-
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
427
|
-
return execution;
|
|
428
|
-
return {
|
|
429
|
-
...execution,
|
|
430
|
-
environment: {
|
|
431
|
-
...execution?.environment,
|
|
432
|
-
...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
365
|
function environmentValue(environment, name) {
|
|
437
366
|
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
438
367
|
? environment?.[name]?.trim() ?? ""
|
|
@@ -444,7 +373,9 @@ function isolatedPostgresProvided(checkId, environment, postgresAdminConnection)
|
|
|
444
373
|
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
445
374
|
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
446
375
|
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
447
|
-
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
376
|
+
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
377
|
+
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
378
|
+
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
448
379
|
}
|
|
449
380
|
return Boolean(postgresAdminConnection);
|
|
450
381
|
}
|
|
@@ -452,6 +383,8 @@ function validationExactSecrets(environment) {
|
|
|
452
383
|
return [
|
|
453
384
|
environment?.[hostRuntimeTestPostgresAdminEnvironment]?.trim() ?? "",
|
|
454
385
|
environment?.[hostRuntimeLegacyTestPostgresEnvironment]?.trim() ?? "",
|
|
386
|
+
environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
|
|
387
|
+
...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
|
|
455
388
|
].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
456
389
|
}
|
|
457
390
|
function diagnosticDetail(result) {
|
|
@@ -583,6 +516,7 @@ function withoutPrivilegedPostgresEnvironment(environment) {
|
|
|
583
516
|
const privilegedNames = new Set([
|
|
584
517
|
hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
|
|
585
518
|
hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
|
|
519
|
+
hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
|
|
586
520
|
]);
|
|
587
521
|
return Object.fromEntries(Object.entries(environment)
|
|
588
522
|
.filter(([name]) => !privilegedNames.has(name.toLowerCase())));
|
|
@@ -652,6 +586,12 @@ function canonicalizeJson(value) {
|
|
|
652
586
|
}
|
|
653
587
|
return value;
|
|
654
588
|
}
|
|
655
|
-
function validationEvent(eventType, checkId, content) {
|
|
656
|
-
return {
|
|
589
|
+
function validationEvent(eventType, checkId, content, detail) {
|
|
590
|
+
return {
|
|
591
|
+
role: "runner",
|
|
592
|
+
kind: "checkpoint",
|
|
593
|
+
content,
|
|
594
|
+
eventType,
|
|
595
|
+
data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1", ...detail }),
|
|
596
|
+
};
|
|
657
597
|
}
|
|
@@ -2,6 +2,7 @@ import { GitClient } from "../../shared/git/git.js";
|
|
|
2
2
|
import { type CompletionPhase, type CompletionToolRuntime, type DebugCompletionPhase, type QaCompletionGate } from "../phase-completion.js";
|
|
3
3
|
import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchSidecar } from "../session.types.js";
|
|
4
4
|
import type { ProviderCliRunContext } from "./provider-cli.types.js";
|
|
5
|
+
import { type ProviderProcessRunResult } from "./provider-cli.process.js";
|
|
5
6
|
export declare function emitDraftGateArtifacts(emit: ProviderCliRunContext["emit"], worktreePath: string, workItemId: string): Promise<void>;
|
|
6
7
|
export declare function emitDecomposeGateArtifacts(emit: ProviderCliRunContext["emit"], worktreePath: string, workItemId: string): Promise<void>;
|
|
7
8
|
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
@@ -91,5 +92,5 @@ export declare class LiveCompletionArtifactEmitter {
|
|
|
91
92
|
private pollQueued;
|
|
92
93
|
private poll;
|
|
93
94
|
}
|
|
94
|
-
export declare function readCompletionArtifactsForRun(worktreePath: string, workItemId: string, phase: CompletionPhase, developCycle: boolean, debugCycle: boolean): Promise<RunnerDispatchArtifact[]>;
|
|
95
|
+
export declare function readCompletionArtifactsForRun(worktreePath: string, workItemId: string, phase: CompletionPhase, developCycle: boolean, debugCycle: boolean, providerResult?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): Promise<RunnerDispatchArtifact[]>;
|
|
95
96
|
export {};
|
|
@@ -2,12 +2,14 @@ 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 { isRuntimeOnlyPath, stagePublishableWorktreeChangeSet } from "../publishable-worktree-changes.js";
|
|
6
|
+
import { providerCompletionToolMissingFailure } from "./provider-cli.process.js";
|
|
5
7
|
import { hasLaunchTarget } from "./provider-cli.qa-sidecars.js";
|
|
6
8
|
import { clip, isNodeError, messageFromError, normalizedString, parseJsonLine, stringField } from "./provider-output-state.js";
|
|
9
|
+
import { assertMergeResolutionPreservesUpstreamChanges, isMergeInProgress, mergeResolutionCommitNotes } from "./provider-cli.merge-integrity.js";
|
|
7
10
|
const maxTransportedQaSidecarBytes = 8 * 1024 * 1024;
|
|
8
11
|
const maxTransportedQaSidecarsTotalBytes = 16 * 1024 * 1024;
|
|
9
12
|
const developCyclePhaseOrder = ["implementation", "self_review", "validation"];
|
|
10
|
-
const nonPublishableWorktreePaths = [".forge", ".local"];
|
|
11
13
|
export async function emitDraftGateArtifacts(emit, worktreePath, workItemId) {
|
|
12
14
|
const draftArtifactFiles = {
|
|
13
15
|
draft_intent: "draft.intent.json",
|
|
@@ -150,21 +152,25 @@ export async function cleanupCompletionTools(completionTools, emit) {
|
|
|
150
152
|
}
|
|
151
153
|
export async function commitWorktreeChanges(git, worktreePath, workItemId, alreadyStagedChangedFiles) {
|
|
152
154
|
const changedFiles = alreadyStagedChangedFiles ?? await stagePublishableWorktreeChanges(git, worktreePath);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
const mergeReport = await assertMergeResolutionPreservesUpstreamChanges(git, worktreePath, { ignorePath: isRuntimeOnlyPath });
|
|
156
|
+
// A merge is always finalized, even when every change it brought is unpublishable
|
|
157
|
+
// runtime output; skipping the commit would leave MERGE_HEAD dangling.
|
|
158
|
+
const merging = await isMergeInProgress(git, worktreePath);
|
|
159
|
+
if (changedFiles.length > 0 || merging) {
|
|
160
|
+
const notes = mergeResolutionCommitNotes(mergeReport).flatMap(note => ["-m", note]);
|
|
161
|
+
await git.run(worktreePath, [
|
|
162
|
+
"commit",
|
|
163
|
+
...(changedFiles.length === 0 ? ["--allow-empty"] : []),
|
|
164
|
+
"-m",
|
|
165
|
+
`provider cli changeset for ${workItemId.slice(0, 8)}`,
|
|
166
|
+
...notes,
|
|
167
|
+
]);
|
|
155
168
|
}
|
|
156
169
|
const commitSha = (await git.run(worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
157
170
|
return { commitSha, changedFiles };
|
|
158
171
|
}
|
|
159
172
|
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);
|
|
173
|
+
return (await stagePublishableWorktreeChangeSet(git, worktreePath)).publishable;
|
|
168
174
|
}
|
|
169
175
|
export function phaseCompleteEventType(phase) {
|
|
170
176
|
return phase === "implementation" ? "implementation_complete" : `${phase}_complete`;
|
|
@@ -779,11 +785,11 @@ export class LiveCompletionArtifactEmitter {
|
|
|
779
785
|
}
|
|
780
786
|
}
|
|
781
787
|
}
|
|
782
|
-
export async function readCompletionArtifactsForRun(worktreePath, workItemId, phase, developCycle, debugCycle) {
|
|
788
|
+
export async function readCompletionArtifactsForRun(worktreePath, workItemId, phase, developCycle, debugCycle, providerResult) {
|
|
783
789
|
if (!developCycle && !debugCycle) {
|
|
784
790
|
const artifact = await readCompletionArtifact(worktreePath, workItemId, phase);
|
|
785
791
|
if (!artifact) {
|
|
786
|
-
throw
|
|
792
|
+
throw providerCompletionToolMissingFailure(`Provider CLI completed but did not call the Forge ${phase} completion tool.`, providerResult);
|
|
787
793
|
}
|
|
788
794
|
return [artifact];
|
|
789
795
|
}
|
|
@@ -795,11 +801,11 @@ export async function readCompletionArtifactsForRun(worktreePath, workItemId, ph
|
|
|
795
801
|
const artifact = await readCompletionArtifact(worktreePath, workItemId, expectedPhase);
|
|
796
802
|
if (!artifact) {
|
|
797
803
|
if (artifacts.length === 0) {
|
|
798
|
-
throw
|
|
804
|
+
throw providerCompletionToolMissingFailure(`Provider CLI completed but did not call the Forge ${expectedPhase} completion tool.`, providerResult);
|
|
799
805
|
}
|
|
800
806
|
const previous = artifacts[artifacts.length - 1];
|
|
801
807
|
if ((previous.status ?? "").trim().toLowerCase() === "pass") {
|
|
802
|
-
throw
|
|
808
|
+
throw providerCompletionToolMissingFailure(`Provider CLI completed after ${previous.phase} passed but did not call the Forge ${expectedPhase} completion tool.`, providerResult);
|
|
803
809
|
}
|
|
804
810
|
return artifacts;
|
|
805
811
|
}
|