@parhelia/capture 0.0.0-stage → 0.4.12894

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 (65) hide show
  1. package/README.md +83 -2
  2. package/dist/browserHost.d.ts +19 -0
  3. package/dist/browserHost.d.ts.map +1 -0
  4. package/dist/browserHost.js +247 -0
  5. package/dist/browserHostLink.d.ts +50 -0
  6. package/dist/browserHostLink.d.ts.map +1 -0
  7. package/dist/browserHostLink.js +193 -0
  8. package/dist/browserHostProtocol.d.ts +61 -0
  9. package/dist/browserHostProtocol.d.ts.map +1 -0
  10. package/dist/browserHostProtocol.js +29 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +239 -0
  14. package/dist/cmsJob.d.ts +38 -0
  15. package/dist/cmsJob.d.ts.map +1 -0
  16. package/dist/cmsJob.js +218 -0
  17. package/dist/egressProxy.d.ts +59 -0
  18. package/dist/egressProxy.d.ts.map +1 -0
  19. package/dist/egressProxy.js +205 -0
  20. package/dist/index.d.ts +11 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +10 -0
  23. package/dist/install/doctor.d.ts +31 -0
  24. package/dist/install/doctor.d.ts.map +1 -0
  25. package/dist/install/doctor.js +189 -0
  26. package/dist/install/install.d.ts +72 -0
  27. package/dist/install/install.d.ts.map +1 -0
  28. package/dist/install/install.js +267 -0
  29. package/dist/install/layout.d.ts +81 -0
  30. package/dist/install/layout.d.ts.map +1 -0
  31. package/dist/install/layout.js +77 -0
  32. package/dist/install/services.d.ts +16 -0
  33. package/dist/install/services.d.ts.map +1 -0
  34. package/dist/install/services.js +94 -0
  35. package/dist/install/sys.d.ts +91 -0
  36. package/dist/install/sys.d.ts.map +1 -0
  37. package/dist/install/sys.js +260 -0
  38. package/dist/install/units.d.ts +57 -0
  39. package/dist/install/units.d.ts.map +1 -0
  40. package/dist/install/units.js +244 -0
  41. package/dist/install/updater.d.ts +66 -0
  42. package/dist/install/updater.d.ts.map +1 -0
  43. package/dist/install/updater.js +111 -0
  44. package/dist/install/versions.d.ts +61 -0
  45. package/dist/install/versions.d.ts.map +1 -0
  46. package/dist/install/versions.js +204 -0
  47. package/dist/isolation.d.ts +76 -0
  48. package/dist/isolation.d.ts.map +1 -0
  49. package/dist/isolation.js +163 -0
  50. package/dist/parheliaClient.d.ts +97 -0
  51. package/dist/parheliaClient.d.ts.map +1 -0
  52. package/dist/parheliaClient.js +111 -0
  53. package/dist/version.d.ts +13 -0
  54. package/dist/version.d.ts.map +1 -0
  55. package/dist/version.js +36 -0
  56. package/dist/webIsolation.d.ts +24 -0
  57. package/dist/webIsolation.d.ts.map +1 -0
  58. package/dist/webIsolation.js +112 -0
  59. package/dist/webJob.d.ts +56 -0
  60. package/dist/webJob.d.ts.map +1 -0
  61. package/dist/webJob.js +177 -0
  62. package/dist/worker.d.ts +53 -0
  63. package/dist/worker.d.ts.map +1 -0
  64. package/dist/worker.js +213 -0
  65. package/package.json +28 -4
