Skip to content

Commit 4dd0790

Browse files
author
Peter Steinberger
committed
test(ui): preserve bundled E2E gateway semantics
1 parent 0297d4b commit 4dd0790

10 files changed

Lines changed: 96 additions & 65 deletions

‎ui/src/e2e/appearance-settings-defaults.e2e.test.ts‎

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { afterAll, beforeAll, describe, expect, it } from "vitest";
66
import { importCustomThemeFromUrl } from "../app/custom-theme.ts";
77
import {
88
canRunPlaywrightChromium,
9+
controlUiBundledGatewayUrl,
10+
controlUiBundledSettingsStorageKey,
911
installMockGateway,
1012
resolvePlaywrightChromiumExecutablePath,
1113
startControlUiE2eServer,
@@ -27,11 +29,13 @@ const uiProofArtifactDir = path.join(
2729
"control-ui-e2e",
2830
"appearance-settings-defaults",
2931
);
30-
const settingsStorageKey = "openclaw.control.settings.v1:ws://127.0.0.1:18789";
31-
3232
let browser: Browser;
3333
let server: ControlUiE2eServer;
3434

35+
function settingsStorageKey(): string {
36+
return controlUiBundledSettingsStorageKey(server.baseUrl);
37+
}
38+
3539
function configResponse(prefs: Record<string, unknown>, hash: string) {
3640
const config = { ui: { prefs } };
3741
return {
@@ -110,7 +114,7 @@ async function readPersistedSettings(page: Page): Promise<Record<string, unknown
110114
return page.evaluate((key) => {
111115
const raw = localStorage.getItem(key);
112116
return raw ? (JSON.parse(raw) as Record<string, unknown>) : {};
113-
}, settingsStorageKey);
117+
}, settingsStorageKey());
114118
}
115119

