import { ScrollView } from "@earendil-works/pi-tui"; import { describe, expect, it, vi } from "vitest"; import { createNativeVoiceHistoryView, showNativeVoiceHistory, } from "../src/voice-history-view.ts"; const theme = { fg: (_color: string, text: string) => text, bold: (text: string) => text, } as never; describe("native voice history view", () => { it("reports history review as waiting for a question and closes normally", async () => { let options: unknown; const ctx = { ui: { custom: async (factory: any, customOptions: unknown) => { options = customOptions; return await new Promise((resolve) => { const view = factory({ requestRender() {} }, theme, {}, resolve); view.handleInput("q"); }); }, }, } as never; await expect(showNativeVoiceHistory(ctx, [])).resolves.toBeUndefined(); expect(options).toEqual({ blocked: { kind: "question", message: "Review voice history" }, }); }); it("marks assistant progress as status commentary with truthful playback", () => { const view = createNativeVoiceHistoryView( { requestRender() {} } as never, theme, [ { id: "status", role: "assistant", kind: "status", text: "Pi is still working.", playedText: "", interrupted: true, playback: "not-played", }, ], () => {}, ); const rendered = view.render(100).join("\n"); expect(rendered).toContain("VOICE ยท STATUS [interrupted]"); expect(rendered).toContain("Played: none"); }); it("closes on Escape without changing the normal editor", () => { const close = vi.fn(); const view = createNativeVoiceHistoryView( { requestRender() {} } as never, theme, [], close, ); view.handleInput?.("\u001b"); expect(close).toHaveBeenCalledOnce(); }); it("shows generated replies with unspoken markers and bounded transcript", () => { const view = createNativeVoiceHistoryView( { requestRender() {} } as never, theme, Array.from({ length: 200 }, (_, index) => ({ id: String(index), role: "assistant" as const, text: `generated ${index}`, playedText: "", interrupted: index === 199, playback: "not-played" as const, })), () => {}, ); expect(view).toBeInstanceOf(ScrollView); const rendered = view.render(80).join("\n"); expect(rendered).toContain("generated 199"); expect(rendered).toContain("not-played"); expect(rendered).not.toContain("generated 0"); for (let i = 0; i < 4; i++) view.handleInput?.("["); const oldest = view.render(80).join("\n"); expect(oldest).toContain("generated 0"); expect(oldest).not.toContain("generated 199"); }); });