/** * @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 }); }); it("falls back to 80x24 when the client named no size", () => { assert.deepEqual(sizeFromQuery(query("")), { cols: 80, rows: 24 }); }); it("refuses anything out of bounds — this number reaches an ioctl", () => { assert.deepEqual(sizeFromQuery(query("?cols=0&rows=-5")), { cols: 80, rows: 24 }); assert.deepEqual(sizeFromQuery(query("?cols=99999&rows=99999")), { cols: 80, rows: 24 }); assert.deepEqual(sizeFromQuery(query("?cols=abc&rows=12.5")), { cols: 80, rows: 12 }); }); });