/** * KHAELOR * File: tests/tui/pty-echo.test.ts * Description: PTY integration test — typed characters must echo in the live region before Enter is ever pressed. * * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai */ import { execFile } from "node:child_process"; import { existsSync } from "node:fs"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; const run = promisify(execFile); const EXPECT_BIN = ["/usr/bin/expect", "/bin/expect", "/usr/local/bin/expect"].find((p) => existsSync(p), ); describe.skipIf(EXPECT_BIN === undefined)("live keystroke echo under a real PTY", () => { it( "shows typed text in the composer before Enter (regression: invisible typing)", async () => { const { stdout } = await run(EXPECT_BIN as string, ["tests/tui/fixtures/pty-echo.exp"], { cwd: process.cwd(), timeout: 60_000, env: { ...process.env, TERM: "xterm-256color" }, }); expect(stdout).toContain("STARTUP_OK"); expect(stdout).toContain("BOX_VISIBLE"); expect(stdout).toContain("ECHO_VISIBLE"); // Real latency from send to on-screen echo (PTY round trip included). const ms = /ECHO_VISIBLE (\d+)ms/.exec(stdout); expect(ms).not.toBeNull(); expect(Number((ms as RegExpExecArray)[1])).toBeLessThan(1000); }, 60_000, ); });