@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 68 lines 2.83 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 // gcc prints a file compiled from its own folder by bare name.
11 const DIAGNOSTIC = "main.c:1:25: error: 'missing' undeclared";
12 const EDITOR_ARGS = `${T3_HOME}/editor-args.txt`;
13
14 /** The file's lines, or none while it does not exist. */
15 const readLines = (file: string) =>
16 runPromise(
17 Effect.gen(function* () {
18 const fs = yield* FileSystem.FileSystem;
19 if (!(yield* fs.exists(file))) return [];
20 return (yield* fs.readFileString(file)).trim().split("\n");
21 }),
22 );
23
24 test(
25 "Ctrl+click on a bare compiler filename in the terminal opens that file at its line and column",
26 WEB,
27 async ({ t3, app, browser, screen }) => {
28 await runPromise(
29 Effect.flatMap(FileSystem.FileSystem, (fs) => fs.remove(EDITOR_ARGS, { force: true })),
30 );
31 const project = await t3.project("demo", {
32 "main.c": "int main(void) { return missing; }\n",
33 // Enough rows that the middle of the terminal shows the diagnostic, whatever its height.
34 "build.log": `${DIAGNOSTIC}\n`.repeat(200),
35 });
36 const thread = await t3.thread({ project, title: "Build", messages: ["Build it"] });
37 await t3.open(thread);
38
39 await screen.getByRole("button", "Toggle terminal drawer").tap();
40 const input = screen.getByRole("textbox", "Terminal input");
41 // The input mounts before fonts and WASM finish loading and its handlers are installed.
42 await expect(input).toHaveAttribute("data-workspace-focus-default", "");
43 await input.focus();
44 await browser.keyboard.type("cat build.log; touch cat.done\n");
45 await expect.poll(() => readLines(`${project}/cat.done`), { timeout: 30_000 }).toEqual([""]);
46 await app.screenshot("diagnostic-printed");
47
48 // The terminal draws on a canvas, so point at the first cells of its middle row.
49 const canvas = await browser.evaluate(() => {
50 const box = document
51 .querySelector('[aria-label="Terminal input"]')
52 ?.parentElement?.querySelector("canvas")
53 ?.getBoundingClientRect();
54 return box ? { x: box.x, y: box.y, width: box.width, height: box.height } : null;
55 });
56 if (!canvas) throw new Error("The terminal canvas is not on the page.");
57 await browser.mouse.move(canvas.x + 16, canvas.y + canvas.height / 2);
58 await browser.keyboard.down("Control");
59 await browser.mouse.down();
60 await browser.mouse.up();
61 await browser.keyboard.up("Control");
62 await app.screenshot("after-ctrl-click");
63
64 await expect
65 .poll(() => readLines(EDITOR_ARGS), { timeout: 15_000 })
66 .toEqual(["--classic", "--goto", `${project}/main.c:1:25`]);
67 },
68 );