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.
This commit is contained in:
paseo-bot[bot]
2026-10-31 05:03:42 +00:00
parent 3c8537bb38
commit 2d87b2ce32
@@ -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);