The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as NodeAssert from "node:assert/strict"; |
| 2 | |
| 3 | import { describe, it } from "vite-plus/test"; |
| 4 | |
| 5 | import * as OpenCodeRuntime from "./OpenCodeRuntime.ts"; |
| 6 | |
| 7 | describe("parseServerUrlFromOutput", () => { |
| 8 | it.each([ |
| 9 | ["opencode server listening on http://127.0.0.1:4096", null], |
| 10 | ["opencode server listening on http://127.0.0.1:40961\n", "http://127.0.0.1:40961"], |
| 11 | ["opencode server listening on http://127.0.0.1:40961\r\n", "http://127.0.0.1:40961"], |
| 12 | ])("reads only a newline-terminated ready line: %j", (output, expected) => { |
| 13 | NodeAssert.equal(OpenCodeRuntime.parseServerUrlFromOutput(output), expected); |
| 14 | }); |
| 15 | }); |
| 16 | |
| 17 | describe("toOpenCodeFileParts", () => { |
| 18 | const attachment = (mimeType: string, sizeBytes = 12) => ({ |
| 19 | type: "file" as const, |
| 20 | id: "thread-1-00000000-0000-4000-8000-000000000001-bin", |
| 21 | name: "attachment", |
| 22 | mimeType, |
| 23 | sizeBytes, |
| 24 | }); |
| 25 | |
| 26 | it("sends supported images, text, and PDFs natively and skips what models reject", () => { |
| 27 | const parts = OpenCodeRuntime.toOpenCodeFileParts({ |
| 28 | attachments: [ |
| 29 | attachment("application/pdf"), |
| 30 | attachment("text/plain"), |
| 31 | attachment("image/png"), |
| 32 | // ZIP file parts fail Anthropic before turn start; send only the prompt's path line. |
| 33 | attachment("application/zip"), |
| 34 | // OpenCode inlines only text/plain; other text MIME parts fail Anthropic/OpenAI. |
| 35 | attachment("text/html"), |
| 36 | attachment("text/markdown"), |
| 37 | attachment("application/octet-stream"), |
| 38 | |
| 39 | attachment("image/bmp"), |
| 40 | attachment("image/svg+xml"), |
| 41 | |
| 42 | attachment("application/pdf", 21 * 1024 * 1024), |
| 43 | ], |
| 44 | resolveAttachmentPath: () => "/tmp/attachment", |
| 45 | }); |
| 46 | |
| 47 | NodeAssert.deepEqual( |
| 48 | parts.map((part) => part.mime), |
| 49 | ["application/pdf", "text/plain", "image/png"], |
| 50 | ); |
| 51 | }); |
| 52 | |
| 53 | it("keeps folded clipboard text on the lazy path fallback", () => { |
| 54 | const parts = OpenCodeRuntime.toOpenCodeFileParts({ |
| 55 | attachments: [ |
| 56 | { |
| 57 | ...attachment("text/plain"), |
| 58 | source: { _tag: "pasted-text" as const }, |
| 59 | }, |
| 60 | ], |
| 61 | resolveAttachmentPath: () => "/tmp/pasted-text.txt", |
| 62 | }); |
| 63 | |
| 64 | NodeAssert.deepEqual(parts, []); |
| 65 | }); |
| 66 | }); |