@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.81e48ecc185d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +54 -2
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +125 -0
  4. package/dist/bridge/bridge.base.d.ts +9 -0
  5. package/dist/bridge/bridge.service.d.ts +85 -3
  6. package/dist/bridge/bridge.service.js +361 -122
  7. package/dist/bridge/bridge.types.d.ts +22 -0
  8. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  9. package/dist/bridge/dispatch-result-outbox.js +31 -6
  10. package/dist/bridge/local-yield-flag.d.ts +6 -0
  11. package/dist/bridge/local-yield-flag.js +34 -0
  12. package/dist/bridge/runner-host-capabilities.d.ts +2 -0
  13. package/dist/bridge/runner-host-capabilities.js +4 -0
  14. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  15. package/dist/bridge/test-postgres-capability.js +120 -0
  16. package/dist/cleanup/cleanup.service.d.ts +9 -0
  17. package/dist/cleanup/cleanup.service.js +72 -109
  18. package/dist/cleanup/cleanup.types.d.ts +4 -0
  19. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  20. package/dist/cleanup/forge-owned-paths.js +53 -0
  21. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  22. package/dist/cleanup/host-runtime-ledger.js +109 -0
  23. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  24. package/dist/cleanup/managed-branch-sweep.js +111 -0
  25. package/dist/cli/cli.help.js +18 -0
  26. package/dist/cli/cli.service.d.ts +16 -0
  27. package/dist/cli/cli.service.js +142 -16
  28. package/dist/cli/local-config.d.ts +4 -0
  29. package/dist/cli/local-config.js +26 -4
  30. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  31. package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
  32. package/dist/runtime/attempt-process-supervisor.js +50 -0
  33. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  34. package/dist/runtime/host-database-capability-boundary.js +1 -0
  35. package/dist/runtime/host-facts.d.ts +35 -0
  36. package/dist/runtime/host-facts.js +95 -0
  37. package/dist/runtime/host-load-admission.d.ts +64 -0
  38. package/dist/runtime/host-load-admission.js +99 -0
  39. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  40. package/dist/runtime/host-load-child-environment.js +76 -0
  41. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  42. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  43. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  44. package/dist/runtime/host-load-governor-config.js +83 -0
  45. package/dist/runtime/host-load-governor.d.ts +184 -0
  46. package/dist/runtime/host-load-governor.js +632 -0
  47. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  48. package/dist/runtime/host-load-ledger-lock.js +185 -0
  49. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  50. package/dist/runtime/host-load-runtime-settings.js +78 -0
  51. package/dist/runtime/host-load-sampler.d.ts +126 -0
  52. package/dist/runtime/host-load-sampler.js +232 -0
  53. package/dist/runtime/host-load-step-class.d.ts +70 -0
  54. package/dist/runtime/host-load-step-class.js +161 -0
  55. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  56. package/dist/runtime/host-load-step-reaper.js +95 -0
  57. package/dist/runtime/host-load-step-run.d.ts +73 -0
  58. package/dist/runtime/host-load-step-run.js +102 -0
  59. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  60. package/dist/runtime/host-load-test-slot.js +81 -0
  61. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  62. package/dist/runtime/host-load-token-ledger.js +453 -0
  63. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  64. package/dist/runtime/host-pressure-stall.js +168 -0
  65. package/dist/runtime/host-runtime-contract.d.ts +4 -0
  66. package/dist/runtime/host-runtime-contract.js +6 -1
  67. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  68. package/dist/runtime/host-runtime-lease.js +336 -20
  69. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  70. package/dist/runtime/host-runtime-promotion.js +48 -0
  71. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  72. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  73. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  74. package/dist/runtime/host-runtime-requirements.js +117 -0
  75. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  76. package/dist/runtime/managed-command-teardown.js +607 -0
  77. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  78. package/dist/runtime/playwright-browser-cache.js +227 -0
  79. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  80. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  81. package/dist/runtime/runner-settings.d.ts +100 -0
  82. package/dist/runtime/runner-settings.js +214 -0
  83. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  84. package/dist/sandbox/host-capacity-broker.js +334 -0
  85. package/dist/sandbox/runtime.d.ts +10 -1
  86. package/dist/sandbox/runtime.js +45 -2
  87. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  88. package/dist/sandbox/sandbox-cgroups.js +42 -0
  89. package/dist/session/managed-attempt-tools.d.ts +27 -0
  90. package/dist/session/managed-attempt-tools.js +356 -41
  91. package/dist/session/managed-build-coordinator.d.ts +1 -1
  92. package/dist/session/managed-build-coordinator.js +4 -1
  93. package/dist/session/managed-command-host-load.d.ts +47 -0
  94. package/dist/session/managed-command-host-load.js +83 -0
  95. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  96. package/dist/session/mcp-argument-coercion.js +121 -0
  97. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  98. package/dist/session/phase-completion.artifacts.js +98 -25
  99. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  100. package/dist/session/phase-completion.command-validation.js +77 -0
  101. package/dist/session/phase-completion.d.ts +4 -0
  102. package/dist/session/phase-completion.helpers.js +13 -12
  103. package/dist/session/phase-completion.js +4 -0
  104. package/dist/session/phase-completion.prompts.js +6 -1
  105. package/dist/session/phase-completion.runtime.d.ts +5 -3
  106. package/dist/session/phase-completion.runtime.js +70 -35
  107. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  108. package/dist/session/phase-completion.schema-parts.js +188 -0
  109. package/dist/session/phase-completion.schemas.d.ts +3 -3
  110. package/dist/session/phase-completion.schemas.js +206 -221
  111. package/dist/session/phase-completion.validation.d.ts +2 -3
  112. package/dist/session/phase-completion.validation.js +46 -92
  113. package/dist/session/pre-publication-host-load.d.ts +27 -0
  114. package/dist/session/pre-publication-host-load.js +111 -0
  115. package/dist/session/pre-publication-pass.d.ts +61 -0
  116. package/dist/session/pre-publication-pass.js +148 -0
  117. package/dist/session/pre-publication-process.d.ts +23 -0
  118. package/dist/session/pre-publication-process.js +109 -0
  119. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  120. package/dist/session/pre-publication-skipped-tests.js +109 -0
  121. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  122. package/dist/session/pre-publication-step-execution.js +49 -0
  123. package/dist/session/pre-publication-validation.d.ts +32 -20
  124. package/dist/session/pre-publication-validation.js +202 -195
  125. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  126. package/dist/session/provider-cli/claude-background-work.js +180 -0
  127. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  128. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  129. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  130. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  131. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  132. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  133. package/dist/session/provider-cli/provider-cli.process.d.ts +39 -2
  134. package/dist/session/provider-cli/provider-cli.process.js +276 -42
  135. package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
  136. package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
  137. package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
  138. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  139. package/dist/session/provider-cli/provider-cli.service.js +203 -172
  140. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  141. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  142. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  143. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  144. package/dist/session/provider-cli/provider-output-state.js +15 -0
  145. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  146. package/dist/session/publishable-worktree-changes.js +193 -0
  147. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  148. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  149. package/dist/session/session.base.d.ts +9 -1
  150. package/dist/session/session.service.d.ts +9 -2
  151. package/dist/session/session.service.js +120 -5
  152. package/dist/session/session.types.d.ts +3 -0
  153. package/dist/session/session.types.js +15 -3
  154. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  155. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  156. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  157. package/dist/shared/process/host-process-supervisor.js +1 -1
  158. package/dist/shared/process/process-tree.d.ts +52 -0
  159. package/dist/shared/process/process-tree.js +144 -0
  160. package/dist/shared/process/process.d.ts +67 -0
  161. package/dist/shared/process/process.js +213 -11
  162. package/dist/shared/provider-capabilities.js +5 -6
  163. package/dist/version.d.ts +1 -1
  164. package/dist/version.js +1 -1
  165. package/dist/worktree/dependency-warmer.d.ts +25 -0
  166. package/dist/worktree/dependency-warmer.js +46 -10
  167. package/dist/worktree/worktree.service.d.ts +10 -1
  168. package/dist/worktree/worktree.service.js +42 -2
  169. package/dist/worktree/worktree.types.d.ts +7 -0
  170. package/package.json +2 -2
