- Add agent log persistence layer with JSONL append/read and event emission in core store - Add server-side SSE log streaming endpoint and REST route for fetching logs - Create AgentLogViewer component and useAgentLogs hook for real-time log display - Integrate log viewer into TaskDetailModal - Fix pre-existing build and test errors
67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { AgentLogViewer } from "../AgentLogViewer";
|
|
import type { AgentLogEntry } from "@hai/core";
|
|
|
|
function makeEntry(overrides: Partial<AgentLogEntry> = {}): AgentLogEntry {
|
|
return {
|
|
timestamp: "2026-01-01T00:00:00Z",
|
|
taskId: "HAI-001",
|
|
text: "Hello world",
|
|
type: "text",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("AgentLogViewer", () => {
|
|
it("shows loading message when loading with no entries", () => {
|
|
render(<AgentLogViewer entries={[]} loading={true} />);
|
|
expect(screen.getByText("Loading agent logs…")).toBeTruthy();
|
|
});
|
|
|
|
it("shows empty message when no entries and not loading", () => {
|
|
render(<AgentLogViewer entries={[]} loading={false} />);
|
|
expect(screen.getByText("No agent output yet.")).toBeTruthy();
|
|
});
|
|
|
|
it("renders text entries as spans", () => {
|
|
const entries = [
|
|
makeEntry({ text: "first chunk" }),
|
|
makeEntry({ text: "second chunk" }),
|
|
];
|
|
const { container } = render(<AgentLogViewer entries={entries} loading={false} />);
|
|
const textSpans = container.querySelectorAll(".agent-log-text");
|
|
expect(textSpans).toHaveLength(2);
|
|
expect(textSpans[0].textContent).toBe("first chunk");
|
|
expect(textSpans[1].textContent).toBe("second chunk");
|
|
});
|
|
|
|
it("renders tool entries with distinct styling", () => {
|
|
const entries = [
|
|
makeEntry({ text: "Read", type: "tool" }),
|
|
];
|
|
const { container } = render(<AgentLogViewer entries={entries} loading={false} />);
|
|
const toolDiv = container.querySelector(".agent-log-tool");
|
|
expect(toolDiv).toBeTruthy();
|
|
expect(toolDiv!.textContent).toContain("Read");
|
|
});
|
|
|
|
it("renders a mix of text and tool entries", () => {
|
|
const entries = [
|
|
makeEntry({ text: "Starting...", type: "text" }),
|
|
makeEntry({ text: "Bash", type: "tool" }),
|
|
makeEntry({ text: "Done!", type: "text" }),
|
|
];
|
|
const { container } = render(<AgentLogViewer entries={entries} loading={false} />);
|
|
expect(container.querySelectorAll(".agent-log-text")).toHaveLength(2);
|
|
expect(container.querySelectorAll(".agent-log-tool")).toHaveLength(1);
|
|
});
|
|
|
|
it("has a monospace font family", () => {
|
|
const entries = [makeEntry()];
|
|
const { container } = render(<AgentLogViewer entries={entries} loading={false} />);
|
|
const viewer = container.querySelector("[data-testid='agent-log-viewer']") as HTMLElement;
|
|
expect(viewer.style.fontFamily).toBe("monospace");
|
|
});
|
|
});
|