Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

toolItems.test.ts

43 lines1.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 MAX_TOOL_OUTPUT_IMAGES,
4 MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH,
5 toolOutputImages,
6} from "@t3tools/shared/toolOutput";
7​
8import { openCodeToolOutput } from "./toolItems.ts";
9​
10describe("openCodeToolOutput", () => {
11 it("preserves inline raster file content and leaves other files unserved", () => {
12 const output = openCodeToolOutput("Preview complete", [
13 { uri: "https://example.com/preview.png", mime: "image/png" },
14 { uri: "file:///tmp/preview.png", mime: "image/png" },
15 { uri: "data:image/svg+xml;base64,AAAA", mime: "image/svg+xml" },
16 { uri: "data:image/png;base64,AAAA", mime: "image/jpeg" },
17 { uri: "data:image/png;base64,", mime: "image/png" },
18 { uri: "data:image/png;base64,iVBORw0KGgo=", mime: "image/png" },
19 ]);
20 expect(toolOutputImages(output)).toEqual([{ mimeType: "image/png", data: "iVBORw0KGgo=" }]);
21 expect(output).toEqual({
22 content: [
23 { type: "text", text: "Preview complete" },
24 { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" },
25 ],
26 });
27 expect(openCodeToolOutput("Text result")).toBe("Text result");
28 const oversized = "A".repeat(MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH + 4);
29 const bounded = openCodeToolOutput(
30 "Preview complete",
31 Array.from({ length: MAX_TOOL_OUTPUT_IMAGES + 2 }, (_, index) => ({
32 uri: `data:image/png;base64,${index === 0 ? oversized : "AQ=="}`,
33 mime: "image/png",
34 })),
35 );
36 expect(typeof bounded === "object" ? bounded.content.length : 0).toBe(
37 MAX_TOOL_OUTPUT_IMAGES + 1,
38 );
39 const images = toolOutputImages(bounded);
40 expect(images[0]?.data?.length).toBe(oversized.length);
41 expect(images[1]?.data).toBe("AQ==");
42 });
43});