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