import test from "node:test"; import assert from "node:assert/strict"; import { normalizePiEvent } from "./normalize.mjs"; test("normalizePiEvent converts tool start events into protocol tool-call records", () => { const normalized = normalizePiEvent({ type: "tool_execution_start", toolName: "read", args: { path: "src/app.ts", offset: 1, limit: 20 }, }); assert.deepEqual(normalized, { type: "tool_call", toolName: "read", args: { path: "src/app.ts", offset: 1, limit: 20 }, }); }); test("normalizePiEvent converts assistant message_end into a final-text record", () => { const normalized = normalizePiEvent({ type: "message_end", message: { role: "assistant", model: "anthropic/claude-sonnet-4-5", stopReason: "end_turn", content: [{ type: "text", text: "Final answer" }], usage: { input: 10, output: 5, totalTokens: 15, cost: { total: 0.001 } }, }, }); assert.deepEqual(normalized, { type: "assistant_text", text: "Final answer", model: "anthropic/claude-sonnet-4-5", stopReason: "end_turn", usage: { input: 10, output: 5, totalTokens: 15, cost: { total: 0.001 } }, }); });