write tui debug/crash logs into the configured pi agent dir (#6958)

fixes #6652
This commit is contained in:
David Brailovsky
2026-07-22 15:48:25 +02:00
committed by GitHub
parent 346c85473d
commit fe42ba5b38
5 changed files with 34 additions and 6 deletions
+25
View File
@@ -1,4 +1,7 @@
import assert from "node:assert";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, it } from "node:test";
import type { Terminal as XtermTerminalType } from "@xterm/headless";
import { Image } from "../src/components/image.ts";
@@ -71,6 +74,28 @@ function getCellItalic(terminal: VirtualTerminal, row: number, col: number): num
return cell.isItalic();
}
describe("TUI debug logging", () => {
it("writes redraw logs to the provided directory", async () => {
const logDir = mkdtempSync(join(tmpdir(), "pi-tui-log-"));
try {
await withEnv({ PI_DEBUG_REDRAW: "1" }, async () => {
const terminal = new VirtualTerminal(40, 10);
const tui = new TUI(terminal, undefined, logDir);
const component = new TestComponent();
tui.addChild(component);
component.lines = ["test"];
tui.start();
await terminal.waitForRender();
assert.match(readFileSync(join(logDir, "pi-debug.log"), "utf-8"), /fullRender: first render/);
tui.stop();
});
} finally {
rmSync(logDir, { recursive: true, force: true });
}
});
});
describe("TUI Kitty image cleanup", () => {
it("clears reserved Kitty image rows before drawing appended image placements", async () => {
setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });