/** * @file PetChat.test.ts * @description Unit tests for the pet chat's transcript-to-bubbles folding (`chatLines`). * @author Nguyễn Ngọc Trí Vĩ */ import { describe, it, expect } from "vitest"; import { chatLines } from "../PetChat"; import type { TranscriptMessage } from "../../../lib/types"; const msg = (m: Partial): TranscriptMessage => ({ type: "user", timestamp: null, content: [], ...m }) as TranscriptMessage; describe("chatLines", () => { it("keeps the user's words and the assistant's prose, folding tool calls into one chip", () => { const lines = chatLines([ msg({ type: "user", sender: "user", content: [{ type: "text", text: "hi" }] }), msg({ type: "assistant", content: [ { type: "thinking", text: "hmm" }, { type: "tool_use", name: "Read" }, ], }), msg({ type: "user", sender: "tool", content: [{ type: "tool_result", output: "x" }] }), msg({ type: "assistant", content: [ { type: "tool_use", name: "Read" }, { type: "text", text: "hello!" }, ], }), ]); expect(lines.map((l) => (l.role === "tools" ? l.names : l.text))).toEqual([ "hi", ["Read", "Read"], "hello!", ]); }); it("drops Claude Code's own injected lines", () => { const lines = chatLines([ msg({ sender: "user", content: [{ type: "text", text: "/clear" }] }), ]); expect(lines).toEqual([]); }); });