fix(coding-agent/debug): Sanitized debug log rendering

- Sanitized debug log lines by stripping ANSI/control codes, replacing tabs, and truncating to terminal width.
- Added formatting helper and unit tests covering sanitization, tab handling, and truncation.
This commit is contained in:
julia
2026-02-13 23:58:47 +00:00
committed by can1357
parent 918bf9b043
commit 8d3fe37ca5
4 changed files with 47 additions and 2 deletions
@@ -0,0 +1,29 @@
import { describe, expect, it } from "bun:test";
import { formatDebugLogLine } from "../../src/debug/log-formatting";
describe("formatDebugLogLine", () => {
it("strips ANSI codes and carriage returns", () => {
const input = "\u001b[31merror\r\u001b[0m";
const result = formatDebugLogLine(input, 80);
expect(result).toBe("error");
});
it("replaces tabs with spaces", () => {
const input = "col1\tcol2";
const result = formatDebugLogLine(input, 80);
expect(result).toBe("col1 col2");
});
it("removes unsafe control characters", () => {
const input = "ok\u0007bad";
const result = formatDebugLogLine(input, 80);
expect(result).toBe("okbad");
});
it("truncates long lines", () => {
const input = "0123456789ABCDEFGHIJ";
const result = formatDebugLogLine(input, 10);
expect(Bun.stringWidth(result)).toBeLessThanOrEqual(10);
expect(result.startsWith("012345")).toBe(true);
});
});