/** * pdf-import.test.ts — coverage for the parser surface only. * * The actual pdf.js rendering + Aztec scan loop in importCodexPDF requires * a DOM (HTMLCanvasElement) which vitest's node environment does not provide. * End-to-end PDF round-trip lives in the manual Codex verification matrix * (see peach_codex_reliability.md §5.2). Here we only test the bits we can: * the defensive envelope parser. */ import { describe, expect, it } from "vitest"; import { parseChunkEnvelope } from "./pdf-import"; describe("parseChunkEnvelope", () => { it("parses a well-formed envelope", () => { const env = { v: 2, c: "PX-TEST-1234", i: 0, t: 15, p: false, d: "AAAA", h: "ABCDEF1234567890ABCDEF1234567890", }; expect(parseChunkEnvelope(JSON.stringify(env))).toEqual(env); }); it("returns null for non-JSON input", () => { expect(parseChunkEnvelope("not json at all")).toBeNull(); }); it("returns null for non-Peach JSON", () => { expect(parseChunkEnvelope(JSON.stringify({ hello: "world" }))).toBeNull(); }); it("returns null when version is missing", () => { expect( parseChunkEnvelope( JSON.stringify({ c: "PX", i: 0, t: 5, p: false, d: "A", h: "A" }), ), ).toBeNull(); }); it("returns null when fields have the wrong types", () => { expect( parseChunkEnvelope( JSON.stringify({ v: 2, c: "PX", i: "0", // should be number t: 5, p: false, d: "A", h: "A", }), ), ).toBeNull(); }); it("returns null for v=1 envelopes", () => { expect( parseChunkEnvelope( JSON.stringify({ v: 1, c: "PX", i: 0, t: 5, p: false, d: "A", h: "A", }), ), ).toBeNull(); }); });