Files
oh-my-pi/packages/coding-agent/test/debug/log-formatting.test.ts
T
julia 2047b9ccd1 feat(coding-agent/debug): Added interactive debug log viewer with selection controls
- Replaced the log preview with an interactive viewer supporting navigation, selection, expansion, and clipboard copy.
- Added log formatting helpers to wrap multi-line entries and parse timestamps for session boundary detection.
- Covered viewer selection, copy payload sanitization, expanded formatting, and timestamp parsing with new tests.
2026-02-15 09:53:17 +01:00

54 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
formatDebugLogExpandedLines,
formatDebugLogLine,
parseDebugLogTimestampMs,
} 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);
});
it("wraps expanded log lines without dropping content", () => {
const input = "0123456789ABCDEFGHIJ";
const lines = formatDebugLogExpandedLines(input, 6);
expect(lines.length).toBeGreaterThan(1);
for (const line of lines) {
expect(Bun.stringWidth(line)).toBeLessThanOrEqual(6);
}
});
it("parses timestamp from JSON log lines", () => {
const input = '{"timestamp":"2026-02-14T12:34:56.000Z","level":"info","message":"ok"}';
expect(parseDebugLogTimestampMs(input)).toBe(Date.parse("2026-02-14T12:34:56.000Z"));
});
it("returns undefined when timestamp is missing or invalid", () => {
expect(parseDebugLogTimestampMs('{"message":"ok"}')).toBeUndefined();
expect(parseDebugLogTimestampMs('{"timestamp":"not-a-date"}')).toBeUndefined();
expect(parseDebugLogTimestampMs("not-json")).toBeUndefined();
});
});