@@ -0,0 +1,109 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
4
+ import { withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
5
+ import { isSubPath } from "../shared/path/path.js";
6
+ import { NodeProcessRunner, ProcessTreeTerminationError } from "../shared/process/process.js";
7
+ /** Output kept per stream for one validation step (the tail). */
8
+ export const prePublicationOutputLimitChars = 4 * 1024 * 1024;
9
+ export class ProcessPrePublicationCommandRunner {
10
+ async run(command, args, cwd, signal, environment) {
11
+ try {
12
+ const launch = await pnpmDirectoryLaunch(command, args, cwd);
13
+ const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm");
14
+ const executable = windowsBatch ? (process.env.ComSpec ?? "cmd.exe") : command;
15
+ const commandArgs = windowsBatch
16
+ ? ["/d", "/s", "/c", [`${command}.cmd`, ...launch.args].map(quoteWindowsCommandArgument).join(" ")]
17
+ : [...launch.args];
18
+ // A process group the runner stops as a whole, settling only once it is gone:
19
+ // a validation step's host capacity is never returned while its test hosts,
20
+ // build nodes or browser workers still run.
21
+ const result = await new NodeProcessRunner().run({
22
+ command: executable,
23
+ args: commandArgs,
24
+ cwd: launch.cwd,
25
+ env: prePublicationChildEnvironment(environment),
26
+ rawOutput: true,
27
+ processGroup: true,
28
+ // The bound execFile had: a noisy step keeps its last 4 MiB (where failures
29
+ // are reported) instead of holding all of its output in the bridge.
30
+ maxOutputChars: prePublicationOutputLimitChars,
31
+ signal,
32
+ });
33
+ return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
34
+ }
35
+ catch (error) {
36
+ const failure = error;
37
+ // Neither is a command result: a stop, or a tree that outlived it.
38
+ if (failure.name === "AbortError" || error instanceof ProcessTreeTerminationError)
39
+ throw error;
40
+ if (failure.code === "ENOENT") {
41
+ return { exitCode: 127, stderr: `executable_not_found: ${command}` };
42
+ }
43
+ return {
44
+ exitCode: typeof failure.code === "number" ? failure.code : 1,
45
+ stdout: failure.stdout,
46
+ stderr: failure.stderr ?? failure.message,
47
+ };
48
+ }
49
+ }
50
+ }
51
+ function quoteWindowsCommandArgument(value) {
52
+ return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `"${value.replaceAll('"', '""')}"`;
53
+ }
54
+ export function prePublicationChildEnvironment(environment) {
55
+ const child = {};
56
+ const privilegedNames = new Set([
57
+ hostRuntimeTestPostgresAdminEnvironment.toLowerCase(),
58
+ hostRuntimeLegacyTestPostgresEnvironment.toLowerCase(),
59
+ hostRuntimeTestPostgresProvisionerEnvironment.toLowerCase(),
60
+ ]);
61
+ for (const [name, value] of Object.entries(process.env)) {
62
+ if (typeof value === "string" && !privilegedNames.has(name.toLowerCase())) {
63
+ child[name] = value;
64
+ }
65
+ }
66
+ // A validation step must not join the host ledger (it would queue behind its own token)
67
+ // or the sandbox broker, whether the variable is inherited or passed in explicitly.
68
+ return withoutHostLoadGovernorVariables({ ...child, ...environment });
69
+ }
70
+ /**
71
+ * Corepack picks the pnpm version from the nearest package.json `packageManager`
72
+ * pin at or above the process working directory; pnpm's own `--dir` is not
73
+ * consulted. The repository root carries no pin, so `pnpm --dir client ...`
74
+ * launched from the root would run Corepack's host-global default, and pnpm
75
+ * then refuses client's pin (ERR_PNPM_BAD_PM_VERSION). `pnpm --dir X cmd` is
76
+ * `pnpm cmd` run from X, so launch from X and let Corepack walk up from there
77
+ * to the nearest pin. Targets that are absolute, leave the worktree, or do not
78
+ * exist stay unchanged so pnpm reports them itself.
79
+ */
80
+ export async function pnpmDirectoryLaunch(command, args, cwd) {
81
+ const unchanged = { args, cwd };
82
+ if (command !== "pnpm")
83
+ return unchanged;
84
+ const target = pnpmDirectoryArgument(args);
85
+ if (!target || path.isAbsolute(target.directory))
86
+ return unchanged;
87
+ if (!isSubPath(cwd, path.resolve(cwd, target.directory)))
88
+ return unchanged;
89
+ // The lexical check alone would let a symlink (or junction) inside the worktree
90
+ // move the child's cwd outside it, so compare and launch from real paths.
91
+ const realCwd = await fs.realpath(cwd).catch(() => null);
92
+ const packageDirectory = await fs.realpath(path.resolve(cwd, target.directory)).catch(() => null);
93
+ if (!realCwd || !packageDirectory || !isSubPath(realCwd, packageDirectory))
94
+ return unchanged;
95
+ const stat = await fs.stat(packageDirectory).catch(() => null);
96
+ if (!stat?.isDirectory())
97
+ return unchanged;
98
+ return { args: args.slice(target.consumed), cwd: packageDirectory };
99
+ }
100
+ /** Reads a leading `--dir X`, `--dir=X`, `-C X`, `-CX` or `-C=X`. */
101
+ function pnpmDirectoryArgument(args) {
102
+ const first = args[0] ?? "";
103
+ if (first === "--dir" || first === "-C")
104
+ return args[1] ? { directory: args[1], consumed: 2 } : null;
105
+ const inline = first.startsWith("--dir=") ? first.slice("--dir=".length)
106
+ : first.startsWith("-C") ? first.slice(2).replace(/^=/u, "")
107
+ : "";
108
+ return inline ? { directory: inline, consumed: 1 } : null;
109
+ }
@@ -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
+ }
@@ -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,12 @@
1
1
  import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
