/** * @file websocket-pty-size.test.js * @description Regression test for issue #33: the `/ws-pty/:runId` attach * spawns `tmux attach-session` at the size the CLIENT reports in the attach * URL, not a hardcoded 80×24. tmux sizes the window to the newest client, so * attaching at 80 columns and fixing it from the first `resize` message made * `claude` redraw its whole UI at 80 columns — wreckage that stays in the * scrollback and shows up as torn left-margin fragments when scrolling back. * @author Nguyễn Ngọc Trí Vĩ */ const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const { sizeFromQuery } = require("../websocket"); const query = (search) => new URL(`http://x/ws-pty/agenthub-lane-1${search}`).searchParams; describe("sizeFromQuery — the attach carries the client's real size", () => { it("reads the terminal's own cols/rows", () => { assert.deepEqual(sizeFromQuery(query("?cols=226&rows=29")), { cols: 226, rows: 29 }); }); // No size (a terminal on a hidden tab) stays no size: the attach then takes // the window's own, never a default that would resize the pane. const none = { cols: undefined, rows: undefined }; it("names no size when the client named none", () => { assert.deepEqual(sizeFromQuery(query("")), none); }); it("refuses anything out of bounds — this number reaches an ioctl", () => { assert.deepEqual(sizeFromQuery(query("?cols=0&rows=-5")), none); assert.deepEqual(sizeFromQuery(query("?cols=99999&rows=99999")), none); assert.deepEqual(sizeFromQuery(query("?cols=abc&rows=12")), none); }); });