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

itemDetail.test.ts

92 lines3.3 KB

1import { ThreadId, TurnItemId } from "@t3tools/contracts";
2import * as DateTime from "effect/DateTime";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { turnItemOutputImages, turnItemOutputText } from "./itemDetail.ts";
6​
7const screenshot = {
8 id: TurnItemId.make("tool-screenshot"),
9 type: "dynamic_tool" as const,
10 threadId: ThreadId.make("thread-1"),
11 runId: null,
12 nodeId: null,
13 providerThreadId: null,
14 providerTurnId: null,
15 nativeItemRef: null,
16 parentItemId: null,
17 ordinal: 1,
18 status: "completed" as const,
19 title: null,
20 toolName: "mcp__t3-code__device_screenshot",
21 input: { deviceId: "phone" },
22 output: {
23 content: [
24 { type: "text", text: "Captured the home screen." },
25 { type: "image", mimeType: "image/png" },
26 ],
27 },
28 startedAt: DateTime.makeUnsafe("2026-10-05T00:00:00.000Z"),
29 completedAt: DateTime.makeUnsafe("2026-10-05T00:00:01.000Z"),
30 updatedAt: DateTime.makeUnsafe("2026-10-05T00:00:01.000Z"),
31};
32​
33describe("tool output images", () => {
34 it("shows a screenshot as an image asset, not as text", () => {
35 expect(turnItemOutputImages(screenshot)).toEqual([
36 {
37 _tag: "tool-output-image",
38 threadId: screenshot.threadId,
39 itemId: screenshot.id,
40 index: 0,
41 },
42 ]);
43 expect(turnItemOutputText(screenshot)).toBe("Captured the home screen.");
44 expect(
45 turnItemOutputText({ ...screenshot, output: { content: [screenshot.output.content[1]] } }),
46 ).toBeNull();
47 });
48​
49 it("keeps a placeholder for images it cannot show", () => {
50 const output = { content: [{ type: "image", mimeType: "image/svg+xml" }] };
51 expect(turnItemOutputImages({ ...screenshot, output })).toEqual([]);
52 expect(turnItemOutputText({ ...screenshot, output })).toBe("[image]");
53 });
54​
55 it("omits Claude Read's image placeholder when the file has a preview", () => {
56 const output = {
57 type: "image",
58 file: { filePath: "/tmp/blk.png", type: "image/png", sizeBytes: 1024 },
59 };
60 const item = { ...screenshot, toolName: "Read", viewedImagePath: "/tmp/blk.png", output };
61​
62 expect(turnItemOutputImages(item)).toEqual([]);
63 expect(turnItemOutputText(item)).toBeNull();
64 expect(turnItemOutputText({ ...item, viewedImagePath: undefined })).toBe("[image]");
65 });
66​
67 it("keeps accompanying text and literal image markers when the file has a preview", () => {
68 const output = {
69 content: [
70 { type: "text", text: "Read /tmp/blk.png. Literal marker: [image]" },
71 screenshot.output.content[1],
72 ],
73 };
74 expect(turnItemOutputText({ ...screenshot, viewedImagePath: "/tmp/blk.png", output })).toBe(
75 "Read /tmp/blk.png. Literal marker: [image]",
76 );
77 });
78​
79 it("keeps placeholders for unserved images in a list despite a file preview", () => {
80 const blocks = [
81 { type: "text", text: "Read /tmp/blk.png." },
82 { type: "image", file: { type: "image/png", sizeBytes: 1024 } },
83 screenshot.output.content[1],
84 { type: "image", mimeType: "image/svg+xml" },
85 ];
86 for (const output of [blocks, { content: blocks }, { content: blocks, isError: false }]) {
87 const item = { ...screenshot, viewedImagePath: "/tmp/blk.png", output };
88 expect(turnItemOutputText(item)).toBe("Read /tmp/blk.png.\n[image]\n[image]");
89 expect(turnItemOutputImages(item)).toHaveLength(1);
90 }
91 });
92});