The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect } from "e2e"; |
| 2 | |
| 3 | import { test, WEB } from "./t3.ts"; |
| 4 | |
| 5 | // The thread CLI takes at most 120,000 characters per message: 3,000 lines of ten "the". |
| 6 | const SEEDED_MATCHES = 30_000; |
| 7 | const LONG_MESSAGE = Array.from({ length: SEEDED_MATCHES / 10 }, () => |
| 8 | "the ".repeat(10).trim(), |
| 9 | ).join("\n"); |
| 10 | |
| 11 | const findTotal = `(() => { |
| 12 | const label = document.querySelector("[data-thread-find-bar] span[aria-hidden]")?.textContent ?? ""; |
| 13 | const match = /^\\d+\\/(\\d+)$/.exec(label.trim()); |
| 14 | return match ? Number(match[1]) : 0; |
| 15 | })()`; |
| 16 | |
| 17 | const paint = `(() => { |
| 18 | const inactive = CSS.highlights.get("t3-thread-find"); |
| 19 | const active = CSS.highlights.get("t3-thread-find-active"); |
| 20 | let onScreen = 0; |
| 21 | for (const highlight of [inactive, active]) |
| 22 | for (const range of highlight ?? []) { |
| 23 | const rect = range.getBoundingClientRect(); |
| 24 | if (rect.height > 0 && rect.bottom >= 0 && rect.top <= innerHeight) onScreen++; |
| 25 | } |
| 26 | return { |
| 27 | registered: (inactive?.size ?? 0) + (active?.size ?? 0), |
| 28 | active: active?.size ?? 0, |
| 29 | onScreen, |
| 30 | }; |
| 31 | })()`; |
| 32 | |
| 33 | test( |
| 34 | "Find paints only matches near the viewport of a message with 30,000 matches", |
| 35 | WEB, |
| 36 | async ({ t3, app, screen, browser }) => { |
| 37 | const project = await t3.project("find-paint"); |
| 38 | const thread = await t3.thread({ |
| 39 | project, |
| 40 | title: "Paint bound proof", |
| 41 | messages: [LONG_MESSAGE], |
| 42 | }); |
| 43 | await t3.open(thread); |
| 44 | await expect(screen.getByText("first fixture turn complete", { exact: false })).toBeVisible({ |
| 45 | timeout: 120_000, |
| 46 | }); |
| 47 | |
| 48 | // The CLI's message folds to one line; find unfolds it to reach the first match. |
| 49 | await browser.keyboard.press("Control+f"); |
| 50 | const find = screen.getByRole("searchbox", "Find in thread"); |
| 51 | await expect(find).toBeVisible(); |
| 52 | await find.fill("the"); |
| 53 | // The count is the server's: every match in the thread, whatever is painted. |
| 54 | await expect |
| 55 | .poll(() => browser.evaluate<number>(findTotal), { timeout: 60_000 }) |
| 56 | .toBeGreaterThanOrEqual(SEEDED_MATCHES); |
| 57 | await expect |
| 58 | .poll(async () => (await browser.evaluate<{ active: number }>(paint)).active, { |
| 59 | timeout: 30_000, |
| 60 | }) |
| 61 | .toBe(1); |
| 62 | |
| 63 | try { |
| 64 | const painted = await browser.evaluate<{ |
| 65 | registered: number; |
| 66 | active: number; |
| 67 | onScreen: number; |
| 68 | }>(paint); |
| 69 | expect(painted.onScreen).toBeGreaterThan(0); |
| 70 | expect(painted.registered).toBeLessThan(5_000); |
| 71 | } finally { |
| 72 | await app.screenshot("find-open-paint"); |
| 73 | } |
| 74 | }, |
| 75 | ); |