Files
agent/apps/web/tests/attachments.test.tsx

25 lines
1.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { HarnessAttachmentAdapter } from "../src/assistant/attachment-adapter.js";
describe("HarnessAttachmentAdapter", () => {
it("uploads immediately, emits no base64, and revokes its local preview", async () => {
const createObjectURL = vi.spyOn(URL, "createObjectURL").mockReturnValue("blob:preview");
const revokeObjectURL = vi.spyOn(URL, "revokeObjectURL").mockImplementation(() => undefined);
const upload = vi.fn().mockResolvedValue({
attachment: { attachmentId: "att_server", sessionId: "ses_1", name: "one.png", mediaType: "image/png", byteSize: 68, width: 1, height: 1, status: "ready" },
});
const remove = vi.fn().mockResolvedValue({ removed: true });
const adapter = new HarnessAttachmentAdapter({ uploadAttachment: upload, deleteAttachment: remove });
const file = new File([new Uint8Array([137, 80, 78, 71])], "one.png", { type: "image/png" });
const pending = await adapter.add({ file });
expect(upload).toHaveBeenCalledWith(file);
expect(adapter.previewUrl("att_server")).toBe("blob:preview");
const complete = await adapter.send(pending);
expect(JSON.stringify(complete)).not.toContain("base64");
expect(revokeObjectURL).toHaveBeenCalledWith("blob:preview");
expect(createObjectURL).toHaveBeenCalledWith(file);
});
});