@loucompanion/forge-bridge 0.1.4-dev.9e8a5b93cbcb → 0.1.4-dev.acacfdecaad2
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 +35 -2
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +84 -2
- package/dist/bridge/bridge.service.js +357 -12
- package/dist/bridge/bridge.types.d.ts +22 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
- package/dist/runtime/attempt-process-supervisor.js +50 -0
- 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-admission.d.ts +60 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +67 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +43 -0
- package/dist/runtime/host-load-governor-config.js +76 -0
- package/dist/runtime/host-load-governor.d.ts +174 -0
- package/dist/runtime/host-load-governor.js +541 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -0
- package/dist/runtime/host-load-step-class.d.ts +68 -0
- package/dist/runtime/host-load-step-class.js +106 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +4 -0
- package/dist/runtime/host-runtime-contract.js +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +334 -19
- package/dist/runtime/host-runtime-promotion.js +12 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/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 +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +27 -0
- package/dist/session/managed-attempt-tools.js +356 -40
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +98 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +70 -35
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +184 -209
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +9 -9
- package/dist/session/pre-publication-validation.js +48 -112
- 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 +35 -1
- package/dist/session/provider-cli/provider-cli.process.js +189 -19
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +20 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.service.js +244 -36
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +229 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -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,22 @@ 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;
|
|
31
|
+
/**
|
|
32
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
33
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
34
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
35
|
+
* The next `prepare` writes a fresh one.
|
|
36
|
+
*/
|
|
37
|
+
discardOverlay(temporaryDirectory: string): Promise<void>;
|
|
20
38
|
prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
|
|
21
39
|
}
|
|
@@ -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,43 @@ 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
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
40
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
41
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
42
|
+
* The next `prepare` writes a fresh one.
|
|
43
|
+
*/
|
|
44
|
+
async discardOverlay(temporaryDirectory) {
|
|
45
|
+
if (!await assertCanonicalDirectory(temporaryDirectory, true))
|
|
46
|
+
return;
|
|
47
|
+
await fs.rm(path.join(path.resolve(temporaryDirectory), playwrightOverlayFileName), { force: true });
|
|
48
|
+
}
|
|
15
49
|
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");
|
|
50
|
+
const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
|
|
51
|
+
const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
|
|
23
52
|
const sourceBytes = await readCanonicalSourceFile(sourceConfig, maximumConfigBytes);
|
|
24
53
|
if (sourceBytes.length < 1) {
|
|
25
54
|
throw new Error(`playwright_runtime_adapter_invalid: project config must be a regular 1-${maximumConfigBytes} byte file.`);
|
|
@@ -44,9 +73,11 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
44
73
|
if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
|
|
45
74
|
throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
|
|
46
75
|
}
|
|
47
|
-
const overlayPath = path.join(temporaryDirectory,
|
|
48
|
-
const
|
|
49
|
-
const
|
|
76
|
+
const overlayPath = path.join(temporaryDirectory, playwrightOverlayFileName);
|
|
77
|
+
const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
|
|
78
|
+
const browserCache = readyCache
|
|
79
|
+
? { path: readyCache, ready: true }
|
|
80
|
+
: { path: await attemptBrowserCache(attemptRoot), ready: false };
|
|
50
81
|
await writeAttemptOverlay(overlayPath, renderOverlay({
|
|
51
82
|
projectConfigUrl: pathToFileURL(realSource).href,
|
|
52
83
|
projectConfigDirectory: path.dirname(realSource),
|
|
@@ -76,6 +107,24 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
76
107
|
};
|
|
77
108
|
}
|
|
78
109
|
}
|
|
110
|
+
async function projectConfigLocation(config, worktreePath) {
|
|
111
|
+
const resolvedWorktree = path.resolve(worktreePath);
|
|
112
|
+
const [realWorktree, realSource] = await Promise.all([
|
|
113
|
+
fs.realpath(resolvedWorktree),
|
|
114
|
+
fs.realpath(path.resolve(resolvedWorktree, config.config)),
|
|
115
|
+
]);
|
|
116
|
+
assertContained(realWorktree, realSource, "project Playwright config");
|
|
117
|
+
return { realWorktree, realSource };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Without an installed Playwright the pinned build is unknown; the attempt
|
|
121
|
+
* gets its own empty cache and the readiness manifest names the install command.
|
|
122
|
+
*/
|
|
123
|
+
async function attemptBrowserCache(attemptRoot) {
|
|
124
|
+
const attemptCache = path.join(attemptRoot, "cache", "ms-playwright");
|
|
125
|
+
await createPrivateCanonicalDirectory(attemptCache);
|
|
126
|
+
return attemptCache;
|
|
127
|
+
}
|
|
79
128
|
async function ensureAttemptWritableDirectories(targets, realWorktree) {
|
|
80
129
|
const resolvedTargets = targets.map(target => path.resolve(target));
|
|
81
130
|
const attemptRoots = new Set(resolvedTargets.map(target => path.dirname(target)));
|
|
@@ -97,6 +146,7 @@ async function ensureAttemptWritableDirectories(targets, realWorktree) {
|
|
|
97
146
|
for (const target of resolvedTargets)
|
|
98
147
|
await createPrivateCanonicalDirectory(target);
|
|
99
148
|
}
|
|
149
|
+
const playwrightOverlayFileName = "forge.playwright.config.mjs";
|
|
100
150
|
async function writeAttemptOverlay(target, content) {
|
|
101
151
|
const parent = path.dirname(target);
|
|
102
152
|
const identity = await assertCanonicalDirectory(parent);
|
|
@@ -125,50 +175,6 @@ async function isFile(candidate) {
|
|
|
125
175
|
function quoteCommandArgument(value) {
|
|
126
176
|
return /[\s"']/u.test(value) ? JSON.stringify(value) : value;
|
|
127
177
|
}
|
|
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
178
|
function renderOverlay(values) {
|
|
173
179
|
return [
|
|
174
180
|
"// Generated by forge-bridge for one fenced host attempt.",
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type HostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
2
|
+
export declare const runnerSettingKeys: readonly ["maxConcurrentAttempts", "cpuBudgetPercent", "yieldCpuBudgetPercent", "memoryReserveBytes", "maxHeavySteps", "yieldToForeground"];
|
|
3
|
+
export type RunnerSettingKey = typeof runnerSettingKeys[number];
|
|
4
|
+
/** The `ApplySettings` hub message. Null numeric fields mean "no server value": keep today's env/default behaviour. */
|
|
5
|
+
export interface RunnerSettingsDocument {
|
|
6
|
+
readonly runnerId: string | null;
|
|
7
|
+
readonly version: number;
|
|
8
|
+
readonly maxConcurrentAttempts: number | null;
|
|
9
|
+
readonly cpuBudgetPercent: number | null;
|
|
10
|
+
readonly yieldCpuBudgetPercent: number | null;
|
|
11
|
+
readonly memoryReserveBytes: number | null;
|
|
12
|
+
readonly maxHeavySteps: number | null;
|
|
13
|
+
readonly yieldToForeground: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RunnerSettingsValues {
|
|
16
|
+
readonly maxConcurrentAttempts: number;
|
|
17
|
+
readonly cpuBudgetPercent: number;
|
|
18
|
+
readonly yieldCpuBudgetPercent: number;
|
|
19
|
+
readonly memoryReserveBytes: number;
|
|
20
|
+
/** Null: the governor's budget alone limits heavy steps (no count limit). */
|
|
21
|
+
readonly maxHeavySteps: number | null;
|
|
22
|
+
readonly yieldToForeground: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where an effective value came from: the server's value as is, the bridge default,
|
|
26
|
+
* an env var that capped/floored the server value or supplied it, or the host's
|
|
27
|
+
* `forge-bridge yield on` flag.
|
|
28
|
+
*/
|
|
29
|
+
export type RunnerSettingSource = "server" | "default" | "host_env" | "host_local";
|
|
30
|
+
export interface RunnerSettingBound {
|
|
31
|
+
readonly key: RunnerSettingKey;
|
|
32
|
+
readonly envVar: string;
|
|
33
|
+
readonly value: number;
|
|
34
|
+
readonly kind: "ceiling" | "floor";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Why a key was rejected. `invalid`: the server value is outside the contract, so
|
|
38
|
+
* the host default applies (version skew; it never holds placement). `apply_failed`:
|
|
39
|
+
* the host could not put the value in force, so the previous value stays in force
|
|
40
|
+
* and the server holds placement until a later apply succeeds. Clamping by an env
|
|
41
|
+
* bound is neither: it is a `bound` and a `host_env` source.
|
|
42
|
+
*/
|
|
43
|
+
export type RunnerSettingRejectionKind = "invalid" | "apply_failed";
|
|
44
|
+
export interface RunnerSettingRejection {
|
|
45
|
+
readonly key: RunnerSettingKey;
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
readonly kind: RunnerSettingRejectionKind;
|
|
48
|
+
}
|
|
49
|
+
/** The `SettingsApplied` report; also carried in the capabilities `settings` block (schema 8). */
|
|
50
|
+
export interface RunnerSettingsReport {
|
|
51
|
+
/** The applied document version, or null before any ApplySettings was applied. */
|
|
52
|
+
readonly version: number | null;
|
|
53
|
+
/** FORGE_HOST_LOAD_GOVERNOR: CPU budget, yield budget and heavy steps only take effect when on. */
|
|
54
|
+
readonly governor: HostLoadGovernorMode;
|
|
55
|
+
readonly values: RunnerSettingsValues;
|
|
56
|
+
readonly sources: Readonly<Record<RunnerSettingKey, RunnerSettingSource>>;
|
|
57
|
+
readonly bounds: readonly RunnerSettingBound[];
|
|
58
|
+
readonly rejected: readonly RunnerSettingRejection[];
|
|
59
|
+
}
|
|
60
|
+
/** Today's bridge defaults for the keys whose default depends on the host. */
|
|
61
|
+
export interface RunnerHostDefaults {
|
|
62
|
+
/** floor(threads / 2) capped at 8 (at least 1). */
|
|
63
|
+
readonly maxConcurrentAttempts: number;
|
|
64
|
+
/** The adaptive reserve: 12.5% of RAM within 1–4 GiB, before FORGE_HOST_MEMORY_RESERVE_BYTES. */
|
|
65
|
+
readonly memoryReserveBytes: number;
|
|
66
|
+
}
|
|
67
|
+
export interface EffectiveRunnerSettings {
|
|
68
|
+
readonly report: RunnerSettingsReport;
|
|
69
|
+
/** Effective yield (server OR local flag). */
|
|
70
|
+
readonly yielding: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The governor CPU budget in force, as a fraction of logical CPUs: the CPU budget,
|
|
73
|
+
* or min(yield budget, CPU budget) while yielding.
|
|
74
|
+
*/
|
|
75
|
+
readonly governorCpuBudgetFraction: number;
|
|
76
|
+
}
|
|
77
|
+
export declare const defaultCpuBudgetPercent = 80;
|
|
78
|
+
export declare const defaultYieldCpuBudgetPercent = 50;
|
|
79
|
+
/**
|
|
80
|
+
* Computes every effective value (decision 0014 precedence):
|
|
81
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
82
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
83
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
84
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeEffectiveRunnerSettings(document: RunnerSettingsDocument | null, environment: Readonly<Record<string, string | undefined>>, hostDefaults: RunnerHostDefaults, localYield: boolean): EffectiveRunnerSettings;
|
|
87
|
+
/**
|
|
88
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
89
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseRunnerSettingsDocument(raw: unknown): RunnerSettingsDocument | null;
|
|
92
|
+
/**
|
|
93
|
+
* The report for what is actually in force after an apply in which the host
|
|
94
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
95
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
96
|
+
* rejection, so the server never reads a desired value as applied.
|
|
97
|
+
*/
|
|
98
|
+
export declare function runnerSettingsInForce(report: RunnerSettingsReport, previous: RunnerSettingsReport, failures: readonly RunnerSettingRejection[]): RunnerSettingsReport;
|
|
99
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
100
|
+
export declare function sameRunnerSettingsReport(left: RunnerSettingsReport, right: RunnerSettingsReport): boolean;
|