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

threadActivity.test.ts

816 lines24.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 EventId,
5 MessageId,
6 ProjectId,
7 ProviderInstanceId,
8 ThreadId,
9 TurnId,
10 type OrchestrationThread,
11 type OrchestrationThreadActivity,
12} from "@t3tools/contracts";
13​
14import {
15 buildPendingUserInputAnswers,
16 buildThreadFeed,
17 deriveThreadFeedPresentation,
18 isPendingUserInputOptionSelected,
19 setPendingUserInputCustomAnswer,
20 togglePendingUserInputOptionSelection,
21 type ThreadFeedActivity,
22 type ThreadFeedEntry,
23} from "./threadActivity";
24​
25const singleSelectQuestion = {
26 id: "runtime",
27 header: "Runtime",
28 question: "Which runtime should be used?",
29 options: [
30 { label: "Go", description: "One binary" },
31 { label: "Node.js", description: "Reuse TypeScript" },
32 ],
33 multiSelect: false,
34} as const;
35​
36const multiSelectQuestion = {
37 id: "scope",
38 header: "Scope",
39 question: "Which data should be collected?",
40 options: [
41 { label: "Orders", description: "Receipts" },
42 { label: "Listings", description: "Inventory" },
43 ],
44 multiSelect: true,
45} as const;
46​
47describe("pending user input answers", () => {
48 it("replaces single-select options and toggles multi-select options", () => {
49 expect(
50 togglePendingUserInputOptionSelection(
51 singleSelectQuestion,
52 { selectedOptionLabels: ["Go"] },
53 "Node.js",
54 ),
55 ).toEqual({ customAnswer: "", selectedOptionLabels: ["Node.js"] });
56​
57 const orders = togglePendingUserInputOptionSelection(multiSelectQuestion, undefined, "Orders");
58 const ordersAndListings = togglePendingUserInputOptionSelection(
59 multiSelectQuestion,
60 orders,
61 "Listings",
62 );
63 expect(ordersAndListings).toEqual({
64 customAnswer: "",
65 selectedOptionLabels: ["Orders", "Listings"],
66 });
67 expect(
68 togglePendingUserInputOptionSelection(multiSelectQuestion, ordersAndListings, "Orders"),
69 ).toEqual({ customAnswer: "", selectedOptionLabels: ["Listings"] });
70​
71 const paddedOrders = togglePendingUserInputOptionSelection(
72 multiSelectQuestion,
73 undefined,
74 " Orders ",
75 );
76 expect(paddedOrders).toEqual({ customAnswer: "", selectedOptionLabels: ["Orders"] });
77 expect(
78 togglePendingUserInputOptionSelection(multiSelectQuestion, paddedOrders, " Orders "),
79 ).toEqual({ customAnswer: "" });
80 });
81​
82 it("builds array answers for multi-select questions", () => {
83 expect(
84 buildPendingUserInputAnswers([singleSelectQuestion, multiSelectQuestion], {
85 runtime: { selectedOptionLabels: ["Go"] },
86 scope: { selectedOptionLabels: ["Orders", "Listings"] },
87 }),
88 ).toEqual({
89 runtime: "Go",
90 scope: ["Orders", "Listings"],
91 });
92 });
93​
94 it("clears selected options while a custom answer is active", () => {
95 expect(
96 setPendingUserInputCustomAnswer(
97 { selectedOptionLabels: ["Orders", "Listings"] },
98 "Orders first",
99 ),
100 ).toEqual({ customAnswer: "Orders first" });
101 });
102​
103 it("matches selected chips against normalized option labels", () => {
104 expect(
105 isPendingUserInputOptionSelected({ selectedOptionLabels: ["Orders"] }, " Orders "),
106 ).toBe(true);
107 expect(
108 isPendingUserInputOptionSelected(
109 { selectedOptionLabels: ["Orders"], customAnswer: "Orders first" },
110 " Orders ",
111 ),
112 ).toBe(false);
113 });
114});
115​
116function makeActivity(
117 input: Partial<OrchestrationThreadActivity> &
118 Pick<OrchestrationThreadActivity, "id" | "kind" | "summary" | "createdAt">,
119): OrchestrationThreadActivity {
120 return {
121 tone: "info",
122 payload: {},
123 turnId: null,
124 ...input,
125 };
127​
128function makeThread(
129 input: Partial<OrchestrationThread> & Pick<OrchestrationThread, "id" | "projectId" | "title">,
130): OrchestrationThread {
131 return {
132 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
133 runtimeMode: "full-access",
134 interactionMode: "default",
135 branch: null,
136 worktreePath: null,
137 latestTurn: null,
138 createdAt: "2026-04-01T00:00:00.000Z",
139 updatedAt: "2026-04-01T00:00:00.000Z",
140 archivedAt: null,
141 deletedAt: null,
142 messages: [],
143 proposedPlans: [],
144 activities: [],
145 checkpoints: [],
146 session: null,
147 ...input,
148 settledOverride: input.settledOverride ?? null,
149 settledAt: input.settledAt ?? null,
150 };
152​
153describe("buildThreadFeed", () => {
154 it("keeps historic work entries attributed to their turns", () => {
155 const thread = makeThread({
156 id: ThreadId.make("thread-1"),
157 projectId: ProjectId.make("project-1"),
158 title: "Runtime warning thread",
159 latestTurn: {
160 turnId: TurnId.make("turn-latest"),
161 state: "running",
162 requestedAt: "2026-04-01T00:00:00.000Z",
163 startedAt: "2026-04-01T00:00:01.000Z",
164 completedAt: null,
165 assistantMessageId: null,
166 },
167 activities: [
168 makeActivity({
169 id: EventId.make("activity-old"),
170 kind: "runtime.warning",
171 summary: "Runtime warning",
172 createdAt: "2026-04-01T00:00:02.000Z",
173 turnId: TurnId.make("turn-old"),
174 payload: {
175 message: "Old warning",
176 },
177 }),
178 makeActivity({
179 id: EventId.make("activity-latest"),
180 kind: "runtime.warning",
181 summary: "Runtime warning",
182 createdAt: "2026-04-01T00:00:03.000Z",
183 turnId: TurnId.make("turn-latest"),
184 payload: {
185 message: "Latest warning",
186 },
187 }),
188 ],
189 });
190​
191 const feed = buildThreadFeed(thread);
192 expect(feed).toMatchObject([
193 {
194 type: "activity-group",
195 turnId: "turn-old",
196 activities: [{ id: "activity-old", turnId: "turn-old" }],
197 },
198 {
199 type: "activity-group",
200 turnId: "turn-latest",
201 activities: [{ id: "activity-latest", turnId: "turn-latest" }],
202 },
203 ]);
204 });
205​
206 it("collapses matching tool lifecycle rows like desktop", () => {
207 const thread = makeThread({
208 id: ThreadId.make("thread-2"),
209 projectId: ProjectId.make("project-1"),
210 title: "Collapsed tools",
211 latestTurn: {
212 turnId: TurnId.make("turn-1"),
213 state: "completed",
214 requestedAt: "2026-04-01T00:00:00.000Z",
215 startedAt: "2026-04-01T00:00:01.000Z",
216 completedAt: "2026-04-01T00:00:03.000Z",
217 assistantMessageId: null,
218 },
219 activities: [
220 makeActivity({
221 id: EventId.make("tool-updated"),
222 kind: "tool.updated",
223 tone: "tool",
224 summary: "Run tests",
225 createdAt: "2026-04-01T00:00:01.000Z",
226 turnId: TurnId.make("turn-1"),
227 payload: {
228 title: "Run tests",
229 itemType: "command_execution",
230 detail: "/bin/zsh -lc 'bun run test'",
231 },
232 }),
233 makeActivity({
234 id: EventId.make("tool-completed"),
235 kind: "tool.completed",
236 tone: "tool",
237 summary: "Run tests completed",
238 createdAt: "2026-04-01T00:00:02.000Z",
239 turnId: TurnId.make("turn-1"),
240 payload: {
241 title: "Run tests",
242 itemType: "command_execution",
243 detail: "/bin/zsh -lc 'bun run test'",
244 },
245 }),
246 ],
247 });
248​
249 const feed = buildThreadFeed(thread);
250 const group = feed[0];
251​
252 expect(group).toMatchObject({
253 type: "activity-group",
254 });
255 if (!group || group.type !== "activity-group") {
256 return;
257 }
258​
259 expect(group.activities).toHaveLength(1);
260 expect(group.activities[0]).toMatchObject({
261 id: "tool-completed",
262 createdAt: "2026-04-01T00:00:02.000Z",
263 turnId: "turn-1",
264 summary: "Run tests",
265 detail: "bun run test",
266 canExpand: true,
267 icon: "command",
268 toolLike: true,
269 status: "success",
270 });
271 expect(group.activities[0]?.getFullDetail()).toBe("/bin/zsh -lc 'bun run test'");
272 expect(group.activities[0]?.getCopyText()).toBe(
273 "Run tests\nbun run test\n/bin/zsh -lc 'bun run test'",
274 );
275 });
276​
277 it("keeps MCP inputs available to expanded mobile work rows", () => {
278 const turnId = TurnId.make("turn-mcp");
279 const thread = makeThread({
280 id: ThreadId.make("thread-mcp"),
281 projectId: ProjectId.make("project-1"),
282 title: "Expandable MCP call",
283 latestTurn: {
284 turnId,
285 state: "completed",
286 requestedAt: "2026-04-01T00:00:00.000Z",
287 startedAt: "2026-04-01T00:00:01.000Z",
288 completedAt: "2026-04-01T00:00:03.000Z",
289 assistantMessageId: null,
290 },
291 activities: [
292 makeActivity({
293 id: EventId.make("mcp-completed"),
294 kind: "tool.completed",
295 tone: "tool",
296 summary: "Call repository tool",
297 createdAt: "2026-04-01T00:00:02.000Z",
298 turnId,
299 payload: {
300 title: "Call repository tool",
301 itemType: "mcp_tool_call",
302 detail: "repository.search",
303 status: "completed",
304 data: {
305 item: {
306 server: "repository",
307 tool: "search",
308 arguments: { query: "work log" },
309 },
310 },
311 },
312 }),
313 ],
314 });
315​
316 const group = buildThreadFeed(thread)[0];
317 expect(group).toMatchObject({ type: "activity-group" });
318 if (!group || group.type !== "activity-group") {
319 return;
320 }
321​
322 expect(group.activities[0]?.icon).toBe("wrench");
323 expect(group.activities[0]?.getFullDetail()).toContain('"query": "work log"');
324 expect(group.activities[0]?.getFullDetail()).toContain("repository.search");
325 });
326​
327 it("includes persisted Claude Bash result content in the expanded work row", () => {
328 const turnId = TurnId.make("turn-bash");
329 const output = "hello from bash\nsecond line";
330 const thread = makeThread({
331 id: ThreadId.make("thread-bash"),
332 projectId: ProjectId.make("project-1"),
333 title: "Bash output",
334 latestTurn: {
335 turnId,
336 state: "completed",
337 requestedAt: "2026-04-01T00:00:00.000Z",
338 startedAt: "2026-04-01T00:00:01.000Z",
339 completedAt: "2026-04-01T00:00:03.000Z",
340 assistantMessageId: null,
341 },
342 activities: [
343 makeActivity({
344 id: EventId.make("bash-completed"),
345 kind: "tool.completed",
346 tone: "tool",
347 summary: "Command run",
348 createdAt: "2026-04-01T00:00:02.000Z",
349 turnId,
350 payload: {
351 title: "Command run",
352 itemType: "command_execution",
353 detail: "Bash: printf hello",
354 status: "completed",
355 data: {
356 toolName: "Bash",
357 input: { command: "printf hello" },
358 result: {
359 type: "tool_result",
360 content: output,
361 is_error: false,
362 },
363 },
364 },
365 }),
366 ],
367 });
368​
369 const group = buildThreadFeed(thread)[0];
370 expect(group).toMatchObject({ type: "activity-group" });
371 if (!group || group.type !== "activity-group") {
372 return;
373 }
374​
375 expect(group.activities[0]?.detail).toBe("printf hello");
376 expect(group.activities[0]?.getFullDetail()).toBe(`printf hello\n\n${output}`);
377 });
378​
379 it("does not duplicate MCP summarized result as a separate output block", () => {
380 const turnId = TurnId.make("turn-mcp-result");
381 const item = {
382 server: "repository",
383 tool: "search",
384 arguments: { query: "work log" },
385 result: { content: "first line of output" },
386 };
387 const thread = makeThread({
388 id: ThreadId.make("thread-mcp-result"),
389 projectId: ProjectId.make("project-1"),
390 title: "MCP result",
391 latestTurn: {
392 turnId,
393 state: "completed",
394 requestedAt: "2026-04-01T00:00:00.000Z",
395 startedAt: "2026-04-01T00:00:01.000Z",
396 completedAt: "2026-04-01T00:00:03.000Z",
397 assistantMessageId: null,
398 },
399 activities: [
400 makeActivity({
401 id: EventId.make("mcp-result-completed"),
402 kind: "tool.completed",
403 tone: "tool",
404 summary: "Call repository tool",
405 createdAt: "2026-04-01T00:00:02.000Z",
406 turnId,
407 payload: {
408 title: "Call repository tool",
409 itemType: "mcp_tool_call",
410 detail: "repository.search",
411 status: "completed",
412 data: { item },
413 },
414 }),
415 ],
416 });
417​
418 const group = buildThreadFeed(thread)[0];
419 expect(group).toMatchObject({ type: "activity-group" });
420 if (!group || group.type !== "activity-group") {
421 return;
422 }
423​
424 expect(group.activities[0]?.getFullDetail()).toBe(
425 `MCP call\n${JSON.stringify(item, null, 2)}\n\nrepository.search`,
426 );
427 expect(group.activities[0]?.status).toBe("success");
428 });
429​
430 it("does not mark completed commands failed from stdout phrases", () => {
431 const turnId = TurnId.make("turn-stdout-phrases");
432 const output = "this tutorial mentions command not found, ENOENT, and exit code 1";
433 const thread = makeThread({
434 id: ThreadId.make("thread-stdout-phrases"),
435 projectId: ProjectId.make("project-1"),
436 title: "Stdout phrases",
437 latestTurn: {
438 turnId,
439 state: "completed",
440 requestedAt: "2026-04-01T00:00:00.000Z",
441 startedAt: "2026-04-01T00:00:01.000Z",
442 completedAt: "2026-04-01T00:00:03.000Z",
443 assistantMessageId: null,
444 },
445 activities: [
446 makeActivity({
447 id: EventId.make("bash-stdout-phrases"),
448 kind: "tool.completed",
449 tone: "tool",
450 summary: "Command run",
451 createdAt: "2026-04-01T00:00:02.000Z",
452 turnId,
453 payload: {
454 title: "Command run",
455 itemType: "command_execution",
456 detail: "cat notes.txt",
457 status: "completed",
458 data: {
459 toolName: "Bash",
460 input: { command: "cat notes.txt" },
461 result: { content: output, is_error: false },
462 },
463 },
464 }),
465 ],
466 });
467​
468 const group = buildThreadFeed(thread)[0];
469 expect(group).toMatchObject({ type: "activity-group" });
470 if (!group || group.type !== "activity-group") {
471 return;
472 }
473​
474 expect(group.activities[0]?.status).toBe("success");
475 expect(group.activities[0]?.getFullDetail()).toBe(`cat notes.txt\n\n${output}`);
476 });
477​
478 it("defers large tool output expansion until a work row is opened or copied", () => {
479 let serializedToolOutputs = 0;
480 const activities = Array.from({ length: 5_000 }, (_, index) =>
481 makeActivity({
482 id: EventId.make(`large-tool-${index}`),
483 kind: "tool.completed",
484 tone: "tool",
485 summary: `Tool ${index}`,
486 createdAt: new Date(Date.UTC(2026, 3, 1, 0, 0, index)).toISOString(),
487 payload: {
488 title: `Tool ${index}`,
489 itemType: "mcp_tool_call",
490 status: "completed",
491 data: {
492 item: {
493 toJSON: () => {
494 serializedToolOutputs += 1;
495 return { output: "x".repeat(32_768) };
496 },
497 },
498 },
499 },
500 }),
501 );
502 const thread = makeThread({
503 id: ThreadId.make("thread-large-tools"),
504 projectId: ProjectId.make("project-1"),
505 title: "Large tools",
506 activities,
507 });
508​
509 const feed = buildThreadFeed(thread);
510 expect(serializedToolOutputs).toBe(0);
511​
512 const group = feed[0];
513 expect(group).toMatchObject({ type: "activity-group" });
514 if (!group || group.type !== "activity-group") {
515 return;
516 }
517​
518 expect(group.activities).toHaveLength(5_000);
519 expect(group.activities[0]?.getFullDetail()).toContain('"output"');
520 expect(serializedToolOutputs).toBe(1);
521 expect(group.activities[0]?.getCopyText()).toContain('"output"');
522 expect(serializedToolOutputs).toBe(1);
523 });
524​
525 it("folds settled turn work while leaving the terminal answer visible", () => {
526 const turnId = TurnId.make("turn-1");
527 const thread = makeThread({
528 id: ThreadId.make("thread-3"),
529 projectId: ProjectId.make("project-1"),
530 title: "Folded work",
531 latestTurn: {
532 turnId,
533 state: "completed",
534 requestedAt: "2026-04-01T00:00:00.000Z",
535 startedAt: "2026-04-01T00:00:01.000Z",
536 completedAt: "2026-04-01T00:00:18.000Z",
537 assistantMessageId: MessageId.make("assistant-final"),
538 },
539 messages: [
540 {
541 id: MessageId.make("assistant-commentary"),
542 role: "assistant",
543 text: "I am checking.",
544 turnId,
545 streaming: false,
546 createdAt: "2026-04-01T00:00:02.000Z",
547 updatedAt: "2026-04-01T00:00:03.000Z",
548 },
549 {
550 id: MessageId.make("assistant-final"),
551 role: "assistant",
552 text: "Done.",
553 turnId,
554 streaming: false,
555 createdAt: "2026-04-01T00:00:17.000Z",
556 updatedAt: "2026-04-01T00:00:18.000Z",
557 },
558 ],
559 activities: [
560 makeActivity({
561 id: EventId.make("tool-completed"),
562 kind: "tool.completed",
563 tone: "tool",
564 summary: "Read files",
565 createdAt: "2026-04-01T00:00:05.000Z",
566 turnId,
567 payload: {
568 title: "Read files",
569 itemType: "file_read",
570 status: "completed",
571 },
572 }),
573 ],
574 });
575​
576 const feed = buildThreadFeed(thread);
577 const collapsed = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
578 expect(collapsed.map((entry) => entry.id)).toEqual(["turn-fold:turn-1", "assistant-final"]);
579 expect(collapsed[0]).toMatchObject({
580 type: "turn-fold",
581 label: "Worked for 17s",
582 expanded: false,
583 });
584​
585 const expanded = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set([turnId]));
586 expect(expanded.map((entry) => entry.id)).toEqual([
587 "turn-fold:turn-1",
588 "assistant-commentary",
589 "tool-completed",
590 "assistant-final",
591 ]);
592 });
593​
594 it("measures a steer-superseded turn from its user boundary through trailing work", () => {
595 const firstTurnId = TurnId.make("turn-1");
596 const secondTurnId = TurnId.make("turn-2");
597 const thread = makeThread({
598 id: ThreadId.make("thread-steered"),
599 projectId: ProjectId.make("project-1"),
600 title: "Steered work",
601 latestTurn: {
602 turnId: secondTurnId,
603 state: "running",
604 requestedAt: "2026-04-01T00:00:14.000Z",
605 startedAt: "2026-04-01T00:00:14.000Z",
606 completedAt: null,
607 assistantMessageId: MessageId.make("assistant-next"),
608 },
609 messages: [
610 {
611 id: MessageId.make("user-1"),
612 role: "user",
613 text: "Do it once more.",
614 turnId: null,
615 streaming: false,
616 createdAt: "2026-04-01T00:00:00.000Z",
617 updatedAt: "2026-04-01T00:00:00.000Z",
618 },
619 {
620 id: MessageId.make("assistant-commentary"),
621 role: "assistant",
622 text: "Kicking off call 1.",
623 turnId: firstTurnId,
624 streaming: false,
625 createdAt: "2026-04-01T00:00:09.000Z",
626 updatedAt: "2026-04-01T00:00:09.000Z",
627 },
628 {
629 id: MessageId.make("user-2"),
630 role: "user",
631 text: "Actually do 15.",
632 turnId: null,
633 streaming: false,
634 createdAt: "2026-04-01T00:00:14.000Z",
635 updatedAt: "2026-04-01T00:00:14.000Z",
636 },
637 {
638 id: MessageId.make("assistant-next"),
639 role: "assistant",
640 text: "One down - adjusting.",
641 turnId: secondTurnId,
642 streaming: true,
643 createdAt: "2026-04-01T00:00:17.000Z",
644 updatedAt: "2026-04-01T00:00:17.000Z",
645 },
646 ],
647 activities: [
648 makeActivity({
649 id: EventId.make("work-1"),
650 kind: "tool.completed",
651 tone: "tool",
652 summary: "Ran command",
653 createdAt: "2026-04-01T00:00:12.000Z",
654 turnId: firstTurnId,
655 payload: {
656 title: "Ran command",
657 itemType: "command_execution",
658 status: "completed",
659 },
660 }),
661 ],
662 });
663​
664 const feed = buildThreadFeed(thread);
665 const collapsed = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
666 expect(collapsed.find((entry) => entry.type === "turn-fold")).toMatchObject({
667 turnId: firstTurnId,
668 label: "Worked for 12s",
669 });
670 });
671​
672 it("keeps an active turn expanded and classifies error-shaped tool output", () => {
673 const turnId = TurnId.make("turn-running");
674 const thread = makeThread({
675 id: ThreadId.make("thread-4"),
676 projectId: ProjectId.make("project-1"),
677 title: "Running work",
678 latestTurn: {
679 turnId,
680 state: "running",
681 requestedAt: "2026-04-01T00:00:00.000Z",
682 startedAt: "2026-04-01T00:00:01.000Z",
683 completedAt: null,
684 assistantMessageId: null,
685 },
686 activities: [
687 makeActivity({
688 id: EventId.make("tool-failed"),
689 kind: "tool.completed",
690 tone: "tool",
691 summary: "Run command",
692 createdAt: "2026-04-01T00:00:05.000Z",
693 turnId,
694 payload: {
695 title: "Run command",
696 itemType: "command_execution",
697 detail: "zsh: command not found: nope",
698 status: "completed",
699 },
700 }),
701 ],
702 });
703​
704 const feed = buildThreadFeed(thread);
705 expect(deriveThreadFeedPresentation(feed, thread.latestTurn, new Set())).toEqual(feed);
706 expect(feed[0]).toMatchObject({
707 type: "activity-group",
708 activities: [{ status: "failure" }],
709 });
710 });
711​
712 it("appends active work as a normal timeline row", () => {
713 const startedAt = "2026-04-01T00:00:01.000Z";
714 const presented = deriveThreadFeedPresentation([], null, new Set(), new Set(), startedAt);
715​
716 expect(presented).toEqual([
717 {
718 type: "working",
719 id: "working-indicator-row",
720 createdAt: startedAt,
721 },
722 ]);
723 expect(deriveThreadFeedPresentation(presented, null, new Set())).toEqual([]);
724 });
725​
726 it("models work-log overflow as list rows", () => {
727 const activity = (
728 id: string,
729 createdAt: string,
730 status: ThreadFeedActivity["status"] = "success",
731 ): ThreadFeedActivity => ({
732 id,
733 createdAt,
734 turnId: null,
735 summary: `Tool ${id}`,
736 detail: null,
737 canExpand: false,
738 getFullDetail: () => null,
739 getCopyText: () => id,
740 icon: "command",
741 toolLike: true,
742 status,
743 });
744 const feed: ThreadFeedEntry[] = [
745 {
746 type: "activity-group",
747 id: "work-group-1",
748 createdAt: "2026-04-01T00:00:01.000Z",
749 turnId: null,
750 activities: [
751 activity("activity-1", "2026-04-01T00:00:01.000Z"),
752 activity("activity-neutral", "2026-04-01T00:00:02.000Z", "neutral"),
753 activity("activity-2", "2026-04-01T00:00:03.000Z"),
754 activity("activity-3", "2026-04-01T00:00:04.000Z"),
755 ],
756 },
757 ];
758​
759 const collapsed = deriveThreadFeedPresentation(feed, null, new Set());
760 expect(collapsed.map((entry) => entry.id)).toEqual(["activity-3", "work-toggle:work-group-1"]);
761 expect(collapsed[1]).toMatchObject({
762 type: "work-toggle",
763 groupId: "work-group-1",
764 hiddenCount: 2,
765 expanded: false,
766 });
767​
768 const expanded = deriveThreadFeedPresentation(feed, null, new Set(), new Set(["work-group-1"]));
769 expect(expanded.map((entry) => entry.id)).toEqual([
770 "activity-1",
771 "activity-2",
772 "activity-3",
773 "work-toggle:work-group-1",
774 ]);
775 expect(expanded.at(-1)).toMatchObject({
776 type: "work-toggle",
777 expanded: true,
778 });
779 });
780});
781​
782describe("quiet timeline: nested agents", () => {
783 it("keeps a nested agent's terminal row but hides its background work", () => {
784 const thread = makeThread({
785 id: ThreadId.make("thread-nested"),
786 projectId: ProjectId.make("project-1"),
787 title: "Nested agents",
788 activities: [
789 // A subagent's own shell: internal, covered by the owner's liveness.
790 makeActivity({
791 id: EventId.make("shell-done"),
792 kind: "task.completed",
793 summary: "Task completed",
794 createdAt: "2026-04-01T00:00:02.000Z",
795 payload: { taskId: "sh-1", agentId: "owner", agentKind: "background" },
796 }),
797 // A nested AGENT's completion: mobile has no Agents sheet, so this
798 // terminal row is the only signal it ever finished.
799 makeActivity({
800 id: EventId.make("nested-done"),
801 kind: "task.completed",
802 summary: "Task completed",
803 createdAt: "2026-04-01T00:00:03.000Z",
804 payload: { taskId: "n-1", agentId: "owner", agentKind: "agent" },
805 }),
806 ],
807 });
808​
809 const feed = buildThreadFeed(thread);
810 const ids = feed.flatMap((entry) =>
811 entry.type === "activity-group" ? entry.activities.map((row) => row.id) : [],
812 );
813 expect(ids).toContain("nested-done");
814 expect(ids).not.toContain("shell-done");
815 });
816});