Fix terminal snapshots reflowing after resize

Terminal snapshots now carry soft-wrap row metadata only to clients that advertise support, so restored output can resize like live output without breaking older clients.
This commit is contained in:
Mohamed Boudra
2026-05-31 19:40:15 +07:00
parent 794cbcef63
commit 4cc72a84e8
18 changed files with 538 additions and 146 deletions
@@ -91,24 +91,26 @@ describe("terminal binary frames", () => {
).toBeNull();
});
it("rejects unknown fields in resize and snapshot payloads", () => {
it("ignores unknown fields in resize and snapshot payloads", () => {
// Protocol schemas are non-strict: unknown keys are stripped, not rejected, so a
// new daemon can add fields without breaking an old client's parse.
expect(
decodeTerminalResizePayload(
new TextEncoder().encode(JSON.stringify({ rows: 24, cols: 80, extra: true })),
),
).toBeNull();
expect(
decodeTerminalSnapshotPayload(
new TextEncoder().encode(
JSON.stringify({
rows: 1,
cols: 1,
grid: [[{ char: "A", extra: true }]],
scrollback: [],
cursor: { row: 0, col: 1 },
}),
),
).toEqual({ rows: 24, cols: 80 });
const snapshot = decodeTerminalSnapshotPayload(
new TextEncoder().encode(
JSON.stringify({
rows: 1,
cols: 1,
grid: [[{ char: "A", extra: true }]],
scrollback: [],
cursor: { row: 0, col: 1 },
}),
),
).toBeNull();
);
expect(snapshot?.grid[0]?.[0]).toEqual({ char: "A" });
});
});