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

presentation.test.ts

810 lines25.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { ThreadId, TurnItemId, type OrchestrationV2TurnItem } from "@t3tools/contracts";
4import * as DateTime from "effect/DateTime";
5​
6import {
7 commandDetailRepeatsCommand,
8 extractCommandOutputText,
9 resolveViewedImageAsset,
10 resolveWorkEntryToolPresentation,
11 summarizeToolGroup,
12 toolGroupAction,
13 toolGroupSummaryKind,
14 toolItemForDisplay,
15 type WorkLogPresentationEntry,
16 type WorkLogToolLifecycleStatus,
17 workEntryViewedImagePath,
18 workEntryIndicatesToolFailure,
19 workEntryDisplayIndicatesToolFailure,
20 workEntryIndicatesToolSuccess,
21} from "./presentation.js";
22​
23function commandItem(
24 fields: Partial<Extract<OrchestrationV2TurnItem, { type: "command_execution" }>> = {},
25): OrchestrationV2TurnItem {
26 return {
27 id: TurnItemId.make("command"),
28 threadId: ThreadId.make("thread"),
29 runId: null,
30 nodeId: null,
31 providerThreadId: null,
32 providerTurnId: null,
33 nativeItemRef: null,
34 parentItemId: null,
35 ordinal: 1,
36 status: "completed",
37 title: null,
38 startedAt: null,
39 completedAt: null,
40 updatedAt: DateTime.makeUnsafe("2026-09-08T00:00:00.000Z"),
41 type: "command_execution",
42 input: 'rg "command not found"',
43 exitCode: 0,
44 ...fields,
45 };
47​
48describe("workEntryIndicatesToolFailure", () => {
49 const base = {
50 id: "w1",
51 createdAt: "2026-01-01T00:00:00.000Z",
52 label: "Read",
53 };
54​
55 it.each([
56 [{ outputIndicatesFailure: true }, true],
57 [{ exitCode: 2 }, true],
58 [{ output: "sh: missing-command: command not found" }, true],
59 [{ output: "Found 3 matches" }, false],
60 [{ output: `${"x".repeat(32_768)} command not found` }, false],
61 [{}, false],
62 ] as const)(
63 "preserves command failure state after removing displayed output: %j",
64 (fields, failed) => {
65 const structuredPayload = commandItem(fields);
66 const entry: WorkLogPresentationEntry = {
67 ...base,
68 tone: "tool",
69 itemType: "command_execution",
70 toolLifecycleStatus: "completed",
71 structuredPayload,
72 };
73 expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(failed);
74 expect(workEntryIndicatesToolSuccess(entry)).toBe(!failed);
75 expect(JSON.stringify(toolItemForDisplay(structuredPayload))).not.toContain('"output":');
76 },
77 );
78​
79 it("is true for error tone", () => {
80 expect(
81 workEntryIndicatesToolFailure({
82 ...base,
83 tone: "error",
84 detail: "nothing special",
85 }),
86 ).toBe(true);
87 });
88​
89 it("is true when lifecycle says failed even if detail is empty", () => {
90 expect(
91 workEntryIndicatesToolFailure({
92 ...base,
93 tone: "tool",
94 toolLifecycleStatus: "failed",
95 }),
96 ).toBe(true);
97 });
98​
99 it("detects file-not-found style tool output with completed lifecycle", () => {
100 expect(
101 workEntryIndicatesToolFailure({
102 ...base,
103 tone: "tool",
104 toolLifecycleStatus: "completed",
105 detail: "File not found: C:\\foo\\nonexistent.ts",
106 }),
107 ).toBe(true);
108 });
109​
110 it("detects glob no files and PowerShell command errors", () => {
111 expect(
112 workEntryIndicatesToolFailure({
113 ...base,
114 label: "Glob",
115 tone: "tool",
116 detail: "No files found",
117 }),
118 ).toBe(true);
119 expect(
120 workEntryIndicatesToolFailure({
121 ...base,
122 label: "Bash",
123 tone: "tool",
124 detail:
125 "The term 'this_is_not_a_command' is not recognized as the name of a cmdlet, function, script file, or operable program.",
126 }),
127 ).toBe(true);
128 });
129​
130 it("is false for successful completed tools", () => {
131 expect(
132 workEntryIndicatesToolFailure({
133 ...base,
134 tone: "tool",
135 toolLifecycleStatus: "completed",
136 detail: "Found 3 matching files",
137 }),
138 ).toBe(false);
139 });
140​
141 it("does not treat error text in a command as rendered failure", () => {
142 const entry = {
143 ...base,
144 label: "Ran command",
145 tone: "tool",
146 toolLifecycleStatus: "completed",
147 command: 'rg "file not found"',
148 detail: "Found 3 matches",
149 } satisfies WorkLogPresentationEntry;
150​
151 expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
152 // Older activities can store output in this field, so that path stays separate.
153 expect(workEntryIndicatesToolFailure(entry)).toBe(true);
154 expect(workEntryDisplayIndicatesToolFailure({ ...entry, detail: "File not found" })).toBe(true);
155 });
156​
157 it("treats successful tool rows as success candidates", () => {
158 expect(
159 workEntryIndicatesToolSuccess({
160 ...base,
161 tone: "tool",
162 toolLifecycleStatus: "completed",
163 detail: "ok",
164 }),
165 ).toBe(true);
166 expect(
167 workEntryIndicatesToolSuccess({
168 ...base,
169 tone: "tool",
170 toolLifecycleStatus: "inProgress",
171 detail: "…",
172 }),
173 ).toBe(false);
174 expect(workEntryIndicatesToolSuccess({ ...base, tone: "thinking", detail: "…" })).toBe(false);
175 expect(
176 workEntryIndicatesToolSuccess({ ...base, tone: "tool", toolLifecycleStatus: "stopped" }),
177 ).toBe(false);
178 expect(
179 workEntryIndicatesToolSuccess({ ...base, tone: "tool", toolLifecycleStatus: "idle" }),
180 ).toBe(false);
181 });
182​
183 it("does not run heuristics on non-tool info rows", () => {
184 expect(
185 workEntryIndicatesToolFailure({
186 ...base,
187 label: "Context compacted",
188 tone: "info",
189 detail: "File not found in conversation",
190 }),
191 ).toBe(false);
192 });
193});
194​
195describe("summarizeToolGroup", () => {
196 const entry = (
197 id: string,
198 overrides: Partial<WorkLogPresentationEntry>,
199 ): WorkLogPresentationEntry => ({
200 id,
201 createdAt: "2026-09-01T00:00:00Z",
202 label: "Tool call",
203 tone: "tool",
204 ...overrides,
205 });
206​
207 it("excludes reasoning from mixed tool counts and icons", () => {
208 const thought = entry("thought", {
209 itemType: "reasoning",
210 tone: "thinking",
211 detail: "Check the source",
212 });
213 const command = entry("command", { itemType: "command_execution", command: "vp test run" });
214 expect(summarizeToolGroup([thought, command, { ...thought, id: "thought-2" }])).toEqual({
215 summary: "Ran 1 command",
216 hasFailure: false,
217 });
218 expect(toolGroupSummaryKind([thought, command])).toBe("command");
219 expect(summarizeToolGroup([thought]).summary).toBe("Thought");
220 expect(summarizeToolGroup([thought, { ...thought, id: "thought-2" }]).summary).toBe(
221 "Thought (×2)",
222 );
223 expect(toolGroupSummaryKind([thought])).toBe("reasoning");
224 });
225​
226 it("counts created threads alongside adjacent commands", () => {
227 expect(
228 summarizeToolGroup([
229 entry("command", { itemType: "command_execution", command: "vp test run" }),
230 entry("created", {
231 itemType: "thread_created",
232​
233 label: "Created thread",
234 }),
235 ]).summary,
236 ).toBe("Ran 1 command and created 1 thread");
237 });
238​
239 it("deduplicates named sources ahead of ordinary actions", () => {
240 const source = { key: "browser-use:chrome", name: "Chrome", kind: "integration" as const };
241 expect(
242 summarizeToolGroup([
243 entry("open", { label: "Open page", toolSource: source }),
244 entry("inspect", { label: "Inspect page", toolSource: source }),
245 entry("command", {
246 label: "Ran command",
247 itemType: "command_execution",
248 command: "git status",
249 }),
250 ]).summary,
251 ).toBe("Used Chrome integration and ran 1 command");
252 });
253​
254 it("omits the integration suffix for special browser and computer sources", () => {
255 expect(
256 summarizeToolGroup([
257 entry("inspect", {
258 label: "Inspect page",
259 toolSource: { key: "browser-use", name: "Browser", kind: "browser" },
260 }),
261 entry("click", {
262 label: "Click",
263 toolSource: { key: "computer-use", name: "Computer Use", kind: "computer" },
264 }),
265 ]).summary,
266 ).toBe("Used Browser and Computer Use");
267 });
268});
269​
270describe("resolveWorkEntryToolPresentation", () => {
271 it.each([
272 "mcp__t3-code__preview_click",
273 "mcp__t3_code__preview_click",
274 "mcp__t3code__preview_click",
275 "T3-code.preview_click",
276 "t3-code · preview_click completed",
277 "t3_code/preview_click",
278 "preview_click",
279 ])("recognizes browser tool names across providers: %s", (label) => {
280 expect(resolveWorkEntryToolPresentation({ label })).toEqual({
281 displayName: "Clicking in the preview browser",
282 icon: "browser",
283 });
284 });
285​
286 it("labels device tools with the device icon", () => {
287 expect(
288 resolveWorkEntryToolPresentation({
289 label: "mcp__t3-code__device_open",
290 toolLifecycleStatus: "completed",
291 }),
292 ).toEqual({ displayName: "Opened a device in the Device panel", icon: "device" });
293 expect(resolveWorkEntryToolPresentation({ label: "t3-code · device_screenshot" })).toEqual({
294 displayName: "Taking a screenshot of the device",
295 icon: "device",
296 });
297 });
298​
299 it("uses structured MCP identity when the provider supplies a custom title", () => {
300 expect(
301 resolveWorkEntryToolPresentation({
302 label: "Tool call complete",
303 toolTitle: "Inspect the current page",
304 toolData: { server: "t3-code", tool: "preview_snapshot", result: { title: "Example" } },
305 }),
306 ).toEqual({ displayName: "Taking a snapshot of the preview page", icon: "browser" });
307 });
308​
309 it.each([
310 ["inProgress", "Clicking in the preview browser"],
311 ["completed", "Clicked in the preview browser"],
312 ["failed", "Failed to click in the preview browser"],
313 ["declined", "Declined to click in the preview browser"],
314 ["stopped", "Stopped clicking in the preview browser"],
315 ["unknown", "Clicking in the preview browser"],
316 ] as const)("describes the tool's own %s state", (toolLifecycleStatus, displayName) => {
317 expect(
318 resolveWorkEntryToolPresentation({
319 label: "T3-code.preview_click",
320 toolLifecycleStatus: toolLifecycleStatus as WorkLogToolLifecycleStatus,
321 }),
322 ).toEqual({ displayName, icon: "browser" });
323 });
324​
325 it("uses the summary's state only when the provider omitted a lifecycle status", () => {
326 const entry = { label: "T3-code.preview_click" };
327 expect(resolveWorkEntryToolPresentation(entry, "inProgress")?.displayName).toBe(
328 "Clicking in the preview browser",
329 );
330 expect(resolveWorkEntryToolPresentation(entry, "completed")?.displayName).toBe(
331 "Clicked in the preview browser",
332 );
333 expect(
334 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "completed" }, "inProgress")
335 ?.displayName,
336 ).toBe("Clicked in the preview browser");
337 expect(
338 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "failed" }, "completed")
339 ?.displayName,
340 ).toBe("Failed to click in the preview browser");
341 });
342​
343 it.each([
344 ["preview_type", "Typing in the preview browser", "Typed in the preview browser"],
345 [
346 "preview_set_appearance",
347 "Setting preview browser appearance",
348 "Set preview browser appearance",
349 ],
350 [
351 "preview_snapshot",
352 "Taking a snapshot of the preview page",
353 "Took a snapshot of the preview page",
354 ],
355 [
356 "preview_recording_stop",
357 "Stopping recording the preview browser",
358 "Stopped recording the preview browser",
359 ],
360 ["t3_thread_read", "Reading a T3 thread", "Read a T3 thread"],
361 ["t3_thread_send", "Sending to a T3 thread", "Sent to a T3 thread"],
362 [
363 "t3_worktree_handoff",
364 "Handing off thread to a git worktree",
365 "Handed off thread to a git worktree",
366 ],
367 ])("preserves verb forms and the rest of %s's label", (tool, running, completed) => {
368 const entry = { label: `t3-code.${tool}` };
369 expect(
370 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "inProgress" })
371 ?.displayName,
372 ).toBe(running);
373 expect(
374 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "completed" })?.displayName,
375 ).toBe(completed);
376 });
377​
378 it("keeps T3 branding for non-browser tools and falls back to the original tool label", () => {
379 expect(
380 resolveWorkEntryToolPresentation({
381 label: "mcp__t3_code__task_status",
382 toolTitle: "Check the child task",
383 }),
384 ).toEqual({ displayName: "Getting delegated task status", icon: "t3-code" });
385 });
386​
387 it("does not brand unknown tools or another server's matching tool name", () => {
388 for (const label of [
389 "mcp__github__preview_click",
390 "t3-code.unknown_tool",
391 "t3-code.toString",
392 "Search files",
393 ]) {
394 expect(resolveWorkEntryToolPresentation({ label })).toBeNull();
395 }
396 expect(
397 resolveWorkEntryToolPresentation({
398 label: "preview_click",
399 toolData: { server: "another-server", tool: "preview_click" },
400 }),
401 ).toBeNull();
402 });
403});
404​
405describe("browser group summaries", () => {
406 const summarizeGroupLabel = (entries: ReadonlyArray<WorkLogPresentationEntry>) =>
407 summarizeToolGroup(entries).summary;
408 const browserEntry: WorkLogPresentationEntry = {
409 id: "browser",
410 createdAt: "2026-09-01T00:00:00Z",
411 label: "MCP tool call",
412 toolData: { server: "t3-code", tool: "preview_click" },
413 itemType: "dynamic_tool",
414 toolLifecycleStatus: "completed",
415 tone: "tool",
416 };
417 const commandEntry: WorkLogPresentationEntry = {
418 id: "command",
419 createdAt: "2026-09-01T00:00:00Z",
420 label: "Ran command",
421 command: "/bin/bash -lc 'vp test run'",
422 itemType: "command_execution",
423 toolLifecycleStatus: "completed",
424 tone: "tool",
425 };
426​
427 it.each([1, 18])("counts %s browser calls separately from generic tools", (count) => {
428 const entries = Array.from({ length: count }, (_, index) => ({
429 ...browserEntry,
430 toolCallId: `browser-${index}`,
431 }));
432 expect(summarizeGroupLabel(entries)).toBe(
433 `Used browser ${count} ${count === 1 ? "time" : "times"}`,
434 );
435 expect(toolGroupSummaryKind(entries)).toBe("browser");
436 });
437​
438 it("combines command and browser counts in a single sentence", () => {
439 const entries = [
440 ...Array.from({ length: 4 }, () => commandEntry),
441 ...Array.from({ length: 15 }, () => browserEntry),
442 ];
443 expect(summarizeGroupLabel(entries)).toBe("Ran 4 commands and used browser 15 times");
444 expect(toolGroupSummaryKind(entries)).toBe("mixed");
445 });
446​
447 it("preserves first-seen action ordering alongside non-browser tools", () => {
448 expect(
449 summarizeGroupLabel([
450 browserEntry,
451 commandEntry,
452 {
453 ...browserEntry,
454 toolData: { server: "t3-code", tool: "task_status" },
455 },
456 ]),
457 ).toBe("Used browser 1 time, ran 1 command, and performed 1 other action");
458 });
459​
460 it("recognizes Claude browser identity without treating script metadata as a shell command", () => {
461 expect(
462 summarizeGroupLabel([
463 {
464 ...browserEntry,
465 command: "node inspect-page.js",
466 toolData: { toolName: "mcp__t3_code__preview_evaluate" },
467 },
468 ]),
469 ).toBe("Used browser 1 time");
470 });
471​
472 it("keeps foreign tools and web searches out of the browser count", () => {
473 expect(
474 summarizeGroupLabel([
475 browserEntry,
476 {
477 ...browserEntry,
478 label: "preview_click",
479 toolData: { server: "another-server", tool: "preview_click" },
480 },
481 {
482 id: "search",
483 createdAt: "2026-09-01T00:00:00Z",
484 label: "Search",
485 tone: "tool",
486 itemType: "web_search",
487 },
488 ]),
489 ).toBe("Used browser 1 time, searched the web 1 time, and performed 1 other action");
490 });
491​
492 it("keeps browser screenshots in the browser count while preserving their image path", () => {
493 const entry = { ...browserEntry, viewedImagePath: "/workspace/page.png" };
494 expect(summarizeGroupLabel([entry])).toBe("Used browser 1 time");
495 expect(workEntryViewedImagePath(entry)).toBe("/workspace/page.png");
496 });
497});
498​
499describe("command work-log details", () => {
500 it("extracts Claude result blocks and projected output", () => {
501 expect(
502 extractCommandOutputText({
503 result: {
504 content: [
505 { type: "text", text: "first" },
506 { type: "text", text: "second" },
507 ],
508 },
509 }),
510 ).toBe("first\nsecond");
511 expect(extractCommandOutputText({ rawOutput: { content: "projected summary" } })).toBe(
512 "projected summary",
513 );
514 });
515​
516 it("only removes a detail with the matching tool-name prefix", () => {
517 expect(
518 commandDetailRepeatsCommand({
519 detail: "Bash: printf hello",
520 command: "printf hello",
521 rawCommand: null,
522 toolName: "Bash",
523 data: { toolName: "Bash", command: "printf hello" },
524 }),
525 ).toBe(true);
526 expect(
527 commandDetailRepeatsCommand({
528 detail: "warning: printf hello",
529 command: "printf hello",
530 rawCommand: null,
531 toolName: "Bash",
532 data: { toolName: "Bash", command: "printf hello" },
533 }),
534 ).toBe(false);
535 });
536​
537 it("treats an ingestion-truncated echo of a long command as a repeat", () => {
538 const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
539 const truncated = `Bash: ${command}`.slice(0, 177) + "...";
540 expect(
541 commandDetailRepeatsCommand({
542 detail: truncated,
543 command,
544 rawCommand: null,
545 toolName: "Bash",
546 data: { toolName: "Bash", command },
547 }),
548 ).toBe(true);
549 expect(
550 commandDetailRepeatsCommand({
551 detail: "Bash: printf hello...",
552 command: "printf goodbye",
553 rawCommand: null,
554 toolName: "Bash",
555 data: { toolName: "Bash", command: "printf goodbye" },
556 }),
557 ).toBe(false);
558 });
559​
560 it("treats ACP command echoes as synthetic even without a tool kind", () => {
561 expect(
562 commandDetailRepeatsCommand({
563 detail: "pnpm test",
564 command: "pnpm test",
565 rawCommand: null,
566 toolName: undefined,
567 data: { toolCallId: "tool-1", command: "pnpm test" },
568 }),
569 ).toBe(true);
570 expect(
571 commandDetailRepeatsCommand({
572 detail: "pnpm test",
573 command: "pnpm test",
574 rawCommand: null,
575 toolName: undefined,
576 data: { command: "pnpm test" },
577 }),
578 ).toBe(false);
579 });
580});
581​
582describe("workEntryViewedImagePath", () => {
583 const entry = {
584 id: "entry-1",
585 createdAt: "2026-01-01T00:00:00Z",
586 label: "Read",
587 tone: "tool",
588 } as const;
589​
590 it("returns a single image path from supported read entries", () => {
591 expect(
592 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: " assets/a.png " }),
593 ).toBe("assets/a.png");
594 expect(
595 workEntryViewedImagePath({
596 ...entry,
597 itemType: "dynamic_tool",
598 toolTitle: "Read file",
599 detail: "C:\\workspace\\a.webp",
600 }),
601 ).toBe("C:\\workspace\\a.webp");
602 expect(
603 workEntryViewedImagePath({
604 ...entry,
605 itemType: "dynamic_tool",
606 detail: 'Read: {"file_path":"truncated..."}',
607 viewedImagePath: " /workspace/reference image.webp ",
608 }),
609 ).toBe("/workspace/reference image.webp");
610 });
611​
612 it("rejects non-image, multi-line, and non-read details", () => {
613 expect(
614 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.txt" }),
615 ).toBeNull();
616 expect(
617 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.png\nb.png" }),
618 ).toBeNull();
619 expect(workEntryViewedImagePath({ ...entry, detail: "a.png" })).toBeNull();
620 });
621});
622​
623describe("toolGroupAction", () => {
624 it("groups legacy Claude image reads with other reads", () => {
625 expect(
626 toolGroupAction({
627 id: "legacy-read",
628 createdAt: "2026-09-01T00:00:00Z",
629 label: "Tool call",
630 tone: "tool",
631 itemType: "dynamic_tool",
632 viewedImagePath: "/workspace/reference.png",
633 }),
634 ).toBe("read");
635 });
636});
637​
638describe("resolveViewedImageAsset", () => {
639 const threadId = ThreadId.make("thread-1");
640​
641 it("serves t3 attachment paths in place like any other host path", () => {
642 const path = "/Users/demo/.t3/dev/attachments/11111111-1111-4111-8111-111111111111.png";
643 expect(resolveViewedImageAsset(path, { threadId, workspaceRoot: "/workspace" })).toEqual({
644 resource: { _tag: "media-file", threadId, path },
645 alt: "11111111-1111-4111-8111-111111111111.png",
646 srcFragment: "",
647 });
648 });
649​
650 it("normalizes workspace image sources", () => {
651 expect(
652 resolveViewedImageAsset("screens/logo.svg?v=2#mark", {
653 threadId,
654 workspaceRoot: "/workspace",
655 }),
656 ).toEqual({
657 resource: {
658 _tag: "media-file",
659 threadId,
660 path: "/workspace/screens/logo.svg",
661 },
662 alt: "logo.svg",
663 srcFragment: "#mark",
664 });
665 expect(resolveViewedImageAsset("https://example.com/logo.png", { threadId })).toBeNull();
666 });
667});
668​
669describe("pull request tool presentation", () => {
670 it.each([
671 "mcp__t3-code__link_pull_request",
672 "mcp__t3_code__link_pull_request",
673 "T3-code · link_pull_request",
674 "t3code/link_pull_request",
675 "link_pull_request",
676 ])("recognizes the native linking tool: %s", (label) => {
677 const entry: WorkLogPresentationEntry = {
678 id: "link",
679 createdAt: "2026-09-10T00:00:00.000Z",
680 label,
681 tone: "tool",
682 toolLifecycleStatus: "completed",
683 };
684 expect(resolveWorkEntryToolPresentation(entry)).toMatchObject({
685 displayName: "Linked a pull request",
686 icon: "pull-request",
687 });
688 expect(toolGroupAction(entry)).toBe("link-pr");
689 });
690​
691 it.each([
692 ["inProgress", "Linking PR #42"],
693 ["completed", "Linked PR #42"],
694 ["failed", "Failed to link PR #42"],
695 ["declined", "Declined to link PR #42"],
696 ["stopped", "Stopped linking PR #42"],
697 ] as const)("describes the target and %s status", (toolLifecycleStatus, displayName) => {
698 expect(
699 resolveWorkEntryToolPresentation({
700 label: "MCP tool call",
701 toolTitle: "Custom title",
702 toolLifecycleStatus,
703 toolData: {
704 server: "t3-code",
705 tool: "link_pull_request",
706 arguments: { url: "https://github.com/acme/web/pull/42" },
707 },
708 })?.displayName,
709 ).toBe(displayName);
710 });
711​
712 it("recognizes unlink targets supplied as repository and number", () => {
713 expect(
714 resolveWorkEntryToolPresentation({
715 label: "MCP tool call",
716 toolLifecycleStatus: "completed",
717 toolData: {
718 toolName: "mcp__t3-code__unlink_pull_request",
719 rawInput: { repository: "acme/web", number: 42 },
720 },
721 }),
722 ).toMatchObject({ displayName: "Unlinked PR #42", icon: "pull-request", action: "unlink-pr" });
723 });
724​
725 it("summarizes native PR work separately from ordinary tools and integration metadata", () => {
726 const link: WorkLogPresentationEntry = {
727 id: "link",
728 createdAt: "2026-09-10T00:00:00.000Z",
729 label: "T3-code · link_pull_request",
730 tone: "tool",
731 itemType: "dynamic_tool",
732 toolLifecycleStatus: "completed",
733 toolSource: { key: "t3-code", name: "T3 Code", kind: "integration" },
734 };
735 const list: WorkLogPresentationEntry = {
736 ...link,
737 label: "T3-code · list_thread_pull_requests",
738 };
739 expect(summarizeToolGroup([link, link, list]).summary).toBe(
740 "Linked 2 pull requests and checked linked pull requests",
741 );
742 expect(summarizeToolGroup([{ ...link, label: "T3-code · unlink_pull_request" }]).summary).toBe(
743 "Unlinked 1 pull request",
744 );
745 expect(toolGroupSummaryKind([link, link, list])).toBe("pull-request");
746 expect(summarizeToolGroup([list, list]).summary).toBe("Checked linked pull requests 2 times");
747 expect(
748 resolveWorkEntryToolPresentation({ label: "mcp__another-server__link_pull_request" }),
749 ).toBeNull();
750 });
751});
752​
753describe("device group summaries", () => {
754 const deviceEntry = (tool: string): WorkLogPresentationEntry => ({
755 id: tool,
756 createdAt: "2026-09-10T00:00:00.000Z",
757 label: "MCP tool call",
758 toolData: { server: "t3-code", tool },
759 itemType: "dynamic_tool",
760 toolLifecycleStatus: "completed",
761 tone: "tool",
762 });
763​
764 it.each(["device_list", "device_open", "device_screenshot", "device_close"])(
765 "recognizes %s as device controls",
766 (tool) => {
767 const entry = deviceEntry(tool);
768 expect(summarizeToolGroup([entry]).summary).toBe("Used device controls 1 time");
769 expect(toolGroupSummaryKind([entry])).toBe("device");
770 },
771 );
772​
773 it("summarizes device calls alongside shell commands", () => {
774 expect(
775 summarizeToolGroup([
776 {
777 id: "command",
778 createdAt: "2026-09-10T00:00:00.000Z",
779 label: "Ran command",
780 itemType: "command_execution",
781 command: "pwd",
782 tone: "tool",
783 },
784 deviceEntry("device_list"),
785 deviceEntry("device_open"),
786 ]).summary,
787 ).toBe("Ran 1 command and used device controls 2 times");
788 });
789​
790 it("recognizes Claude tool names and preserves screenshot previews", () => {
791 const entry = {
792 ...deviceEntry("device_screenshot"),
793 toolData: { toolName: "mcp__t3_code__device_screenshot" },
794 viewedImagePath: "/workspace/device.png",
795 };
796 expect(summarizeToolGroup([entry]).summary).toBe("Used device controls 1 time");
797 expect(workEntryViewedImagePath(entry)).toBe("/workspace/device.png");
798 });
799​
800 it("does not classify another server's tools as T3 device controls", () => {
801 expect(
802 summarizeToolGroup([
803 {
804 ...deviceEntry("device_open"),
805 toolData: { server: "another-server", tool: "device_open" },
806 },
807 ]).summary,
808 ).toBe("Used 1 tool");
809 });
810});