Skip to content

Commit e29765f

Browse files
committed
test(ui): prove literal-$ tilde local media preview through Control UI e2e
1 parent 9f5e7e6 commit e29765f

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { mkdir } from "node:fs/promises";
2+
import path from "node:path";
3+
import { expect, it } from "vitest";
4+
import { createChatFlowE2eSuite, installMockGateway } from "./chat-flow.test-support.ts";
5+
6+
const suite = createChatFlowE2eSuite();
7+
8+
suite.define(() => {
9+
it("allows tilde local media previews when the preview root home contains a literal $ pattern", async () => {
10+
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
11+
const context = await suite.newBrowserContext({
12+
locale: "en-US",
13+
serviceWorkers: "block",
14+
viewport: { height: 900, width: 1280 },
15+
});
16+
const page = await context.newPage();
17+
const source = "~/media/report-voice.mp3";
18+
const requestedMediaUrls: URL[] = [];
19+
20+
await page.route("**/__openclaw__/assistant-media?**", async (route) => {
21+
const url = new URL(route.request().url());
22+
requestedMediaUrls.push(url);
23+
if (url.searchParams.get("meta") === "1") {
24+
await route.fulfill({
25+
contentType: "application/json",
26+
body: JSON.stringify({
27+
available: true,
28+
mediaTicket: "ticket-dollar-home",
29+
mediaTicketExpiresAt: new Date(Date.now() + 5 * 60_000).toISOString(),
30+
}),
31+
});
32+
return;
33+
}
34+
await route.fulfill({
35+
contentType: "audio/mpeg",
36+
body: Buffer.from("ID3\u0003\u0000\u0000\u0000\u0000\u0000\u0000"),
37+
});
38+
});
39+
40+
await installMockGateway(page, {
41+
localMediaPreviewRoots: ["/home/us$&r/media"],
42+
historyMessages: [
43+
{
44+
id: "assistant-dollar-home-audio",
45+
role: "assistant",
46+
content: [
47+
{ type: "text", text: "Your recording" },
48+
{
49+
type: "attachment",
50+
attachment: {
51+
kind: "audio",
52+
label: "report-voice.mp3",
53+
mimeType: "audio/mpeg",
54+
url: source,
55+
},
56+
},
57+
],
58+
timestamp: Date.now(),
59+
},
60+
],
61+
});
62+
63+
try {
64+
await page.goto(`${suite.server.baseUrl}chat`);
65+
const audio = page.locator(".chat-assistant-attachment-card audio");
66+
await audio.waitFor({ state: "attached", timeout: 10_000 });
67+
await expect.poll(() => requestedMediaUrls.length, { timeout: 10_000 }).toBe(2);
68+
expect(requestedMediaUrls[0]?.searchParams.get("meta")).toBe("1");
69+
expect(requestedMediaUrls[0]?.searchParams.get("source")).toBe(source);
70+
expect(requestedMediaUrls[1]?.searchParams.get("mediaTicket")).toBe("ticket-dollar-home");
71+
expect(requestedMediaUrls[1]?.searchParams.get("source")).toBe(source);
72+
expect(await page.getByText("Outside allowed folders").count()).toBe(0);
73+
if (artifactDir) {
74+
await mkdir(artifactDir, { recursive: true });
75+
await page.screenshot({
76+
fullPage: true,
77+
path: path.join(artifactDir, "local-media-dollar-home-allowed.png"),
78+
});
79+
}
80+
} finally {
81+
await suite.closeBrowserContext(context);
82+
}
83+
});
84+
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ export type ControlUiMockGatewayScenario = {
322322
cliAgentsEnabled?: boolean;
323323
workspace?: string;
324324
workspaceGit?: boolean;
325+
/** Local media preview roots served in the bootstrap config; tilde sources expand against these. */
326+
localMediaPreviewRoots?: string[];
325327
};
326328

327329
type NormalizedControlUiMockGatewayScenario = Required<ControlUiMockGatewayScenario>;
@@ -889,6 +891,7 @@ function normalizeScenario(
889891
cliAgentsEnabled: scenario.cliAgentsEnabled ?? false,
890892
workspace: scenario.workspace ?? "",
891893
workspaceGit: scenario.workspaceGit ?? false,
894+
localMediaPreviewRoots: scenario.localMediaPreviewRoots ?? [],
892895
};
893896
}
894897

@@ -902,7 +905,7 @@ export function createControlUiMockBootstrapConfig(scenario: ControlUiMockGatewa
902905
basePath: normalizedScenario.basePath,
903906
devGitBranch: normalizedScenario.devGitBranch || undefined,
904907
embedSandbox: "scripts",
905-
localMediaPreviewRoots: [],
908+
localMediaPreviewRoots: normalizedScenario.localMediaPreviewRoots,
906909
serverVersion: normalizedScenario.serverVersion,
907910
serverBuildId: normalizedScenario.serverBuildId,
908911
terminalEnabled: normalizedScenario.terminalEnabled,

0 commit comments

Comments
 (0)