28d9de74ce
* windows sixel imp * windows sixel imp, terminal capability check, pessimistic sixel selection * fix codex suggestions --------- Co-authored-by: Brit <lol@no.com>
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
import { BashExecutionComponent } from "@oh-my-pi/pi-coding-agent/modes/components/bash-execution";
|
|
import { getThemeByName, setThemeInstance } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
|
import type { TUI } from "@oh-my-pi/pi-tui";
|
|
|
|
const SIXEL = "\x1bPqabc\x1b\\";
|
|
|
|
describe("BashExecutionComponent SIXEL sanitization", () => {
|
|
const originalForceProtocol = Bun.env.PI_FORCE_IMAGE_PROTOCOL;
|
|
const originalAllowPassthrough = Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH;
|
|
const ui = { requestRender: () => {} } as unknown as TUI;
|
|
|
|
beforeEach(async () => {
|
|
const theme = await getThemeByName("dark");
|
|
expect(theme).toBeDefined();
|
|
setThemeInstance(theme!);
|
|
});
|
|
afterEach(() => {
|
|
if (originalForceProtocol === undefined) delete Bun.env.PI_FORCE_IMAGE_PROTOCOL;
|
|
else Bun.env.PI_FORCE_IMAGE_PROTOCOL = originalForceProtocol;
|
|
if (originalAllowPassthrough === undefined) delete Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH;
|
|
else Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH = originalAllowPassthrough;
|
|
});
|
|
|
|
it("preserves SIXEL output when passthrough gates are enabled", () => {
|
|
Bun.env.PI_FORCE_IMAGE_PROTOCOL = "sixel";
|
|
Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH = "1";
|
|
|
|
const component = new BashExecutionComponent("echo sixel", ui, false);
|
|
component.appendOutput(SIXEL);
|
|
component.setComplete(0, false);
|
|
|
|
expect(component.getOutput()).toContain(SIXEL);
|
|
});
|
|
|
|
it("does not truncate long SIXEL payload lines", () => {
|
|
Bun.env.PI_FORCE_IMAGE_PROTOCOL = "sixel";
|
|
Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH = "1";
|
|
|
|
const payload = `\x1bPq${"A".repeat(5000)}\x1b\\`;
|
|
const component = new BashExecutionComponent("echo sixel", ui, false);
|
|
component.appendOutput(payload);
|
|
component.setComplete(0, false);
|
|
|
|
const output = component.getOutput();
|
|
expect(output).toContain("\x1bPq");
|
|
expect(output).toContain("\x1b\\");
|
|
expect(output).not.toContain("chars omitted");
|
|
});
|
|
|
|
it("still truncates long non-SIXEL lines", () => {
|
|
Bun.env.PI_FORCE_IMAGE_PROTOCOL = "sixel";
|
|
Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH = "1";
|
|
|
|
const longText = "x".repeat(5000);
|
|
const component = new BashExecutionComponent("echo text", ui, false);
|
|
component.appendOutput(longText);
|
|
component.setComplete(0, false);
|
|
|
|
const output = component.getOutput();
|
|
expect(output).toContain("chars omitted");
|
|
expect(output).not.toContain("\x1bPq");
|
|
});
|
|
|
|
it("strips SIXEL control escapes when passthrough gates are disabled", () => {
|
|
delete Bun.env.PI_FORCE_IMAGE_PROTOCOL;
|
|
delete Bun.env.PI_ALLOW_SIXEL_PASSTHROUGH;
|
|
|
|
const component = new BashExecutionComponent("echo sixel", ui, false);
|
|
component.appendOutput(SIXEL);
|
|
component.setComplete(0, false);
|
|
|
|
expect(component.getOutput()).not.toContain("\x1bPq");
|
|
expect(component.getOutput()).toBe("");
|
|
});
|
|
});
|