Open History to see the last commit
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 };
126}
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 };
151}
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("merges a late tool result into the completed work-log row", () => {
278 const thread = makeThread({
279 id: ThreadId.make("thread-late-tool"),
280 projectId: ProjectId.make("project-1"),
281 title: "Late tool result",
282 latestTurn: {
283 turnId: TurnId.make("turn-1"),
284 state: "completed",
285 requestedAt: "2026-04-01T00:00:00.000Z",
286 startedAt: "2026-04-01T00:00:01.000Z",
287 completedAt: "2026-04-01T00:00:03.000Z",
288 assistantMessageId: null,
289 },
290 activities: [
291 makeActivity({
292 id: EventId.make("tool-force-complete"),
293 kind: "tool.completed",
294 tone: "tool",
295 summary: "Grep",
296 createdAt: "2026-04-01T00:00:01.000Z",
297 turnId: TurnId.make("turn-1"),
298 payload: {
299 title: "Grep",
300 itemType: "dynamic_tool_call",
301 data: {
302 toolCallId: "tool-late-1",
303 toolName: "Grep",
304 input: { pattern: "foo" },
305 },
306 },
307 }),
308 makeActivity({
309 id: EventId.make("tool-late-updated"),
310 kind: "tool.updated",
311 tone: "tool",
312 summary: "Grep",
313 createdAt: "2026-04-01T00:00:02.000Z",
314 turnId: TurnId.make("turn-1"),
315 payload: {
316 title: "Grep",
317 itemType: "dynamic_tool_call",
318 status: "completed",
319 data: {
320 toolCallId: "tool-late-1",
321 toolName: "Grep",
322 input: { pattern: "foo" },
323 result: { content: "src/example.ts:1:foo" },
324 },
325 },
326 }),
327 ],
328 });
329
330 const feed = buildThreadFeed(thread);
331 const group = feed[0];
332 expect(group).toMatchObject({ type: "activity-group" });
333 if (!group || group.type !== "activity-group") {
334 return;
335 }
336
337 expect(group.activities).toHaveLength(1);
338 expect(group.activities[0]?.id).toBe("tool-late-updated");
339 });
340
341 it("merges a late tool result onto a non-adjacent completed work-log row", () => {
342 const thread = makeThread({
343 id: ThreadId.make("thread-late-multi-tool"),
344 projectId: ProjectId.make("project-1"),
345 title: "Late multi-tool result",
346 latestTurn: {
347 turnId: TurnId.make("turn-1"),
348 state: "completed",
349 requestedAt: "2026-04-01T00:00:00.000Z",
350 startedAt: "2026-04-01T00:00:01.000Z",
351 completedAt: "2026-04-01T00:00:04.000Z",
352 assistantMessageId: null,
353 },
354 activities: [
355 makeActivity({
356 id: EventId.make("tool-a-complete"),
357 kind: "tool.completed",
358 tone: "tool",
359 summary: "Grep",
360 createdAt: "2026-04-01T00:00:01.000Z",
361 turnId: TurnId.make("turn-1"),
362 payload: {
363 title: "Grep",
364 itemType: "dynamic_tool_call",
365 data: {
366 toolCallId: "tool-a",
367 toolName: "Grep",
368 input: { pattern: "foo" },
369 },
370 },
371 }),
372 makeActivity({
373 id: EventId.make("tool-b-complete"),
374 kind: "tool.completed",
375 tone: "tool",
376 summary: "Read File",
377 createdAt: "2026-04-01T00:00:02.000Z",
378 turnId: TurnId.make("turn-1"),
379 payload: {
380 title: "Read File",
381 itemType: "dynamic_tool_call",
382 data: {
383 toolCallId: "tool-b",
384 toolName: "Read",
385 input: { path: "/tmp/a.ts" },
386 },
387 },
388 }),
389 makeActivity({
390 id: EventId.make("tool-a-late"),
391 kind: "tool.updated",
392 tone: "tool",
393 summary: "Grep",
394 createdAt: "2026-04-01T00:00:03.000Z",
395 turnId: TurnId.make("turn-1"),
396 payload: {
397 title: "Grep",
398 itemType: "dynamic_tool_call",
399 status: "completed",
400 data: {
401 toolCallId: "tool-a",
402 toolName: "Grep",
403 input: { pattern: "foo" },
404 result: { content: "src/example.ts:1:foo" },
405 },
406 },
407 }),
408 ],
409 });
410
411 const feed = buildThreadFeed(thread);
412 const group = feed[0];
413 expect(group).toMatchObject({ type: "activity-group" });
414 if (!group || group.type !== "activity-group") {
415 return;
416 }
417
418 expect(group.activities.map((activity) => activity.id)).toEqual([
419 "tool-a-late",
420 "tool-b-complete",
421 ]);
422 expect(group.activities[0]?.createdAt).toBe("2026-04-01T00:00:01.000Z");
423 });
424
425 it("keeps MCP inputs available to expanded mobile work rows", () => {
426 const turnId = TurnId.make("turn-mcp");
427 const thread = makeThread({
428 id: ThreadId.make("thread-mcp"),
429 projectId: ProjectId.make("project-1"),
430 title: "Expandable MCP call",
431 latestTurn: {
432 turnId,
433 state: "completed",
434 requestedAt: "2026-04-01T00:00:00.000Z",
435 startedAt: "2026-04-01T00:00:01.000Z",
436 completedAt: "2026-04-01T00:00:03.000Z",
437 assistantMessageId: null,
438 },
439 activities: [
440 makeActivity({
441 id: EventId.make("mcp-completed"),
442 kind: "tool.completed",
443 tone: "tool",
444 summary: "Call repository tool",
445 createdAt: "2026-04-01T00:00:02.000Z",
446 turnId,
447 payload: {
448 title: "Call repository tool",
449 itemType: "mcp_tool_call",
450 detail: "repository.search",
451 status: "completed",
452 data: {
453 item: {
454 server: "repository",
455 tool: "search",
456 arguments: { query: "work log" },
457 },
458 },
459 },
460 }),
461 ],
462 });
463
464 const group = buildThreadFeed(thread)[0];
465 expect(group).toMatchObject({ type: "activity-group" });
466 if (!group || group.type !== "activity-group") {
467 return;
468 }
469
470 expect(group.activities[0]?.icon).toBe("wrench");
471 expect(group.activities[0]?.getFullDetail()).toContain('"query": "work log"');
472 expect(group.activities[0]?.getFullDetail()).toContain("repository.search");
473 });
474
475 it("defers large tool output expansion until a work row is opened or copied", () => {
476 let serializedToolOutputs = 0;
477 const activities = Array.from({ length: 5_000 }, (_, index) =>
478 makeActivity({
479 id: EventId.make(`large-tool-${index}`),
480 kind: "tool.completed",
481 tone: "tool",
482 summary: `Tool ${index}`,
483 createdAt: new Date(Date.UTC(2026, 3, 1, 0, 0, index)).toISOString(),
484 payload: {
485 title: `Tool ${index}`,
486 itemType: "mcp_tool_call",
487 status: "completed",
488 data: {
489 item: {
490 toJSON: () => {
491 serializedToolOutputs += 1;
492 return { output: "x".repeat(32_768) };
493 },
494 },
495 },
496 },
497 }),
498 );
499 const thread = makeThread({
500 id: ThreadId.make("thread-large-tools"),
501 projectId: ProjectId.make("project-1"),
502 title: "Large tools",
503 activities,
504 });
505
506 const feed = buildThreadFeed(thread);
507 expect(serializedToolOutputs).toBe(0);
508
509 const group = feed[0];
510 expect(group).toMatchObject({ type: "activity-group" });
511 if (!group || group.type !== "activity-group") {
512 return;
513 }
514
515 expect(group.activities).toHaveLength(5_000);
516 expect(group.activities[0]?.getFullDetail()).toContain('"output"');
517 expect(serializedToolOutputs).toBe(1);
518 expect(group.activities[0]?.getCopyText()).toContain('"output"');
519 expect(serializedToolOutputs).toBe(1);
520 });
521
522 it("folds settled turn work while leaving the terminal answer visible", () => {
523 const turnId = TurnId.make("turn-1");
524 const thread = makeThread({
525 id: ThreadId.make("thread-3"),
526 projectId: ProjectId.make("project-1"),
527 title: "Folded work",
528 latestTurn: {
529 turnId,
530 state: "completed",
531 requestedAt: "2026-04-01T00:00:00.000Z",
532 startedAt: "2026-04-01T00:00:01.000Z",
533 completedAt: "2026-04-01T00:00:18.000Z",
534 assistantMessageId: MessageId.make("assistant-final"),
535 },
536 messages: [
537 {
538 id: MessageId.make("assistant-commentary"),
539 role: "assistant",
540 text: "I am checking.",
541 turnId,
542 streaming: false,
543 createdAt: "2026-04-01T00:00:02.000Z",
544 updatedAt: "2026-04-01T00:00:03.000Z",
545 },
546 {
547 id: MessageId.make("assistant-final"),
548 role: "assistant",
549 text: "Done.",
550 turnId,
551 streaming: false,
552 createdAt: "2026-04-01T00:00:17.000Z",
553 updatedAt: "2026-04-01T00:00:18.000Z",
554 },
555 ],
556 activities: [
557 makeActivity({
558 id: EventId.make("tool-completed"),
559 kind: "tool.completed",
560 tone: "tool",
561 summary: "Read files",
562 createdAt: "2026-04-01T00:00:05.000Z",
563 turnId,
564 payload: {
565 title: "Read files",
566 itemType: "file_read",
567 status: "completed",
568 },
569 }),
570 ],
571 });
572
573 const feed = buildThreadFeed(thread);
574 const collapsed = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
575 expect(collapsed.map((entry) => entry.id)).toEqual(["turn-fold:turn-1", "assistant-final"]);
576 expect(collapsed[0]).toMatchObject({
577 type: "turn-fold",
578 label: "Worked for 17s",
579 expanded: false,
580 });
581
582 const expanded = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set([turnId]));
583 expect(expanded.map((entry) => entry.id)).toEqual([
584 "turn-fold:turn-1",
585 "assistant-commentary",
586 "tool-completed",
587 "assistant-final",
588 ]);
589 });
590
591 it("measures a steer-superseded turn from its user boundary through trailing work", () => {
592 const firstTurnId = TurnId.make("turn-1");
593 const secondTurnId = TurnId.make("turn-2");
594 const thread = makeThread({
595 id: ThreadId.make("thread-steered"),
596 projectId: ProjectId.make("project-1"),
597 title: "Steered work",
598 latestTurn: {
599 turnId: secondTurnId,
600 state: "running",
601 requestedAt: "2026-04-01T00:00:14.000Z",
602 startedAt: "2026-04-01T00:00:14.000Z",
603 completedAt: null,
604 assistantMessageId: MessageId.make("assistant-next"),
605 },
606 messages: [
607 {
608 id: MessageId.make("user-1"),
609 role: "user",
610 text: "Do it once more.",
611 turnId: null,
612 streaming: false,
613 createdAt: "2026-04-01T00:00:00.000Z",
614 updatedAt: "2026-04-01T00:00:00.000Z",
615 },
616 {
617 id: MessageId.make("assistant-commentary"),
618 role: "assistant",
619 text: "Kicking off call 1.",
620 turnId: firstTurnId,
621 streaming: false,
622 createdAt: "2026-04-01T00:00:09.000Z",
623 updatedAt: "2026-04-01T00:00:09.000Z",
624 },
625 {
626 id: MessageId.make("user-2"),
627 role: "user",
628 text: "Actually do 15.",
629 turnId: null,
630 streaming: false,
631 createdAt: "2026-04-01T00:00:14.000Z",
632 updatedAt: "2026-04-01T00:00:14.000Z",
633 },
634 {
635 id: MessageId.make("assistant-next"),
636 role: "assistant",
637 text: "One down - adjusting.",
638 turnId: secondTurnId,
639 streaming: true,
640 createdAt: "2026-04-01T00:00:17.000Z",
641 updatedAt: "2026-04-01T00:00:17.000Z",
642 },
643 ],
644 activities: [
645 makeActivity({
646 id: EventId.make("work-1"),
647 kind: "tool.completed",
648 tone: "tool",
649 summary: "Ran command",
650 createdAt: "2026-04-01T00:00:12.000Z",
651 turnId: firstTurnId,
652 payload: {
653 title: "Ran command",
654 itemType: "command_execution",
655 status: "completed",
656 },
657 }),
658 ],
659 });
660
661 const feed = buildThreadFeed(thread);
662 const collapsed = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
663 expect(collapsed.find((entry) => entry.type === "turn-fold")).toMatchObject({
664 turnId: firstTurnId,
665 label: "Worked for 12s",
666 });
667 });
668
669 it("keeps an active turn expanded and classifies error-shaped tool output", () => {
670 const turnId = TurnId.make("turn-running");
671 const thread = makeThread({
672 id: ThreadId.make("thread-4"),
673 projectId: ProjectId.make("project-1"),
674 title: "Running work",
675 latestTurn: {
676 turnId,
677 state: "running",
678 requestedAt: "2026-04-01T00:00:00.000Z",
679 startedAt: "2026-04-01T00:00:01.000Z",
680 completedAt: null,
681 assistantMessageId: null,
682 },
683 activities: [
684 makeActivity({
685 id: EventId.make("tool-failed"),
686 kind: "tool.completed",
687 tone: "tool",
688 summary: "Run command",
689 createdAt: "2026-04-01T00:00:05.000Z",
690 turnId,
691 payload: {
692 title: "Run command",
693 itemType: "command_execution",
694 detail: "zsh: command not found: nope",
695 status: "completed",
696 },
697 }),
698 ],
699 });
700
701 const feed = buildThreadFeed(thread);
702 expect(deriveThreadFeedPresentation(feed, thread.latestTurn, new Set())).toEqual(feed);
703 expect(feed[0]).toMatchObject({
704 type: "activity-group",
705 activities: [{ status: "failure" }],
706 });
707 });
708
709 it("appends active work as a normal timeline row", () => {
710 const startedAt = "2026-04-01T00:00:01.000Z";
711 const presented = deriveThreadFeedPresentation([], null, new Set(), new Set(), startedAt);
712
713 expect(presented).toEqual([
714 {
715 type: "working",
716 id: "working-indicator-row",
717 createdAt: startedAt,
718 },
719 ]);
720 expect(deriveThreadFeedPresentation(presented, null, new Set())).toEqual([]);
721 });
722
723 it("models work-log overflow as list rows", () => {
724 const activity = (
725 id: string,
726 createdAt: string,
727 status: ThreadFeedActivity["status"] = "success",
728 ): ThreadFeedActivity => ({
729 id,
730 createdAt,
731 turnId: null,
732 summary: `Tool ${id}`,
733 detail: null,
734 canExpand: false,
735 getFullDetail: () => null,
736 getCopyText: () => id,
737 icon: "command",
738 toolLike: true,
739 status,
740 });
741 const feed: ThreadFeedEntry[] = [
742 {
743 type: "activity-group",
744 id: "work-group-1",
745 createdAt: "2026-04-01T00:00:01.000Z",
746 turnId: null,
747 activities: [
748 activity("activity-1", "2026-04-01T00:00:01.000Z"),
749 activity("activity-neutral", "2026-04-01T00:00:02.000Z", "neutral"),
750 activity("activity-2", "2026-04-01T00:00:03.000Z"),
751 activity("activity-3", "2026-04-01T00:00:04.000Z"),
752 ],
753 },
754 ];
755
756 const collapsed = deriveThreadFeedPresentation(feed, null, new Set());
757 expect(collapsed.map((entry) => entry.id)).toEqual(["activity-3", "work-toggle:work-group-1"]);
758 expect(collapsed[1]).toMatchObject({
759 type: "work-toggle",
760 groupId: "work-group-1",
761 hiddenCount: 2,
762 expanded: false,
763 });
764
765 const expanded = deriveThreadFeedPresentation(feed, null, new Set(), new Set(["work-group-1"]));
766 expect(expanded.map((entry) => entry.id)).toEqual([
767 "activity-1",
768 "activity-2",
769 "activity-3",
770 "work-toggle:work-group-1",
771 ]);
772 expect(expanded.at(-1)).toMatchObject({
773 type: "work-toggle",
774 expanded: true,
775 });
776 });
777});
778
779describe("quiet timeline: nested agents", () => {
780 it("keeps a nested agent's terminal row but hides its background work", () => {
781 const thread = makeThread({
782 id: ThreadId.make("thread-nested"),
783 projectId: ProjectId.make("project-1"),
784 title: "Nested agents",
785 activities: [
786 // A subagent's own shell: internal, covered by the owner's liveness.
787 makeActivity({
788 id: EventId.make("shell-done"),
789 kind: "task.completed",
790 summary: "Task completed",
791 createdAt: "2026-04-01T00:00:02.000Z",
792 payload: { taskId: "sh-1", agentId: "owner", agentKind: "background" },
793 }),
794 // A nested AGENT's completion: mobile has no Agents sheet, so this
795 // terminal row is the only signal it ever finished.
796 makeActivity({
797 id: EventId.make("nested-done"),
798 kind: "task.completed",
799 summary: "Task completed",
800 createdAt: "2026-04-01T00:00:03.000Z",
801 payload: { taskId: "n-1", agentId: "owner", agentKind: "agent" },
802 }),
803 ],
804 });
805
806 const feed = buildThreadFeed(thread);
807 const ids = feed.flatMap((entry) =>
808 entry.type === "activity-group" ? entry.activities.map((row) => row.id) : [],
809 );
810 expect(ids).toContain("nested-done");
811 expect(ids).not.toContain("shell-done");
812 });
813});