@loucompanion/forge-bridge 0.1.4-dev.e1b4f55fb18d → 0.1.4-dev.e3697e9f5c98

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.
Files changed (53) hide show
  1. package/README.md +42 -0
  2. package/dist/bridge/bridge.base.d.ts +9 -0
  3. package/dist/bridge/bridge.service.d.ts +70 -1
  4. package/dist/bridge/bridge.service.js +278 -4
  5. package/dist/bridge/bridge.types.d.ts +11 -0
  6. package/dist/bridge/local-yield-flag.d.ts +6 -0
  7. package/dist/bridge/local-yield-flag.js +34 -0
  8. package/dist/cleanup/cleanup.service.js +15 -9
  9. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  10. package/dist/cleanup/forge-owned-paths.js +53 -0
  11. package/dist/cli/cli.help.js +18 -0
  12. package/dist/cli/cli.service.d.ts +16 -0
  13. package/dist/cli/cli.service.js +132 -14
  14. package/dist/cli/local-config.d.ts +4 -0
  15. package/dist/cli/local-config.js +26 -4
  16. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  17. package/dist/runtime/host-load-admission.d.ts +9 -1
  18. package/dist/runtime/host-load-admission.js +19 -4
  19. package/dist/runtime/host-load-child-environment.js +3 -1
  20. package/dist/runtime/host-load-governor-config.d.ts +9 -0
  21. package/dist/runtime/host-load-governor-config.js +30 -0
  22. package/dist/runtime/host-load-governor.d.ts +2 -0
  23. package/dist/runtime/host-load-governor.js +23 -1
  24. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  25. package/dist/runtime/host-load-runtime-settings.js +78 -0
  26. package/dist/runtime/host-runtime-lease.d.ts +58 -2
  27. package/dist/runtime/host-runtime-lease.js +198 -7
  28. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  29. package/dist/runtime/host-runtime-promotion.js +36 -0
  30. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  31. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  32. package/dist/runtime/runner-settings.d.ts +100 -0
  33. package/dist/runtime/runner-settings.js +214 -0
  34. package/dist/session/pre-publication-pass.d.ts +60 -0
  35. package/dist/session/pre-publication-pass.js +145 -0
  36. package/dist/session/pre-publication-validation.d.ts +21 -11
  37. package/dist/session/pre-publication-validation.js +149 -104
  38. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  39. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  40. package/dist/session/provider-cli/provider-cli.prompts.js +4 -1
  41. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  42. package/dist/session/provider-cli/provider-cli.service.js +72 -143
  43. package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
  44. package/dist/session/session.base.d.ts +6 -1
  45. package/dist/session/session.service.d.ts +7 -2
  46. package/dist/session/session.service.js +100 -2
  47. package/dist/session/session.types.js +2 -2
  48. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  49. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  50. package/dist/shared/provider-capabilities.js +5 -6
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +2 -2
@@ -0,0 +1,214 @@
1
+ import { parseHostLoadGovernorMode } from "./host-load-governor-config.js";
2
+ // Decision 0014 §3 "Precedence" and §6 "Bridge hub": the server pushes a runner
3
+ // settings document (`ApplySettings`) and is the source of truth. Host env vars
4
+ // are one-sided safety bounds only: a ceiling on capacity, a floor on reserves.
5
+ // The bridge reports the effective values, their sources and every env bound it
6
+ // saw back to the server (`SettingsApplied`), so a host bound is never silent.
7
+ // Nothing here is persisted to bridge.json (0014 agent constraint).
8
+ export const runnerSettingKeys = [
9
+ "maxConcurrentAttempts",
10
+ "cpuBudgetPercent",
11
+ "yieldCpuBudgetPercent",
12
+ "memoryReserveBytes",
13
+ "maxHeavySteps",
14
+ "yieldToForeground",
15
+ ];
16
+ export const defaultCpuBudgetPercent = 80;
17
+ export const defaultYieldCpuBudgetPercent = 50;
18
+ const MiB = 1024 ** 2;
19
+ const GiB = 1024 ** 3;
20
+ /** The server's ranges (contract); a value outside them is rejected, not clamped, so it is never silent. */
21
+ const serverRanges = {
22
+ maxConcurrentAttempts: { min: 1, max: 32 },
23
+ cpuBudgetPercent: { min: 10, max: 100 },
24
+ yieldCpuBudgetPercent: { min: 10, max: 100 },
25
+ memoryReserveBytes: { min: 512 * MiB, max: 128 * GiB },
26
+ maxHeavySteps: { min: 1, max: 64 },
27
+ };
28
+ /**
29
+ * Computes every effective value (decision 0014 precedence):
30
+ * - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
31
+ * - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
32
+ * - yield: server OR the local `forge-bridge yield on` flag.
33
+ * With no document at all (and the local flag off) the values equal today's env/default behaviour.
34
+ */
35
+ export function computeEffectiveRunnerSettings(document, environment, hostDefaults, localYield) {
36
+ const rejected = [];
37
+ const server = (key) => {
38
+ const value = document?.[key] ?? null;
39
+ if (value === null)
40
+ return null;
41
+ const range = serverRanges[key];
42
+ if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
43
+ rejected.push({ key, reason: `${String(value)} is not a whole number; the host default applies.`, kind: "invalid" });
44
+ return null;
45
+ }
46
+ if (value < range.min || value > range.max) {
47
+ rejected.push({ key, reason: `${value} is outside ${range.min}-${range.max}; the host default applies.`, kind: "invalid" });
48
+ return null;
49
+ }
50
+ return value;
51
+ };
52
+ const attemptsCeiling = integerEnv(environment, "FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", 1, 32);
53
+ const cpuCeilings = cpuBudgetCeilings(environment);
54
+ const reserveFloor = integerEnv(environment, "FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * MiB, 128 * GiB);
55
+ const heavyStepsCeiling = integerEnv(environment, "FORGE_HOST_MAX_HEAVY_STEPS", 1, 64);
56
+ const attempts = ceilingValue(server("maxConcurrentAttempts"), lowest(attemptsCeiling), hostDefaults.maxConcurrentAttempts);
57
+ const cpu = ceilingValue(server("cpuBudgetPercent"), lowest(...cpuCeilings), defaultCpuBudgetPercent);
58
+ // The yield budget's ceilings are the CPU budget's. Without a server value they
59
+ // cap its default rather than replace it: a host allowing 90% CPU must not raise
60
+ // the 50% yield default, which no env var sets today.
61
+ const serverYieldCpu = server("yieldCpuBudgetPercent");
62
+ const yieldCpu = ceilingValue(serverYieldCpu ?? defaultYieldCpuBudgetPercent, lowest(...cpuCeilings), defaultYieldCpuBudgetPercent);
63
+ const yieldCpuSource = serverYieldCpu === null && yieldCpu.source === "server" ? "default" : yieldCpu.source;
64
+ const reserve = floorValue(server("memoryReserveBytes"), reserveFloor?.value ?? null, hostDefaults.memoryReserveBytes);
65
+ const heavySteps = ceilingValue(server("maxHeavySteps"), lowest(heavyStepsCeiling), null);
66
+ const serverYield = document?.yieldToForeground === true;
67
+ const yielding = serverYield || localYield;
68
+ // The host's own switch wins the label: turning the server toggle off would not stop it.
69
+ const yieldSource = localYield ? "host_local" : serverYield ? "server" : "default";
70
+ const bounds = [];
71
+ const addCeilings = (key, set) => {
72
+ for (const bound of set)
73
+ if (bound)
74
+ bounds.push({ key, envVar: bound.envVar, value: bound.value, kind: "ceiling" });
75
+ };
76
+ addCeilings("maxConcurrentAttempts", [attemptsCeiling]);
77
+ addCeilings("cpuBudgetPercent", cpuCeilings);
78
+ addCeilings("yieldCpuBudgetPercent", cpuCeilings);
79
+ if (reserveFloor)
80
+ bounds.push({ key: "memoryReserveBytes", envVar: reserveFloor.envVar, value: reserveFloor.value, kind: "floor" });
81
+ addCeilings("maxHeavySteps", [heavyStepsCeiling]);
82
+ const values = {
83
+ maxConcurrentAttempts: attempts.value,
84
+ cpuBudgetPercent: cpu.value,
85
+ yieldCpuBudgetPercent: yieldCpu.value,
86
+ memoryReserveBytes: reserve.value,
87
+ maxHeavySteps: heavySteps.value,
88
+ yieldToForeground: yielding,
89
+ };
90
+ const budgetPercent = yielding ? Math.min(values.yieldCpuBudgetPercent, values.cpuBudgetPercent) : values.cpuBudgetPercent;
91
+ return {
92
+ report: {
93
+ version: null,
94
+ governor: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
95
+ values,
96
+ sources: {
97
+ maxConcurrentAttempts: attempts.source,
98
+ cpuBudgetPercent: cpu.source,
99
+ yieldCpuBudgetPercent: yieldCpuSource,
100
+ memoryReserveBytes: reserve.source,
101
+ maxHeavySteps: heavySteps.source,
102
+ yieldToForeground: yieldSource,
103
+ },
104
+ bounds,
105
+ rejected,
106
+ },
107
+ yielding,
108
+ governorCpuBudgetFraction: budgetPercent / 100,
109
+ };
110
+ }
111
+ /**
112
+ * Parses the `ApplySettings` argument. Returns null when it has no usable version
113
+ * (the bridge then ignores it); malformed values become null so the host default applies.
114
+ */
115
+ export function parseRunnerSettingsDocument(raw) {
116
+ if (!raw || typeof raw !== "object")
117
+ return null;
118
+ const record = raw;
119
+ const version = record.version;
120
+ if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0)
121
+ return null;
122
+ const numeric = (key) => {
123
+ const value = record[key];
124
+ // Kept as-is (even out of range) so computeEffectiveRunnerSettings can report it as rejected.
125
+ return typeof value === "number" ? value : null;
126
+ };
127
+ return {
128
+ runnerId: typeof record.runnerId === "string" ? record.runnerId : null,
129
+ version,
130
+ maxConcurrentAttempts: numeric("maxConcurrentAttempts"),
131
+ cpuBudgetPercent: numeric("cpuBudgetPercent"),
132
+ yieldCpuBudgetPercent: numeric("yieldCpuBudgetPercent"),
133
+ memoryReserveBytes: numeric("memoryReserveBytes"),
134
+ maxHeavySteps: numeric("maxHeavySteps"),
135
+ yieldToForeground: record.yieldToForeground === true,
136
+ };
137
+ }
138
+ /**
139
+ * The report for what is actually in force after an apply in which the host
140
+ * failed to put some keys in force: each failed key keeps the value (and source)
141
+ * that was in force before, and its failure is reported as an `apply_failed`
142
+ * rejection, so the server never reads a desired value as applied.
143
+ */
144
+ export function runnerSettingsInForce(report, previous, failures) {
145
+ if (failures.length === 0)
146
+ return report;
147
+ const values = { ...report.values };
148
+ const sources = { ...report.sources };
149
+ for (const failure of failures) {
150
+ keepPrevious(values, previous.values, failure.key);
151
+ sources[failure.key] = previous.sources[failure.key];
152
+ }
153
+ return { ...report, values, sources, rejected: [...report.rejected, ...failures] };
154
+ }
155
+ function keepPrevious(target, previous, key) {
156
+ target[key] = previous[key];
157
+ }
158
+ /** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
159
+ export function sameRunnerSettingsReport(left, right) {
160
+ return JSON.stringify(left) === JSON.stringify(right);
161
+ }
162
+ function ceilingValue(server, ceiling, fallback) {
163
+ if (server !== null) {
164
+ return ceiling && ceiling.value < server
165
+ ? { value: ceiling.value, source: "host_env" }
166
+ : { value: server, source: "server" };
167
+ }
168
+ return ceiling ? { value: ceiling.value, source: "host_env" } : { value: fallback, source: "default" };
169
+ }
170
+ function floorValue(server, floor, fallback) {
171
+ if (server !== null) {
172
+ return floor !== null && floor > server
173
+ ? { value: floor, source: "host_env" }
174
+ : { value: server, source: "server" };
175
+ }
176
+ return floor !== null ? { value: floor, source: "host_env" } : { value: fallback, source: "default" };
177
+ }
178
+ function lowest(...bounds) {
179
+ let result = null;
180
+ for (const bound of bounds) {
181
+ if (bound && (result === null || bound.value < result.value))
182
+ result = bound;
183
+ }
184
+ return result;
185
+ }
186
+ /**
187
+ * Both CPU ceilings: the new FORGE_HOST_CPU_BUDGET_PERCENT (10–100) and the
188
+ * existing FORGE_HOST_LOAD_CPU_BUDGET_FRACTION (0.05–1, the governor's own
189
+ * parse), reported as a percent.
190
+ */
191
+ function cpuBudgetCeilings(environment) {
192
+ const percent = numberEnv(environment, "FORGE_HOST_CPU_BUDGET_PERCENT", 10, 100);
193
+ const fraction = numberEnv(environment, "FORGE_HOST_LOAD_CPU_BUDGET_FRACTION", 0.05, 1);
194
+ return [
195
+ percent,
196
+ fraction ? { envVar: fraction.envVar, value: Math.round(fraction.value * 10_000) / 100 } : null,
197
+ ];
198
+ }
199
+ /** Matches the lease manager's parse (parseInt, clamped); an unparsable value counts as unset. */
200
+ function integerEnv(environment, envVar, minimum, maximum) {
201
+ const raw = environment[envVar];
202
+ if (raw === undefined || raw.trim() === "")
203
+ return null;
204
+ const parsed = Number.parseInt(raw, 10);
205
+ return Number.isFinite(parsed) ? { envVar, value: Math.max(minimum, Math.min(maximum, parsed)) } : null;
206
+ }
207
+ /** Matches the governor config's parse (Number, clamped); an unparsable value counts as unset. */
208
+ function numberEnv(environment, envVar, minimum, maximum) {
209
+ const raw = environment[envVar];
210
+ if (raw === undefined || raw.trim() === "")
211
+ return null;
212
+ const parsed = Number(raw);
213
+ return Number.isFinite(parsed) ? { envVar, value: Math.min(maximum, Math.max(minimum, parsed)) } : null;
214
+ }
@@ -0,0 +1,60 @@
1
+ import type { ValidationStep } from "./pre-publication-step-execution.js";
2
+ import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
3
+ /** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
4
+ export declare const runtimeRestartCheckId = "host-runtime-restart";
5
+ /** One check that failed in a pass: the step that failed and its clipped diagnostics. */
6
+ export interface PrePublicationCheckFailure {
7
+ readonly checkId: string;
8
+ readonly exitCode: number;
9
+ readonly command: string;
10
+ readonly args: readonly string[];
11
+ readonly detail: string;
12
+ }
13
+ /**
14
+ * A failed validation pass. The single-check fields name the first failure, as they always have;
15
+ * `failures` lists every check that failed in the pass, in the order the checks ran.
16
+ */
17
+ export declare class PrePublicationValidationError extends ForgeFailureError {
18
+ readonly checkId: string;
19
+ readonly exitCode: number;
20
+ readonly command: string;
21
+ readonly args: readonly string[];
22
+ readonly detail: string;
23
+ readonly code = "prepublication_validation_failed";
24
+ readonly failures: readonly PrePublicationCheckFailure[];
25
+ constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string, additionalFailures?: readonly PrePublicationCheckFailure[]);
26
+ /** Every failed check's id, first failure first. */
27
+ get checkIds(): readonly string[];
28
+ }
29
+ export declare class PrePublicationPass {
30
+ private readonly runtimeRestartFailure?;
31
+ private readonly failures;
32
+ private dotnetCompileFailed;
33
+ /** A failed runtime restart before the pass is its first failure. */
34
+ constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
35
+ record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
36
+ /** The failed checks that keep this check from running meaningfully in this pass. */
37
+ blockers(checkId: string): readonly string[];
38
+ /**
39
+ * Whether an error ends the pass with the failures it already found. Only a classified retryable
40
+ * failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
41
+ * pass has found a failure: the repair turn can fix those failures now, and the next pass meets
42
+ * the condition again. Any other error, or cancellation, still ends the attempt as it did.
43
+ */
44
+ stopsAt(error: unknown, signal?: AbortSignal): error is ForgeFailureError;
45
+ stoppedEvent(checkId: string, error: ForgeFailureError): RunnerDispatchEvent;
46
+ /** Throws every failure the pass found as one validation failure. */
47
+ throwIfFailed(): void;
48
+ }
49
+ export declare function skippedCheckEvent(checkId: string, blockedBy: readonly string[]): RunnerDispatchEvent;
50
+ /** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
51
+ export declare class SkippedTestTally {
52
+ private readonly worktreePath;
53
+ private readonly environment?;
54
+ private summary;
55
+ constructor(worktreePath: string, environment?: Readonly<Record<string, string>> | undefined);
56
+ /** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
57
+ add(args: readonly string[], stepStartedMs: number): Promise<void>;
58
+ passedEvent(checkId: string, secrets: readonly string[]): RunnerDispatchEvent;
59
+ }
60
+ export declare function validationEvent(eventType: string, checkId: string, content: string, detail?: Readonly<Record<string, unknown>>): RunnerDispatchEvent;
@@ -0,0 +1,145 @@
1
+ import { redactText } from "../shared/redaction/redaction.js";
2
+ import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
3
+ import { ForgeFailureError, failureFactsFromError } from "./session.types.js";
4
+ // One pre-publication validation pass. A failed check no longer ends the pass: the remaining checks
5
+ // that can still meaningfully run keep going, so one in-place repair turn sees every independent
6
+ // failure at once instead of one per turn. The pass records each failure, says which checks it
7
+ // could not run because a check they depend on failed, and reports them all as one failure.
8
+ /** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
9
+ export const runtimeRestartCheckId = "host-runtime-restart";
10
+ const dotnetBuildCheckId = "dotnet-build-and-unit";
11
+ // Checks that build the .NET solution themselves and would only repeat the compiler errors once its
12
+ // compile step fails: the OpenAPI export builds Forge.Api and the E2E suite publishes it.
13
+ const dotnetBuildConsumers = new Set(["openapi-and-generated-types", "playwright-e2e"]);
14
+ // Checks that run against the attempt's application stack, which a failed restart left stopped.
15
+ const runtimeStackConsumers = new Set(["playwright-e2e"]);
16
+ // The diagnostics of each further failure that the error message carries; the repair prompt
17
+ // carries every failure's diagnostics in full.
18
+ const additionalFailureMessageDetail = 1500;
19
+ /**
20
+ * A failed validation pass. The single-check fields name the first failure, as they always have;
21
+ * `failures` lists every check that failed in the pass, in the order the checks ran.
22
+ */
23
+ export class PrePublicationValidationError extends ForgeFailureError {
24
+ checkId;
25
+ exitCode;
26
+ command;
27
+ args;
28
+ detail;
29
+ code = "prepublication_validation_failed";
30
+ failures;
31
+ constructor(checkId, exitCode, command, args, detail, additionalFailures = []) {
32
+ super("prepublication_validation_failed", validationFailureMessage([{ checkId, exitCode, command, args, detail }, ...additionalFailures]), "bridge");
33
+ this.checkId = checkId;
34
+ this.exitCode = exitCode;
35
+ this.command = command;
36
+ this.args = args;
37
+ this.detail = detail;
38
+ this.name = "PrePublicationValidationError";
39
+ this.failures = [{ checkId, exitCode, command, args, detail }, ...additionalFailures];
40
+ }
41
+ /** Every failed check's id, first failure first. */
42
+ get checkIds() {
43
+ return this.failures.map(failure => failure.checkId);
44
+ }
45
+ }
46
+ function validationFailureMessage(failures) {
47
+ const [first, ...others] = failures;
48
+ const summary = (failure, detail) => `${failure.checkId} exited ${failure.exitCode}${detail ? `: ${detail}` : ""}`;
49
+ if (others.length === 0)
50
+ return `prepublication_validation_failed: ${summary(first, first.detail)}`;
51
+ // The other check ids come before the first detail, so a clipped failure message still names them.
52
+ const also = `[also failed: ${others.map(failure => failure.checkId).join(", ")}]`;
53
+ const more = others.map(failure => summary(failure, clipDetail(failure.detail)));
54
+ return `prepublication_validation_failed: ${first.checkId} exited ${first.exitCode} ${also}${first.detail ? `: ${first.detail}` : ""}`
55
+ + `\n\nAlso failed in the same validation pass: ${more.join("\n\n")}`;
56
+ }
57
+ function clipDetail(detail) {
58
+ return detail.length <= additionalFailureMessageDetail
59
+ ? detail
60
+ : `${detail.slice(0, additionalFailureMessageDetail)}… (clipped)`;
61
+ }
62
+ export class PrePublicationPass {
63
+ runtimeRestartFailure;
64
+ failures = [];
65
+ dotnetCompileFailed = false;
66
+ /** A failed runtime restart before the pass is its first failure. */
67
+ constructor(runtimeRestartFailure) {
68
+ this.runtimeRestartFailure = runtimeRestartFailure;
69
+ this.failures.push(...runtimeRestartFailure?.failures ?? []);
70
+ }
71
+ record(failure, failedStep) {
72
+ this.failures.push(failure);
73
+ if (failure.checkId === dotnetBuildCheckId && failedStep?.command === "dotnet" && failedStep.args[0] === "build") {
74
+ this.dotnetCompileFailed = true;
75
+ }
76
+ }
77
+ /** The failed checks that keep this check from running meaningfully in this pass. */
78
+ blockers(checkId) {
79
+ return [
80
+ ...(this.dotnetCompileFailed && dotnetBuildConsumers.has(checkId) ? [dotnetBuildCheckId] : []),
81
+ ...(this.runtimeRestartFailure && runtimeStackConsumers.has(checkId) ? [runtimeRestartCheckId] : []),
82
+ ];
83
+ }
84
+ /**
85
+ * Whether an error ends the pass with the failures it already found. Only a classified retryable
86
+ * failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
87
+ * pass has found a failure: the repair turn can fix those failures now, and the next pass meets
88
+ * the condition again. Any other error, or cancellation, still ends the attempt as it did.
89
+ */
90
+ stopsAt(error, signal) {
91
+ if (this.failures.length === 0 || signal?.aborted || !(error instanceof ForgeFailureError))
92
+ return false;
93
+ return failureFactsFromError(error).retryability === "retryable";
94
+ }
95
+ stoppedEvent(checkId, error) {
96
+ const failedCheckIds = this.failures.map(failure => failure.checkId);
97
+ return validationEvent("prepublication_validation_pass_stopped", checkId, `Stopped this pre-publication pass at '${checkId}' (${error.failureCode}). Reporting the ${failedCheckIds.length} failed check${failedCheckIds.length === 1 ? "" : "s"} it already found (${failedCheckIds.join(", ")}) for repair; the next pass runs '${checkId}' again.`, { failureCode: error.failureCode, failedCheckIds });
98
+ }
99
+ /** Throws every failure the pass found as one validation failure. */
100
+ throwIfFailed() {
101
+ const [first, ...others] = this.failures;
102
+ if (!first)
103
+ return;
104
+ throw new PrePublicationValidationError(first.checkId, first.exitCode, first.command, first.args, first.detail, others);
105
+ }
106
+ }
107
+ export function skippedCheckEvent(checkId, blockedBy) {
108
+ const reason = blockedBy.map(blocker => blocker === runtimeRestartCheckId
109
+ ? "the attempt's runtime stack, whose restart failed"
110
+ : `the .NET build, which failed in '${blocker}'`).join(" and ");
111
+ return validationEvent("prepublication_validation_skipped", checkId, `Skipped pre-publication CI parity check '${checkId}' in this pass: it needs ${reason}. The next pass runs it again.`, { blockedBy });
112
+ }
113
+ /** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
114
+ export class SkippedTestTally {
115
+ worktreePath;
116
+ environment;
117
+ summary = { count: 0, reasons: [] };
118
+ constructor(worktreePath, environment) {
119
+ this.worktreePath = worktreePath;
120
+ this.environment = environment;
121
+ }
122
+ /** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
123
+ async add(args, stepStartedMs) {
124
+ this.summary = mergeSkippedTests(this.summary, await readSkippedTests(this.worktreePath, args, stepStartedMs, this.environment));
125
+ }
126
+ passedEvent(checkId, secrets) {
127
+ const skipped = {
128
+ ...this.summary,
129
+ reasons: this.summary.reasons.map(entry => ({ ...entry, reason: redactText(entry.reason, secrets) })),
130
+ };
131
+ if (skipped.count === 0) {
132
+ return validationEvent("prepublication_validation_passed", checkId, `Pre-publication CI parity check '${checkId}' passed.`);
133
+ }
134
+ return validationEvent("prepublication_validation_passed", checkId, `Pre-publication CI parity check '${checkId}' passed with ${describeSkippedTests(skipped)}.`, { skippedTests: skipped.count, skippedReasons: skipped.reasons });
135
+ }
136
+ }
137
+ export function validationEvent(eventType, checkId, content, detail) {
138
+ return {
139
+ role: "runner",
140
+ kind: "checkpoint",
141
+ content,
142
+ eventType,
143
+ data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1", ...detail }),
144
+ };
145
+ }
@@ -3,6 +3,7 @@ import type { NativeTestPostgresFallback } from "../runtime/native-test-postgres
3
3
  import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
4
4
  import { type PrePublicationHostLoadOwner } from "./pre-publication-host-load.js";
5
5
  import { type ValidationStep } from "./pre-publication-step-execution.js";
6
+ import { PrePublicationValidationError, type PrePublicationCheckFailure } from "./pre-publication-pass.js";
6
7
  import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
7
8
  import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
8
9
  export type PrePublicationProfile = "implementation" | "comment_repair" | "ci_repair" | "conflict_repair";
@@ -34,16 +35,13 @@ export interface PrePublicationExecutionContext {
34
35
  readonly processRunner?: ProviderProcessRunner;
35
36
  /** The attempt governed steps reserve host capacity for (decision 0013). */
