The best way to control Claude Code, Codex and more from any computer or phone
| 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 { run } from "./shell.ts"; |
| 8 | import { runPromise, test, WEB } from "./t3.ts"; |
| 9 | |
| 10 | const SOCKET = `t3-scenario-divider-${process.pid}`; |
| 11 | |
| 12 | const tmux = (...args: ReadonlyArray<string>) => |
| 13 | runPromise( |
| 14 | run("tmux", ["-L", SOCKET, ...args], { |
| 15 | env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "" }, |
| 16 | allowExit: [0, 1], |
| 17 | }), |
| 18 | ); |
| 19 | |
| 20 | const paneWidths = async () => |
| 21 | (await tmux("list-panes", "-F", "#{pane_width}")).stdout.trim().split("\n").filter(Boolean); |
| 22 | |
| 23 | test( |
| 24 | "Dragging a tmux pane divider in the web terminal resizes the panes", |
| 25 | WEB, |
| 26 | async ({ t3, app, browser, screen }) => { |
| 27 | const project = await t3.project("demo"); |
| 28 | const thread = await t3.thread({ project, title: "Panes", messages: ["hello"] }); |
| 29 | const read = (file: string) => |
| 30 | runPromise( |
| 31 | Effect.gen(function* () { |
| 32 | const fs = yield* FileSystem.FileSystem; |
| 33 | return yield* fs.readFileString(`${project}/${file}`); |
| 34 | }).pipe(Effect.orElseSucceed(() => "")), |
| 35 | ); |
| 36 | await t3.open(thread); |
| 37 | |
| 38 | await screen.getByRole("button", "Toggle terminal drawer").tap(); |
| 39 | const terminal = screen.getByLabel("Terminal input"); |
| 40 | |
| 41 | // Input sent before the shell runs is dropped, so retype until it lands. |
| 42 | await expect |
| 43 | .poll( |
| 44 | async () => { |
| 45 | await terminal.focus(); |
| 46 | await browser.keyboard.type(`echo ready > '${project}/shell-ready'`); |
| 47 | await browser.keyboard.press("Enter"); |
| 48 | return read("shell-ready"); |
| 49 | }, |
| 50 | { timeout: 30_000 }, |
| 51 | ) |
| 52 | .toBe("ready\n"); |
| 53 | |
| 54 | try { |
| 55 | await terminal.focus(); |
| 56 | await browser.keyboard.type( |
| 57 | `tmux -L ${SOCKET} -f /dev/null new-session \\; set -g mouse on \\; set -g status off \\; split-window -h -l 30%`, |
| 58 | ); |
| 59 | await browser.keyboard.press("Enter"); |
| 60 | await expect.poll(async () => (await paneWidths()).length, { timeout: 15_000 }).toBe(2); |
| 61 | const [leftWidth] = await paneWidths(); |
| 62 | |
| 63 | // Find the divider tmux drew from the canvas pixels of an empty row, not from cell math. |
| 64 | const findDivider = () => |
| 65 | browser.evaluate(() => { |
| 66 | const input = document.querySelector('textarea[aria-label="Terminal input"]'); |
| 67 | const canvas = input?.parentElement?.querySelector("canvas"); |
| 68 | const context = canvas?.getContext("2d"); |
| 69 | if (!canvas || !context) return null; |
| 70 | const bounds = canvas.getBoundingClientRect(); |
| 71 | const ratio = canvas.width / bounds.width; |
| 72 | const row = Math.floor(canvas.height * 0.75); |
| 73 | const pixels = context.getImageData(0, row, canvas.width, 1).data; |
| 74 | const lit: number[] = []; |
| 75 | for (let x = 0; x < canvas.width; x += 1) { |
| 76 | const offset = x * 4; |
| 77 | const difference = |
| 78 | Math.abs(pixels[offset]! - pixels[0]!) + |
| 79 | Math.abs(pixels[offset + 1]! - pixels[1]!) + |
| 80 | Math.abs(pixels[offset + 2]! - pixels[2]!); |
| 81 | if (difference > 90) lit.push(x); |
| 82 | } |
| 83 | const first = lit[0]; |
| 84 | const last = lit.at(-1); |
| 85 | if (first === undefined || last === undefined || last - first > 4 * ratio) return null; |
| 86 | return { |
| 87 | x: bounds.left + (first + last + 1) / 2 / ratio, |
| 88 | y: bounds.top + (row + 0.5) / ratio, |
| 89 | }; |
| 90 | }); |
| 91 | await expect.poll(findDivider, { timeout: 10_000 }).not.toBeNull(); |
| 92 | const divider = (await findDivider())!; |
| 93 | await app.screenshot("before-drag"); |
| 94 | |
| 95 | await browser.mouse.move(divider.x, divider.y); |
| 96 | await browser.mouse.down(); |
| 97 | for (let step = 1; step <= 8; step += 1) { |
| 98 | await browser.mouse.move(divider.x - step * 10, divider.y); |
| 99 | } |
| 100 | await browser.mouse.up(); |
| 101 | |
| 102 | await app.screenshot("after-drag"); |
| 103 | await expect |
| 104 | .poll(async () => Number((await paneWidths())[0]), { timeout: 5_000 }) |
| 105 | .toBeLessThan(Number(leftWidth)); |
| 106 | } finally { |
| 107 | await tmux("kill-server"); |
| 108 | } |
| 109 | }, |
| 110 | ); |