@loucompanion/forge-bridge 0.1.4-dev.41da3780c451 → 0.1.4-dev.4677bbd22f17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bridge/bridge.service.d.ts +12 -1
- package/dist/bridge/bridge.service.js +51 -5
- package/dist/bridge/bridge.types.d.ts +6 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/cli/cli.help.js +2 -2
- package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
- package/dist/runtime/attempt-process-supervisor.js +74 -1
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-sampler.d.ts +83 -0
- package/dist/runtime/host-load-sampler.js +164 -0
- package/dist/runtime/host-pressure-stall.d.ts +41 -0
- package/dist/runtime/host-pressure-stall.js +121 -0
- package/dist/runtime/host-runtime-contract.d.ts +1 -0
- package/dist/runtime/host-runtime-contract.js +2 -0
- package/dist/runtime/host-runtime-lease.js +55 -9
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/session/managed-attempt-tools.d.ts +25 -0
- package/dist/session/managed-attempt-tools.js +212 -15
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.runtime.js +22 -17
- package/dist/session/pre-publication-process.d.ts +20 -0
- package/dist/session/pre-publication-process.js +97 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-validation.js +27 -57
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +37 -1
- package/dist/session/provider-cli/provider-cli.process.js +297 -23
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +15 -0
- package/dist/session/provider-cli/provider-cli.service.js +112 -22
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/session.types.js +12 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.js +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
2
|
+
/** Host browser caches to try, given the directory of the project's resolved playwright-core (if any). */
|
|
3
|
+
export type PlaywrightBrowserCacheCandidates = (playwrightCoreDirectory: string | null) => readonly string[];
|
|
4
|
+
export declare function defaultPlaywrightBrowserCacheCandidates(playwrightCoreDirectory: string | null, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, homeDirectory?: string): readonly string[];
|
|
5
|
+
export interface PinnedChromiumBuilds {
|
|
6
|
+
readonly version: string;
|
|
7
|
+
readonly playwrightCoreDirectory: string;
|
|
8
|
+
readonly builds: readonly PinnedChromiumBuild[];
|
|
9
|
+
}
|
|
10
|
+
interface PinnedChromiumBuild {
|
|
11
|
+
readonly directory: string;
|
|
12
|
+
readonly executables: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export interface PlaywrightBrowserCacheResolution {
|
|
15
|
+
/** The first host cache holding every pinned build, or the legacy any-Chromium match when nothing is pinned. */
|
|
16
|
+
readonly cache: string | null;
|
|
17
|
+
readonly pinned: PinnedChromiumBuilds | null;
|
|
18
|
+
readonly checked: readonly string[];
|
|
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 declare function findPlaywrightBrowserCache(realWorktree: string, configDirectory: string, candidatesFor: PlaywrightBrowserCacheCandidates, hostPlatform: string): Promise<PlaywrightBrowserCacheResolution>;
|
|
26
|
+
export declare function missingPlaywrightBrowsersError(resolution: PlaywrightBrowserCacheResolution & {
|
|
27
|
+
readonly pinned: PinnedChromiumBuilds;
|
|
28
|
+
}, installCommand: string): ForgeFailureError;
|
|
29
|
+
export interface PlaywrightHostProbe {
|
|
30
|
+
readonly env: NodeJS.ProcessEnv;
|
|
31
|
+
readonly platform: NodeJS.Platform;
|
|
32
|
+
readonly release: string;
|
|
33
|
+
readonly arch: string;
|
|
34
|
+
readonly appleCpu: boolean;
|
|
35
|
+
readonly osRelease: () => string | null;
|
|
36
|
+
}
|
|
37
|
+
/** Mirrors Playwright's own host platform key, which selects `revisionOverrides` entries. */
|
|
38
|
+
export declare function playwrightHostPlatform(probe?: PlaywrightHostProbe): string;
|
|
39
|
+
export {};
|
|
@@ -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,4 +1,5 @@
|
|
|
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;
|
|
@@ -17,5 +18,15 @@ export interface PreparedPlaywrightHostRuntime {
|
|
|
17
18
|
* Playwright-managed web servers, and keeps writable artifacts attempt-local.
|
|
18
19
|
*/
|
|
19
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;
|
|
20
31
|
prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
|
|
21
32
|
}
|
|
@@ -1,10 +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";
|
|
5
4
|
import { assertCanonicalDirectory, createPrivateCanonicalDirectory } from "./attempt-private-directory.js";
|
|
6
5
|
import { readCanonicalSourceFile } from "./canonical-source-file.js";
|
|
7
6
|
import { runAttemptPathOperation } from "./attempt-path-operation.js";
|
|
7
|
+
import { defaultPlaywrightBrowserCacheCandidates, findPlaywrightBrowserCache, missingPlaywrightBrowsersError, playwrightHostPlatform, } from "./playwright-browser-cache.js";
|
|
8
8
|
const maximumConfigBytes = 1024 * 1024;
|
|
9
9
|
/**
|
|
10
10
|
* Prepares a finite Playwright test boundary for a managed-host attempt.
|
|
@@ -12,14 +12,32 @@ const maximumConfigBytes = 1024 * 1024;
|
|
|
12
12
|
* Playwright-managed web servers, and keeps writable artifacts attempt-local.
|
|
13
13
|
*/
|
|
14
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
|
+
}
|
|
15
38
|
async prepare(config, context) {
|
|
16
|
-
const
|
|
17
|
-
const sourceConfig = path.resolve(worktreePath, config.config);
|
|
18
|
-
const [realWorktree, realSource] = await Promise.all([
|
|
19
|
-
fs.realpath(worktreePath),
|
|
20
|
-
fs.realpath(sourceConfig),
|
|
21
|
-
]);
|
|
22
|
-
assertContained(realWorktree, realSource, "project Playwright config");
|
|
39
|
+
const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
|
|
40
|
+
const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
|
|
23
41
|
const sourceBytes = await readCanonicalSourceFile(sourceConfig, maximumConfigBytes);
|
|
24
42
|
if (sourceBytes.length < 1) {
|
|
25
43
|
throw new Error(`playwright_runtime_adapter_invalid: project config must be a regular 1-${maximumConfigBytes} byte file.`);
|
|
@@ -45,8 +63,10 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
45
63
|
throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
|
|
46
64
|
}
|
|
47
65
|
const overlayPath = path.join(temporaryDirectory, "forge.playwright.config.mjs");
|
|
48
|
-
const
|
|
49
|
-
const
|
|
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 };
|
|
50
70
|
await writeAttemptOverlay(overlayPath, renderOverlay({
|
|
51
71
|
projectConfigUrl: pathToFileURL(realSource).href,
|
|
52
72
|
projectConfigDirectory: path.dirname(realSource),
|
|
@@ -76,6 +96,24 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
76
96
|
};
|
|
77
97
|
}
|
|
78
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
|
+
}
|
|
79
117
|
async function ensureAttemptWritableDirectories(targets, realWorktree) {
|
|
80
118
|
const resolvedTargets = targets.map(target => path.resolve(target));
|
|
81
119
|
const attemptRoots = new Set(resolvedTargets.map(target => path.dirname(target)));
|
|
@@ -125,50 +163,6 @@ async function isFile(candidate) {
|
|
|
125
163
|
function quoteCommandArgument(value) {
|
|
126
164
|
return /[\s"']/u.test(value) ? JSON.stringify(value) : value;
|
|
127
165
|
}
|
|
128
|
-
async function resolvePlaywrightBrowserCache(attemptRoot) {
|
|
129
|
-
const candidates = [
|
|
130
|
-
process.env.PLAYWRIGHT_BROWSERS_PATH,
|
|
131
|
-
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "ms-playwright") : null,
|
|
132
|
-
path.join(os.homedir(), ".cache", "ms-playwright"),
|
|
133
|
-
].filter((candidate) => Boolean(candidate?.trim()));
|
|
134
|
-
for (const candidate of [...new Set(candidates.map(candidate => path.resolve(candidate)))]) {
|
|
135
|
-
if (await hasChromiumExecutable(candidate)) {
|
|
136
|
-
return { path: candidate, ready: true };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const attemptCache = path.join(attemptRoot, "cache", "ms-playwright");
|
|
140
|
-
await createPrivateCanonicalDirectory(attemptCache);
|
|
141
|
-
return { path: attemptCache, ready: false };
|
|
142
|
-
}
|
|
143
|
-
async function hasChromiumExecutable(cachePath) {
|
|
144
|
-
let entries;
|
|
145
|
-
try {
|
|
146
|
-
entries = await fs.readdir(cachePath, { withFileTypes: true });
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
const executableSuffixes = process.platform === "win32"
|
|
152
|
-
? [path.join("chrome-win64", "chrome.exe"), path.join("chrome-win", "chrome.exe")]
|
|
153
|
-
: process.platform === "darwin"
|
|
154
|
-
? [path.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium")]
|
|
155
|
-
: [path.join("chrome-linux", "chrome"), path.join("chrome-linux64", "chrome")];
|
|
156
|
-
for (const entry of entries) {
|
|
157
|
-
if (!entry.isDirectory() || !entry.name.startsWith("chromium-"))
|
|
158
|
-
continue;
|
|
159
|
-
for (const suffix of executableSuffixes) {
|
|
160
|
-
try {
|
|
161
|
-
const stat = await fs.stat(path.join(cachePath, entry.name, suffix));
|
|
162
|
-
if (stat.isFile())
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
// Continue through known Playwright layouts.
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
166
|
function renderOverlay(values) {
|
|
173
167
|
return [
|
|
174
168
|
"// Generated by forge-bridge for one fenced host attempt.",
|
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { type NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
2
2
|
export declare const managedAttemptToolNames: readonly ["forge.run_managed_command", "run_managed_command", "forge.start_managed_command", "start_managed_command", "forge.get_managed_command", "get_managed_command", "forge.wait_managed_command", "wait_managed_command", "forge.start_managed_verification", "start_managed_verification", "forge.reset_generated_outputs", "reset_generated_outputs"];
|
|
3
|
+
/**
|
|
4
|
+
* Stops every managed command this MCP server started, proves each process tree stopped,
|
|
5
|
+
* and writes their terminal receipts. Called when the provider closes the MCP connection
|
|
6
|
+
* or the server is signalled: once this server exits nothing could supervise them.
|
|
7
|
+
*/
|
|
8
|
+
export declare function stopManagedCommandsForOwnerExit(): Promise<void>;
|
|
9
|
+
/** Test support: lets one test process act as a fresh MCP server after a simulated exit. */
|
|
10
|
+
export declare function resetManagedCommandOwnerShutdownForTesting(): void;
|
|
11
|
+
declare const ownerShutdownSignals: readonly ["SIGTERM", "SIGHUP", "SIGINT"];
|
|
12
|
+
export interface OwnerShutdownSignalTarget {
|
|
13
|
+
once(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
|
|
14
|
+
removeListener(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Makes a termination signal stop this server's managed commands before it exits, so none
|
|
18
|
+
* outlives its only supervisor. Returns a function that removes the handlers.
|
|
19
|
+
*/
|
|
20
|
+
export declare function installOwnerShutdownHandlers(target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Runs an MCP server body, then stops every managed command it started before returning.
|
|
23
|
+
* The signal handlers stay installed until that stop completes: a signal during the body
|
|
24
|
+
* or the stop exits only after the same stop finishes, never by Node's default exit.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runWithOwnerShutdown<T>(body: () => Promise<T>, target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): Promise<T>;
|
|
3
27
|
export declare function isManagedAttemptTool(name: string): boolean;
|
|
4
28
|
export declare function managedAttemptToolDefinition(name: string): unknown;
|
|
5
29
|
export interface ManagedAttemptToolResult {
|
|
@@ -26,3 +50,4 @@ export declare function playwrightProjectNamesFromConfigSource(source: string):
|
|
|
26
50
|
*/
|
|
27
51
|
export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
|
|
28
52
|
export declare function isBuildProducingManagedCommand(command: string, args: readonly string[]): boolean;
|
|
53
|
+
export {};
|