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

toolPresentation.test.ts

159 lines4.7 KB

1import { describe, expect, it } from "@effect/vitest";
2​
3import {
4 extractToolActivityData,
5 extractToolActivityPresentation,
6 hasToolActivityData,
7 toolActivityDataBody,
8} from "./toolPresentation.ts";
9​
10const devinResourceToolEvent = {
11 type: "item.completed",
12 payload: {
13 itemType: "dynamic_tool_call",
14 status: "completed",
15 title: "Resource fixture",
16 data: {
17 toolCallId: "devin-resource-tool",
18 kind: "other",
19 resource: {
20 uri: "urn:acp:fixture:resource-link",
21 name: "schema fixture",
22 description: "typed protocol fixture",
23 mimeType: "text/markdown",
24 },
25 content: [
26 {
27 type: "content",
28 content: { type: "text", text: "ordinary tool output" },
29 },
30 ],
31 },
32 },
33} as const;
34​
35describe("extractToolActivityPresentation", () => {
36 it("expands generic resource URI and embedded text without serializing collapsed rows", () => {
37 const resource = { uri: "urn:notes", text: "Resource notes" };
38 const entry = { itemType: "dynamic_tool_call", toolData: { resource } };
39 expect(hasToolActivityData(entry)).toBe(true);
40 expect(toolActivityDataBody(entry)).toBe(`Resource\n${JSON.stringify(resource, null, 2)}`);
41 expect(hasToolActivityData({ itemType: "dynamic_tool_call", toolData: {} })).toBe(false);
42 expect(toolActivityDataBody({ itemType: "dynamic_tool_call" })).toBeUndefined();
43 });
44​
45 it("retains canonical ACP resource metadata for generic tool activity", () => {
46 expect(extractToolActivityData(devinResourceToolEvent.payload)).toBe(
47 devinResourceToolEvent.payload.data,
48 );
49 });
50​
51 it("keeps MCP item extraction precedence when MCP data also has a resource", () => {
52 const item = {
53 type: "mcpToolCall",
54 server: "t3-code",
55 tool: "preview_status",
56 result: { content: [{ type: "text", text: "attached" }] },
57 };
58 const data = {
59 toolName: "mcp__t3_code__preview_status",
60 item,
61 resource: devinResourceToolEvent.payload.data.resource,
62 };
63​
64 expect(extractToolActivityData({ itemType: "mcp_tool_call", data })).toBe(item);
65 expect(toolActivityDataBody({ itemType: "mcp_tool_call", toolData: item })).toBe(
66 `MCP call\n${JSON.stringify(item, null, 2)}`,
67 );
68 });
69​
70 it("reads provider-neutral presentation fields", () => {
71 expect(
72 extractToolActivityPresentation({
73 toolSurface: "browser",
74 toolIcon: {
75 _tag: "website",
76 pageUrl: "https://example.com/docs",
77 faviconUrl: "https://example.com/favicon.png",
78 faviconUrlDark: "https://example.com/favicon-dark.png",
79 },
80 toolSource: {
81 key: "integration:example",
82 name: "Example",
83 kind: "integration",
84 icon: {
85 _tag: "themed-logo",
86 logoUrl: "https://example.com/logo-light.png",
87 logoUrlDark: "https://example.com/logo-dark.png",
88 },
89 },
90 }),
91 ).toEqual({
92 toolSurface: "browser",
93 toolIcon: {
94 _tag: "website",
95 pageUrl: "https://example.com/docs",
96 faviconUrl: "https://example.com/favicon.png",
97 faviconUrlDark: "https://example.com/favicon-dark.png",
98 },
99 toolSource: {
100 key: "integration:example",
101 name: "Example",
102 kind: "integration",
103 icon: {
104 _tag: "themed-logo",
105 logoUrl: "https://example.com/logo-light.png",
106 logoUrlDark: "https://example.com/logo-dark.png",
107 },
108 },
109 });
110 });
111​
112 it("reads provider-neutral native app icons", () => {
113 expect(
114 extractToolActivityPresentation({
115 toolSurface: "computer",
116 toolIcon: {
117 _tag: "native-app",
118 app: { _tag: "app-id", appId: "com.example.Editor" },
119 },
120 toolSource: {
121 key: "native-app:com.example.editor",
122 name: "Editor",
123 kind: "computer",
124 },
125 }),
126 ).toEqual({
127 toolSurface: "computer",
128 toolIcon: {
129 _tag: "native-app",
130 app: { _tag: "app-id", appId: "com.example.Editor" },
131 },
132 toolSource: {
133 key: "native-app:com.example.editor",
134 name: "Editor",
135 kind: "computer",
136 },
137 });
138 });
139​
140 it("does not infer presentation from provider-specific payload data", () => {
141 expect(
142 extractToolActivityPresentation({
143 data: {
144 item: {
145 arguments: { code: 'await sky.click({ app: "Finder" })' },
146 result: {
147 _meta: {
148 "codex/toolSurface": {
149 kind: "computerUse",
150 app: { kind: "displayName", displayName: "Finder" },
151 },
152 },
153 },
154 },
155 },
156 }),
157 ).toEqual({});
158 });
159});