Open History to see the last commit
1import * as NodeAssert from "node:assert/strict";
2
3import { describe, it } from "vite-plus/test";
4
5import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
6
7describe("toOpenCodeFileParts", () => {
8 const attachment = (mimeType: string, sizeBytes = 12) => ({
9 type: "file" as const,
10 id: "thread-1-00000000-0000-4000-8000-000000000001-bin",
11 name: "attachment",
12 mimeType,
13 sizeBytes,
14 });
15
16 it("sends supported images, text, and PDFs natively and skips what models reject", () => {
17 const parts = OpenCodeRuntime.toOpenCodeFileParts({
18 attachments: [
19 attachment("application/pdf"),
20 attachment("text/plain"),
21 attachment("image/png"),
22 // ZIP file parts fail Anthropic before turn start; send only the prompt's path line.
23 attachment("application/zip"),
24 // OpenCode inlines only text/plain; other text MIME parts fail Anthropic/OpenAI.
25 attachment("text/html"),
26 attachment("text/markdown"),
27 attachment("application/octet-stream"),
28
29 attachment("image/bmp"),
30 attachment("image/svg+xml"),
31
32 attachment("application/pdf", 21 * 1024 * 1024),
33 ],
34 resolveAttachmentPath: () => "/tmp/attachment",
35 });
36
37 NodeAssert.deepEqual(
38 parts.map((part) => part.mime),
39 ["application/pdf", "text/plain", "image/png"],
40 );
41 });
42
43 it("keeps folded clipboard text on the lazy path fallback", () => {
44 const parts = OpenCodeRuntime.toOpenCodeFileParts({
45 attachments: [
46 {
47 ...attachment("text/plain"),
48 source: { _tag: "pasted-text" as const },
49 },
50 ],
51 resolveAttachmentPath: () => "/tmp/pasted-text.txt",
52 });
53
54 NodeAssert.deepEqual(parts, []);
55 });
56});