-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathclient-launch-options.test.js
More file actions
79 lines (67 loc) · 2.96 KB
/
Copy pathclient-launch-options.test.js
File metadata and controls
79 lines (67 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { buildLaunchOptions, resolvePhase2Headless } from "../src/client.js";
import { OFFSCREEN_POSITION_ARG } from "../src/browser-window.js";
describe("buildLaunchOptions off-screen positioning (issue #9)", () => {
it("positions the headed CF-solving bootstrap window off-screen", () => {
const opts = buildLaunchOptions(false);
expect(opts.headless).toBe(false);
expect(opts.args).toContain(OFFSCREEN_POSITION_ARG);
});
it("adds no positioning arg to headless launches (there is no window)", () => {
const opts = buildLaunchOptions(true);
expect(opts.headless).toBe(true);
expect(opts.args).not.toContain(OFFSCREEN_POSITION_ARG);
});
});
describe("resolvePhase2Headless (issue #12)", () => {
const ENV_KEYS = ["PERPLEXITY_PERSISTENT_HEADED", "DISPLAY", "WAYLAND_DISPLAY"];
let saved;
let realPlatform;
const setPlatform = (value) =>
Object.defineProperty(process, "platform", { value, configurable: true });
beforeEach(() => {
saved = Object.fromEntries(ENV_KEYS.map((k) => [k, process.env[k]]));
for (const k of ENV_KEYS) delete process.env[k];
realPlatform = process.platform;
});
afterEach(() => {
for (const [k, v] of Object.entries(saved)) {
if (v === undefined) delete process.env[k];
else process.env[k] = v;
}
setPlatform(realPlatform);
});
// The headed-offscreen DEFAULT shipped briefly for #12 and was reverted the
// same day: a long-lived headed window has a taskbar icon and ordinary
// window-manager events re-place it on-screen — users saw a permanent
// visible Chrome. Headed is opt-in now.
it("defaults to headless on every platform (visible-browser regression guard)", () => {
for (const platform of ["darwin", "win32", "linux"]) {
setPlatform(platform);
expect(resolvePhase2Headless(false)).toBe(true);
}
});
it("honours PERPLEXITY_HEADLESS_ONLY=1 (servers, airgapped, doctor probe)", () => {
setPlatform("darwin");
expect(resolvePhase2Headless(true)).toBe(true);
});
it("PERPLEXITY_PERSISTENT_HEADED=1 opts into headed-offscreen (the #12 mitigation)", () => {
setPlatform("win32");
process.env.PERPLEXITY_PERSISTENT_HEADED = "1";
expect(resolvePhase2Headless(false)).toBe(false);
expect(resolvePhase2Headless(true)).toBe(false); // explicit opt-in beats HEADLESS_ONLY
setPlatform("linux");
process.env.DISPLAY = ":0";
expect(resolvePhase2Headless(false)).toBe(false);
});
it("refuses the headed opt-in on display-less Linux — a dead daemon helps nobody", () => {
setPlatform("linux"); // no DISPLAY/WAYLAND_DISPLAY
process.env.PERPLEXITY_PERSISTENT_HEADED = "1";
expect(resolvePhase2Headless(false)).toBe(true);
});
it("PERPLEXITY_PERSISTENT_HEADED=0 still forces headless explicitly", () => {
setPlatform("darwin");
process.env.PERPLEXITY_PERSISTENT_HEADED = "0";
expect(resolvePhase2Headless(false)).toBe(true);
});
});