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

presentation.test.ts

75 lines2.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { ThreadId } from "@t3tools/contracts";
4​
5import { resolveViewedImageAsset, workEntryViewedImagePath } from "./presentation.js";
6​
7describe("workEntryViewedImagePath", () => {
8 const entry = {
9 id: "entry-1",
10 createdAt: "2026-01-01T00:00:00Z",
11 label: "Read",
12 tone: "tool",
13 } as const;
14​
15 it("returns a single image path from supported read entries", () => {
16 expect(
17 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: " assets/a.png " }),
18 ).toBe("assets/a.png");
19 expect(
20 workEntryViewedImagePath({
21 ...entry,
22 itemType: "dynamic_tool",
23 toolTitle: "Read file",
24 detail: "C:\\workspace\\a.webp",
25 }),
26 ).toBe("C:\\workspace\\a.webp");
27 });
28​
29 it("rejects non-image, multi-line, and non-read details", () => {
30 expect(
31 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.txt" }),
32 ).toBeNull();
33 expect(
34 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.png\nb.png" }),
35 ).toBeNull();
36 expect(workEntryViewedImagePath({ ...entry, detail: "a.png" })).toBeNull();
37 });
38});
39​
40describe("resolveViewedImageAsset", () => {
41 const threadId = ThreadId.make("thread-1");
42​
43 it("loads t3 attachment paths as attachments", () => {
44 const attachmentId =
45 "11111111-1111-4111-8111-111111111111-22222222-2222-4222-8222-222222222222";
46 expect(
47 resolveViewedImageAsset(`/Users/demo/.t3/dev/attachments/${attachmentId}.png`, {
48 threadId,
49 workspaceRoot: "/workspace",
50 }),
51 ).toEqual({
52 resource: { _tag: "attachment", attachmentId },
53 alt: `${attachmentId}.png`,
54 srcFragment: "",
55 });
56 });
57​
58 it("normalizes workspace image sources", () => {
59 expect(
60 resolveViewedImageAsset("screens/logo.svg?v=2#mark", {
61 threadId,
62 workspaceRoot: "/workspace",
63 }),
64 ).toEqual({
65 resource: {
66 _tag: "workspace-file",
67 threadId,
68 path: "/workspace/screens/logo.svg",
69 },
70 alt: "logo.svg",
71 srcFragment: "#mark",
72 });
73 expect(resolveViewedImageAsset("https://example.com/logo.png", { threadId })).toBeNull();
74 });
75});