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

main
ts 98 lines 4.09 KB
Raw
1 /// <reference lib="dom" />
2 // The DOM lib types the function this scenario runs in the page.
3 import { expect } from "e2e";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6
7 import { T3_HOME } from "../e2e.config.ts";
8 import { runPromise, test, WEB } from "./t3.ts";
9
10 const EDITOR_ARGS = `${T3_HOME}/editor-args.txt`;
11
12 /** The file's lines, or none while it does not exist. */
13 const readLines = (file: string) =>
14 runPromise(
15 Effect.gen(function* () {
16 const fs = yield* FileSystem.FileSystem;
17 if (!(yield* fs.exists(file))) return [];
18 return (yield* fs.readFileString(file)).trim().split("\n");
19 }),
20 );
21
22 const removeEditorArgs = () =>
23 runPromise(
24 Effect.flatMap(FileSystem.FileSystem, (fs) => fs.remove(EDITOR_ARGS, { force: true })),
25 );
26
27 // GNU ls, made hostless, for filenames that end like a position.
28 const listed = (name: string) =>
29 `command ls -d --hyperlink=always --color=never -1 --quoting-style=literal -- '${name}' | sed -E 's@file://[^/]+/@file:///@'`;
30 // An opaque label, so only the URI can name the file.
31 const hashed = (uriPath: string) =>
32 `printf '\\033]8;;file://%s\\033\\\\CLICKME\\033]8;;\\033\\\\\\n' "$PWD/${uriPath}"`;
33
34 const LINKS = [
35 { print: listed("report.txt:12-64"), opens: ["report.txt:12-64"] },
36 { print: listed("zero.txt:0"), opens: ["zero.txt:0"] },
37 { print: hashed("numeric.txt%3A12#L5"), opens: ["numeric.txt:12"] },
38 { print: hashed("position.txt#L5C3"), opens: ["--goto", "position.txt:5:3"] },
39 { print: listed("build:2026"), opens: ["--new-window", "build:2026"] },
40 ];
41
42 test(
43 "Ctrl+click on a terminal file URI opens the exact file it names, even one ending like a position",
44 WEB,
45 async ({ t3, app, browser, screen }) => {
46 await removeEditorArgs();
47 const files: Record<string, string> = {
48 "build:2026/keep.txt": "keep\n",
49 "numeric.txt:12:1:1/keep.txt": "decoy\n",
50 };
51 for (const name of ["report.txt:12-64", "zero.txt:0", "numeric.txt:12", "position.txt"]) {
52 files[name] = `${name}\n`;
53 }
54 // Enough rows to scroll, so every row is the link. Scripts keep the typed commands short.
55 for (const [index, link] of LINKS.entries()) {
56 files[`print-${index}.sh`] =
57 `for i in $(seq 1 100); do ${link.print}; done; touch printed-${index}\n`;
58 }
59 const project = await t3.project("demo", files);
60 const thread = await t3.thread({ project, title: "List", messages: ["List it"] });
61 await t3.open(thread);
62
63 await screen.getByRole("button", "Toggle terminal drawer").tap();
64 const input = screen.getByRole("textbox", "Terminal input");
65 // The input mounts before fonts and WASM finish loading and its handlers are installed.
66 await expect(input).toHaveAttribute("data-workspace-focus-default", "");
67
68 for (const [index, { opens }] of LINKS.entries()) {
69 await removeEditorArgs();
70 await input.focus();
71 await browser.keyboard.type(`bash print-${index}.sh\n`);
72 await expect
73 .poll(() => readLines(`${project}/printed-${index}`), { timeout: 30_000 })
74 .toEqual([""]);
75 await app.screenshot(`printed-${index}`);
76
77 // The terminal draws on a canvas, so point at the first cells of a row near its middle.
78 const canvas = await browser.evaluate(() => {
79 const box = document
80 .querySelector('[aria-label="Terminal input"]')
81 ?.parentElement?.querySelector("canvas")
82 ?.getBoundingClientRect();
83 return box ? { x: box.x, y: box.y, width: box.width, height: box.height } : null;
84 });
85 if (!canvas) throw new Error("The terminal canvas is not on the page.");
86 // Alternate rows, or a quick second click on the same spot counts as a double-click.
87 await browser.mouse.move(canvas.x + 16, canvas.y + canvas.height / 2 - (index % 2) * 40);
88 await browser.keyboard.down("Control");
89 await browser.mouse.down();
90 await browser.mouse.up();
91 await browser.keyboard.up("Control");
92
93 await expect
94 .poll(() => readLines(EDITOR_ARGS), { timeout: 15_000 })
95 .toEqual(["--classic", ...opens.slice(0, -1), `${project}/${opens.at(-1)}`]);
96 }
97 },
98 );