@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.028808a841c8

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 (185) hide show
  1. package/README.md +89 -3
  2. package/dist/bridge/bridge-chat.types.d.ts +111 -0
  3. package/dist/bridge/bridge-chat.types.js +401 -0
  4. package/dist/bridge/bridge.base.d.ts +4 -1
  5. package/dist/bridge/bridge.service.d.ts +83 -3
  6. package/dist/bridge/bridge.service.js +1609 -152
  7. package/dist/bridge/bridge.types.d.ts +52 -1
  8. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  9. package/dist/bridge/dispatch-result-outbox.js +87 -0
  10. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  11. package/dist/bridge/dispatch-result-worker.js +122 -0
  12. package/dist/bridge/internals.d.ts +2 -0
  13. package/dist/bridge/internals.js +1 -0
  14. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  15. package/dist/bridge/readiness-result-outbox.js +54 -0
  16. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  17. package/dist/bridge/readiness-result-worker.js +121 -0
  18. package/dist/bridge/runner-host-capabilities.d.ts +15 -0
  19. package/dist/bridge/runner-host-capabilities.js +93 -0
  20. package/dist/cleanup/cleanup.service.d.ts +1 -0
  21. package/dist/cleanup/cleanup.service.js +70 -9
  22. package/dist/cli/cli.help.js +4 -4
  23. package/dist/cli/cli.service.d.ts +14 -6
  24. package/dist/cli/cli.service.js +75 -16
  25. package/dist/cli/local-config.d.ts +1 -0
  26. package/dist/cli/local-config.js +4 -0
  27. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  28. package/dist/runtime/aspnet-runtime-prebuild.js +341 -0
  29. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  30. package/dist/runtime/attempt-database-broker.js +390 -0
  31. package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
  32. package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
  33. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  34. package/dist/runtime/attempt-path-operation.js +94 -0
  35. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  36. package/dist/runtime/attempt-private-directory.js +54 -0
  37. package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
  38. package/dist/runtime/attempt-process-supervisor.js +144 -23
  39. package/dist/runtime/canonical-source-file.d.ts +3 -0
  40. package/dist/runtime/canonical-source-file.js +54 -0
  41. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  42. package/dist/runtime/docker-engine-probe.js +333 -0
  43. package/dist/runtime/generated-output-reset.d.ts +10 -0
  44. package/dist/runtime/generated-output-reset.js +62 -8
  45. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  46. package/dist/runtime/host-database-capability-boundary.js +63 -0
  47. package/dist/runtime/host-diagnostics.d.ts +11 -0
  48. package/dist/runtime/host-diagnostics.js +192 -0
  49. package/dist/runtime/host-execution-root.d.ts +4 -0
  50. package/dist/runtime/host-execution-root.js +39 -0
  51. package/dist/runtime/host-facts.d.ts +35 -0
  52. package/dist/runtime/host-facts.js +95 -0
  53. package/dist/runtime/host-listener-inspector.d.ts +8 -1
  54. package/dist/runtime/host-listener-inspector.js +121 -60
  55. package/dist/runtime/host-load-sampler.d.ts +83 -0
  56. package/dist/runtime/host-load-sampler.js +164 -0
  57. package/dist/runtime/host-pressure-stall.d.ts +41 -0
  58. package/dist/runtime/host-pressure-stall.js +121 -0
  59. package/dist/runtime/host-runtime-contract.d.ts +13 -1
  60. package/dist/runtime/host-runtime-contract.js +170 -55
  61. package/dist/runtime/host-runtime-lease.d.ts +92 -8
  62. package/dist/runtime/host-runtime-lease.js +1193 -120
  63. package/dist/runtime/host-runtime-promotion.d.ts +12 -3
  64. package/dist/runtime/host-runtime-promotion.js +59 -12
  65. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  66. package/dist/runtime/managed-command-teardown.js +607 -0
  67. package/dist/runtime/memory-capacity.d.ts +70 -0
  68. package/dist/runtime/memory-capacity.js +123 -0
  69. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  70. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  71. package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
  72. package/dist/runtime/node-host-runtime-adapter.js +29 -11
  73. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  74. package/dist/runtime/pinned-directory-process.js +61 -0
  75. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  76. package/dist/runtime/pinned-source-directory.js +94 -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 +12 -0
  80. package/dist/runtime/playwright-host-runtime-adapter.js +100 -58
  81. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  82. package/dist/runtime/prepared-runtime-identity.js +218 -0
  83. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  84. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  85. package/dist/runtime/runtime-isolation-lease.js +4 -1
  86. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  87. package/dist/runtime/workspace-resource-estimator.js +174 -0
  88. package/dist/sandbox/preflight.d.ts +31 -1
  89. package/dist/sandbox/preflight.js +237 -51
  90. package/dist/sandbox/repository-lock.d.ts +2 -1
  91. package/dist/sandbox/repository-lock.js +19 -9
  92. package/dist/sandbox/runtime.d.ts +6 -1
  93. package/dist/sandbox/runtime.js +137 -107
  94. package/dist/sandbox/sandbox.types.d.ts +7 -0
  95. package/dist/sandbox/workspace.service.js +2 -0
  96. package/dist/session/managed-attempt-tools.d.ts +42 -1
  97. package/dist/session/managed-attempt-tools.js +692 -40
  98. package/dist/session/managed-build-coordinator.d.ts +5 -0
  99. package/dist/session/managed-build-coordinator.js +109 -0
  100. package/dist/session/managed-build-receipt.d.ts +21 -0
  101. package/dist/session/managed-build-receipt.js +337 -0
  102. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  103. package/dist/session/managed-verification-timeouts.js +17 -0
  104. package/dist/session/phase-completion.artifacts.d.ts +17 -0
  105. package/dist/session/phase-completion.artifacts.js +228 -22
  106. package/dist/session/phase-completion.d.ts +11 -1
  107. package/dist/session/phase-completion.helpers.d.ts +5 -0
  108. package/dist/session/phase-completion.helpers.js +30 -7
  109. package/dist/session/phase-completion.js +14 -3
  110. package/dist/session/phase-completion.prompts.js +17 -18
  111. package/dist/session/phase-completion.runtime.d.ts +3 -1
  112. package/dist/session/phase-completion.runtime.js +148 -34
  113. package/dist/session/phase-completion.schemas.js +49 -2
  114. package/dist/session/phase-completion.validation.d.ts +1 -0
  115. package/dist/session/phase-completion.validation.js +111 -21
  116. package/dist/session/pre-publication-process.d.ts +20 -0
  117. package/dist/session/pre-publication-process.js +97 -0
  118. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  119. package/dist/session/pre-publication-skipped-tests.js +109 -0
  120. package/dist/session/pre-publication-validation.d.ts +75 -0
  121. package/dist/session/pre-publication-validation.js +631 -0
  122. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  123. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  124. package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
  125. package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
  126. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
  127. package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
  128. package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
  129. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  130. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  131. package/dist/session/provider-cli/provider-cli.process.d.ts +80 -0
  132. package/dist/session/provider-cli/provider-cli.process.js +694 -28
  133. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  134. package/dist/session/provider-cli/provider-cli.prompts.js +151 -16
  135. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  136. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  137. package/dist/session/provider-cli/provider-cli.runtime.d.ts +14 -1
  138. package/dist/session/provider-cli/provider-cli.runtime.js +54 -3
  139. package/dist/session/provider-cli/provider-cli.service.d.ts +30 -5
  140. package/dist/session/provider-cli/provider-cli.service.js +858 -77
  141. package/dist/session/provider-cli/provider-cli.types.d.ts +2 -0
  142. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  143. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  144. package/dist/session/provider-cli/provider-output-state.d.ts +16 -0
  145. package/dist/session/provider-cli/provider-output-state.js +370 -17
  146. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  147. package/dist/session/provider-cli/provider-usage.js +28 -5
  148. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  149. package/dist/session/publishable-worktree-changes.js +193 -0
  150. package/dist/session/session-redaction.js +434 -9
  151. package/dist/session/session.service.js +145 -23
  152. package/dist/session/session.types.d.ts +147 -2
  153. package/dist/session/session.types.js +599 -7
  154. package/dist/session/unreferenced-exports.d.ts +12 -0
  155. package/dist/session/unreferenced-exports.js +59 -0
  156. package/dist/shared/format/format-bytes.d.ts +1 -0
  157. package/dist/shared/format/format-bytes.js +9 -0
  158. package/dist/shared/git/git.js +2 -1
  159. package/dist/shared/path/path.d.ts +1 -0
  160. package/dist/shared/path/path.js +18 -0
  161. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  162. package/dist/shared/process/dotnet-toolchain.js +307 -0
  163. package/dist/shared/process/host-process-recovery.js +3 -2
  164. package/dist/shared/process/host-process-supervisor.d.ts +2 -0
  165. package/dist/shared/process/host-process-supervisor.js +60 -11
  166. package/dist/shared/process/process.d.ts +2 -0
  167. package/dist/shared/process/process.js +12 -7
  168. package/dist/shared/provider-capabilities.d.ts +3 -0
  169. package/dist/shared/provider-capabilities.js +85 -0
  170. package/dist/shared/redaction/redaction.d.ts +1 -0
  171. package/dist/shared/redaction/redaction.js +39 -3
  172. package/dist/shared/time/monotonic.d.ts +1 -0
  173. package/dist/shared/time/monotonic.js +8 -0
  174. package/dist/version.d.ts +1 -1
  175. package/dist/version.js +1 -1
  176. package/dist/worktree/dependency-warmer.d.ts +41 -9
  177. package/dist/worktree/dependency-warmer.js +571 -22
  178. package/dist/worktree/index.d.ts +1 -1
  179. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  180. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  181. package/dist/worktree/worktree.service.d.ts +7 -0
  182. package/dist/worktree/worktree.service.js +253 -21
  183. package/dist/worktree/worktree.types.d.ts +7 -1
  184. package/package.json +7 -5
  185. package/runtime/windows-job-supervisor.ps1 +380 -14
