feat(packages/coding-agent): added terminal protocol debug diagnostics
- Added debug menu options for terminal state and protocol checks with new handlers. - Added terminal diagnostics models and collectors to report geometry, protocol flags, and multiplexer data. - Added protocol-probe utilities to encode RGB PNGs, generate sample content, and render test panels. - Added support components for verbatim line rendering and OSC66-scaled text rows. - Added tests validating image encoding, OSC66 output, and terminal state formatting.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { beforeAll, describe, expect, it } from "bun:test";
|
||||
import { getImageDimensions } from "@oh-my-pi/pi-tui";
|
||||
import { buildLargeTextLines, buildSampleImage, encodeRgbPng } from "../../src/debug/protocol-probe";
|
||||
import { initTheme } from "../../src/modes/theme/theme";
|
||||
|
||||
beforeAll(async () => {
|
||||
// buildLargeTextLines styles the OSC 66 span through the global theme singleton.
|
||||
await initTheme();
|
||||
});
|
||||
|
||||
describe("encodeRgbPng / buildSampleImage", () => {
|
||||
it("emits a PNG whose IHDR dimensions decode back to the requested size", () => {
|
||||
// The graphics test relies on producing a *valid* PNG: Kitty/iTerm2 hand
|
||||
// the bytes to the terminal and Sixel decodes them natively, so a malformed
|
||||
// header (wrong CRC, bad chunk framing) silently breaks the whole panel.
|
||||
const sample = buildSampleImage(48, 24);
|
||||
expect(sample.mimeType).toBe("image/png");
|
||||
expect(sample.dimensions).toEqual({ widthPx: 48, heightPx: 24 });
|
||||
|
||||
const decoded = getImageDimensions(sample.base64, "image/png");
|
||||
expect(decoded).toEqual({ widthPx: 48, heightPx: 24 });
|
||||
});
|
||||
|
||||
it("begins with the PNG signature and round-trips arbitrary pixel sizes", () => {
|
||||
const png = encodeRgbPng(3, 2, new Uint8Array(3 * 2 * 3));
|
||||
expect(Array.from(png.subarray(0, 8))).toEqual([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||
|
||||
const decoded = getImageDimensions(Buffer.from(png).toString("base64"), "image/png");
|
||||
expect(decoded).toEqual({ widthPx: 3, heightPx: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildLargeTextLines", () => {
|
||||
it("encodes each scale as an OSC 66 span and reserves scale-1 blank rows below it", () => {
|
||||
const lines = buildLargeTextLines([2, 3]);
|
||||
// scale 2 → 1 reserved row, scale 3 → 2 reserved rows.
|
||||
expect(lines).toHaveLength(5);
|
||||
expect(lines[0]).toContain("\x1b]66;s=2;");
|
||||
expect(lines[1]).toBe("");
|
||||
expect(lines[2]).toContain("\x1b]66;s=3;");
|
||||
expect(lines[3]).toBe("");
|
||||
expect(lines[4]).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user