1import { ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { buildMessageContext } from "~/lib/composerContextRecords";
5import { composerContextRecordsFromDraft } from "./composerContextPresentation";
6
7describe("composerContextRecordsFromDraft", () => {
8 it("resolves each wire reference to its own backing draft even when producer ids collide", () => {
9 const id = "same.id:1";
10 const terminal = {
11 id,
12 threadId: ThreadId.make("t1"),
13 terminalId: "default",
14 terminalLabel: "Terminal",
15 lineStart: 1,
16 lineEnd: 1,
17 text: "output",
18 createdAt: "2026-01-01T00:00:00.000Z",
19 };
20 const image = {
21 type: "image" as const,
22 id,
23 name: "shot.png",
24 mimeType: "image/png",
25 sizeBytes: 1,
26 file: new File(["x"], "shot.png"),
27 previewUrl: "blob:shot",
28 };
29 const file = {
30 type: "file" as const,
31 id,
32 name: "file.txt",
33 mimeType: "text/plain",
34 sizeBytes: 1,
35 file: null,
36 };
37 const draftRecords = composerContextRecordsFromDraft({
38 terminalContexts: [terminal],
39 images: [image],
40 files: [file],
41 });
42 const message = buildMessageContext({
43 terminalContexts: [terminal],
44 reviewComments: [],
45 previewAnnotations: [],
46 attachments: [
47 { attachment: image, attachmentId: "uploaded-image" },
48 { attachment: file, attachmentId: "uploaded-file" },
49 ],
50 })!;
51 expect(draftRecords.size).toBe(3);
52 for (const record of message.records) {
53 expect(draftRecords.get(record.contextId)?.kind).toBe(record.kind);
54 }
55 });
56});