From 2d87b2ce322e6b0de002fbc9d646bc70aefac0e0 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 05:03:42 +0000 Subject: [PATCH] test(terminal): finish output before comparing replay captures A marker can arrive before its trailing newline. Comparing captures taken on either side of that output compares different terminal states. Split that output deliberately and wait for its parsed completion before capturing the expected replay. --- .../terminal/worker-terminal-manager.test.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/server/src/terminal/worker-terminal-manager.test.ts b/packages/server/src/terminal/worker-terminal-manager.test.ts index ad066327a2..f8ee897e46 100644 --- a/packages/server/src/terminal/worker-terminal-manager.test.ts +++ b/packages/server/src/terminal/worker-terminal-manager.test.ts @@ -1710,6 +1710,7 @@ it.skipIf(isPlatform("win32"))( it("replays bounded ANSI chunks independently of live output and reconstructs the revision cut", async () => { const cwd = createTemporaryHome(); + const finishBefore = join(cwd, "finish-before"); manager = await startRealWorkerManager(); const session = trackTerminal( await manager.createTerminal({ @@ -1719,7 +1720,15 @@ it("replays bounded ANSI chunks independently of live output and reconstructs th cols: 120, ...nodeTerminalCommand(` for (let i = 0; i < 800; i++) process.stdout.write("\\x1b[31m" + String(i).padStart(4, "0") + ":" + "x".repeat(100) + "\\x1b[0m\\r\\n"); - require("node:readline").createInterface({ input: process.stdin }).on("line", line => process.stdout.write(line === "before" ? "PRE-CUT\\r\\n" : "LIVE-AFTER-REPLAY\\r\\n")); + require("node:readline").createInterface({ input: process.stdin }).on("line", line => { + if (line !== "before") { process.stdout.write("LIVE-AFTER-REPLAY\\r\\n"); return; } + process.stdout.write("PRE-CUT"); + const finish = setInterval(() => { + if (!require("node:fs").existsSync(${JSON.stringify(finishBefore)})) return; + clearInterval(finish); + process.stdout.write("\\r\\n"); + }, 5); + }); setInterval(() => {}, 1000); `), }), @@ -1743,6 +1752,13 @@ it("replays bounded ANSI chunks independently of live output and reconstructs th }); session.send({ type: "input", data: "before\r" }); await waitForCondition(() => live.includes("PRE-CUT"), 10000); + // A PTY may deliver the marker and its trailing newline separately. Finish + // that output before replay, so the two captures must describe the same cut. + writeFileSync(finishBefore, ""); + await waitForCondition(async () => { + const { lines } = await manager!.captureTerminal(session.id); + return lines.at(-2) === "PRE-CUT" && lines.at(-1) === ""; + }, 10000); const expected = await manager.captureTerminal(session.id); const metadata = await manager.replayTerminal(session.id, undefined, (event) => { events.push(event.type);