Open History to see the last commit
1import {
2 MessageId,
3 RuntimeRequestId,
4 NodeId,
5 PlanId,
6 ProviderInstanceId,
7 ProviderDriverKind,
8 ProviderThreadId,
9 RunId,
10 RunAttemptId,
11 ScheduledTaskId,
12 ThreadId,
13 TurnItemId,
14 type OrchestrationV2RunAttempt,
15 type OrchestrationV2ProjectedTurnItem,
16 type OrchestrationV2TurnItem,
17} from "@t3tools/contracts";
18import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
19import * as DateTime from "effect/DateTime";
20import { describe, expect, it } from "vite-plus/test";
21
22import {
23 buildThreadFeed,
24 deriveThreadFeedPresentation,
25 threadFeedActivityIsVisible,
26 threadFeedRunIsUnsettled,
27 type ThreadFeedActivity,
28 type ThreadFeedEntry,
29 togglePendingUserInputOptionSelection,
30 setPendingUserInputCustomAnswer,
31 isPendingUserInputOptionSelected,
32 buildPendingUserInputAnswers,
33} from "./threadActivity";
34
35const threadId = ThreadId.make("thread-1");
36const sourceThreadId = ThreadId.make("thread-source");
37const runId = RunId.make("run-1");
38
39it("keeps historical plan detail accessible from its paged turn item", () => {
40 const item = {
41 ...base("historical-plan", "2026-08-29T00:00:00.000Z", 1),
42 type: "proposed_plan",
43 planId: "plan-historical",
44 markdown: "Full historical plan text",
45 streaming: false,
46 } as OrchestrationV2TurnItem;
47
48 const entries = buildThreadFeed([projected(item, 0)]);
49 const activity = entries.flatMap((entry) =>
50 entry.type === "activity-group" ? entry.activities : [],
51 )[0];
52 expect(activity?.detail).toBe("Full historical plan text");
53 expect(activity?.getFullDetail()).toContain("Full historical plan text");
54});
55
56function base(id: string, updatedAt: string, ordinal: number) {
57 const timestamp = DateTime.makeUnsafe(updatedAt);
58 return {
59 id: TurnItemId.make(id),
60 threadId,
61 runId,
62 nodeId: null,
63 providerThreadId: null,
64 providerTurnId: null,
65 nativeItemRef: null,
66 parentItemId: null,
67 ordinal,
68 status: "completed" as const,
69 title: null,
70 startedAt: timestamp,
71 completedAt: timestamp,
72 updatedAt: timestamp,
73 };
74}
75
76function projected(
77 item: OrchestrationV2TurnItem,
78 position: number,
79 visibility: OrchestrationV2ProjectedTurnItem["visibility"] = "local",
80): OrchestrationV2ProjectedTurnItem {
81 return {
82 position,
83 visibility,
84 sourceThreadId: visibility === "local" ? threadId : sourceThreadId,
85 sourceItemId: item.id,
86 item,
87 };
88}
89
90function userMessage(updatedAt = "2026-06-20T00:00:01.000Z") {
91 return {
92 ...base("item-user", updatedAt, 0),
93 type: "user_message" as const,
94 messageId: MessageId.make("message-user"),
95 createdBy: "user" as const,
96 creationSource: "mobile" as const,
97 inputIntent: "turn_start" as const,
98 text: "Run checks",
99 attachments: [],
100 };
101}
102
103function command(updatedAt = "2026-06-20T00:00:02.000Z") {
104 return {
105 ...base("item-command", updatedAt, 1),
106 type: "command_execution" as const,
107 input: "vp check",
108 output: "ok",
109 exitCode: 0,
110 };
111}
112
113function assistantMessage(updatedAt = "2026-06-20T00:00:03.000Z") {
114 return {
115 ...base("item-assistant", updatedAt, 2),
116 type: "assistant_message" as const,
117 messageId: MessageId.make("message-assistant"),
118 text: "Done",
119 streaming: false,
120 };
121}
122
123describe("buildThreadFeed", () => {
124 it("omits cached tool output and patch bodies from expanded and copied activity", () => {
125 const rawOutput = "RAW_TOOL_OUTPUT";
126 const items: OrchestrationV2TurnItem[] = [
127 { ...command(), output: rawOutput },
128 {
129 ...base("dynamic-output", "2026-06-20T00:00:03.000Z", 2),
130 type: "dynamic_tool",
131 toolName: "example",
132 input: { query: "keep input" },
133 output: { text: rawOutput },
134 },
135 {
136 ...base("file-output", "2026-06-20T00:00:04.000Z", 3),
137 type: "file_change",
138 fileName: "src/example.ts",
139 diffStr: rawOutput,
140 oldStr: rawOutput,
141 newStr: rawOutput,
142 },
143 ];
144 const activities = buildThreadFeed(items.map((item, index) => projected(item, index))).flatMap(
145 (entry) => (entry.type === "activity-group" ? entry.activities : []),
146 );
147 expect(activities).toHaveLength(3);
148 for (const activity of activities) {
149 expect(activity.workEntry.detail).toBeUndefined();
150 expect(activity.getFullDetail()).not.toContain(rawOutput);
151 expect(activity.getCopyText()).not.toContain(rawOutput);
152 }
153 expect(activities[0]?.detail).toBe("vp check");
154 expect(activities[1]?.getFullDetail()).toContain("keep input");
155 expect(activities[2]?.detail).toBe("src/example.ts");
156 expect(items[0]).toMatchObject({ output: rawOutput });
157 });
158
159 it("recognizes automation attribution after projecting a user message", () => {
160 const feed = buildThreadFeed([
161 projected(
162 {
163 ...userMessage(),
164 createdBy: "agent",
165 creationSource: "server",
166 scheduledTaskId: ScheduledTaskId.make("daily-audit"),
167 },
168 0,
169 ),
170 ]);
171 const messageEntry = feed.find((entry) => entry.type === "message");
172
173 expect(messageEntry).toBeDefined();
174 expect(resolveUserMessagePresentation(messageEntry!.message)).toMatchObject({
175 text: "Run checks",
176 isAutomation: true,
177 });
178 });
179
180 it("adds local feedback messages to an otherwise server-authored feed", () => {
181 const feed = buildThreadFeed([], {
182 localMessages: [
183 {
184 id: MessageId.make("feedback-local"),
185 role: "assistant",
186 text: "Feedback sent to OpenAI.\n\nThread ID: `codex-thread-1`",
187 turnId: null,
188 streaming: false,
189 createdAt: "2026-08-29T00:00:00.000Z",
190 updatedAt: "2026-08-29T00:00:00.000Z",
191 },
192 ],
193 });
194
195 expect(feed).toHaveLength(1);
196 expect(feed[0]).toMatchObject({
197 type: "message",
198 message: {
199 id: "feedback-local",
200 role: "assistant",
201 text: expect.stringContaining("codex-thread-1"),
202 },
203 });
204 });
205
206 it("anchors feedback before later committed turns and appends true optimistic messages", () => {
207 const laterUser = {
208 ...userMessage("2026-08-29T00:00:05.000Z"),
209 id: TurnItemId.make("item-later-user"),
210 messageId: MessageId.make("message-later-user"),
211 ordinal: 2,
212 text: "Later user turn",
213 };
214 const laterAssistant = {
215 ...assistantMessage("2026-08-29T00:00:04.000Z"),
216 id: TurnItemId.make("item-later-assistant"),
217 messageId: MessageId.make("message-later-assistant"),
218 ordinal: 3,
219 text: "Later assistant turn",
220 };
221 const localMessage = (id: string, role: "user" | "assistant") => ({
222 id: MessageId.make(id),
223 role,
224 text: id,
225 turnId: null,
226 streaming: false,
227 createdAt: "2026-08-29T00:00:03.000Z",
228 updatedAt: "2026-08-29T00:00:03.000Z",
229 });
230 const feed = buildThreadFeed(
231 [
232 projected(userMessage("2026-08-29T00:00:01.000Z"), 0),
233 projected(laterUser, 1),
234 projected(laterAssistant, 2),
235 ],
236 {
237 anchoredMessages: [
238 localMessage("feedback-user", "user"),
239 localMessage("feedback-assistant", "assistant"),
240 localMessage("message-later-user", "user"),
241 ],
242 localMessages: [
243 {
244 ...localMessage("optimistic-user", "user"),
245 createdAt: "2026-08-29T00:00:00.000Z",
246 },
247 ],
248 },
249 );
250 const messages = feed.filter((entry) => entry.type === "message");
251
252 expect(messages.map((entry) => entry.id)).toEqual([
253 "message-user",
254 "feedback-user",
255 "feedback-assistant",
256 "message-later-user",
257 "message-later-assistant",
258 "optimistic-user",
259 ]);
260 expect(
261 messages
262 .filter((entry) => entry.id.startsWith("feedback-"))
263 .every((entry) => entry.message.projectedItem === undefined),
264 ).toBe(true);
265 });
266
267 it("keeps prominent activity visible while it is running", () => {
268 expect(
269 threadFeedActivityIsVisible({ prominent: true, status: "neutral", toolLike: true }),
270 ).toBe(true);
271 expect(
272 threadFeedActivityIsVisible({ prominent: false, status: "neutral", toolLike: true }),
273 ).toBe(false);
274 });
275
276 it("keeps provider notices visible outside completed work folds without failure styling", () => {
277 const message = "Safeguards flagged this message. Switched to Opus 4.8.";
278 const item = {
279 ...base("item-system-notice", "2026-06-20T00:00:02.000Z", 1),
280 type: "system_notice" as const,
281 message,
282 };
283 const feed = buildThreadFeed([projected(item, 0)]);
284 const presented = deriveThreadFeedPresentation(feed, null, new Set());
285 const activities = presented.flatMap((entry) =>
286 entry.type === "activity-group" ? entry.activities : [],
287 );
288 expect(activities).toHaveLength(1);
289 expect(activities[0]).toMatchObject({
290 summary: message,
291 detail: message,
292 prominent: true,
293 toolLike: false,
294 status: null,
295 icon: "warning",
296 workEntry: { tone: "info", itemType: "system_notice" },
297 });
298 expect(presented.some((entry) => entry.type === "run-fold")).toBe(false);
299 });
300
301 it("presents provider retries as visible work-log activity", () => {
302 const retryBase = {
303 ...base("item-provider-retry", "2026-06-20T00:00:02.000Z", 1),
304 type: "error" as const,
305 failure: {
306 class: "transport_error" as const,
307 message: "The response stream disconnected.",
308 code: "responseStreamDisconnected",
309 retryable: true,
310 },
311 retry: {
312 attempt: 2,
313 maxAttempts: 5,
314 retryDelayMs: null,
315 },
316 };
317 const runningFeed = buildThreadFeed([
318 projected(
319 {
320 ...retryBase,
321 status: "running",
322 title: "Provider retry",
323 completedAt: null,
324 },
325 0,
326 ),
327 ]);
328 const recoveredFeed = buildThreadFeed([
329 projected(
330 {
331 ...retryBase,
332 status: "completed",
333 title: "Provider recovered",
334 },
335 0,
336 ),
337 ]);
338 const failedFeed = buildThreadFeed([
339 projected(
340 {
341 ...retryBase,
342 status: "failed",
343 title: "Provider retry failed",
344 },
345 0,
346 ),
347 projected(command("2026-06-20T00:00:03.000Z"), 1),
348 ]);
349 const runningActivity = runningFeed.find((entry) => entry.type === "activity-group")
350 ?.activities[0];
351 const recoveredActivity = recoveredFeed.find((entry) => entry.type === "activity-group")
352 ?.activities[0];
353 if (runningActivity === undefined || recoveredActivity === undefined) {
354 throw new Error("Expected provider retry work-log activities.");
355 }
356
357 expect(runningActivity).toMatchObject({
358 summary: "Provider retry",
359 status: "neutral",
360 toolLike: false,
361 });
362 expect(threadFeedActivityIsVisible(runningActivity)).toBe(true);
363 expect(recoveredActivity).toMatchObject({
364 summary: "Provider recovered",
365 status: "success",
366 toolLike: false,
367 });
368 const failedPresentation = deriveThreadFeedPresentation(
369 failedFeed,
370 { runId, status: "running", startedAt: null, completedAt: null },
371 new Set(),
372 );
373 expect(failedPresentation.map((entry) => entry.type)).toEqual([
374 "activity-group",
375 "work-toggle",
376 ]);
377 expect(
378 failedPresentation[0]?.type === "activity-group"
379 ? failedPresentation[0].activities[0]?.summary
380 : null,
381 ).toBe("Provider retry failed");
382 });
383
384 it.each(["pending", "running", "completed"] as const)(
385 "omits %s task progress without hiding adjacent conversation items",
386 (stepStatus) => {
387 const todoItem = {
388 ...base("item-tasks", "2026-06-20T00:00:02.500Z", 2),
389 type: "todo_list" as const,
390 planId: PlanId.make("plan-tasks"),
391 steps: [{ id: "step-1", text: "Verify the change", status: stepStatus }],
392 } satisfies OrchestrationV2TurnItem;
393 const user = projected(userMessage(), 0);
394 const tool = projected(command(), 1);
395 const assistant = projected(assistantMessage(), 3);
396
397 expect(buildThreadFeed([user, tool, projected(todoItem, 2), assistant])).toEqual(
398 buildThreadFeed([user, tool, assistant]),
399 );
400 },
401 );
402
403 it("hides synthetic workspace preparation activity", () => {
404 const workspacePreparation = projected(
405 {
406 ...command(),
407 title: "Workspace ready",
408 input: "Preparing workspace",
409 output: "Workspace preparation completed.",
410 },
411 0,
412 );
413
414 expect(buildThreadFeed([workspacePreparation])).toEqual([]);
415 });
416
417 it("does not treat a queued-only run as live feed activity", () => {
418 expect(
419 threadFeedRunIsUnsettled({
420 runId,
421 status: "queued",
422 startedAt: null,
423 completedAt: null,
424 }),
425 ).toBe(false);
426 expect(
427 threadFeedRunIsUnsettled({
428 runId,
429 status: "running",
430 startedAt: "2026-06-20T00:00:01.000Z",
431 completedAt: null,
432 }),
433 ).toBe(true);
434 expect(
435 threadFeedRunIsUnsettled({
436 runId,
437 status: "completed",
438 startedAt: "2026-06-20T00:00:01.000Z",
439 completedAt: null,
440 }),
441 ).toBe(true);
442 expect(
443 threadFeedRunIsUnsettled({
444 runId,
445 status: "waiting",
446 startedAt: "2026-06-20T00:00:01.000Z",
447 completedAt: null,
448 }),
449 ).toBe(true);
450 });
451
452 it("adds queued input only after dispatch creates its turn item", () => {
453 const dispatchedRunId = RunId.make("run-dispatched-queued");
454 const dispatchedMessageId = MessageId.make("message-dispatched-queued");
455 expect(buildThreadFeed([])).toEqual([]);
456
457 const promotedEntries = buildThreadFeed([
458 projected(
459 {
460 ...userMessage(),
461 id: TurnItemId.make("item-dispatched-queued"),
462 runId: dispatchedRunId,
463 messageId: dispatchedMessageId,
464 inputIntent: "turn_start",
465 },
466 0,
467 ),
468 ]);
469 expect(promotedEntries.map((entry) => entry.id)).toEqual([dispatchedMessageId]);
470 expect(
471 promotedEntries[0]?.type === "message" ? promotedEntries[0].message.inputIntent : undefined,
472 ).toBe("turn_start");
473 });
474
475 it("hides the interruption request and keeps the terminal result", () => {
476 const request = projected(
477 {
478 ...base("item-interrupt-request", "2026-06-20T00:00:02.000Z", 1),
479 type: "run_interrupt_request",
480 message: "Interrupt requested",
481 },
482 0,
483 );
484 const result = projected(
485 {
486 ...base("item-interrupt-result", "2026-06-20T00:00:03.000Z", 2),
487 type: "run_interrupt_result",
488 message: "Run interrupted before provider start",
489 },
490 1,
491 );
492
493 const activities = buildThreadFeed([request, result]).flatMap((entry) =>
494 entry.type === "activity-group" ? entry.activities : [],
495 );
496
497 expect(activities).toHaveLength(1);
498 expect(activities[0]?.summary).toBe("Run interrupted");
499 expect(activities[0]?.detail).toBe("Run interrupted before provider start");
500 expect(
501 deriveThreadFeedPresentation(
502 buildThreadFeed([request, result]),
503 {
504 runId,
505 status: "interrupted",
506 startedAt: "2026-06-20T00:00:01.000Z",
507 completedAt: "2026-06-20T00:00:03.000Z",
508 },
509 new Set(),
510 ).some((entry) => entry.type === "run-fold"),
511 ).toBe(false);
512 });
513
514 it("preserves authoritative V2 order instead of sorting reconstructed collections", () => {
515 const rows = [
516 projected(userMessage("2026-06-20T00:00:03.000Z"), 0),
517 projected(command("2026-06-20T00:00:01.000Z"), 1),
518 projected(assistantMessage("2026-06-20T00:00:02.000Z"), 2),
519 ];
520
521 const feed = buildThreadFeed(rows);
522 expect(feed.map((entry) => entry.type)).toEqual(["message", "activity-group", "message"]);
523 expect(feed.map((entry) => entry.id)).toEqual([
524 "message-user",
525 "local:thread-1:item-command",
526 "message-assistant",
527 ]);
528 const activity = feed.find((entry) => entry.type === "activity-group")?.activities[0];
529 expect(activity?.projectedItem).toBe(rows[1]);
530 expect(activity?.getFullDetail()).toContain('"input": "vp check"');
531 });
532
533 it("keeps adjacent work from different V2 attempts in separate groups", () => {
534 const firstRootNodeId = NodeId.make("node-attempt-1");
535 const secondRootNodeId = NodeId.make("node-attempt-2");
536 const firstCommand = { ...command(), nodeId: firstRootNodeId };
537 const secondCommand = {
538 ...command("2026-06-20T00:00:03.000Z"),
539 id: TurnItemId.make("item-command-retry"),
540 ordinal: 2,
541 nodeId: secondRootNodeId,
542 };
543 const attempts = [
544 {
545 id: RunAttemptId.make("attempt-1"),
546 runId,
547 attemptOrdinal: 1,
548 rootNodeId: firstRootNodeId,
549 providerInstanceId: ProviderInstanceId.make("provider-instance-1"),
550 providerThreadId: ProviderThreadId.make("provider-thread-1"),
551 providerTurnId: null,
552 reason: "initial",
553 status: "completed",
554 startedAt: DateTime.makeUnsafe("2026-06-20T00:00:01.000Z"),
555 completedAt: DateTime.makeUnsafe("2026-06-20T00:00:02.000Z"),
556 },
557 {
558 id: RunAttemptId.make("attempt-2"),
559 runId,
560 attemptOrdinal: 2,
561 rootNodeId: secondRootNodeId,
562 providerInstanceId: ProviderInstanceId.make("provider-instance-1"),
563 providerThreadId: ProviderThreadId.make("provider-thread-1"),
564 providerTurnId: null,
565 reason: "retry",
566 status: "completed",
567 startedAt: DateTime.makeUnsafe("2026-06-20T00:00:02.000Z"),
568 completedAt: DateTime.makeUnsafe("2026-06-20T00:00:03.000Z"),
569 },
570 ] satisfies ReadonlyArray<OrchestrationV2RunAttempt>;
571
572 const feed = buildThreadFeed([projected(firstCommand, 0), projected(secondCommand, 1)], {
573 attempts,
574 });
575
576 expect(feed).toHaveLength(2);
577 expect(
578 feed.map((entry) =>
579 entry.type === "activity-group" ? entry.activities[0]?.attemptId : null,
580 ),
581 ).toEqual(["attempt-1", "attempt-2"]);
582 });
583
584 it("retains inherited and synthetic rows with their original projected identity", () => {
585 const inherited = projected(command(), 0, "inherited");
586 const { providerThreadId: _providerThreadId, ...forkBase } = base(
587 "item-fork",
588 "2026-06-20T00:00:03.000Z",
589 2,
590 );
591 const synthetic = projected(
592 {
593 ...forkBase,
594 type: "fork",
595 source: { type: "run", threadId: sourceThreadId, runId },
596 targetThreadId: threadId,
597 },
598 1,
599 "synthetic",
600 );
601
602 const feed = buildThreadFeed([inherited, synthetic]);
603 const activities = feed.flatMap((entry) =>
604 entry.type === "activity-group" ? entry.activities : [],
605 );
606 expect(activities.map((activity) => activity.projectedItem)).toEqual([inherited, synthetic]);
607 expect(activities.map((activity) => activity.projectedItem.visibility)).toEqual([
608 "inherited",
609 "synthetic",
610 ]);
611 expect(activities.at(-1)?.prominent).toBe(true);
612 });
613
614 it("keeps orchestration relationship cards visible when a completed run is folded", () => {
615 const { providerThreadId: _providerThreadId, ...forkBase } = base(
616 "item-fork",
617 "2026-06-20T00:00:02.500Z",
618 2,
619 );
620 const feed = buildThreadFeed([
621 projected(userMessage(), 0),
622 projected(command(), 1),
623 projected(
624 {
625 ...forkBase,
626 type: "fork",
627 source: { type: "run", threadId, runId },
628 targetThreadId: sourceThreadId,
629 },
630 2,
631 ),
632 projected(assistantMessage(), 3),
633 ]);
634
635 const collapsed = deriveThreadFeedPresentation(
636 feed,
637 {
638 runId,
639 status: "completed",
640 startedAt: "2026-06-20T00:00:01.000Z",
641 completedAt: "2026-06-20T00:00:03.000Z",
642 },
643 new Set(),
644 );
645
646 expect(
647 collapsed.some(
648 (entry) =>
649 entry.type === "activity-group" &&
650 entry.activities.some((activity) => activity.projectedItem.item.type === "fork"),
651 ),
652 ).toBe(true);
653 expect(
654 collapsed.some(
655 (entry) =>
656 entry.type === "activity-group" &&
657 entry.activities.some(
658 (activity) => activity.projectedItem.item.type === "command_execution",
659 ),
660 ),
661 ).toBe(false);
662 });
663
664 it("keeps opening and final assistant messages around the first hidden work", () => {
665 const opening = {
666 ...assistantMessage("2026-06-20T00:00:01.500Z"),
667 id: TurnItemId.make("item-opening"),
668 messageId: MessageId.make("message-opening"),
669 text: "I will check the deployment configuration.",
670 };
671 const middle = {
672 ...assistantMessage("2026-06-20T00:00:02.500Z"),
673 id: TurnItemId.make("item-middle"),
674 messageId: MessageId.make("message-middle"),
675 text: "The configuration is valid; checking the build next.",
676 };
677 const feed = buildThreadFeed([
678 projected(userMessage(), 0),
679 projected(opening, 1),
680 projected(command(), 2),
681 projected(middle, 3),
682 projected(assistantMessage(), 4),
683 ]);
684 const latestRun = {
685 runId,
686 status: "completed" as const,
687 startedAt: "2026-06-20T00:00:01.000Z",
688 completedAt: "2026-06-20T00:00:03.000Z",
689 };
690
691 const collapsed = deriveThreadFeedPresentation(feed, latestRun, new Set());
692 expect(collapsed.map((entry) => entry.id)).toEqual([
693 "message-user",
694 "message-opening",
695 "run-fold:run-1",
696 "message-assistant",
697 ]);
698 expect(collapsed[1]).toMatchObject({ message: { text: opening.text } });
699 expect(collapsed[2]).toMatchObject({
700 type: "run-fold",
701 createdAt: "2026-06-20T00:00:02.000Z",
702 label: "Worked for 2.0s",
703 });
704
705 const expanded = deriveThreadFeedPresentation(feed, latestRun, new Set([runId]));
706 expect(expanded.map((entry) => entry.type)).toEqual([
707 "message",
708 "message",
709 "run-fold",
710 "work-toggle",
711 "message",
712 "message",
713 ]);
714 expect(expanded[4]).toMatchObject({ message: { id: middle.messageId, text: middle.text } });
715 });
716
717 it("does not fold a response that only has opening and final messages", () => {
718 const feed = buildThreadFeed([
719 projected(userMessage(), 0),
720 projected(
721 {
722 ...assistantMessage("2026-06-20T00:00:02.000Z"),
723 id: TurnItemId.make("item-opening"),
724 messageId: MessageId.make("message-opening"),
725 text: "The result is ready.",
726 },
727 1,
728 ),
729 projected(assistantMessage(), 2),
730 ]);
731
732 const presented = deriveThreadFeedPresentation(feed, null, new Set());
733 expect(presented.map((entry) => entry.id)).toEqual([
734 "message-user",
735 "message-opening",
736 "message-assistant",
737 ]);
738 });
739
740 it("places the fold after leading resource cards and keeps later cards visible", () => {
741 const { providerThreadId: _providerThreadId, ...forkBase } = base(
742 "item-fork",
743 "2026-06-20T00:00:02.000Z",
744 2,
745 );
746 const resourceItems = [
747 {
748 ...base("item-subagent", "2026-06-20T00:00:01.500Z", 1),
749 type: "subagent",
750 subagentId: NodeId.make("child-agent"),
751 origin: "app_owned",
752 driver: ProviderDriverKind.make("codex"),
753 providerInstanceId: ProviderInstanceId.make("codex"),
754 childThreadId: sourceThreadId,
755 prompt: "Inspect the deployment configuration",
756 result: "Configuration is valid",
757 },
758 {
759 ...forkBase,
760 type: "fork",
761 source: { type: "run", threadId, runId },
762 targetThreadId: sourceThreadId,
763 },
764 {
765 ...base("item-created-thread", "2026-06-20T00:00:04.000Z", 4),
766 type: "thread_created",
767 targetThreadId: sourceThreadId,
768 targetRunId: null,
769 targetProviderInstanceId: ProviderInstanceId.make("codex"),
770 targetModel: "gpt-5.4",
771 },
772 ] satisfies ReadonlyArray<OrchestrationV2TurnItem>;
773 const projectedResources = [
774 projected(resourceItems[0]!, 1),
775 projected(resourceItems[1]!, 2),
776 projected(resourceItems[2]!, 4),
777 ];
778 const feed = buildThreadFeed([
779 projected(userMessage(), 0),
780 projectedResources[0]!,
781 projectedResources[1]!,
782 projected(command("2026-06-20T00:00:03.000Z"), 3),
783 projectedResources[2]!,
784 projected(assistantMessage("2026-06-20T00:00:05.000Z"), 5),
785 ]);
786
787 const collapsed = deriveThreadFeedPresentation(feed, null, new Set());
788 expect(collapsed.map((entry) => entry.type)).toEqual([
789 "message",
790 "activity-group",
791 "activity-group",
792 "run-fold",
793 "activity-group",
794 "message",
795 ]);
796 expect(collapsed[3]).toMatchObject({
797 type: "run-fold",
798 createdAt: "2026-06-20T00:00:03.000Z",
799 });
800 expect(
801 collapsed.flatMap((entry) =>
802 entry.type === "activity-group"
803 ? entry.activities.map((activity) => activity.projectedItem)
804 : [],
805 ),
806 ).toEqual(projectedResources);
807 });
808
809 it("folds settled V2 run work while keeping the terminal assistant message visible", () => {
810 const feed = buildThreadFeed([
811 projected(userMessage(), 0),
812 projected(command(), 1),
813 projected(assistantMessage(), 2),
814 ]);
815 const latestRun = {
816 runId,
817 status: "completed" as const,
818 startedAt: "2026-06-20T00:00:01.000Z",
819 completedAt: "2026-06-20T00:00:03.000Z",
820 };
821
822 const collapsed = deriveThreadFeedPresentation(feed, latestRun, new Set());
823 expect(collapsed.map((entry) => entry.type)).toEqual(["message", "run-fold", "message"]);
824
825 const expanded = deriveThreadFeedPresentation(feed, latestRun, new Set([runId]));
826 expect(expanded.map((entry) => entry.type)).toEqual([
827 "message",
828 "run-fold",
829 "work-toggle",
830 "message",
831 ]);
832 });
833
834 it("keeps an active run expanded and detects failures from completed command output", () => {
835 const failedCommand: OrchestrationV2TurnItem = {
836 ...command(),
837 output: "sh: missing-command: command not found",
838 };
839 const feed = buildThreadFeed([projected(userMessage(), 0), projected(failedCommand, 1)]);
840 const presented = deriveThreadFeedPresentation(
841 feed,
842 {
843 runId,
844 status: "running",
845 startedAt: "2026-06-20T00:00:01.000Z",
846 completedAt: null,
847 },
848 new Set(),
849 );
850
851 expect(presented.some((entry) => entry.type === "run-fold")).toBe(false);
852 expect(presented.find((entry) => entry.type === "work-toggle")).toMatchObject({
853 summary: "vp check",
854 hiddenCount: 1,
855 hasFailure: true,
856 live: false,
857 });
858 });
859
860 it("uses a stable Thinking row while work has started without a projected item", () => {
861 const startedAt = "2026-04-01T00:00:01.000Z";
862 const presented = deriveThreadFeedPresentation([], null, new Set(), new Set(), startedAt);
863
864 expect(presented).toEqual([
865 { type: "thinking", id: "live-activity-row", createdAt: startedAt, runId: null },
866 ]);
867 expect(deriveThreadFeedPresentation([], null, new Set(), new Set(), startedAt)[0]).toBe(
868 presented[0],
869 );
870 });
871
872 it("keeps expanded work in one group with stable row identities", () => {
873 const activity = (
874 id: string,
875 createdAt: string,
876 status: ThreadFeedActivity["status"] = "success",
877 ): ThreadFeedActivity => ({
878 id,
879 createdAt,
880 runId: null,
881 attemptId: null,
882 summary: `Tool ${id}`,
883 detail: null,
884 canExpand: false,
885 getFullDetail: () => null,
886 getCopyText: () => id,
887 icon: "command",
888 logo: null,
889 toolLike: true,
890 prominent: false,
891 status,
892 lifecycleStatus: status === "neutral" ? "inProgress" : "completed",
893 workEntry: {
894 id,
895 createdAt,
896 label: `Tool ${id}`,
897 tone: "tool",
898 command: "vp check",
899 itemType: "command_execution",
900 toolLifecycleStatus: status === "neutral" ? "inProgress" : "completed",
901 },
902 projectedItem: projected(command(createdAt), 0),
903 });
904 const feed: ThreadFeedEntry[] = [
905 {
906 type: "activity-group",
907 id: "work-group-1",
908 createdAt: "2026-04-01T00:00:01.000Z",
909 runId: null,
910 activities: [
911 activity("activity-neutral", "2026-04-01T00:00:01.000Z", "neutral"),
912 activity("activity-1", "2026-04-01T00:00:02.000Z"),
913 activity("activity-2", "2026-04-01T00:00:03.000Z"),
914 activity("activity-3", "2026-04-01T00:00:04.000Z"),
915 ],
916 },
917 ];
918
919 const collapsed = deriveThreadFeedPresentation(feed, null, new Set());
920 expect(collapsed.map((entry) => entry.id)).toEqual(["work-toggle:work-group:activity-neutral"]);
921 expect(collapsed[0]).toMatchObject({
922 type: "work-toggle",
923 groupId: "work-group:activity-neutral",
924 hiddenCount: 3,
925 expanded: false,
926 summary: "Ran 3 commands",
927 });
928
929 const expanded = deriveThreadFeedPresentation(
930 feed,
931 null,
932 new Set(),
933 new Set(["work-group:activity-neutral"]),
934 );
935 expect(expanded.map((entry) => entry.id)).toEqual([
936 "work-toggle:work-group:activity-neutral",
937 "work-details:work-group:activity-neutral",
938 ]);
939 expect(expanded[0]).toMatchObject({
940 type: "work-toggle",
941 expanded: true,
942 });
943 expect(expanded[1]).toMatchObject({
944 type: "activity-group",
945 activities: [
946 { id: "activity-1", groupedToolDetail: true, live: false },
947 { id: "activity-2", groupedToolDetail: true, live: false },
948 { id: "activity-3", groupedToolDetail: true, live: false },
949 ],
950 });
951 });
952
953 it("retains Claude Read image previews without tool output", () => {
954 const item = {
955 ...base("image-read", "2026-06-20T00:00:04.000Z", 3),
956 type: "dynamic_tool" as const,
957 toolName: "Read",
958 input: { file_path: "/workspace/reference.png" },
959 viewedImagePath: "/workspace/reference.png",
960 } satisfies OrchestrationV2TurnItem;
961 const feed = buildThreadFeed([projected(item, 0)]);
962 const activity = feed[0]?.type === "activity-group" ? feed[0].activities[0] : null;
963 expect(activity?.workEntry.viewedImagePath).toBe("/workspace/reference.png");
964 });
965
966 it("pretty prints T3 MCP dynamic tool activities and attaches the product logo", () => {
967 const toolItem: OrchestrationV2TurnItem = {
968 ...base("item-t3-tool", "2026-06-20T00:00:04.000Z", 3),
969 type: "dynamic_tool",
970 toolName: "mcp__t3-code__t3_thread_read",
971 input: { threadId: "thread-child" },
972 output: { messages: [] },
973 };
974
975 const feed = buildThreadFeed([projected(toolItem, 0)]);
976 const activity = feed[0]?.type === "activity-group" ? feed[0].activities[0] : null;
977
978 expect(activity?.summary).toBe("Read a T3 thread");
979 expect(activity?.logo).toBe("t3-code");
980 expect(activity?.getCopyText().split("\n")[0]).toBe("Read a T3 thread");
981 });
982
983 it("uses canonical T3 orchestration summaries in compact work groups", () => {
984 const rows = [
985 projected(command("2026-06-20T00:00:01.000Z"), 0),
986 ...["mcp__t3-code__t3_thread_send", "t3_code.t3_thread_send", "t3_thread_send"].map(
987 (toolName, index) =>
988 projected(
989 {
990 ...base(`item-send-${index}`, `2026-06-20T00:00:0${index + 2}.000Z`, index + 2),
991 type: "dynamic_tool" as const,
992 toolName,
993 input: { threadId: `thread-${index}`, message: "Continue" },
994 output: { threadId: `thread-${index}`, messageId: `message-${index}` },
995 },
996 index + 1,
997 ),
998 ),
999 projected(
1000 {
1001 ...command("2026-06-20T00:00:06.000Z"),
1002 id: TurnItemId.make("item-command-2"),
1003 ordinal: 6,
1004 },
1005 4,
1006 ),
1007 ];
1008
1009 const presented = deriveThreadFeedPresentation(
1010 buildThreadFeed(rows),
1011 { runId, status: "running", startedAt: null, completedAt: null },
1012 new Set(),
1013 );
1014
1015 expect(presented).toMatchObject([
1016 {
1017 type: "work-toggle",
1018 summary: "Ran 2 commands and sent messages to 3 threads",
1019 hiddenCount: 5,
1020 hasFailure: false,
1021 },
1022 ]);
1023 });
1024});
1025
1026describe("retained v2 feed presentation", () => {
1027 it("retains unchanged rows while the assistant streams", () => {
1028 const rows = [
1029 projected(userMessage(), 0),
1030 projected(command(), 1),
1031 projected({ ...assistantMessage(), streaming: true }, 2),
1032 ];
1033 const latestRun = {
1034 runId,
1035 status: "running" as const,
1036 startedAt: "2026-06-20T00:00:01.000Z",
1037 completedAt: null,
1038 };
1039 const before = buildThreadFeed(rows);
1040 const beforePresentation = deriveThreadFeedPresentation(
1041 before,
1042 latestRun,
1043 new Set(),
1044 new Set(),
1045 latestRun.startedAt,
1046 );
1047 const after = buildThreadFeed([
1048 rows[0]!,
1049 rows[1]!,
1050 projected(
1051 { ...assistantMessage("2026-06-20T00:00:04.000Z"), text: "Still working", streaming: true },
1052 2,
1053 ),
1054 ]);
1055 const afterPresentation = deriveThreadFeedPresentation(
1056 after,
1057 latestRun,
1058 new Set(),
1059 new Set(),
1060 latestRun.startedAt,
1061 );
1062 expect(after[0]).toBe(before[0]);
1063 expect(after[1]).toBe(before[1]);
1064 expect(after[2]).not.toBe(before[2]);
1065 expect(afterPresentation[0]).toBe(beforePresentation[0]);
1066 expect(afterPresentation[1]).toBe(beforePresentation[1]);
1067 });
1068
1069 it.each(["running", "completed", "interrupted"] as const)(
1070 "uses the compaction row as the live activity only while %s",
1071 (status) => {
1072 const compact = projected(
1073 {
1074 ...base("compacted", "2026-06-20T00:00:02.000Z", 1),
1075 type: "compaction",
1076 status,
1077 driver: null,
1078 beforeTokenCount: 899_000,
1079 ...(status === "completed" ? { afterTokenCount: 19_000 } : {}),
1080 },
1081 1,
1082 );
1083 const latestRun = {
1084 runId,
1085 status: "running" as const,
1086 startedAt: "2026-06-20T00:00:01.000Z",
1087 completedAt: null,
1088 };
1089 const rows = deriveThreadFeedPresentation(
1090 buildThreadFeed([projected(userMessage(), 0), compact]),
1091 latestRun,
1092 new Set(),
1093 new Set(),
1094 latestRun.startedAt,
1095 );
1096 expect(rows.some((row) => row.type === "thinking")).toBe(status !== "running");
1097 expect(rows.find((row) => row.type === "activity-group")).toMatchObject({
1098 activities: [
1099 {
1100 summary:
1101 status === "running"
1102 ? "Compacting context"
1103 : status === "completed"
1104 ? "Context compacted 899K → 19K tokens"
1105 : "Context compacted",
1106 },
1107 ],
1108 });
1109 },
1110 );
1111
1112 it("keeps a standalone compaction visible and folds it with other completed work", () => {
1113 const compact = projected(
1114 {
1115 ...base("compacted", "2026-06-20T00:00:02.000Z", 1),
1116 type: "compaction",
1117 driver: null,
1118 summary: "Shorter context",
1119 },
1120 1,
1121 );
1122 const latestRun = {
1123 runId,
1124 status: "completed" as const,
1125 startedAt: "2026-06-20T00:00:01.000Z",
1126 completedAt: "2026-06-20T00:00:04.000Z",
1127 };
1128 const onlyCompaction = deriveThreadFeedPresentation(
1129 buildThreadFeed([projected(userMessage(), 0), compact]),
1130 latestRun,
1131 new Set(),
1132 );
1133 expect(onlyCompaction.map((entry) => entry.type)).toEqual(["message", "activity-group"]);
1134 const feed = buildThreadFeed([
1135 projected(userMessage(), 0),
1136 compact,
1137 projected(command("2026-06-20T00:00:03.000Z"), 2),
1138 projected(assistantMessage("2026-06-20T00:00:04.000Z"), 3),
1139 ]);
1140 expect(
1141 deriveThreadFeedPresentation(feed, latestRun, new Set()).map((entry) => entry.type),
1142 ).toEqual(["message", "run-fold", "message"]);
1143 const expanded = deriveThreadFeedPresentation(feed, latestRun, new Set([runId]));
1144 expect(
1145 expanded.find(
1146 (entry) =>
1147 entry.type === "activity-group" &&
1148 entry.activities[0]?.projectedItem.item.type === "compaction",
1149 ),
1150 ).toMatchObject({ activities: [{ summary: "Context compacted" }] });
1151 });
1152
1153 it("retains assistant image attachments from the wire", () => {
1154 const image = {
1155 type: "image" as const,
1156 id: "assistant-image",
1157 name: "result.png",
1158 mimeType: "image/png",
1159 sizeBytes: 100,
1160 };
1161 const feed = buildThreadFeed([
1162 projected({ ...assistantMessage(), text: "", attachments: [image] }, 0),
1163 ]);
1164 expect(feed).toMatchObject([
1165 { type: "message", message: { role: "assistant", attachments: [image] } },
1166 ]);
1167 });
1168
1169 it("keeps native application icons and source identity in collapsed and expanded work", () => {
1170 const icon = {
1171 _tag: "native-app" as const,
1172 app: { _tag: "app-id" as const, appId: "com.example.Editor" },
1173 };
1174 const source = {
1175 key: "native-app:com.example.editor",
1176 name: "Editor",
1177 kind: "computer" as const,
1178 icon,
1179 };
1180 const rows = [0, 1].map((index) =>
1181 projected(
1182 {
1183 ...base(`native-${index}`, `2026-06-20T00:00:0${index + 2}.000Z`, index + 1),
1184 type: "dynamic_tool" as const,
1185 toolName: "computer.click",
1186 input: { x: index, y: 1 },
1187 output: null,
1188 toolSurface: "computer" as const,
1189 toolIcon: icon,
1190 toolSource: source,
1191 },
1192 index,
1193 ),
1194 );
1195 const feed = buildThreadFeed(rows);
1196 const latestRun = { runId, status: "running" as const, startedAt: null, completedAt: null };
1197 const collapsed = deriveThreadFeedPresentation(feed, latestRun, new Set());
1198 const toggle = collapsed[0];
1199 if (toggle?.type !== "work-toggle") throw new Error("Expected a collapsed work group");
1200 const presented = deriveThreadFeedPresentation(
1201 feed,
1202 latestRun,
1203 new Set(),
1204 new Set([toggle.groupId]),
1205 );
1206 expect(presented[0]).toMatchObject({
1207 type: "work-toggle",
1208 summary: "Used Editor",
1209 toolSurface: "computer",
1210 toolIcon: icon,
1211 });
1212 expect(presented[1]).toMatchObject({
1213 type: "activity-group",
1214 activities: [
1215 { icon: "computer", workEntry: { toolSource: source, toolIcon: icon } },
1216 { icon: "computer", workEntry: { toolSource: source, toolIcon: icon } },
1217 ],
1218 });
1219 });
1220
1221 it.each([
1222 ["failed", "Failed to click in the preview browser", true],
1223 ["cancelled", "Stopped clicking in the preview browser", false],
1224 ] as const)(
1225 "keeps %s calls terminal while the parent run remains live",
1226 (status, summary, hasFailure) => {
1227 const feed = buildThreadFeed([
1228 projected(
1229 {
1230 ...base("preview-click", "2026-06-20T00:00:02.000Z", 1),
1231 type: "dynamic_tool",
1232 status,
1233 toolName: "mcp__t3-code__preview_click",
1234 input: { element: "button" },
1235 output: null,
1236 },
1237 0,
1238 ),
1239 ]);
1240 const rows = deriveThreadFeedPresentation(
1241 feed,
1242 { runId, status: "running", startedAt: "2026-06-20T00:00:01.000Z", completedAt: null },
1243 new Set(),
1244 new Set(),
1245 "2026-06-20T00:00:01.000Z",
1246 );
1247 expect(rows[0]).toMatchObject({ type: "work-toggle", summary, hasFailure, shimmer: false });
1248 },
1249 );
1250
1251 it("shows an idle native subagent without claiming completion", () => {
1252 const rows = buildThreadFeed([
1253 projected(
1254 {
1255 ...base("native-agent", "2026-06-20T00:00:02.000Z", 1),
1256 type: "subagent",
1257 status: "idle",
1258 subagentId: NodeId.make("native-agent"),
1259 origin: "provider_native",
1260 driver: ProviderDriverKind.make("antigravity"),
1261 providerInstanceId: ProviderInstanceId.make("antigravity"),
1262 childThreadId: null,
1263 title: "Search",
1264 prompt: "Find relevant files",
1265 result: null,
1266 },
1267 0,
1268 ),
1269 ]);
1270 expect(rows[0]).toMatchObject({
1271 type: "activity-group",
1272 activities: [{ status: "neutral", lifecycleStatus: "idle", prominent: true }],
1273 });
1274 expect(deriveThreadFeedPresentation(rows, null, new Set())).toMatchObject([
1275 { type: "activity-group", activities: [{ lifecycleStatus: "idle" }] },
1276 ]);
1277 });
1278});
1279
1280const singleSelectQuestion = {
1281 id: "runtime",
1282 header: "Runtime",
1283 question: "Which runtime should be used?",
1284 options: [
1285 { label: "Go", description: "One binary" },
1286 { label: "Node.js", description: "Reuse TypeScript" },
1287 ],
1288 multiSelect: false,
1289} as const;
1290
1291const multiSelectQuestion = {
1292 id: "scope",
1293 header: "Scope",
1294 question: "Which data should be collected?",
1295 options: [
1296 { label: "Orders", description: "Receipts" },
1297 { label: "Listings", description: "Inventory" },
1298 ],
1299 multiSelect: true,
1300} as const;
1301
1302describe("pending user input answers", () => {
1303 it("replaces single-select options and toggles multi-select options", () => {
1304 expect(
1305 togglePendingUserInputOptionSelection(
1306 singleSelectQuestion,
1307 { selectedOptionValues: ["Go"] },
1308 "Node.js",
1309 ),
1310 ).toEqual({ customAnswer: "", selectedOptionValues: ["Node.js"] });
1311
1312 const orders = togglePendingUserInputOptionSelection(multiSelectQuestion, undefined, "Orders");
1313 const ordersAndListings = togglePendingUserInputOptionSelection(
1314 multiSelectQuestion,
1315 orders,
1316 "Listings",
1317 );
1318 expect(ordersAndListings).toEqual({
1319 customAnswer: "",
1320 selectedOptionValues: ["Orders", "Listings"],
1321 });
1322 expect(
1323 togglePendingUserInputOptionSelection(multiSelectQuestion, ordersAndListings, "Orders"),
1324 ).toEqual({ customAnswer: "", selectedOptionValues: ["Listings"] });
1325
1326 const paddedOrders = togglePendingUserInputOptionSelection(
1327 multiSelectQuestion,
1328 undefined,
1329 " Orders ",
1330 );
1331 expect(paddedOrders).toEqual({ customAnswer: "", selectedOptionValues: ["Orders"] });
1332 expect(
1333 togglePendingUserInputOptionSelection(multiSelectQuestion, paddedOrders, " Orders "),
1334 ).toEqual({ customAnswer: "" });
1335 });
1336
1337 it("builds array answers for multi-select questions", () => {
1338 expect(
1339 buildPendingUserInputAnswers([singleSelectQuestion, multiSelectQuestion], {
1340 runtime: { selectedOptionValues: ["Go"] },
1341 scope: { selectedOptionValues: ["Orders", "Listings"] },
1342 }),
1343 ).toEqual({
1344 runtime: "Go",
1345 scope: ["Orders", "Listings"],
1346 });
1347 });
1348
1349 it("clears selected options while a custom answer is active", () => {
1350 expect(
1351 setPendingUserInputCustomAnswer(
1352 multiSelectQuestion,
1353 { selectedOptionValues: ["Orders", "Listings"] },
1354 "Orders first",
1355 ),
1356 ).toEqual({ customAnswer: "Orders first" });
1357 });
1358
1359 it("matches selected chips against normalized option labels", () => {
1360 expect(
1361 isPendingUserInputOptionSelected(
1362 multiSelectQuestion,
1363 { selectedOptionValues: ["Orders"] },
1364 " Orders ",
1365 ),
1366 ).toBe(true);
1367 expect(
1368 isPendingUserInputOptionSelected(
1369 multiSelectQuestion,
1370 { selectedOptionValues: ["Orders"], customAnswer: "Orders first" },
1371 " Orders ",
1372 ),
1373 ).toBe(false);
1374 });
1375});
1376
1377describe("provider question values", () => {
1378 const question = {
1379 ...singleSelectQuestion,
1380 allowCustomAnswer: false,
1381 options: [
1382 { label: "Same label", value: " exact first ", description: "First" },
1383 { label: "Same label", value: "second", description: "Second" },
1384 ],
1385 } as const;
1386
1387 it("submits raw option values and distinguishes duplicate labels", () => {
1388 const first = togglePendingUserInputOptionSelection(question, undefined, " exact first ");
1389 expect(isPendingUserInputOptionSelected(question, first, " exact first ")).toBe(true);
1390 expect(isPendingUserInputOptionSelected(question, first, "second")).toBe(false);
1391 expect(buildPendingUserInputAnswers([question], { runtime: first })).toEqual({
1392 runtime: " exact first ",
1393 });
1394 expect(togglePendingUserInputOptionSelection(question, first, "Same label")).toBe(first);
1395 });
1396
1397 it("rejects arbitrary text when the provider only accepts offered options", () => {
1398 expect(setPendingUserInputCustomAnswer(question, undefined, "Other")).toEqual({});
1399 expect(
1400 buildPendingUserInputAnswers([question], { runtime: { customAnswer: "Other" } }),
1401 ).toBeNull();
1402 expect(
1403 buildPendingUserInputAnswers([question], { runtime: { selectedOptionValues: ["unknown"] } }),
1404 ).toBeNull();
1405 expect(
1406 buildPendingUserInputAnswers([question], {
1407 runtime: { selectedOptionValues: ["second"], customAnswer: "stale draft" },
1408 }),
1409 ).toEqual({ runtime: "second" });
1410 });
1411});
1412
1413it("accepts ready attachment-only answers while preserving selected options", () => {
1414 const question = {
1415 id: "q",
1416 header: "Spec",
1417 question: "Provide a specification",
1418 options: [{ label: "Yes", description: "Approve" }],
1419 multiSelect: false,
1420 };
1421 expect(buildPendingUserInputAnswers([question], { q: { attachmentCount: 1 } })).toEqual({
1422 q: "",
1423 });
1424 expect(
1425 buildPendingUserInputAnswers([question], {
1426 q: { attachmentCount: 1, selectedOptionValues: ["Yes"] },
1427 }),
1428 ).toEqual({ q: "Yes" });
1429 expect(
1430 buildPendingUserInputAnswers([question], {
1431 q: { attachmentCount: 1, attachmentsBlocked: true },
1432 }),
1433 ).toBeNull();
1434 expect(
1435 buildPendingUserInputAnswers([{ ...question, allowCustomAnswer: false }], {
1436 q: { attachmentCount: 1 },
1437 }),
1438 ).toBeNull();
1439});
1440
1441it("makes attachment-only question answers expandable in the mobile feed", () => {
1442 const answer = {
1443 requestId: RuntimeRequestId.make("question-request"),
1444 answers: { q: "" },
1445 questionTextById: { q: "Attach the specification" },
1446 attachmentsByQuestionId: {
1447 q: [
1448 {
1449 type: "file" as const,
1450 id: "question-file",
1451 name: "spec.txt",
1452 mimeType: "text/plain",
1453 sizeBytes: 4,
1454 },
1455 ],
1456 },
1457 };
1458 const [group] = buildThreadFeed([
1459 projected(
1460 {
1461 ...base("answer-history", "2026-09-08T00:00:00.000Z", 0),
1462 type: "user_input_request",
1463 requestId: answer.requestId,
1464 questions: [],
1465 questionAnswer: answer,
1466 },
1467 0,
1468 ),
1469 ]);
1470 expect(group?.type).toBe("activity-group");
1471 if (group?.type !== "activity-group") return;
1472 expect(group.activities[0]).toMatchObject({
1473 canExpand: true,
1474 workEntry: { questionAnswer: answer },
1475 });
1476 expect(group.activities[0]?.getFullDetail()).toContain("spec.txt");
1477});