36
37
  readonly hostLoadOwner?: PrePublicationHostLoadOwner;
38
+ /**
39
+ * The failed restart of the attempt's runtime stack before this pass. The pass reports it with
40
+ * its own failures and does not run the checks that need the stopped stack.
41
+ */
42
+ readonly runtimeRestartFailure?: PrePublicationValidationError;
37
43
  }
38
- export declare class PrePublicationValidationError extends ForgeFailureError {
39
- readonly checkId: string;
40
- readonly exitCode: number;
41
- readonly command: string;
42
- readonly args: readonly string[];
43
- readonly detail: string;
44
- readonly code = "prepublication_validation_failed";
45
- constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string);
46
- }
44
+ export { PrePublicationValidationError, type PrePublicationCheckFailure };
47
45
  export declare class PrePublicationInfrastructureError extends ForgeFailureError {
48
46
  readonly checkId: string;
49
47
  readonly exitCode: number;
@@ -59,11 +57,24 @@ export declare class PrePublicationValidator {
59
57
  private readonly nativeTestPostgresFallback;
60
58
  private readonly hostLoad?;
61
59
  constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined);
60
+ /**
61
+ * Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
62
+ * can still meaningfully run keeps going, and the pass then throws all of its failures as one
63
+ * PrePublicationValidationError.
64
+ */
62
65
  validate(worktreePath: string, profile: PrePublicationProfile, capabilities: ReadonlySet<string>, emit?: (event: RunnerDispatchEvent) => Promise<void>, signal?: AbortSignal, execution?: PrePublicationExecutionContext): Promise<readonly string[]>;
66
+ private runChecks;
67
+ /** Runs one check's steps in order; the first failed step ends the check, since later steps use its output. */
68
+ private runCheck;
69
+ /** Runs a step, confirming once a failure that matches a known transient pattern. */
70
+ private runConfirmedStep;
71
+ private runCheckedStep;
72
+ private confirmStep;
73
+ private confirmInfrastructure;
63
74
  /** Returns the native fallback connection when this check must use it instead of Docker. */
64
75
  private ensurePrerequisite;
65
76
  private throwIfPrerequisiteWasLost;
66
- private assertNoTestOnlyExports;
77
+ private checkTestOnlyExports;
67
78
  private changedPaths;
68
79
  private assertContractMatchesDispatchBaseline;
69
80
  private runStep;
@@ -72,4 +83,3 @@ export declare class PrePublicationValidator {
72
83
  }
73
84
  export declare function applicableChecks(contract: ValidationContract, profile: PrePublicationProfile | "github_actions", changedPaths: readonly string[]): readonly ValidationCheck[];
74
85
  export declare function loadValidationContract(worktreePath: string): Promise<ValidationContract | null>;
75
- export {};