@@ -0,0 +1,227 @@
1
+ import fs from "node:fs/promises";
2
+ import { readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { ForgeFailureError } from "../session/session.types.js";
7
+ export function defaultPlaywrightBrowserCacheCandidates(playwrightCoreDirectory, env = process.env, platform = process.platform, homeDirectory = os.homedir()) {
8
+ const browsersPath = env.PLAYWRIGHT_BROWSERS_PATH?.trim();
9
+ return [
10
+ // PLAYWRIGHT_BROWSERS_PATH=0 makes Playwright use the browsers installed beside playwright-core.
11
+ browsersPath === "0"
12
+ ? playwrightCoreDirectory ? path.join(playwrightCoreDirectory, ".local-browsers") : null
13
+ : browsersPath || null,
14
+ env.LOCALAPPDATA ? path.join(env.LOCALAPPDATA, "ms-playwright") : null,
15
+ env.XDG_CACHE_HOME ? path.join(env.XDG_CACHE_HOME, "ms-playwright") : null,
16
+ platform === "darwin" ? path.join(homeDirectory, "Library", "Caches", "ms-playwright") : null,
17
+ path.join(homeDirectory, ".cache", "ms-playwright"),
18
+ ].filter((candidate) => Boolean(candidate?.trim()));
19
+ }
20
+ /**
21
+ * Finds a host browser cache holding the Chromium and Chromium headless shell
22
+ * builds the project's installed Playwright pins. Only those two builds are
23
+ * checked: they are what the project's Chromium projects launch.
24
+ */
25
+ export async function findPlaywrightBrowserCache(realWorktree, configDirectory, candidatesFor, hostPlatform) {
26
+ const pinned = await readPinnedChromiumBuilds(realWorktree, configDirectory, hostPlatform);
27
+ const checked = [...new Set(candidatesFor(pinned?.playwrightCoreDirectory ?? null).map(candidate => path.resolve(candidate)))];
28
+ for (const candidate of checked) {
29
+ const ready = pinned
30
+ ? await hasPinnedChromiumBuilds(candidate, pinned.builds)
31
+ : await hasChromiumExecutable(candidate);
32
+ if (ready)
33
+ return { cache: candidate, pinned, checked };
34
+ }
35
+ return { cache: null, pinned, checked };
36
+ }
37
+ export function missingPlaywrightBrowsersError(resolution, installCommand) {
38
+ const missing = resolution.pinned.builds.map(build => build.directory).join(" and ");
39
+ const checked = resolution.checked.length > 0 ? resolution.checked.join(", ") : "none";
40
+ return new ForgeFailureError("host_runtime_project_start_failed", `host_runtime_project_start_failed: playwright_browsers_missing: Playwright ${resolution.pinned.version} launches `
41
+ + `Chromium from ${missing}, and no host browser cache holds them (checked: ${checked}). Only the pinned Chromium `
42
+ + `and Chromium headless shell builds are checked. The attempt stopped before it started; install them on this `
43
+ + `host with \`${installCommand}\` and dispatch again.`, "bridge");
44
+ }
45
+ // Executable layouts Playwright launches from, per browser directory (current and legacy builds).
46
+ const chromiumExecutables = {
47
+ win32: [path.join("chrome-win64", "chrome.exe"), path.join("chrome-win", "chrome.exe")],
48
+ darwin: [
49
+ path.join("chrome-mac-arm64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
50
+ path.join("chrome-mac-x64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
51
+ path.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium"),
52
+ ],
53
+ linux: [path.join("chrome-linux64", "chrome"), path.join("chrome-linux", "chrome")],
54
+ };
55
+ const headlessShellExecutables = {
56
+ win32: [path.join("chrome-headless-shell-win64", "chrome-headless-shell.exe"), path.join("chrome-win", "headless_shell.exe")],
57
+ darwin: [
58
+ path.join("chrome-headless-shell-mac-arm64", "chrome-headless-shell"),
59
+ path.join("chrome-headless-shell-mac-x64", "chrome-headless-shell"),
60
+ path.join("chrome-mac", "headless_shell"),
61
+ ],
62
+ linux: [path.join("chrome-headless-shell-linux64", "chrome-headless-shell"), path.join("chrome-linux", "headless_shell")],
63
+ };
64
+ function platformExecutables(table) {
65
+ return table[process.platform] ?? table.linux;
66
+ }
67
+ async function readPinnedChromiumBuilds(realWorktree, configDirectory, hostPlatform) {
68
+ const manifestPath = await resolvePlaywrightCoreManifest(realWorktree, configDirectory);
69
+ if (!manifestPath)
70
+ return null;
71
+ let version;
72
+ let browsers;
73
+ try {
74
+ version = String(JSON.parse(await fs.readFile(manifestPath, "utf8")).version ?? "unknown");
75
+ const parsed = JSON.parse(await fs.readFile(path.join(path.dirname(manifestPath), "browsers.json"), "utf8"));
76
+ browsers = Array.isArray(parsed.browsers) ? parsed.browsers : [];
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ const builds = [];
82
+ for (const [name, executables] of [
83
+ ["chromium", platformExecutables(chromiumExecutables)],
84
+ ["chromium-headless-shell", platformExecutables(headlessShellExecutables)],
85
+ ]) {
86
+ const entry = browsers.find(browser => browser.name === name);
87
+ if (!entry || typeof entry.revision !== "string")
88
+ continue;
89
+ // Playwright replaces the revision only for the host platform it runs on.
90
+ const override = entry.revisionOverrides && typeof entry.revisionOverrides === "object"
91
+ ? entry.revisionOverrides[hostPlatform]
92
+ : undefined;
93
+ const revision = typeof override === "string" ? override : entry.revision;
94
+ builds.push({ directory: `${name.replaceAll("-", "_")}-${revision}`, executables });
95
+ }
96
+ return builds.length > 0 ? { version, playwrightCoreDirectory: path.dirname(manifestPath), builds } : null;
97
+ }
98
+ async function resolvePlaywrightCoreManifest(realWorktree, configDirectory) {
99
+ // Follow the chain the project's test runner resolves first: pnpm does not
100
+ // hoist playwright-core next to @playwright/test, and a hoisted bare
101
+ // playwright-core may be a different version than the runner's own.
102
+ for (const chain of [
103
+ ["@playwright/test", "playwright", "playwright-core"],
104
+ ["playwright", "playwright-core"],
105
+ ["playwright-core"],
106
+ ]) {
107
+ let from = path.join(configDirectory, "package.json");
108
+ try {
109
+ for (const packageName of chain)
110
+ from = createRequire(from).resolve(`${packageName}/package.json`);
111
+ }
112
+ catch {
113
+ continue;
114
+ }
115
+ // A Playwright found above the worktree is not the project's own pin.
116
+ const realManifest = await fs.realpath(from).catch(() => null);
117
+ if (realManifest && isContained(realWorktree, realManifest))
118
+ return realManifest;
119
+ }
120
+ return null;
121
+ }
122
+ async function hasPinnedChromiumBuilds(cachePath, builds) {
123
+ for (const build of builds) {
124
+ if (!await anyFile(build.executables.map(executable => path.join(cachePath, build.directory, executable))))
125
+ return false;
126
+ }
127
+ return true;
128
+ }
129
+ async function hasChromiumExecutable(cachePath) {
130
+ let entries;
131
+ try {
132
+ entries = await fs.readdir(cachePath, { withFileTypes: true });
133
+ }
134
+ catch {
135
+ return false;
136
+ }
137
+ const executableSuffixes = platformExecutables(chromiumExecutables);
138
+ for (const entry of entries) {
139
+ if (!entry.isDirectory() || !entry.name.startsWith("chromium-"))
140
+ continue;
141
+ if (await anyFile(executableSuffixes.map(suffix => path.join(cachePath, entry.name, suffix))))
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ async function anyFile(candidates) {
147
+ for (const candidate of candidates) {
148
+ try {
149
+ if ((await fs.stat(candidate)).isFile())
150
+ return true;
151
+ }
152
+ catch {
153
+ // Continue through known Playwright layouts.
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+ function isContained(parent, child) {
159
+ const relative = path.relative(parent, child);
160
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
161
+ }
162
+ const defaultHostProbe = {
163
+ env: process.env,
164
+ platform: process.platform,
165
+ release: os.release(),
166
+ arch: os.arch(),
167
+ appleCpu: os.cpus().some(cpu => cpu.model.includes("Apple")),
168
+ osRelease: () => {
169
+ try {
170
+ return readFileSync("/etc/os-release", "utf8");
171
+ }
172
+ catch {
173
+ return null;
174
+ }
175
+ },
176
+ };
177
+ /** Mirrors Playwright's own host platform key, which selects `revisionOverrides` entries. */
178
+ export function playwrightHostPlatform(probe = defaultHostProbe) {
179
+ if (probe.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE)
180
+ return probe.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE;
181
+ if (probe.platform === "win32")
182
+ return "win64";
183
+ if (probe.platform === "darwin") {
184
+ const major = Number.parseInt(probe.release.split(".")[0] ?? "", 10);
185
+ if (major < 18)
186
+ return "mac10.13";
187
+ if (major === 18)
188
+ return "mac10.14";
189
+ if (major === 19)
190
+ return "mac10.15";
191
+ const macVersion = major < 25 ? major - 9 : Math.min(major + 1, 26);
192
+ return `mac${macVersion}${probe.appleCpu ? "-arm64" : ""}`;
193
+ }
194
+ if (probe.platform !== "linux" || !["x64", "arm64"].includes(probe.arch))
195
+ return "<unknown>";
196
+ const suffix = `-${probe.arch}`;
197
+ const fields = new Map((probe.osRelease() ?? "").split("\n").map(line => {
198
+ const [name = "", ...rest] = line.split("=");
199
+ return [name.toLowerCase(), rest.join("=").trim().replace(/^"(.*)"$/u, "$1")];
200
+ }));
201
+ const id = fields.get("id") ?? "";
202
+ const version = fields.get("version_id") ?? "";
203
+ const major = Number.parseInt(version, 10);
204
+ if (["ubuntu", "pop", "neon", "tuxedo"].includes(id)) {
205
+ if (major < 20)
206
+ return `ubuntu18.04${suffix}`;
207
+ if (major < 22)
208
+ return `ubuntu20.04${suffix}`;
209
+ if (major < 24)
210
+ return `ubuntu22.04${suffix}`;
211
+ if (major < 26)
212
+ return `ubuntu24.04${suffix}`;
213
+ return `ubuntu${version}${suffix}`;
214
+ }
215
+ if (id === "linuxmint") {
216
+ if (major <= 20)
217
+ return `ubuntu20.04${suffix}`;
218
+ return major === 21 ? `ubuntu22.04${suffix}` : `ubuntu24.04${suffix}`;
219
+ }
220
+ if (id === "debian" || id === "raspbian") {
221
+ if (["11", "12", "13"].includes(version))
222
+ return `debian${version}${suffix}`;
223
+ if (version === "")
224
+ return `debian13${suffix}`;
225
+ }
226
+ return `ubuntu24.04${suffix}`;
227
+ }
@@ -1,10 +1,12 @@
1
1
  import type { HostRuntimePlaywrightConfig } from "./host-runtime-contract.js";
2
+ import { type PlaywrightBrowserCacheCandidates } from "./playwright-browser-cache.js";
2
3
  export interface PlaywrightHostRuntimeContext {
3
4
  readonly worktreePath: string;
4
5
  readonly temporaryDirectory: string;
5
6
  readonly testOutputDirectory: string;
6
7
  readonly browserProfileDirectory: string;
7
8
  readonly baseUrl: string;
9
+ readonly ownershipToken: string;
8
10
  }
9
11
  export interface PreparedPlaywrightHostRuntime {
10
12
  readonly configPath: string;
@@ -16,5 +18,15 @@ export interface PreparedPlaywrightHostRuntime {
16
18
  * Playwright-managed web servers, and keeps writable artifacts attempt-local.
17
19
  */
18
20
  export declare class PlaywrightHostRuntimeAdapter {
21
+ private readonly browserCacheCandidates;
22
+ private readonly hostPlatform;
23
+ constructor(browserCacheCandidates?: PlaywrightBrowserCacheCandidates, hostPlatform?: () => string);
24
+ /**
25
+ * Fails a host that lacks the project's pinned Chromium builds before any
26
+ * database, build, launch, or promotion work, so the attempt never runs
27
+ * toward a Playwright gate whose every spec would fail at browser launch.
28
+ */
29
+ assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
30
+ private readyBrowserCache;
19
31
  prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
20
32
  }
@@ -1,7 +1,10 @@
1
1
  import fs from "node:fs/promises";
2
- import os from "node:os";
3
2
  import path from "node:path";
4
3
  import { pathToFileURL } from "node:url";
4
+ import { assertCanonicalDirectory, createPrivateCanonicalDirectory } from "./attempt-private-directory.js";
5
+ import { readCanonicalSourceFile } from "./canonical-source-file.js";
6
+ import { runAttemptPathOperation } from "./attempt-path-operation.js";
7
+ import { defaultPlaywrightBrowserCacheCandidates, findPlaywrightBrowserCache, missingPlaywrightBrowsersError, playwrightHostPlatform, } from "./playwright-browser-cache.js";
5
8
  const maximumConfigBytes = 1024 * 1024;
6
9
  /**
7
10
  * Prepares a finite Playwright test boundary for a managed-host attempt.
@@ -9,18 +12,45 @@ const maximumConfigBytes = 1024 * 1024;
9
12
  * Playwright-managed web servers, and keeps writable artifacts attempt-local.
10
13
  */
11
14
  export class PlaywrightHostRuntimeAdapter {
15
+ browserCacheCandidates;
16
+ hostPlatform;
17
+ constructor(browserCacheCandidates = defaultPlaywrightBrowserCacheCandidates, hostPlatform = playwrightHostPlatform) {
18
+ this.browserCacheCandidates = browserCacheCandidates;
19
+ this.hostPlatform = hostPlatform;
20
+ }
21
+ /**
22
+ * Fails a host that lacks the project's pinned Chromium builds before any
23
+ * database, build, launch, or promotion work, so the attempt never runs
24
+ * toward a Playwright gate whose every spec would fail at browser launch.
25
+ */
26
+ async assertBrowserCacheReady(config, worktreePath) {
27
+ const { realWorktree, realSource } = await projectConfigLocation(config, worktreePath);
28
+ await this.readyBrowserCache(worktreePath, realWorktree, path.dirname(realSource));
29
+ }
30
+ async readyBrowserCache(worktreePath, realWorktree, configDirectory) {
31
+ const installCommand = await resolvePlaywrightBrowserInstallCommand(worktreePath, configDirectory);
32
+ const resolution = await findPlaywrightBrowserCache(realWorktree, configDirectory, this.browserCacheCandidates, this.hostPlatform());
33
+ if (resolution.pinned && !resolution.cache) {
34
+ throw missingPlaywrightBrowsersError({ ...resolution, pinned: resolution.pinned }, installCommand);
35
+ }
36
+ return { cache: resolution.cache, installCommand };
37
+ }
12
38
  async prepare(config, context) {
13
- const worktreePath = path.resolve(context.worktreePath);
14
- const sourceConfig = path.resolve(worktreePath, config.config);
15
- const [realWorktree, realSource] = await Promise.all([
16
- fs.realpath(worktreePath),
17
- fs.realpath(sourceConfig),
18
- ]);
19
- assertContained(realWorktree, realSource, "project Playwright config");
20
- const sourceStat = await fs.stat(realSource);
21
- if (!sourceStat.isFile() || sourceStat.size < 1 || sourceStat.size > maximumConfigBytes) {
39
+ const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
40
+ const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
41
+ const sourceBytes = await readCanonicalSourceFile(sourceConfig, maximumConfigBytes);
42
+ if (sourceBytes.length < 1) {
22
43
  throw new Error(`playwright_runtime_adapter_invalid: project config must be a regular 1-${maximumConfigBytes} byte file.`);
23
44
  }
45
+ const sourceConfigText = sourceBytes.toString("utf8");
46
+ const projectNames = [...sourceConfigText.matchAll(/\bname\s*:\s*["']([^"']+)["']/gu)]
47
+ .map(match => match[1])
48
+ .filter((name, index, names) => names.indexOf(name) === index);
49
+ await ensureAttemptWritableDirectories([
50
+ context.temporaryDirectory,
51
+ context.testOutputDirectory,
52
+ context.browserProfileDirectory,
53
+ ], realWorktree);
24
54
  const temporaryDirectory = await realContainedDirectory(context.temporaryDirectory, realWorktree, "temporary directory");
25
55
  const testOutputDirectory = await realContainedDirectory(context.testOutputDirectory, realWorktree, "test output directory");
26
56
  const browserProfileDirectory = await realContainedDirectory(context.browserProfileDirectory, realWorktree, "browser profile directory");
@@ -29,22 +59,30 @@ export class PlaywrightHostRuntimeAdapter {
29
59
  throw new Error("playwright_runtime_adapter_invalid: writable directories must belong to the same attempt root.");
30
60
  }
31
61
  const baseUrl = loopbackHttpUrl(context.baseUrl);
62
+ if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
63
+ throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
64
+ }
32
65
  const overlayPath = path.join(temporaryDirectory, "forge.playwright.config.mjs");
33
- const browserCache = await resolvePlaywrightBrowserCache(attemptRoot);
34
- const browserInstallCommand = await resolvePlaywrightBrowserInstallCommand(context.worktreePath, path.dirname(realSource));
35
- await fs.writeFile(overlayPath, renderOverlay({
66
+ const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
67
+ const browserCache = readyCache
68
+ ? { path: readyCache, ready: true }
69
+ : { path: await attemptBrowserCache(attemptRoot), ready: false };
70
+ await writeAttemptOverlay(overlayPath, renderOverlay({
36
71
  projectConfigUrl: pathToFileURL(realSource).href,
37
72
  projectConfigDirectory: path.dirname(realSource),
38
73
  testOutputDirectory,
39
74
  baseUrl,
40
75
  workers: config.workers,
41
- }), { encoding: "utf8", mode: 0o600 });
76
+ projectNames,
77
+ }));
42
78
  return {
43
79
  configPath: overlayPath,
44
80
  environment: {
45
81
  FORGE_PLAYWRIGHT_CONFIG: overlayPath,
46
82
  FORGE_PLAYWRIGHT_BASE_URL: baseUrl,
47
83
  FORGE_E2E_WEB_URL: baseUrl,
84
+ FORGE_E2E_OWNERSHIP_MODE: "attempt",
85
+ FORGE_E2E_OWNERSHIP_TOKEN: context.ownershipToken,
48
86
  FORGE_PLAYWRIGHT_BROWSER_READY: browserCache.ready ? "true" : "false",
49
87
  FORGE_PLAYWRIGHT_BROWSER_INSTALL_COMMAND: browserInstallCommand,
50
88
  PLAYWRIGHT_BROWSERS_PATH: browserCache.path,
@@ -58,6 +96,52 @@ export class PlaywrightHostRuntimeAdapter {
58
96
  };
59
97
  }
60
98
  }
99
+ async function projectConfigLocation(config, worktreePath) {
100
+ const resolvedWorktree = path.resolve(worktreePath);
101
+ const [realWorktree, realSource] = await Promise.all([
102
+ fs.realpath(resolvedWorktree),
103
+ fs.realpath(path.resolve(resolvedWorktree, config.config)),
104
+ ]);
105
+ assertContained(realWorktree, realSource, "project Playwright config");
106
+ return { realWorktree, realSource };
107
+ }
108
+ /**
109
+ * Without an installed Playwright the pinned build is unknown; the attempt
110
+ * gets its own empty cache and the readiness manifest names the install command.
111
+ */
112
+ async function attemptBrowserCache(attemptRoot) {
113
+ const attemptCache = path.join(attemptRoot, "cache", "ms-playwright");
114
+ await createPrivateCanonicalDirectory(attemptCache);
115
+ return attemptCache;
116
+ }
117
+ async function ensureAttemptWritableDirectories(targets, realWorktree) {
118
+ const resolvedTargets = targets.map(target => path.resolve(target));
119
+ const attemptRoots = new Set(resolvedTargets.map(target => path.dirname(target)));
120
+ if (attemptRoots.size !== 1) {
121
+ throw new Error("playwright_runtime_adapter_invalid: writable directories must belong to the same attempt root.");
122
+ }
123
+ const attemptRoot = [...attemptRoots][0];
124
+ if (!attemptRoot || attemptRoot === realWorktree || isContained(realWorktree, attemptRoot)) {
125
+ throw new Error("playwright_runtime_adapter_invalid: writable directories must be attempt-private and outside the worktree.");
126
+ }
127
+ await assertCanonicalDirectory(attemptRoot, true);
128
+ for (const target of resolvedTargets) {
129
+ if (target === realWorktree || isContained(realWorktree, target)) {
130
+ throw new Error("playwright_runtime_adapter_invalid: writable directories must be attempt-private and outside the worktree.");
131
+ }
132
+ await assertCanonicalDirectory(target, true);
133
+ }
134
+ await createPrivateCanonicalDirectory(attemptRoot);
135
+ for (const target of resolvedTargets)
136
+ await createPrivateCanonicalDirectory(target);
137
+ }
138
+ async function writeAttemptOverlay(target, content) {
139
+ const parent = path.dirname(target);
140
+ const identity = await assertCanonicalDirectory(parent);
141
+ if (!identity)
142
+ throw new Error("playwright_runtime_adapter_invalid: overlay parent is missing.");
143
+ await runAttemptPathOperation(parent, identity, { kind: "overlay", name: path.basename(target), content });
144
+ }
61
145
  async function resolvePlaywrightBrowserInstallCommand(worktreePath, configDirectory) {
62
146
  const relativeDirectory = path.relative(worktreePath, configDirectory).replaceAll(path.sep, "/") || ".";
63
147
  if (await isFile(path.join(configDirectory, "pnpm-lock.yaml"))) {
@@ -79,53 +163,10 @@ async function isFile(candidate) {
79
163
  function quoteCommandArgument(value) {
80
164
  return /[\s"']/u.test(value) ? JSON.stringify(value) : value;
81
165
  }
82
- async function resolvePlaywrightBrowserCache(attemptRoot) {
83
- const candidates = [
84
- process.env.PLAYWRIGHT_BROWSERS_PATH,
85
- process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "ms-playwright") : null,
86
- path.join(os.homedir(), ".cache", "ms-playwright"),
87
- ].filter((candidate) => Boolean(candidate?.trim()));
88
- for (const candidate of [...new Set(candidates.map(candidate => path.resolve(candidate)))]) {
89
- if (await hasChromiumExecutable(candidate)) {
90
- return { path: candidate, ready: true };
91
- }
92
- }
93
- const attemptCache = path.join(attemptRoot, "cache", "ms-playwright");
94
- await fs.mkdir(attemptCache, { recursive: true });
95
- return { path: attemptCache, ready: false };
96
- }
97
- async function hasChromiumExecutable(cachePath) {
98
- let entries;
99
- try {
100
- entries = await fs.readdir(cachePath, { withFileTypes: true });
101
- }
102
- catch {
103
- return false;
104
- }
105
- const executableSuffixes = process.platform === "win32"
106
- ? [path.join("chrome-win64", "chrome.exe"), path.join("chrome-win", "chrome.exe")]
107
- : process.platform === "darwin"
108
- ? [path.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium")]
109
- : [path.join("chrome-linux", "chrome"), path.join("chrome-linux64", "chrome")];
110
- for (const entry of entries) {
111
- if (!entry.isDirectory() || !entry.name.startsWith("chromium-"))
112
- continue;
113
- for (const suffix of executableSuffixes) {
114
- try {
115
- const stat = await fs.stat(path.join(cachePath, entry.name, suffix));
116
- if (stat.isFile())
117
- return true;
118
- }
119
- catch {
120
- // Continue through known Playwright layouts.
121
- }
122
- }
123
- }
124
- return false;
125
- }
126
166
  function renderOverlay(values) {
127
167
  return [
128
168
  "// Generated by forge-bridge for one fenced host attempt.",
169
+ `// forge-playwright-projects: ${JSON.stringify(values.projectNames)}`,
129
170
  "import path from \"node:path\";",
130
171
  `import projectConfig from ${JSON.stringify(values.projectConfigUrl)};`,
131
172
  `const projectConfigDirectory = ${JSON.stringify(values.projectConfigDirectory)};`,
@@ -183,6 +224,7 @@ function renderOverlay(values) {
183
224
  ].join("\n");
184
225
  }
185
226
  async function realContainedDirectory(target, realWorktree, label) {
227
+ await assertCanonicalDirectory(target);
186
228
  const realTarget = await fs.realpath(path.resolve(target));
187
229
  if (realTarget === realWorktree || isContained(realWorktree, realTarget)) {
188
230
  throw new Error(`playwright_runtime_adapter_invalid: ${label} must be attempt-private and outside the worktree.`);
@@ -0,0 +1,6 @@
1
+ import { type HostParallelProofIdentity } from "./host-runtime-promotion.js";
2
+ export interface PreparedRuntimeIdentityDiagnostics {
3
+ readonly entries: Map<string, string>;
4
+ }
5
+ /** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
6
+ export declare function preparedRuntimeIdentity(worktreePath: string, signal?: AbortSignal, diagnostics?: PreparedRuntimeIdentityDiagnostics): Promise<HostParallelProofIdentity>;