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

main
ts 66 lines 2.5 KB
Raw
1 /// <reference lib="dom" />
2 // The DOM lib types the functions 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 { run } from "./shell.ts";
8 import { runPromise, test, WEB } from "./t3.ts";
9
10 const LINES = Array.from({ length: 40 }, (_, index) => `line ${index + 1}`);
11
12 test(
13 "The diff expands unchanged lines beside a Git ident keyword",
14 WEB,
15 async ({ t3, app, browser, screen }) => {
16 const project = await t3.project("demo", {
17 ".gitattributes": "notes.txt ident\n",
18 "notes.txt": `$Id$\n${LINES.join("\n")}\n`,
19 });
20 const notes = `${project}/notes.txt`;
21 // Checkout smudges `$Id$` to `$Id: <blob> $`; then edit a line inside its hunk.
22 await runPromise(
23 Effect.gen(function* () {
24 const fs = yield* FileSystem.FileSystem;
25 yield* fs.remove(notes);
26 yield* run("git", ["checkout-index", "--force", "notes.txt"], { cwd: project });
27 const smudged = yield* fs.readFileString(notes);
28 yield* fs.writeFileString(notes, smudged.replace("line 2\n", "edited 2\n"));
29 }),
30 );
31 const thread = await t3.thread({ project, title: "Ident", messages: ["first"] });
32
33 // The diff renders in shadow roots that locators do not reach.
34 const diffLines = () =>
35 browser.evaluate(() =>
36 Array.from(document.querySelectorAll("*")).flatMap((host) =>
37 Array.from(host.shadowRoot?.querySelectorAll("[data-line]") ?? [], (line) =>
38 (line.textContent ?? "").trim(),
39 ),
40 ),
41 );
42 const expandBelowHunk = () =>
43 browser.evaluate(() => {
44 for (const host of document.querySelectorAll("*")) {
45 const buttons = host.shadowRoot?.querySelectorAll<HTMLElement>("[data-expand-button]");
46 const last = buttons?.[buttons.length - 1];
47 if (last) {
48 last.click();
49 return true;
50 }
51 }
52 return false;
53 });
54
55 await t3.open(thread);
56 await expect(screen.getByText("first fixture turn complete", { exact: false })).toBeVisible();
57 await screen.getByRole("button", "Toggle right panel").tap();
58 await screen.getByText("Diff").tap();
59 await screen.getByRole("button", "Expand notes.txt").tap();
60 await expect.poll(diffLines).toContain("edited 2");
61 await expect.poll(expandBelowHunk).toBe(true);
62 await app.screenshot("after-expand");
63 await expect.poll(diffLines).toContain("line 30");
64 await app.screenshot("expanded");
65 },
66 );