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