116120
async function readThemeImportRaceState(page: Page) {
@@ -169,20 +173,23 @@ describeControlUiE2e("Control UI Appearance defaults mocked Gateway E2E", () =>
169173
serviceWorkers: "block",
170174
viewport: { height: 1000, width: 1440 },
171175
});
172-
await context.addInitScript((key) => {
173-
const seedKey = "openclaw.control-ui-e2e.appearance-defaults-seeded";
174-
if (sessionStorage.getItem(seedKey) === "1") {
175-
return;
176-
}
177-
sessionStorage.setItem(seedKey, "1");
178-
localStorage.setItem(
179-
key,
180-
JSON.stringify({
181-
gatewayUrl: "ws://127.0.0.1:18789",
182-
textScale: 110,
183-
}),
184-
);
185-
}, settingsStorageKey);
176+
await context.addInitScript(
177+
({ gatewayUrl, key }) => {
178+
const seedKey = "openclaw.control-ui-e2e.appearance-defaults-seeded";
179+
if (sessionStorage.getItem(seedKey) === "1") {
180+
return;
181+
}
182+
sessionStorage.setItem(seedKey, "1");
183+
localStorage.setItem(
184+
key,
185+
JSON.stringify({
186+
gatewayUrl,
187+
textScale: 110,
188+
}),
189+
);
190+
},
191+
{ gatewayUrl: controlUiBundledGatewayUrl(server.baseUrl), key: settingsStorageKey() },
192+
);
186193
const page = await context.newPage();
187194
const initialPrefs: Record<string, unknown> = {
188195
chatSendShortcut: "modifier-enter",
@@ -501,17 +508,21 @@ describeControlUiE2e("Control UI Appearance defaults mocked Gateway E2E", () =>
501508
viewport: { height: 1000, width: 1440 },
502509
});
503510
await context.addInitScript(
504-
({ key, theme }) => {
511+
({ gatewayUrl, key, theme }) => {
505512
localStorage.setItem(
506513
key,
507514
JSON.stringify({
508515
customTheme: theme,
509-
gatewayUrl: "ws://127.0.0.1:18789",
516+
gatewayUrl,
510517
theme: "custom",
511518
}),
512519
);
513520
},
514-
{ key: settingsStorageKey, theme: existingTheme },
521+
{
522+
gatewayUrl: controlUiBundledGatewayUrl(server.baseUrl),
523+
key: settingsStorageKey(),
524+
theme: existingTheme,
525+
},
515526
);
516527
const page = await context.newPage();
517528
const gateway = await installMockGateway(page, {

‎ui/src/e2e/approval-page.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ describeControlUiE2e("Control UI standalone approval page", () => {
431431
const appUrl = new URL(server?.baseUrl ?? "http://127.0.0.1/");
432432
const pageGatewayScope = `ws://${appUrl.host}`;
433433
const selectionKey = `openclaw.control.currentGateway.v1:${pageGatewayScope}`;
434-
const pageGateway = `ws://${appUrl.hostname}:18789`;
434+
const pageGateway = pageGatewayScope;
435435
const pageSettingsKey = `openclaw.control.settings.v1:${pageGateway}`;
436436
const pageSettings = JSON.stringify({
437437
gatewayUrl: pageGateway,

‎ui/src/e2e/board-mcp-app.e2e.test.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createSandboxHostHttpServer } from "../../../src/gateway/mcp-app-sandbo
66
import { getFreeGatewayPort } from "../../../src/gateway/test-helpers.e2e.js";
77
import {
88
canRunPlaywrightChromium,
9+
controlUiBundledSettingsStorageKey,
910
installMockGateway,
1011
resolvePlaywrightChromiumExecutablePath,
1112
startControlUiE2eServer,
@@ -49,15 +50,18 @@ function boardSnapshot(count: number) {
4950
}
5051

5152
async function openDashboard(page: Page): Promise<void> {
52-
await page.addInitScript((key) => {
53-
const settingsKey = "openclaw.control.settings.v1:ws://127.0.0.1:18789";
54-
const settings = JSON.parse(localStorage.getItem(settingsKey) ?? "{}") as Record<
55-
string,
56-
unknown
57-
>;
58-
settings.boardSessionViews = { [key]: { activeTabId: "main" } };
59-
localStorage.setItem(settingsKey, JSON.stringify(settings));
60-
}, sessionKey);
53+
const settingsKey = controlUiBundledSettingsStorageKey(controlUi.baseUrl);
54+
await page.addInitScript(
55+
({ key, storageKey }) => {
56+
const settings = JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Record<
57+
string,
58+
unknown
59+
>;
60+
settings.boardSessionViews = { [key]: { activeTabId: "main" } };
61+
localStorage.setItem(storageKey, JSON.stringify(settings));
62+
},
63+
{ key: sessionKey, storageKey: settingsKey },
64+
);
6165
await page.goto(`${controlUi.baseUrl}dashboard`);
6266
await page.locator(".board-session-surface").waitFor();
6367
}

‎ui/src/e2e/chat-flow.navigation-presentation.e2e.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, it } from "vitest";
2+
import { controlUiBundledSettingsStorageKey } from "../test-helpers/control-ui-e2e.ts";
23
import {
34
SESSION_DRAG_MIME,
45
captureSessionAccessibilityProof,
@@ -22,9 +23,9 @@ suite.define(() => {
2223
serviceWorkers: "block",
2324
viewport: { height: 900, width: 1440 },
2425
});
25-
await context.addInitScript(() => {
26+
await context.addInitScript((settingsKey) => {
2627
localStorage.setItem(
27-
"openclaw.control.settings.v1:ws://127.0.0.1:18789",
28+
settingsKey,
2829
JSON.stringify({
2930
chatSplitLayout: {
3031
activePaneId: "p1",
@@ -44,7 +45,7 @@ suite.define(() => {
4445
},
4546
}),
4647
);
47-
});
48+
}, controlUiBundledSettingsStorageKey(suite.server.baseUrl));
4849
const page = await context.newPage();
4950
const gateway = await installMockGateway(page, {
5051
deferredMethods: ["chat.startup", "chat.startup"],

‎ui/src/e2e/locale-offline-retry.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describeControlUiE2e("Control UI offline locale retry", () => {
6262
`Playwright Chromium is not available at ${chromiumExecutablePath}. Run \`pnpm --dir ui exec playwright install --with-deps chromium\`, or set OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM=1 only when intentionally skipping this lane.`,
6363
);
6464
}
65-
server = await startControlUiE2eServer();
65+
server = await startControlUiE2eServer(undefined, { source: true });
6666
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
6767
});
6868

‎ui/src/e2e/logs-layout.e2e.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { chromium, type Browser } from "playwright";
44
import { afterAll, beforeAll, describe, expect, it } from "vitest";
55
import {
66
canRunPlaywrightChromium,
7+
controlUiBundledSettingsStorageKey,
78
installMockGateway,
89
resolvePlaywrightChromiumExecutablePath,
910
startControlUiE2eServer,
@@ -58,11 +59,8 @@ describeControlUiE2e("Control UI logs native app layout E2E", () => {
5859
: {}),
5960
});
6061
const page = await context.newPage();
61-
await page.addInitScript(() => {
62-
localStorage.setItem(
63-
"openclaw.control.settings.v1:ws://127.0.0.1:18789",
64-
JSON.stringify({ textScale: 125, themeMode: "dark" }),
65-
);
62+
await page.addInitScript((settingsKey) => {
63+
localStorage.setItem(settingsKey, JSON.stringify({ textScale: 125, themeMode: "dark" }));
6664
const nativeWindow = window as Window & {
6765
__OPENCLAW_NATIVE_WEB_CHROME__?: boolean;
6866
__OPENCLAW_NATIVE_HISTORY__?: { canGoBack: boolean; canGoForward: boolean };
@@ -82,7 +80,7 @@ describeControlUiE2e("Control UI logs native app layout E2E", () => {
8280
} else {
8381
document.addEventListener("DOMContentLoaded", stamp);
8482
}
85-
});
83+
}, controlUiBundledSettingsStorageKey(server.baseUrl));
8684
await installMockGateway(page, {
8785
methodResponses: {
8886
"logs.tail": {

‎ui/src/e2e/session-dashboard.e2e.test.ts‎

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SANDBOX_HOST_PATH } from "../../../src/agents/sandbox-host.js";
99
import { createSandboxHostHttpServer } from "../../../src/gateway/mcp-app-sandbox-http.js";
1010
import {
1111
canRunPlaywrightChromium,
12+
controlUiBundledSettingsStorageKey,
1213
installMockGateway,
1314
resolvePlaywrightChromiumExecutablePath,
1415
startControlUiE2eServer,
@@ -139,26 +140,29 @@ const pluginWidgetBoardSnapshot = {
139140
};
140141

141142
async function showDashboard(page: Page): Promise<void> {
142-
await page.addInitScript((key) => {
143-
const settingsKey = "openclaw.control.settings.v1:ws://127.0.0.1:18789";
144-
const settings = JSON.parse(localStorage.getItem(settingsKey) ?? "{}") as Record<
145-
string,
146-
unknown
147-
>;
148-
const boardSessionViews =
149-
settings.boardSessionViews && typeof settings.boardSessionViews === "object"
150-
? (settings.boardSessionViews as Record<string, unknown>)
151-
: {};
152-
const savedView = boardSessionViews[key];
153-
settings.boardSessionViews = {
154-
...boardSessionViews,
155-
[key]: {
156-
activeTabId: "main",
157-
...(savedView && typeof savedView === "object" ? savedView : {}),
158-
},
159-
};
160-
localStorage.setItem(settingsKey, JSON.stringify(settings));
161-
}, sessionKey);
143+
const settingsKey = controlUiBundledSettingsStorageKey(server.baseUrl);
144+
await page.addInitScript(
145+
({ key, storageKey }) => {
146+
const settings = JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Record<
147+
string,
148+
unknown
149+
>;
150+
const boardSessionViews =
151+
settings.boardSessionViews && typeof settings.boardSessionViews === "object"
152+
? (settings.boardSessionViews as Record<string, unknown>)
153+
: {};
154+
const savedView = boardSessionViews[key];
155+
settings.boardSessionViews = {
156+
...boardSessionViews,
157+
[key]: {
158+
activeTabId: "main",
159+
...(savedView && typeof savedView === "object" ? savedView : {}),
160+
},
161+
};
162+
localStorage.setItem(storageKey, JSON.stringify(settings));
163+
},
164+
{ key: sessionKey, storageKey: settingsKey },
165+
);
162166
}
163167

164168
function workboardConfigSnapshot(enabled = true) {

‎ui/src/e2e/terminal-runtime.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describeControlUiE2e("Control UI terminal runtime isolation", () => {
3939
`Playwright Chromium is not installed or cannot start at ${chromiumExecutablePath}. Run \`pnpm --dir ui exec playwright install --with-deps chromium\`, or set OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM=1 only when intentionally skipping this lane.`,
4040
);
4141
}
42-
server = await startControlUiE2eServer();
42+
server = await startControlUiE2eServer(undefined, { source: true });
4343
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
4444
});
4545

‎ui/src/e2e/theme-muted-contrast.e2e.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mkdir, writeFile } from "node:fs/promises";
22
import path from "node:path";
33
import { expect, it } from "vitest";
4-
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
4+
import { controlUiBundledGatewayUrl, installMockGateway } from "../test-helpers/control-ui-e2e.ts";
55
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
66

77
const captureUiProof = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
@@ -142,14 +142,17 @@ suite.define(() => {
142142
});
143143
const initialFamily = family === "claw" ? "knot" : "claw";
144144
await context.addInitScript(
145-
({ initialMode, initialTheme }) => {
146-
const gatewayUrl = "ws://127.0.0.1:18789";
145+
({ gatewayUrl, initialMode, initialTheme }) => {
147146
localStorage.setItem(
148147
`openclaw.control.settings.v1:${gatewayUrl}`,
149148
JSON.stringify({ gatewayUrl, theme: initialTheme, themeMode: initialMode }),
150149
);
151150
},
152-
{ initialMode: mode, initialTheme: initialFamily },
151+
{
152+
gatewayUrl: controlUiBundledGatewayUrl(suite.server.baseUrl),
153+
initialMode: mode,
154+
initialTheme: initialFamily,
155+
},
153156
);
154157

155158
const page = await context.newPage();

‎ui/src/test-helpers/control-ui-e2e.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export function controlUiSessionUrl(baseUrl: string, sessionKey: string): string
3131
return url.toString();
3232
}
3333

34+
export function controlUiBundledGatewayUrl(baseUrl: string): string {
35+
const url = new URL(baseUrl);
36+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
37+
return url.origin;
38+
}
39+
40+
export function controlUiBundledSettingsStorageKey(baseUrl: string): string {
41+
return `openclaw.control.settings.v1:${controlUiBundledGatewayUrl(baseUrl)}`;
42+
}
43+
3444
type ControlUiRouteTarget = {
3545
hash?: string;
3646
pathname?: string;

0 commit comments

Comments
 (0)