The best way to control Claude Code, Codex and more from any computer or phone

main
ts 90 lines 3.68 KB
Raw
1 /// <reference lib="dom" />
2 import { expect } from "e2e";
3
4 import { test, WEB } from "./t3.ts";
5
6 test(
7 "The project folder for threads without a project follows the app language",
8 WEB,
9 async ({ t3, app, browser, screen }) => {
10 const project = await t3.project("scenario-scratch");
11 const thread = await t3.thread({ project, title: "Scratch work", messages: ["Start"] });
12
13 // The scenario home is inside a Git checkout, where the server disables native scratch.
14 // Advertise the seeded workspace as scratch while leaving the real project and thread in place.
15 await browser.addInitScript((scratchWorkspaceRoot) => {
16 const configRequests = new WeakMap<WebSocket, string>();
17 const send = WebSocket.prototype.send;
18 WebSocket.prototype.send = function (data) {
19 if (typeof data === "string") {
20 for (const request of [JSON.parse(data)].flat()) {
21 if (request?._tag === "Request" && request.tag === "subscribeServerConfig") {
22 configRequests.set(this, String(request.id));
23 }
24 }
25 }
26 return send.call(this, data);
27 };
28 const addEventListener = WebSocket.prototype.addEventListener;
29 WebSocket.prototype.addEventListener = function (
30 this: WebSocket,
31 type: string,
32 listener: EventListenerOrEventListenerObject,
33 options?: boolean | AddEventListenerOptions,
34 ) {
35 if (type !== "message" || typeof listener !== "function") {
36 return addEventListener.call(this, type, listener, options);
37 }
38 return addEventListener.call(
39 this,
40 type,
41 (event: Event) => {
42 const data = (event as MessageEvent).data;
43 if (typeof data !== "string") return listener.call(this, event);
44 const parsed = JSON.parse(data);
45 let changed = false;
46 for (const message of [parsed].flat()) {
47 if (
48 message?._tag !== "Chunk" ||
49 String(message.requestId) !== configRequests.get(this)
50 )
51 continue;
52 for (const value of message.values) {
53 if (value.type === "snapshot") {
54 value.config.scratchWorkspaceRoot = scratchWorkspaceRoot;
55 changed = true;
56 }
57 }
58 }
59 return listener.call(
60 this,
61 changed ? new MessageEvent("message", { data: JSON.stringify(parsed) }) : event,
62 );
63 },
64 options,
65 );
66 } as typeof WebSocket.prototype.addEventListener;
67 }, project);
68
69 await t3.open("/settings/labs");
70 await screen.getByLabel("Boring sidebar (group by project)", { exact: true }).tap();
71 await screen.getByLabel("Two-line folder rows", { exact: true }).waitFor();
72
73 await t3.open("/settings/general");
74 const openFolder = screen.getByTestId("sidebar-project-folder");
75 await expect(openFolder).toContainText("No project", { timeout: 60_000 });
76 await screen.getByLabel("Language", { exact: true }).tap();
77 await screen.getByText("日本語", { exact: true }).tap();
78 await screen.getByLabel("言語", { exact: true }).waitFor();
79 // Settings leaves the sidebar mounted. Keep this failure through the capture after reopening.
80 await expect.soft(openFolder).toContainText("プロジェクトなし");
81
82 await t3.open(thread);
83 const folder = screen.getByTestId("sidebar-project-folder");
84 await folder.getByText(/^(?:No project|プロジェクトなし)$/, { exact: true }).waitFor({
85 timeout: 60_000,
86 });
87 await app.screenshot("scratch-folder-in-japanese");
88 await expect(folder).toContainText("プロジェクトなし");
89 },
90 );