Skip to content

Commit 32cc733

Browse files
committed
fix(ui): prevent encoded-path readiness timeouts
1 parent 3255882 commit 32cc733

3 files changed

Lines changed: 77 additions & 6 deletions

File tree

‎ui/src/e2e/chat-continue-in-terminal.e2e.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import path from "node:path";
33
import { expect, it } from "vitest";
44
import { decodeResumeHandoff } from "../../../src/shared/resume-handoff.js";
55
import type { ChatPaneElement } from "../pages/chat/route-draft-focus-handoff.ts";
6-
import { controlUiSessionUrl, installMockGateway } from "../test-helpers/control-ui-e2e.ts";
6+
import {
7+
controlUiSessionPath,
8+
controlUiSessionUrl,
9+
installMockGateway,
10+
waitForControlUiRoute,
11+
} from "../test-helpers/control-ui-e2e.ts";
712
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
813

914
const suite = createControlUiE2eSuite({
@@ -100,6 +105,13 @@ suite.define(() => {
100105
await expect
101106
.poll(() => activePane.evaluate((pane) => (pane as ChatPaneElement).sessionKey))
102107
.toBe(sessionKey);
108+
await waitForControlUiRoute(page, {
109+
routeId: "chat",
110+
pathname: controlUiSessionPath(sessionKey, basePath),
111+
pathnamePrefix: `${basePath}/chat/`,
112+
search: "",
113+
hash: "",
114+
});
103115
await activePane.getByText("Ready for terminal continuation.").waitFor({ timeout: 10_000 });
104116

105117
const menuTrigger = activePane.getByRole("button", {
@@ -182,6 +194,7 @@ suite.define(() => {
182194
await expect
183195
.poll(() => activePane.evaluate((pane) => (pane as ChatPaneElement).sessionKey))
184196
.toBe(sessionKey);
197+
await waitForControlUiRoute(page, { routeId: "chat" });
185198
await activePane
186199
.getByRole("paragraph")
187200
.filter({ hasText: /^Mobile session menu proof\.$/ })
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect, it } from "vitest";
2+
import type { ChatPaneElement } from "../pages/chat/route-draft-focus-handoff.ts";
3+
import {
4+
controlUiSessionUrl,
5+
installMockGateway,
6+
navigateToControlUiSession,
7+
} from "../test-helpers/control-ui-e2e.ts";
8+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
9+
10+
const suite = createControlUiE2eSuite({ name: "Control UI route readiness" });
11+
12+
suite.define(() => {
13+
it.each([
14+
{ name: "root", basePath: "" },
15+
{ name: "encoded mount", basePath: "/nested/$&;=()+,![]{}'`/%25PATH%25" },
16+
])("navigates exact session keys at the $name", async ({ basePath }) => {
17+
await suite.withPage({ viewport: { width: 1200, height: 800 } }, async ({ page }) => {
18+
const initialSessionKey = "agent:runner:route:initial";
19+
await installMockGateway(page, { basePath, sessionKey: initialSessionKey });
20+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, initialSessionKey));
21+
const visiblePane = page.locator("openclaw-chat-pane.chat-pane-cache__pane--visible");
22+
await expect
23+
.poll(() => visiblePane.evaluate((pane) => (pane as ChatPaneElement).sessionKey))
24+
.toBe(initialSessionKey);
25+
26+
const mountUrl = new URL(suite.server.baseUrl);
27+
mountUrl.pathname = basePath || "/";
28+
const encodedBase = basePath ? mountUrl.pathname : "";
29+
for (const [rest, suffix] of [
30+
["a/b", "a%2Fb"],
31+
["a:b", "a/b"],
32+
["%2F%25%3F%23", "%252F%2525%253F%2523"],
33+
["a?b#c", "a%3Fb%23c"],
34+
]) {
35+
const sessionKey = `agent:runner:route:${rest}`;
36+
await navigateToControlUiSession(page, sessionKey);
37+
expect(new URL(page.url()).pathname).toBe(`${encodedBase}/chat/runner/route/${suffix}`);
38+
expect(await visiblePane.evaluate((pane) => (pane as ChatPaneElement).sessionKey)).toBe(
39+
sessionKey,
40+
);
41+
}
42+
});
43+
});
44+
});

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,25 @@ export function controlUiSessionUrl(baseUrl: string, sessionKey: string): string
3434
}
3535

3636
export async function navigateToControlUiSession(page: Page, sessionKey: string): Promise<void> {
37-
await page.evaluate((pathname) => {
37+
const expectedPathname = await page.evaluate((sessionPath) => {
3838
const app = document.querySelector("openclaw-app") as HTMLElement & {
3939
runtime?: {
4040
context: {
41+
basePath: string;
4142
navigate: (routeId: string, options: { pathname: string }) => void;
4243
};
4344
};
4445
};
4546
if (!app.runtime) {
4647
throw new Error("OpenClaw application runtime is unavailable");
4748
}
49+
const pathname = `${app.runtime.context.basePath}${sessionPath}`;
50+
const url = new URL(window.location.href);
51+
url.pathname = pathname;
4852
app.runtime.context.navigate("chat", { pathname });
53+
return url.pathname;
4954
}, controlUiSessionPath(sessionKey));
50-
await page.waitForURL((url) => url.pathname === controlUiSessionPath(sessionKey));
55+
await page.waitForURL((url) => url.pathname === expectedPathname);
5156
await page.waitForFunction(
5257
(targetSessionKey) =>
5358
[...document.querySelectorAll<HTMLElement>("openclaw-chat-pane")].some(
@@ -109,13 +114,22 @@ export async function waitForControlUiRoute(page: Page, target: ControlUiRouteTa
109114
};
110115
const state = app.runtime?.router.getState();
111116
const pathname = window.location.pathname;
117+
// Router paths retain literal characters that browser history percent-encodes.
118+
// Serialize as a pathname; decoding would alias encoded delimiters and percent data.
119+
const browserPathname = (value: string) => {
120+
const url = new URL(window.location.href);
121+
url.pathname = value;
122+
return url.pathname;
123+
};
112124
return (
113125
state?.status === "success" &&
114126
state.matches[0]?.routeId === expected.routeId &&
115-
state.resolvedLocation?.pathname === pathname &&
127+
state.resolvedLocation !== null &&
128+
browserPathname(state.resolvedLocation.pathname) === pathname &&
116129
state.pendingMatches.length === 0 &&
117-
(expected.pathname === undefined || pathname === expected.pathname) &&
118-
(expected.pathnamePrefix === undefined || pathname.startsWith(expected.pathnamePrefix)) &&
130+
(expected.pathname === undefined || pathname === browserPathname(expected.pathname)) &&
131+
(expected.pathnamePrefix === undefined ||
132+
pathname.startsWith(browserPathname(expected.pathnamePrefix))) &&
119133
(expected.search === undefined || window.location.search === expected.search) &&
120134
(expected.hash === undefined || window.location.hash === expected.hash)
121135
);

0 commit comments

Comments
 (0)