import { describe, expect, it } from "vitest"; import { attachmentKindOf, MessageBlock, validateThreadsSendInput } from "./index.js"; describe("attachment contracts", () => { it("parses image and file message blocks", () => { expect( MessageBlock.parse({ kind: "image", artifactId: "art_1", mimeType: "image/png", name: "shot.png", }), ).toMatchObject({ kind: "image", name: "shot.png" }); expect( MessageBlock.parse({ kind: "file", artifactId: "art_2", mimeType: "application/pdf", name: "brief.pdf", size: 1234, }), ).toMatchObject({ kind: "file", size: 1234 }); }); it("requires text or attachments for threads.send", () => { expect(validateThreadsSendInput({ text: "hello" })).toBe(true); expect(validateThreadsSendInput({ artifactIds: ["art_1"] })).toBe(true); expect(validateThreadsSendInput({})).toBe(false); expect(validateThreadsSendInput({ artifactIds: ["a", "b", "c", "d", "e"] })).toBe(true); }); it("classifies media types and parses media blocks", () => { expect(attachmentKindOf("image/webp")).toBe("image"); expect(attachmentKindOf("video/mp4")).toBe("video"); expect(attachmentKindOf("audio/mpeg")).toBe("audio"); expect(attachmentKindOf("text/vtt")).toBe("file"); expect( MessageBlock.parse({ kind: "video", artifactId: "art_3", mimeType: "video/mp4", name: "cut.mp4", size: 2048, durationMs: 15000, width: 1080, height: 1920, }), ).toMatchObject({ kind: "video", width: 1080 }); expect( MessageBlock.parse({ kind: "media", jobId: "job_1", operation: "edit_video", status: "running", title: "Cut to 9:16", progress: 0.4, outputs: [], }), ).toMatchObject({ kind: "media", status: "running" }); expect(() => MessageBlock.parse({ kind: "media", jobId: "job_1", operation: "edit_video", status: "running", title: "Cut", progress: 1.5, outputs: [], }), ).toThrow(); }); });