@@ -0,0 +1,111 @@
1
+ import { CaptureUpdateError, browserOf, currentVersion, installRelease, pruneVersions, switchCurrent, } from "./versions.js";
2
+ export async function runUpdate(deps, options) {
3
+ const { sys, layout } = deps;
4
+ const log = deps.log ?? (() => undefined);
5
+ const current = currentVersion(sys, layout);
6
+ const finish = (status) => {
7
+ const written = { checkedUtc: new Date(sys.now()).toISOString(), ...status };
8
+ sys.writeFile(layout.updaterStatusFile, JSON.stringify(written, null, 2) + "\n", { mode: 0o644 });
9
+ log(`${written.result}${written.problems.length ? `: ${written.problems.join("; ")}` : ""}`);
10
+ return written;
11
+ };
12
+ let answer;
13
+ try {
14
+ answer = await deps.fetchManifest();
15
+ }
16
+ catch (error) {
17
+ return finish({ result: "unreachable", current, problems: [`The updater could not ask Parhelia for the wanted version: ${String(error)}`] });
18
+ }
19
+ const { manifest } = answer;
20
+ if (!answer.release)
21
+ return finish({ result: "no-release", current, policy: answer.updatePolicy, problems: [] });
22
+ const wanted = manifest.version;
23
+ if (current === wanted)
24
+ return finish({ result: "up-to-date", current, wanted, policy: answer.updatePolicy, problems: [] });
25
+ if (options.auto && answer.updatePolicy === "notify")
26
+ return finish({ result: "available", current, wanted, policy: answer.updatePolicy,
27
+ problems: [`Version ${wanted} is available; this worker's update policy is "notify": run 'parhelia-capture update' on it.`] });
28
+ // 1. Side by side, every hash checked.
29
+ let versionDir;
30
+ try {
31
+ versionDir = await installRelease(sys, layout, deps.config, manifest, { fromTarball: options.fromTarball, log });
32
+ }
33
+ catch (error) {
34
+ return finish({ result: "refused", current, wanted, policy: answer.updatePolicy, problems: [describe(error, "capture-update-install")] });
35
+ }
36
+ const discard = () => {
37
+ deps.firewall?.remove(wanted);
38
+ if (currentVersion(sys, layout) !== wanted)
39
+ sys.remove(versionDir);
40
+ };
41
+ // 2. Windows: the new browser path gets its rule, verified, before it runs at all (the self-test launches it).
42
+ const executable = browserOf(sys, layout, versionDir);
43
+ if (deps.firewall && executable && !deps.config.browserPath) {
44
+ try {
45
+ deps.firewall.install(wanted, executable);
46
+ const held = deps.firewall.verify(wanted, executable);
47
+ if (!held.ok)
48
+ throw new CaptureUpdateError("capture-update-firewall", `The firewall rule for the new browser does not hold: ${held.detail}`);
49
+ }
50
+ catch (error) {
51
+ discard();
52
+ return finish({ result: "refused", current, wanted, policy: answer.updatePolicy, problems: [describe(error, "capture-update-firewall")] });
53
+ }
54
+ }
55
+ // 3. The new version proves itself before anything switches.
56
+ const tested = await deps.selfTest(versionDir, wanted).catch((error) => ({ ok: false, detail: String(error) }));
57
+ if (!tested.ok) {
58
+ discard();
59
+ return finish({ result: "refused", current, wanted, policy: answer.updatePolicy,
60
+ problems: [`capture-update-self-test: version ${wanted} failed its self-test, ${current ?? "nothing"} stays: ${tested.detail}`] });
61
+ }
62
+ // 4. Between jobs: stop (the worker drains), switch, start, and wait for the new version's first good poll.
63
+ const switchedAt = sys.now();
64
+ deps.services.stop();
65
+ switchCurrent(sys, layout, wanted);
66
+ deps.services.start();
67
+ const healthy = await waitForPoll(deps, wanted, switchedAt);
68
+ if (!healthy.ok) {
69
+ deps.services.stop();
70
+ if (current)
71
+ switchCurrent(sys, layout, current);
72
+ deps.services.start();
73
+ discard();
74
+ return finish({ result: "rolled-back", current, wanted, policy: answer.updatePolicy,
75
+ problems: [`capture-update-rolled-back: version ${wanted} did not poll Parhelia after the switch (${healthy.detail}); ${current ?? "nothing"} runs again.`] });
76
+ }
77
+ // 5. Keep the previous version for a rollback by hand; remove older ones and their rules.
78
+ const removed = pruneVersions(sys, layout, current ? [current] : []);
79
+ for (const version of removed)
80
+ deps.firewall?.remove(version);
81
+ return finish({ result: "updated", current: wanted, wanted, policy: answer.updatePolicy, problems: [] });
82
+ }
83
+ async function waitForPoll(deps, version, since) {
84
+ const { sys, layout } = deps;
85
+ const until = sys.now() + (deps.healthTimeoutMs ?? 120_000);
86
+ let last = "no status yet";
87
+ while (sys.now() < until) {
88
+ const status = readJson(sys, layout.statusFile);
89
+ if (status) {
90
+ const polled = status.lastPollUtc ? Date.parse(status.lastPollUtc) : 0;
91
+ if (status.version === version && polled >= since && status.lastPollOk)
92
+ return { ok: true, detail: "polled" };
93
+ last = status.version !== version ? `the worker still reports ${status.version}` : status.lastPollError ?? "no good poll yet";
94
+ }
95
+ await sys.sleep(2_000);
96
+ }
97
+ return { ok: false, detail: last };
98
+ }
99
+ export function readJson(sys, file) {
100
+ try {
101
+ return JSON.parse(sys.readFile(file));
102
+ }
103
+ catch {
104
+ return undefined;
105
+ }
106
+ }
107
+ function describe(error, fallback) {
108
+ if (error instanceof CaptureUpdateError)
109
+ return `${error.code}: ${error.message}`;
110
+ return `${fallback}: ${error instanceof Error ? error.message : String(error)}`;
111
+ }
@@ -0,0 +1,61 @@
1
+ import { type InstalledConfig, type InstallRecord, type Layout } from "./layout.js";
2
+ import type { Sys } from "./sys.js";
3
+ /** The host's manifest as the worker protocol answers it (CaptureSidecarManifest). */
4
+ export type SidecarManifest = {
5
+ version: string;
6
+ integrity?: string | null;
7
+ tarball?: string | null;
8
+ securityMinimum?: string | null;
9
+ browserMaxAgeDays?: number | null;
10
+ browser?: {
11
+ revision: string;
12
+ releasedUtc?: string | null;
13
+ platforms: Record<string, {
14
+ url: string;
15
+ sha256: string;
16
+ executable: string;
17
+ }>;
18
+ } | null;
19
+ };
20
+ /** A refusal with a name: the updater reports it under Problems and keeps the old version. */
21
+ export declare class CaptureUpdateError extends Error {
22
+ readonly code: string;
23
+ constructor(code: string, message: string);
24
+ }
25
+ export declare const DEFAULT_REGISTRY = "https://registry.npmjs.org";
26
+ export declare function platformKey(sys: Pick<Sys, "platform">, arch?: string): string;
27
+ /** The tarball's URL: the manifest's, on the installation's registry when it names one (the integrity still decides). */
28
+ export declare function tarballUrl(manifest: SidecarManifest, registry?: string): string;
29
+ export declare function mirrored(url: string, mirror?: string): string;
30
+ export declare function readRecord(sys: Sys, versionDir: string): InstallRecord | undefined;
31
+ /** The version `current` points at, or undefined before the first install. */
32
+ export declare function currentVersion(sys: Sys, layout: Layout): string | undefined;
33
+ export declare function installedVersions(sys: Sys, layout: Layout): string[];
34
+ /**
35
+ * Stages and installs one released version from the host's manifest: tarball integrity, then `npm install` of that tarball with
36
+ * scripts off (its shrinkwrap pins every dependency's integrity), then the browser archive's SHA-256 and extraction. Answers the
37
+ * version directory. Throws {@link CaptureUpdateError} on any mismatch, leaving no trace of the attempt.
38
+ */
39
+ export declare function installRelease(sys: Sys, layout: Layout, config: Pick<InstalledConfig, "registry" | "browserMirror" | "browserPath">, manifest: SidecarManifest, options?: {
40
+ fromTarball?: string;
41
+ arch?: string;
42
+ log?: (line: string) => void;
43
+ }): Promise<string>;
44
+ /**
45
+ * A source build (the host names no release): the running package and its playwright-core are copied, and the browser comes from
46
+ * playwright-core's own download (no host hash: stated as unchecked in the record and by `status`).
47
+ */
48
+ export declare function installDev(sys: Sys, layout: Layout, input: {
49
+ packageDir: string;
50
+ playwrightDir: string;
51
+ version: string;
52
+ browserPath?: string;
53
+ browserRevision?: string;
54
+ }): string;
55
+ /** Points `current` at a version: Linux atomically (a new link renamed over the old), Windows by replacing the junction. */
56
+ export declare function switchCurrent(sys: Sys, layout: Layout, version: string): void;
57
+ /** Keeps `current` and `keep` (the previous version, for a rollback); answers the versions removed. */
58
+ export declare function pruneVersions(sys: Sys, layout: Layout, keep: readonly string[]): string[];
59
+ /** The browser executable of an installed version (absolute). */
60
+ export declare function browserOf(sys: Sys, layout: Layout, versionDir: string): string | undefined;
61
+ //# sourceMappingURL=versions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../src/install/versions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAiB,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,sFAAsF;AACtF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAChF,GAAG,IAAI,CAAC;CACV,CAAC;AAEF,8FAA8F;AAC9F,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAjC,YAAqB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAGjD;CACF;AAED,eAAO,MAAM,gBAAgB,+BAA+B,CAAC;AAE7D,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,IAAI,GAAE,MAAqB,GAAG,MAAM,CAE3F;AAED,yHAAyH;AACzH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAO/E;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAI7D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAMlF;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI3E;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpE;AAMD;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,eAAe,GAAG,aAAa,CAAC,EACxI,QAAQ,EAAE,eAAe,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA2EjI;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IACvH,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAwB1D;AAED,4HAA4H;AAC5H,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAY7E;AAED,uGAAuG;AACvG,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAOzF;AAED,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1F"}
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Capture sidecar CS6 (plan CS-D14): installed versions, side by side. A version is staged beside the others, from the tarball
3
+ * whose integrity the host's manifest names and the browser archive whose SHA-256 it names; nothing is used before both match.
4
+ * The `current` link switches atomically (Linux: a new link renamed over the old one); the previous version stays for a rollback,
5
+ * older ones go. The version directories and the link belong to root (Windows: Administrators/SYSTEM) and are read-only to the
6
+ * service users.
7
+ */
8
+ import path from "node:path";
9
+ import { PACKAGE_ENTRY } from "./layout.js";
10
+ /** A refusal with a name: the updater reports it under Problems and keeps the old version. */
11
+ export class CaptureUpdateError extends Error {
12
+ code;
13
+ constructor(code, message) {
14
+ super(message);
15
+ this.code = code;
16
+ this.name = "CaptureUpdateError";
17
+ }
18
+ }
19
+ export const DEFAULT_REGISTRY = "https://registry.npmjs.org";
20
+ export function platformKey(sys, arch = process.arch) {
21
+ return `${sys.platform === "win32" ? "win" : sys.platform}-${arch}`;
22
+ }
23
+ /** The tarball's URL: the manifest's, on the installation's registry when it names one (the integrity still decides). */
24
+ export function tarballUrl(manifest, registry) {
25
+ const base = (registry ?? DEFAULT_REGISTRY).replace(/\/+$/, "");
26
+ if (manifest.tarball) {
27
+ const named = new URL(manifest.tarball);
28
+ return registry ? base + named.pathname : named.toString();
29
+ }
30
+ return `${base}/@parhelia/capture/-/capture-${manifest.version}.tgz`;
31
+ }
32
+ export function mirrored(url, mirror) {
33
+ if (!mirror)
34
+ return url;
35
+ const original = new URL(url);
36
+ return mirror.replace(/\/+$/, "") + original.pathname;
37
+ }
38
+ export function readRecord(sys, versionDir) {
39
+ try {
40
+ return JSON.parse(sys.readFile(path.join(versionDir, "install.json")));
41
+ }
42
+ catch {
43
+ return undefined;
44
+ }
45
+ }
46
+ /** The version `current` points at, or undefined before the first install. */
47
+ export function currentVersion(sys, layout) {
48
+ const target = sys.readLink(layout.currentLink);
49
+ if (!target)
50
+ return undefined;
51
+ return (layout.platform === "win32" ? path.win32 : path.posix).basename(target);
52
+ }
53
+ export function installedVersions(sys, layout) {
54
+ return sys.list(layout.versionsDir).filter((name) => name !== "current" && !name.startsWith(".") && sys.exists(layout.join(layout.versionsDir, name, "install.json")));
55
+ }
56
+ function ownCode(sys, layout, dir) {
57
+ if (layout.platform === "linux")
58
+ sys.chown(dir, "root", "root", { recursive: true });
59
+ }
60
+ /**
61
+ * Stages and installs one released version from the host's manifest: tarball integrity, then `npm install` of that tarball with
62
+ * scripts off (its shrinkwrap pins every dependency's integrity), then the browser archive's SHA-256 and extraction. Answers the
63
+ * version directory. Throws {@link CaptureUpdateError} on any mismatch, leaving no trace of the attempt.
64
+ */
65
+ export async function installRelease(sys, layout, config, manifest, options = {}) {
66
+ const log = options.log ?? (() => undefined);
67
+ if (!manifest.integrity)
68
+ throw new CaptureUpdateError("capture-update-unnamed", `The host names version ${manifest.version} without an integrity hash; nothing is installed.`);
69
+ const target = layout.join(layout.versionsDir, manifest.version);
70
+ if (readRecord(sys, target)?.version === manifest.version)
71
+ return target;
72
+ const work = sys.tempDir("parhelia-capture-update-");
73
+ const staging = layout.join(layout.versionsDir, `.staging-${manifest.version}`);
74
+ try {
75
+ // 1. The tarball, checked against the host's hash before npm sees it.
76
+ const tarball = options.fromTarball ?? layout.join(work, `capture-${manifest.version}.tgz`);
77
+ if (!options.fromTarball) {
78
+ const url = tarballUrl(manifest, config.registry);
79
+ log(`Downloading ${url}`);
80
+ await sys.download(url, tarball);
81
+ }
82
+ const algorithm = manifest.integrity.split("-")[0] || "sha512";
83
+ const actual = sys.integrity(tarball, algorithm);
84
+ if (actual !== manifest.integrity)
85
+ throw new CaptureUpdateError("capture-update-integrity", `The sidecar tarball for ${manifest.version} does not match the host's hash (got ${actual.slice(0, 24)}…); nothing is installed.`);
86
+ // 2. Its install, scripts off; the package's shrinkwrap pins its dependencies.
87
+ sys.remove(staging);
88
+ sys.mkdir(staging, { mode: 0o755 });
89
+ const npm = sys.platform === "win32" ? "npm.cmd" : "npm";
90
+ const installed = sys.exec(npm, ["install", "--prefix", staging, "--ignore-scripts", "--omit=dev", "--no-audit", "--no-fund", "--no-save",
91
+ ...(config.registry ? ["--registry", config.registry] : []), tarball]);
92
+ if (installed.status !== 0)
93
+ throw new CaptureUpdateError("capture-update-install", `npm could not install ${manifest.version}: ${installed.stderr.trim().split("\n").slice(-3).join(" ")}`);
94
+ const packageJson = layout.join(staging, "node_modules", "@parhelia", "capture", "package.json");
95
+ const stagedVersion = sys.exists(packageJson) ? JSON.parse(sys.readFile(packageJson)).version : undefined;
96
+ if (stagedVersion !== manifest.version || !sys.exists(layout.join(staging, ...PACKAGE_ENTRY.split("/"))))
97
+ throw new CaptureUpdateError("capture-update-install", `The installed package is ${stagedVersion ?? "missing"}, not ${manifest.version}.`);
98
+ // 3. The browser archive, checked against the host's hash, then extracted.
99
+ let browserExecutable;
100
+ if (!config.browserPath) {
101
+ const key = platformKey(sys, options.arch);
102
+ const archive = manifest.browser?.platforms[key];
103
+ if (!archive)
104
+ throw new CaptureUpdateError("capture-update-unnamed", `The host names no browser for ${key}; nothing is installed.`);
105
+ const zip = layout.join(work, "browser.zip");
106
+ const url = mirrored(archive.url, config.browserMirror);
107
+ log(`Downloading ${url}`);
108
+ await sys.download(url, zip);
109
+ const sha = sys.sha256(zip);
110
+ if (sha !== archive.sha256.toLowerCase())
111
+ throw new CaptureUpdateError("capture-update-integrity", `The browser archive for ${manifest.version} does not match the host's SHA-256 (got ${sha.slice(0, 16)}…); nothing is installed.`);
112
+ const browserDir = layout.join(staging, "browser");
113
+ sys.mkdir(browserDir, { mode: 0o755 });
114
+ const extracted = sys.platform === "win32"
115
+ ? sys.exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command",
116
+ `Expand-Archive -LiteralPath '${zip.replace(/'/g, "''")}' -DestinationPath '${browserDir.replace(/'/g, "''")}' -Force`])
117
+ : sys.exec("unzip", ["-q", "-o", zip, "-d", browserDir]);
118
+ if (extracted.status !== 0)
119
+ throw new CaptureUpdateError("capture-update-install", `The browser archive did not extract: ${extracted.stderr.trim()}`);
120
+ browserExecutable = ["browser", ...archive.executable.split("/")].join(sys.platform === "win32" ? "\\" : "/");
121
+ if (!sys.exists(layout.join(staging, browserExecutable)))
122
+ throw new CaptureUpdateError("capture-update-install", `The browser archive holds no ${archive.executable}.`);
123
+ }
124
+ const record = {
125
+ version: manifest.version, source: "release", browserRevision: manifest.browser?.revision,
126
+ browserReleasedUtc: manifest.browser?.releasedUtc ?? undefined, browserExecutable: config.browserPath ?? browserExecutable,
127
+ installedUtc: new Date(sys.now()).toISOString(), entry: PACKAGE_ENTRY,
128
+ };
129
+ sys.writeFile(layout.join(staging, "install.json"), JSON.stringify(record, null, 2) + "\n", { mode: 0o644 });
130
+ ownCode(sys, layout, staging);
131
+ sys.remove(target);
132
+ sys.rename(staging, target);
133
+ return target;
134
+ }
135
+ catch (error) {
136
+ sys.remove(staging);
137
+ throw error;
138
+ }
139
+ finally {
140
+ sys.remove(work);
141
+ }
142
+ }
143
+ /**
144
+ * A source build (the host names no release): the running package and its playwright-core are copied, and the browser comes from
145
+ * playwright-core's own download (no host hash: stated as unchecked in the record and by `status`).
146
+ */
147
+ export function installDev(sys, layout, input) {
148
+ const version = input.version === "dev" ? `0.0.0-dev.${new Date(sys.now()).toISOString().replace(/[-:T]/g, "").slice(0, 12)}` : input.version;
149
+ const target = layout.join(layout.versionsDir, version);
150
+ const staging = layout.join(layout.versionsDir, `.staging-${version}`);
151
+ sys.remove(staging);
152
+ sys.mkdir(staging, { mode: 0o755 });
153
+ sys.copyDir(input.packageDir, layout.join(staging, "node_modules", "@parhelia", "capture"));
154
+ sys.copyDir(input.playwrightDir, layout.join(staging, "node_modules", "playwright-core"));
155
+ let browserExecutable = input.browserPath;
156
+ if (!browserExecutable) {
157
+ const browsers = layout.join(staging, "browsers");
158
+ const fetched = sys.exec(sys.nodePath, [layout.join(staging, "node_modules", "playwright-core", "cli.js"), "install", "chromium-headless-shell"], { env: { PLAYWRIGHT_BROWSERS_PATH: browsers } });
159
+ if (fetched.status !== 0)
160
+ throw new CaptureUpdateError("capture-install-browser", `The browser download failed: ${fetched.stderr.trim()}`);
161
+ const shell = sys.platform === "win32" ? ["chrome-headless-shell-win64", "chrome-headless-shell.exe"] : ["chrome-headless-shell-linux64", "chrome-headless-shell"];
162
+ browserExecutable = ["browsers", `chromium_headless_shell-${input.browserRevision ?? "unknown"}`, ...shell].join(sys.platform === "win32" ? "\\" : "/");
163
+ }
164
+ const record = { version, source: "dev", browserRevision: input.browserRevision, browserExecutable,
165
+ installedUtc: new Date(sys.now()).toISOString(), entry: PACKAGE_ENTRY };
166
+ sys.writeFile(layout.join(staging, "install.json"), JSON.stringify(record, null, 2) + "\n", { mode: 0o644 });
167
+ ownCode(sys, layout, staging);
168
+ sys.remove(target);
169
+ sys.rename(staging, target);
170
+ return target;
171
+ }
172
+ /** Points `current` at a version: Linux atomically (a new link renamed over the old), Windows by replacing the junction. */
173
+ export function switchCurrent(sys, layout, version) {
174
+ const target = layout.join(layout.versionsDir, version);
175
+ if (!sys.exists(layout.join(target, "install.json")))
176
+ throw new CaptureUpdateError("capture-update-switch", `Version ${version} is not installed.`);
177
+ if (layout.platform === "linux") {
178
+ const next = layout.join(layout.versionsDir, `.current-${version}`);
179
+ sys.remove(next);
180
+ sys.link(version, next);
181
+ sys.rename(next, layout.currentLink);
182
+ return;
183
+ }
184
+ sys.remove(layout.currentLink);
185
+ sys.link(target, layout.currentLink);
186
+ }
187
+ /** Keeps `current` and `keep` (the previous version, for a rollback); answers the versions removed. */
188
+ export function pruneVersions(sys, layout, keep) {
189
+ const current = currentVersion(sys, layout);
190
+ const removed = installedVersions(sys, layout).filter((version) => version !== current && !keep.includes(version));
191
+ for (const version of removed)
192
+ sys.remove(layout.join(layout.versionsDir, version));
193
+ for (const leftover of sys.list(layout.versionsDir).filter((name) => name.startsWith(".staging-") || name.startsWith(".current-")))
194
+ sys.remove(layout.join(layout.versionsDir, leftover));
195
+ return removed;
196
+ }
197
+ /** The browser executable of an installed version (absolute). */
198
+ export function browserOf(sys, layout, versionDir) {
199
+ const record = readRecord(sys, versionDir);
200
+ if (!record?.browserExecutable)
201
+ return undefined;
202
+ const join = layout.platform === "win32" ? path.win32 : path.posix;
203
+ return join.isAbsolute(record.browserExecutable) ? record.browserExecutable : join.join(versionDir, record.browserExecutable);
204
+ }
@@ -0,0 +1,76 @@
1
+ import type { SelfTestObservations } from "./browserHostProtocol.js";
2
+ /** Where sockets live; each that exists gets an empty tmpfs in the browser host's view. */
3
+ export declare const HIDDEN_TREES: readonly ["/run", "/var", "/srv", "/opt", "/mnt", "/media"];
4
+ export type UnitOptions = {
5
+ socketDir: string;
6
+ /** The pinned sidecar build and the browser build, mapped read-only. */
7
+ readOnlyPaths: readonly string[];
8
+ /** Directories outside the hidden trees that hold a Unix socket ({@link socketDirectoriesOutsideHiddenTrees}). */
9
+ inaccessiblePaths?: readonly string[];
10
+ /** `PrivateUsers=yes` for a user unit (`systemd-run --user`); a system unit runs as its own user instead. */
11
+ userUnit?: boolean;
12
+ user?: string;
13
+ environment?: Record<string, string>;
14
+ exists?: (path: string) => boolean;
15
+ };
16
+ /** The browser host unit's properties (`Key=Value`), as `systemd-run -p` takes them and a unit file's [Service] holds them. */
17
+ export declare function browserHostUnitProperties(options: UnitOptions): string[];
18
+ /** Directories holding a Unix socket that the hidden trees do not cover (amendment A7: `/etc/pacman.d/gnupg` on Arch). */
19
+ export declare function socketDirectoriesOutsideHiddenTrees(root?: string, skip?: readonly string[]): string[];
20
+ /** This machine's own addresses (every interface, loopback included). */
21
+ export declare function ownAddresses(): string[];
22
+ /** Whether Parhelia runs on this machine (its origin resolves to a loopback address or one of the machine's own). */
23
+ export declare function parheliaIsColocated(parheliaAddresses: readonly string[], own: readonly string[]): boolean;
24
+ /**
25
+ * Why `public-web` cannot run here before any test, or undefined. On Windows, loopback (and so the machine's own LAN
26
+ * addresses) is unfiltered: a browser bypassing the proxy would reach Parhelia on the same machine, so that is refused by
27
+ * name. Elsewhere a co-located Parhelia is no remote probe; another host must be named.
28
+ */
29
+ export declare function webPreconditionRefusal(input: {
30
+ platform: string;
31
+ colocated: boolean;
32
+ probeUrl?: string;
33
+ }): {
34
+ code: string;
35
+ message: string;
36
+ } | undefined;
37
+ export type IsolationCheck = {
38
+ name: string;
39
+ ok: boolean;
40
+ detail: string;
41
+ };
42
+ export type IsolationReport = {
43
+ ok: boolean;
44
+ code?: string;
45
+ reason?: string;
46
+ checks: IsolationCheck[];
47
+ };
48
+ export type IsolationEvidence = {
49
+ platform: string;
50
+ /** What the unrestricted worker fetched (the positive control): the marker each probe must show to count as reached. */
51
+ remote: {
52
+ url: string;
53
+ marker: string;
54
+ controlOk: boolean;
55
+ controlDetail?: string;
56
+ };
57
+ local: {
58
+ url: string;
59
+ marker: string;
60
+ controlOk: boolean;
61
+ controlDetail?: string;
62
+ };
63
+ /** The Parhelia probe through the proxy (layer 2), when Parhelia is the remote probe. */
64
+ parheliaThroughProxy?: {
65
+ url: string;
66
+ marker: string;
67
+ };
68
+ publicUrl?: string;
69
+ observations: SelfTestObservations;
70
+ socketDir: string;
71
+ };
72
+ /** The verdict on the evidence (plan §8 "Verification that proves enforcement"); every check names what it saw. */
73
+ export declare function judgeIsolation(evidence: IsolationEvidence): IsolationReport;
74
+ /** Whether a path is a directory this process can see (used by the CLI before writing unit properties). */
75
+ export declare function isDirectory(path: string): boolean;
76
+ //# sourceMappingURL=isolation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolation.d.ts","sourceRoot":"","sources":["../src/isolation.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEvF,2FAA2F;AAC3F,eAAO,MAAM,YAAY,YAAI,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAKxF,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,kHAAkH;IAClH,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,6GAA6G;IAC7G,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,CAAC;AAEF,+HAA+H;AAC/H,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE,CAwBxE;AAED,0HAA0H;AAC1H,wBAAgB,mCAAmC,CAAC,IAAI,SAAM,EAAE,IAAI,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,EAAE,CAoBtG;AAED,yEAAyE;AACzE,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAID,qHAAqH;AACrH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAGzG;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAQxJ;AAED,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3E,MAAM,MAAM,eAAe,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC;AAExG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,wHAAwH;IACxH,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpF,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,yFAAyF;IACzF,oBAAoB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,oBAAoB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,mHAAmH;AACnH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,eAAe,CAiD3E;AAUD,2GAA2G;AAC3G,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMjD"}
@@ -0,0 +1,163 @@
1
+ /*
2
+ * Capture sidecar CS5w (plan §8, CS0 amendments A5-A7): what keeps the browser off the network, and how the worker proves it.
3
+ *
4
+ * Linux: the browser host runs in a systemd unit with its own network namespace (`PrivateNetwork=yes`) and an empty view of
5
+ * every tree sockets live in; only its socket directory is put back. `TemporaryFileSystem=` lists only directories that
6
+ * exist (A6: one missing path fails the unit), and every other directory holding a Unix socket becomes `InaccessiblePaths=`
7
+ * (A7). Windows: an outbound block rule bound to the browser's path (CS6 installs it); loopback is unfiltered there, so a
8
+ * sidecar on the machine that runs Parhelia refuses `public-web` by name.
9
+ *
10
+ * The judgement only ever passes on a positive signal: the unrestricted worker fetched each nonce, and the restricted
11
+ * browser did not. "Nothing listens" can never produce a green.
12
+ */
13
+ import { existsSync, readdirSync, statSync } from "node:fs";
14
+ import { networkInterfaces } from "node:os";
15
+ import { dirname } from "node:path";
16
+ /** Where sockets live; each that exists gets an empty tmpfs in the browser host's view. */
17
+ export const HIDDEN_TREES = ["/run", "/var", "/srv", "/opt", "/mnt", "/media"];
18
+ /** Trees the unit hides by other means, or that hold no sockets worth walking (pseudo filesystems, the OS image). */
19
+ const NOT_WALKED = ["/proc", "/sys", "/dev", "/usr", "/home", "/root", "/tmp", "/var/tmp", "/boot", "/lost+found"];
20
+ /** The browser host unit's properties (`Key=Value`), as `systemd-run -p` takes them and a unit file's [Service] holds them. */
21
+ export function browserHostUnitProperties(options) {
22
+ const exists = options.exists ?? ((path) => existsSync(path));
23
+ const hidden = HIDDEN_TREES.filter((tree) => exists(tree));
24
+ const properties = [
25
+ "PrivateNetwork=yes",
26
+ "PrivateIPC=yes",
27
+ "PrivateTmp=yes",
28
+ "PrivateDevices=yes",
29
+ "ProtectSystem=strict",
30
+ "ProtectHome=tmpfs",
31
+ "ProtectKernelTunables=yes",
32
+ "ProtectKernelModules=yes",
33
+ "ProtectControlGroups=yes",
34
+ "RestrictNamespaces=no", // Chromium's sandbox needs user namespaces (A5, A10).
35
+ "NoNewPrivileges=yes",
36
+ `TemporaryFileSystem=${hidden.join(" ")}`,
37
+ `BindPaths=${options.socketDir}`,
38
+ ...options.readOnlyPaths.map((path) => `BindReadOnlyPaths=${path}`),
39
+ ...(options.inaccessiblePaths ?? []).map((path) => `InaccessiblePaths=-${path}`),
40
+ ];
41
+ if (options.userUnit)
42
+ properties.unshift("PrivateUsers=yes");
43
+ if (options.user)
44
+ properties.push(`User=${options.user}`, "SupplementaryGroups=");
45
+ for (const [name, value] of Object.entries(options.environment ?? {}))
46
+ properties.push(`Environment=${name}=${value}`);
47
+ return properties;
48
+ }
49
+ /** Directories holding a Unix socket that the hidden trees do not cover (amendment A7: `/etc/pacman.d/gnupg` on Arch). */
50
+ export function socketDirectoriesOutsideHiddenTrees(root = "/", skip = []) {
51
+ const excluded = new Set([...NOT_WALKED, ...HIDDEN_TREES, ...skip].map((path) => (root === "/" ? path : root + path)));
52
+ const found = new Set();
53
+ const walk = (dir, depth) => {
54
+ if (depth > 14)
55
+ return;
56
+ let entries;
57
+ try {
58
+ entries = readdirSync(dir, { withFileTypes: true });
59
+ }
60
+ catch {
61
+ return;
62
+ }
63
+ for (const entry of entries) {
64
+ const path = (dir === "/" ? "" : dir) + "/" + entry.name;
65
+ if (excluded.has(path))
66
+ continue;
67
+ if (entry.isSocket())
68
+ found.add(dirname(path));
69
+ else if (entry.isDirectory() && !entry.isSymbolicLink())
70
+ walk(path, depth + 1);
71
+ }
72
+ };
73
+ walk(root, 0);
74
+ return [...found].sort();
75
+ }
76
+ /** This machine's own addresses (every interface, loopback included). */
77
+ export function ownAddresses() {
78
+ return Object.values(networkInterfaces()).flatMap((entries) => (entries ?? []).map((entry) => entry.address.replace(/%.*$/, "")));
79
+ }
80
+ const isLoopback = (address) => /^127\./.test(address) || address === "::1" || address === "::ffff:127.0.0.1";
81
+ /** Whether Parhelia runs on this machine (its origin resolves to a loopback address or one of the machine's own). */
82
+ export function parheliaIsColocated(parheliaAddresses, own) {
83
+ const mine = new Set(own.map((address) => address.toLowerCase()));
84
+ return parheliaAddresses.some((address) => isLoopback(address) || mine.has(address.toLowerCase().replace(/^::ffff:/, "")));
85
+ }
86
+ /**
87
+ * Why `public-web` cannot run here before any test, or undefined. On Windows, loopback (and so the machine's own LAN
88
+ * addresses) is unfiltered: a browser bypassing the proxy would reach Parhelia on the same machine, so that is refused by
89
+ * name. Elsewhere a co-located Parhelia is no remote probe; another host must be named.
90
+ */
91
+ export function webPreconditionRefusal(input) {
92
+ if (input.platform === "win32" && input.colocated)
93
+ return { code: "capture-web-colocated", message: "Screenshots of public websites are refused on a Windows machine that also runs Parhelia: loopback traffic is not filtered there, so the browser could reach Parhelia directly. Run the capture service on another machine." };
94
+ if (input.colocated && !input.probeUrl)
95
+ return { code: "capture-web-unproven", message: "Egress isolation cannot be proven here: Parhelia runs on this machine, so it is no remote probe. Name an endpoint on another host with --probe-url." };
96
+ if (input.platform !== "linux" && input.platform !== "win32")
97
+ return { code: "capture-web-unsupported-os", message: `Screenshots of public websites need the browser host's OS isolation, which this sidecar provides on Linux and Windows only (this is ${input.platform}).` };
98
+ return undefined;
99
+ }
100
+ const reached = (probe, marker) => !!probe?.text && marker.length > 0 && probe.text.includes(marker);
101
+ /** The verdict on the evidence (plan §8 "Verification that proves enforcement"); every check names what it saw. */
102
+ export function judgeIsolation(evidence) {
103
+ const checks = [];
104
+ const probe = (name) => evidence.observations.probes.find((entry) => entry.name === name);
105
+ const describe = (entry) => !entry ? "not tried" : entry.error ? `error: ${entry.error}` : `answered ${entry.status ?? "?"}`;
106
+ checks.push({ name: "positive control (remote)", ok: evidence.remote.controlOk,
107
+ detail: evidence.remote.controlOk ? `the worker fetched the nonce from ${hostOf(evidence.remote.url)}` : `the worker itself could not fetch the remote probe: ${evidence.remote.controlDetail ?? "no nonce"}` });
108
+ checks.push({ name: "positive control (local)", ok: evidence.local.controlOk,
109
+ detail: evidence.local.controlOk ? "the worker fetched the loopback nonce" : `the worker could not fetch its own loopback probe: ${evidence.local.controlDetail ?? "no nonce"}` });
110
+ const remote = probe("remote-direct");
111
+ checks.push({ name: "browser, proxy off: remote", ok: !reached(remote, evidence.remote.marker),
112
+ detail: reached(remote, evidence.remote.marker) ? `the browser reached ${hostOf(evidence.remote.url)} by itself: the OS isolation is not in place` : describe(remote) });
113
+ const local = probe("local-direct");
114
+ if (evidence.platform === "win32") {
115
+ checks.push({ name: "browser, proxy off: loopback", ok: true,
116
+ detail: reached(local, evidence.local.marker) ? "reachable: loopback is unfiltered on Windows (the stated residual)" : describe(local) });
117
+ }
118
+ else {
119
+ checks.push({ name: "browser, proxy off: loopback", ok: !reached(local, evidence.local.marker),
120
+ detail: reached(local, evidence.local.marker) ? "the browser reached this machine's loopback by itself: the network namespace is not in place" : describe(local) });
121
+ }
122
+ if (evidence.platform === "linux") {
123
+ const own = evidence.socketDir.replace(/\/+$/, "");
124
+ const foreign = evidence.observations.socketsVisible.filter((path) => !path.startsWith(own + "/"));
125
+ checks.push({ name: "sockets in the browser host's view", ok: foreign.length === 0,
126
+ detail: foreign.length === 0 ? "only the egress/job directory" : `visible: ${foreign.slice(0, 8).join(", ")}${foreign.length > 8 ? ", …" : ""}` });
127
+ checks.push({ name: "D-Bus", ok: evidence.observations.dbus !== "CONNECTED", detail: evidence.observations.dbus });
128
+ }
129
+ checks.push({ name: "Chromium sandbox", ok: evidence.observations.noSandboxFlag !== true,
130
+ detail: evidence.observations.noSandboxFlag === true ? "a Chromium process runs with --no-sandbox" : evidence.observations.noSandboxFlag === null ? "not observable here" : "on" });
131
+ if (evidence.parheliaThroughProxy) {
132
+ const entry = probe("parhelia-proxied");
133
+ checks.push({ name: "proxy on: Parhelia's address", ok: !reached(entry, evidence.parheliaThroughProxy.marker),
134
+ detail: reached(entry, evidence.parheliaThroughProxy.marker) ? "the proxy let the browser reach Parhelia" : `refused (${describe(entry)})` });
135
+ }
136
+ if (evidence.publicUrl) {
137
+ const entry = probe("public-proxied");
138
+ const ok = !!entry && !entry.error && (entry.status ?? 0) > 0 && (entry.status ?? 0) < 400;
139
+ checks.push({ name: "proxy on: a public page", ok, detail: `${hostOf(evidence.publicUrl)}: ${describe(entry)}` });
140
+ }
141
+ const failed = checks.filter((check) => !check.ok);
142
+ if (failed.length === 0)
143
+ return { ok: true, checks };
144
+ return { ok: false, code: "capture-web-isolation-unproven",
145
+ reason: `Screenshots of public websites stay off: ${failed.map((check) => `${check.name} (${check.detail})`).join("; ")}.`, checks };
146
+ }
147
+ function hostOf(url) {
148
+ try {
149
+ return new URL(url).host;
150
+ }
151
+ catch {
152
+ return url;
153
+ }
154
+ }
155
+ /** Whether a path is a directory this process can see (used by the CLI before writing unit properties). */
156
+ export function isDirectory(path) {
157
+ try {
158
+ return statSync(path).isDirectory();
159
+ }
160
+ catch {
161
+ return false;
162
+ }
163
+ }