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

presentation.test.ts

791 lines24.7 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("counts created threads alongside adjacent commands", () => {
208 expect(
209 summarizeToolGroup([
210 entry("command", { itemType: "command_execution", command: "vp test run" }),
211 entry("created", {
212 itemType: "thread_created",
213​
214 label: "Created thread",
215 }),
216 ]).summary,
217 ).toBe("Ran 1 command and created 1 thread");
218 });
219​
220 it("deduplicates named sources ahead of ordinary actions", () => {
221 const source = { key: "browser-use:chrome", name: "Chrome", kind: "integration" as const };
222 expect(
223 summarizeToolGroup([
224 entry("open", { label: "Open page", toolSource: source }),
225 entry("inspect", { label: "Inspect page", toolSource: source }),
226 entry("command", {
227 label: "Ran command",
228 itemType: "command_execution",
229 command: "git status",
230 }),
231 ]).summary,
232 ).toBe("Used Chrome integration and ran 1 command");
233 });
234​
235 it("omits the integration suffix for special browser and computer sources", () => {
236 expect(
237 summarizeToolGroup([
238 entry("inspect", {
239 label: "Inspect page",
240 toolSource: { key: "browser-use", name: "Browser", kind: "browser" },
241 }),
242 entry("click", {
243 label: "Click",
244 toolSource: { key: "computer-use", name: "Computer Use", kind: "computer" },
245 }),
246 ]).summary,
247 ).toBe("Used Browser and Computer Use");
248 });
249});
250​
251describe("resolveWorkEntryToolPresentation", () => {
252 it.each([
253 "mcp__t3-code__preview_click",
254 "mcp__t3_code__preview_click",
255 "mcp__t3code__preview_click",
256 "T3-code.preview_click",
257 "t3-code · preview_click completed",
258 "t3_code/preview_click",
259 "preview_click",
260 ])("recognizes browser tool names across providers: %s", (label) => {
261 expect(resolveWorkEntryToolPresentation({ label })).toEqual({
262 displayName: "Clicking in the preview browser",
263 icon: "browser",
264 });
265 });
266​
267 it("labels device tools with the device icon", () => {
268 expect(
269 resolveWorkEntryToolPresentation({
270 label: "mcp__t3-code__device_open",
271 toolLifecycleStatus: "completed",
272 }),
273 ).toEqual({ displayName: "Opened a device in the Device panel", icon: "device" });
274 expect(resolveWorkEntryToolPresentation({ label: "t3-code · device_screenshot" })).toEqual({
275 displayName: "Taking a screenshot of the device",
276 icon: "device",
277 });
278 });
279​
280 it("uses structured MCP identity when the provider supplies a custom title", () => {
281 expect(
282 resolveWorkEntryToolPresentation({
283 label: "Tool call complete",
284 toolTitle: "Inspect the current page",
285 toolData: { server: "t3-code", tool: "preview_snapshot", result: { title: "Example" } },
286 }),
287 ).toEqual({ displayName: "Taking a snapshot of the preview page", icon: "browser" });
288 });
289​
290 it.each([
291 ["inProgress", "Clicking in the preview browser"],
292 ["completed", "Clicked in the preview browser"],
293 ["failed", "Failed to click in the preview browser"],
294 ["declined", "Declined to click in the preview browser"],
295 ["stopped", "Stopped clicking in the preview browser"],
296 ["unknown", "Clicking in the preview browser"],
297 ] as const)("describes the tool's own %s state", (toolLifecycleStatus, displayName) => {
298 expect(
299 resolveWorkEntryToolPresentation({
300 label: "T3-code.preview_click",
301 toolLifecycleStatus: toolLifecycleStatus as WorkLogToolLifecycleStatus,
302 }),
303 ).toEqual({ displayName, icon: "browser" });
304 });
305​
306 it("uses the summary's state only when the provider omitted a lifecycle status", () => {
307 const entry = { label: "T3-code.preview_click" };
308 expect(resolveWorkEntryToolPresentation(entry, "inProgress")?.displayName).toBe(
309 "Clicking in the preview browser",
310 );
311 expect(resolveWorkEntryToolPresentation(entry, "completed")?.displayName).toBe(
312 "Clicked in the preview browser",
313 );
314 expect(
315 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "completed" }, "inProgress")
316 ?.displayName,
317 ).toBe("Clicked in the preview browser");
318 expect(
319 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "failed" }, "completed")
320 ?.displayName,
321 ).toBe("Failed to click in the preview browser");
322 });
323​
324 it.each([
325 ["preview_type", "Typing in the preview browser", "Typed in the preview browser"],
326 [
327 "preview_set_appearance",
328 "Setting preview browser appearance",
329 "Set preview browser appearance",
330 ],
331 [
332 "preview_snapshot",
333 "Taking a snapshot of the preview page",
334 "Took a snapshot of the preview page",
335 ],
336 [
337 "preview_recording_stop",
338 "Stopping recording the preview browser",
339 "Stopped recording the preview browser",
340 ],
341 ["t3_thread_read", "Reading a T3 thread", "Read a T3 thread"],
342 ["t3_thread_send", "Sending to a T3 thread", "Sent to a T3 thread"],
343 [
344 "t3_worktree_handoff",
345 "Handing off thread to a git worktree",
346 "Handed off thread to a git worktree",
347 ],
348 ])("preserves verb forms and the rest of %s's label", (tool, running, completed) => {
349 const entry = { label: `t3-code.${tool}` };
350 expect(
351 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "inProgress" })
352 ?.displayName,
353 ).toBe(running);
354 expect(
355 resolveWorkEntryToolPresentation({ ...entry, toolLifecycleStatus: "completed" })?.displayName,
356 ).toBe(completed);
357 });
358​
359 it("keeps T3 branding for non-browser tools and falls back to the original tool label", () => {
360 expect(
361 resolveWorkEntryToolPresentation({
362 label: "mcp__t3_code__task_status",
363 toolTitle: "Check the child task",
364 }),
365 ).toEqual({ displayName: "Getting delegated task status", icon: "t3-code" });
366 });
367​
368 it("does not brand unknown tools or another server's matching tool name", () => {
369 for (const label of [
370 "mcp__github__preview_click",
371 "t3-code.unknown_tool",
372 "t3-code.toString",
373 "Search files",
374 ]) {
375 expect(resolveWorkEntryToolPresentation({ label })).toBeNull();
376 }
377 expect(
378 resolveWorkEntryToolPresentation({
379 label: "preview_click",
380 toolData: { server: "another-server", tool: "preview_click" },
381 }),
382 ).toBeNull();
383 });
384});
385​
386describe("browser group summaries", () => {
387 const summarizeGroupLabel = (entries: ReadonlyArray<WorkLogPresentationEntry>) =>
388 summarizeToolGroup(entries).summary;
389 const browserEntry: WorkLogPresentationEntry = {
390 id: "browser",
391 createdAt: "2026-09-01T00:00:00Z",
392 label: "MCP tool call",
393 toolData: { server: "t3-code", tool: "preview_click" },
394 itemType: "dynamic_tool",
395 toolLifecycleStatus: "completed",
396 tone: "tool",
397 };
398 const commandEntry: WorkLogPresentationEntry = {
399 id: "command",
400 createdAt: "2026-09-01T00:00:00Z",
401 label: "Ran command",
402 command: "/bin/bash -lc 'vp test run'",
403 itemType: "command_execution",
404 toolLifecycleStatus: "completed",
405 tone: "tool",
406 };
407​
408 it.each([1, 18])("counts %s browser calls separately from generic tools", (count) => {
409 const entries = Array.from({ length: count }, (_, index) => ({
410 ...browserEntry,
411 toolCallId: `browser-${index}`,
412 }));
413 expect(summarizeGroupLabel(entries)).toBe(
414 `Used browser ${count} ${count === 1 ? "time" : "times"}`,
415 );
416 expect(toolGroupSummaryKind(entries)).toBe("browser");
417 });
418​
419 it("combines command and browser counts in a single sentence", () => {
420 const entries = [
421 ...Array.from({ length: 4 }, () => commandEntry),
422 ...Array.from({ length: 15 }, () => browserEntry),
423 ];
424 expect(summarizeGroupLabel(entries)).toBe("Ran 4 commands and used browser 15 times");
425 expect(toolGroupSummaryKind(entries)).toBe("mixed");
426 });
427​
428 it("preserves first-seen action ordering alongside non-browser tools", () => {
429 expect(
430 summarizeGroupLabel([
431 browserEntry,
432 commandEntry,
433 {
434 ...browserEntry,
435 toolData: { server: "t3-code", tool: "task_status" },
436 },
437 ]),
438 ).toBe("Used browser 1 time, ran 1 command, and performed 1 other action");
439 });
440​
441 it("recognizes Claude browser identity without treating script metadata as a shell command", () => {
442 expect(
443 summarizeGroupLabel([
444 {
445 ...browserEntry,
446 command: "node inspect-page.js",
447 toolData: { toolName: "mcp__t3_code__preview_evaluate" },
448 },
449 ]),
450 ).toBe("Used browser 1 time");
451 });
452​
453 it("keeps foreign tools and web searches out of the browser count", () => {
454 expect(
455 summarizeGroupLabel([
456 browserEntry,
457 {
458 ...browserEntry,
459 label: "preview_click",
460 toolData: { server: "another-server", tool: "preview_click" },
461 },
462 {
463 id: "search",
464 createdAt: "2026-09-01T00:00:00Z",
465 label: "Search",
466 tone: "tool",
467 itemType: "web_search",
468 },
469 ]),
470 ).toBe("Used browser 1 time, searched the web 1 time, and performed 1 other action");
471 });
472​
473 it("keeps browser screenshots in the browser count while preserving their image path", () => {
474 const entry = { ...browserEntry, viewedImagePath: "/workspace/page.png" };
475 expect(summarizeGroupLabel([entry])).toBe("Used browser 1 time");
476 expect(workEntryViewedImagePath(entry)).toBe("/workspace/page.png");
477 });
478});
479​
480describe("command work-log details", () => {
481 it("extracts Claude result blocks and projected output", () => {
482 expect(
483 extractCommandOutputText({
484 result: {
485 content: [
486 { type: "text", text: "first" },
487 { type: "text", text: "second" },
488 ],
489 },
490 }),
491 ).toBe("first\nsecond");
492 expect(extractCommandOutputText({ rawOutput: { content: "projected summary" } })).toBe(
493 "projected summary",
494 );
495 });
496​
497 it("only removes a detail with the matching tool-name prefix", () => {
498 expect(
499 commandDetailRepeatsCommand({
500 detail: "Bash: printf hello",
501 command: "printf hello",
502 rawCommand: null,
503 toolName: "Bash",
504 data: { toolName: "Bash", command: "printf hello" },
505 }),
506 ).toBe(true);
507 expect(
508 commandDetailRepeatsCommand({
509 detail: "warning: printf hello",
510 command: "printf hello",
511 rawCommand: null,
512 toolName: "Bash",
513 data: { toolName: "Bash", command: "printf hello" },
514 }),
515 ).toBe(false);
516 });
517​
518 it("treats an ingestion-truncated echo of a long command as a repeat", () => {
519 const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
520 const truncated = `Bash: ${command}`.slice(0, 177) + "...";
521 expect(
522 commandDetailRepeatsCommand({
523 detail: truncated,
524 command,
525 rawCommand: null,
526 toolName: "Bash",
527 data: { toolName: "Bash", command },
528 }),
529 ).toBe(true);
530 expect(
531 commandDetailRepeatsCommand({
532 detail: "Bash: printf hello...",
533 command: "printf goodbye",
534 rawCommand: null,
535 toolName: "Bash",
536 data: { toolName: "Bash", command: "printf goodbye" },
537 }),
538 ).toBe(false);
539 });
540​
541 it("treats ACP command echoes as synthetic even without a tool kind", () => {
542 expect(
543 commandDetailRepeatsCommand({
544 detail: "pnpm test",
545 command: "pnpm test",
546 rawCommand: null,
547 toolName: undefined,
548 data: { toolCallId: "tool-1", command: "pnpm test" },
549 }),
550 ).toBe(true);
551 expect(
552 commandDetailRepeatsCommand({
553 detail: "pnpm test",
554 command: "pnpm test",
555 rawCommand: null,
556 toolName: undefined,
557 data: { command: "pnpm test" },
558 }),
559 ).toBe(false);
560 });
561});
562​
563describe("workEntryViewedImagePath", () => {
564 const entry = {
565 id: "entry-1",
566 createdAt: "2026-01-01T00:00:00Z",
567 label: "Read",
568 tone: "tool",
569 } as const;
570​
571 it("returns a single image path from supported read entries", () => {
572 expect(
573 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: " assets/a.png " }),
574 ).toBe("assets/a.png");
575 expect(
576 workEntryViewedImagePath({
577 ...entry,
578 itemType: "dynamic_tool",
579 toolTitle: "Read file",
580 detail: "C:\\workspace\\a.webp",
581 }),
582 ).toBe("C:\\workspace\\a.webp");
583 expect(
584 workEntryViewedImagePath({
585 ...entry,
586 itemType: "dynamic_tool",
587 detail: 'Read: {"file_path":"truncated..."}',
588 viewedImagePath: " /workspace/reference image.webp ",
589 }),
590 ).toBe("/workspace/reference image.webp");
591 });
592​
593 it("rejects non-image, multi-line, and non-read details", () => {
594 expect(
595 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.txt" }),
596 ).toBeNull();
597 expect(
598 workEntryViewedImagePath({ ...entry, requestKind: "file-read", detail: "a.png\nb.png" }),
599 ).toBeNull();
600 expect(workEntryViewedImagePath({ ...entry, detail: "a.png" })).toBeNull();
601 });
602});
603​
604describe("toolGroupAction", () => {
605 it("groups legacy Claude image reads with other reads", () => {
606 expect(
607 toolGroupAction({
608 id: "legacy-read",
609 createdAt: "2026-09-01T00:00:00Z",
610 label: "Tool call",
611 tone: "tool",
612 itemType: "dynamic_tool",
613 viewedImagePath: "/workspace/reference.png",
614 }),
615 ).toBe("read");
616 });
617});
618​
619describe("resolveViewedImageAsset", () => {
620 const threadId = ThreadId.make("thread-1");
621​
622 it("serves t3 attachment paths in place like any other host path", () => {
623 const path = "/Users/demo/.t3/dev/attachments/11111111-1111-4111-8111-111111111111.png";
624 expect(resolveViewedImageAsset(path, { threadId, workspaceRoot: "/workspace" })).toEqual({
625 resource: { _tag: "media-file", threadId, path },
626 alt: "11111111-1111-4111-8111-111111111111.png",
627 srcFragment: "",
628 });
629 });
630​
631 it("normalizes workspace image sources", () => {
632 expect(
633 resolveViewedImageAsset("screens/logo.svg?v=2#mark", {
634 threadId,
635 workspaceRoot: "/workspace",
636 }),
637 ).toEqual({
638 resource: {
639 _tag: "media-file",
640 threadId,
641 path: "/workspace/screens/logo.svg",
642 },
643 alt: "logo.svg",
644 srcFragment: "#mark",
645 });
646 expect(resolveViewedImageAsset("https://example.com/logo.png", { threadId })).toBeNull();
647 });
648});
649​
650describe("pull request tool presentation", () => {
651 it.each([
652 "mcp__t3-code__link_pull_request",
653 "mcp__t3_code__link_pull_request",
654 "T3-code · link_pull_request",
655 "t3code/link_pull_request",
656 "link_pull_request",
657 ])("recognizes the native linking tool: %s", (label) => {
658 const entry: WorkLogPresentationEntry = {
659 id: "link",
660 createdAt: "2026-09-10T00:00:00.000Z",
661 label,
662 tone: "tool",
663 toolLifecycleStatus: "completed",
664 };
665 expect(resolveWorkEntryToolPresentation(entry)).toMatchObject({
666 displayName: "Linked a pull request",
667 icon: "pull-request",
668 });
669 expect(toolGroupAction(entry)).toBe("link-pr");
670 });
671​
672 it.each([
673 ["inProgress", "Linking PR #42"],
674 ["completed", "Linked PR #42"],
675 ["failed", "Failed to link PR #42"],
676 ["declined", "Declined to link PR #42"],
677 ["stopped", "Stopped linking PR #42"],
678 ] as const)("describes the target and %s status", (toolLifecycleStatus, displayName) => {
679 expect(
680 resolveWorkEntryToolPresentation({
681 label: "MCP tool call",
682 toolTitle: "Custom title",
683 toolLifecycleStatus,
684 toolData: {
685 server: "t3-code",
686 tool: "link_pull_request",
687 arguments: { url: "https://github.com/acme/web/pull/42" },
688 },
689 })?.displayName,
690 ).toBe(displayName);
691 });
692​
693 it("recognizes unlink targets supplied as repository and number", () => {
694 expect(
695 resolveWorkEntryToolPresentation({
696 label: "MCP tool call",
697 toolLifecycleStatus: "completed",
698 toolData: {
699 toolName: "mcp__t3-code__unlink_pull_request",
700 rawInput: { repository: "acme/web", number: 42 },
701 },
702 }),
703 ).toMatchObject({ displayName: "Unlinked PR #42", icon: "pull-request", action: "unlink-pr" });
704 });
705​
706 it("summarizes native PR work separately from ordinary tools and integration metadata", () => {
707 const link: WorkLogPresentationEntry = {
708 id: "link",
709 createdAt: "2026-09-10T00:00:00.000Z",
710 label: "T3-code · link_pull_request",
711 tone: "tool",
712 itemType: "dynamic_tool",
713 toolLifecycleStatus: "completed",
714 toolSource: { key: "t3-code", name: "T3 Code", kind: "integration" },
715 };
716 const list: WorkLogPresentationEntry = {
717 ...link,
718 label: "T3-code · list_thread_pull_requests",
719 };
720 expect(summarizeToolGroup([link, link, list]).summary).toBe(
721 "Linked 2 pull requests and checked linked pull requests",
722 );
723 expect(summarizeToolGroup([{ ...link, label: "T3-code · unlink_pull_request" }]).summary).toBe(
724 "Unlinked 1 pull request",
725 );
726 expect(toolGroupSummaryKind([link, link, list])).toBe("pull-request");
727 expect(summarizeToolGroup([list, list]).summary).toBe("Checked linked pull requests 2 times");
728 expect(
729 resolveWorkEntryToolPresentation({ label: "mcp__another-server__link_pull_request" }),
730 ).toBeNull();
731 });
732});
733​
734describe("device group summaries", () => {
735 const deviceEntry = (tool: string): WorkLogPresentationEntry => ({
736 id: tool,
737 createdAt: "2026-09-10T00:00:00.000Z",
738 label: "MCP tool call",
739 toolData: { server: "t3-code", tool },
740 itemType: "dynamic_tool",
741 toolLifecycleStatus: "completed",
742 tone: "tool",
743 });
744​
745 it.each(["device_list", "device_open", "device_screenshot", "device_close"])(
746 "recognizes %s as device controls",
747 (tool) => {
748 const entry = deviceEntry(tool);
749 expect(summarizeToolGroup([entry]).summary).toBe("Used device controls 1 time");
750 expect(toolGroupSummaryKind([entry])).toBe("device");
751 },
752 );
753​
754 it("summarizes device calls alongside shell commands", () => {
755 expect(
756 summarizeToolGroup([
757 {
758 id: "command",
759 createdAt: "2026-09-10T00:00:00.000Z",
760 label: "Ran command",
761 itemType: "command_execution",
762 command: "pwd",
763 tone: "tool",
764 },
765 deviceEntry("device_list"),
766 deviceEntry("device_open"),
767 ]).summary,
768 ).toBe("Ran 1 command and used device controls 2 times");
769 });
770​
771 it("recognizes Claude tool names and preserves screenshot previews", () => {
772 const entry = {
773 ...deviceEntry("device_screenshot"),
774 toolData: { toolName: "mcp__t3_code__device_screenshot" },
775 viewedImagePath: "/workspace/device.png",
776 };
777 expect(summarizeToolGroup([entry]).summary).toBe("Used device controls 1 time");
778 expect(workEntryViewedImagePath(entry)).toBe("/workspace/device.png");
779 });
780​
781 it("does not classify another server's tools as T3 device controls", () => {
782 expect(
783 summarizeToolGroup([
784 {
785 ...deviceEntry("device_open"),
786 toolData: { server: "another-server", tool: "device_open" },
787 },
788 ]).summary,
789 ).toBe("Used 1 tool");
790 });
791});