2
- import { type NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
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";
6
+ import { PrePublicationValidationError, type PrePublicationCheckFailure } from "./pre-publication-pass.js";
3
7
  import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
4
8
  import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
5
9
  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
10
  interface ValidationCheck {
14
11
  readonly id: string;
15
12
  readonly profiles: readonly string[];
@@ -36,16 +33,15 @@ export interface PrePublicationExecutionContext {
36
33
  readonly baselineRevision?: string;
37
34
  readonly environment?: Readonly<Record<string, string>>;
38
35
  readonly processRunner?: ProviderProcessRunner;
36
+ /** The attempt governed steps reserve host capacity for (decision 0013). */
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;
39
43
  }
40
- export declare class PrePublicationValidationError extends ForgeFailureError {
41
- readonly checkId: string;
42
- readonly exitCode: number;
43
- readonly command: string;
44
- readonly args: readonly string[];
45
- readonly detail: string;
46
- readonly code = "prepublication_validation_failed";
47
- constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string);
48
- }
44
+ export { PrePublicationValidationError, type PrePublicationCheckFailure };
49
45
  export declare class PrePublicationInfrastructureError extends ForgeFailureError {
50
46
  readonly checkId: string;
51
47
  readonly exitCode: number;
@@ -59,17 +55,33 @@ export declare class PrePublicationValidator {
59
55
  private readonly commands;
60
56
  private readonly dockerEngineProbe?;
61
57
  private readonly nativeTestPostgresFallback;
62
- constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null);
58
+ private readonly hostLoad?;
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
+ */
63
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;
64
74
  /** Returns the native fallback connection when this check must use it instead of Docker. */
65
75
  private ensurePrerequisite;
66
76
  private throwIfPrerequisiteWasLost;
67
- private assertNoTestOnlyExports;
77
+ private checkTestOnlyExports;
68
78
  private changedPaths;
69
79
  private assertContractMatchesDispatchBaseline;
80
+ /** The approved contract of the branch an in-progress merge brings in (MERGE_HEAD), else null. */
81
+ private mergedInContractDigest;
70
82
  private runStep;
83
+ private launchStep;
71
84
  private runCommand;
72
85
  }
73
86
  export declare function applicableChecks(contract: ValidationContract, profile: PrePublicationProfile | "github_actions", changedPaths: readonly string[]): readonly ValidationCheck[];
74
87
  export declare function loadValidationContract(worktreePath: string): Promise<ValidationContract | null>;
75
- export {};