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

session-logic.test.ts

1,363 lines45.5 KB

1import {
2 MessageId,
3 NodeId,
4 PlanId,
5 ProviderInstanceId,
6 ProviderThreadId,
7 RunAttemptId,
8 RunId,
9 ThreadId,
10 TurnItemId,
11 type OrchestrationV2ProjectedTurnItem,
12 type OrchestrationV2ExecutionNode,
13 type OrchestrationV2RunAttempt,
14 type OrchestrationV2TurnItem,
15} from "@t3tools/contracts";
16import * as DateTime from "effect/DateTime";
17import { describe, expect, it } from "vite-plus/test";
18​
19import {
20 deriveActivePlanState,
21 deriveTimelineEntriesFromVisibleTurnItems,
22 deriveTimelineEntriesFromVisibleTurnItemsWithState,
23 deriveRevertTurnCountByUserMessageId,
24 findLatestProposedPlan,
25 isLatestRunSettled,
26 selectHandoffImageResources,
27 selectMessageImageResources,
28 createMessageAttachmentPreviewProjector,
29 providerErrorPresentation,
30 type TimelineEntry,
31 workEntryIndicatesToolFailure,
32 workEntryDisplayIndicatesToolFailure,
33 workEntryIndicatesToolSuccess,
34} from "./session-logic";
35import { makeStreamingTimelineFixture, makeThreadProjectionFixture } from "./test-fixtures";
36import type { ChatMessage } from "./types";
37​
38describe("V2 session presentation", () => {
39 it("uses run status as the settlement boundary", () => {
40 const runId = RunId.make("run-1");
41 expect(
42 isLatestRunSettled(
43 {
44 runId,
45 status: "completed",
46 startedAt: "2026-06-20T00:00:00.000Z",
47 completedAt: "2026-06-20T00:01:00.000Z",
48 },
49 null,
50 ),
51 ).toBe(true);
52 expect(
53 isLatestRunSettled(
54 { runId, status: "running", startedAt: null, completedAt: null },
55 { status: "running", activeRunId: runId },
56 ),
57 ).toBe(false);
58 expect(
59 isLatestRunSettled(
60 { runId, status: "queued", startedAt: null, completedAt: null },
61 { status: "running", activeRunId: RunId.make("run-active") },
62 ),
63 ).toBe(false);
64 });
65​
66 it("labels provider retry progress, delay, recovery, and exhaustion", () => {
67 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
68 const retryItem = {
69 id: TurnItemId.make("item-provider-retry"),
70 threadId: ThreadId.make("thread-provider-retry"),
71 runId: RunId.make("run-provider-retry"),
72 nodeId: null,
73 providerThreadId: null,
74 providerTurnId: null,
75 nativeItemRef: null,
76 parentItemId: null,
77 ordinal: 1,
78 status: "running" as const,
79 title: "Provider retry",
80 startedAt: now,
81 completedAt: null,
82 updatedAt: now,
83 type: "error" as const,
84 failure: {
85 class: "provider_error" as const,
86 message: "Claude API overloaded.",
87 code: "api_error_529",
88 retryable: true,
89 },
90 retry: {
91 attempt: 2,
92 maxAttempts: 10,
93 retryDelayMs: 1_500,
94 },
95 } satisfies Extract<OrchestrationV2TurnItem, { readonly type: "error" }>;
96​
97 expect(providerErrorPresentation(retryItem)).toEqual({
98 label: "Retrying provider (2/10)",
99 detail: "Claude API overloaded. Retrying in 1.5s.",
100 });
101 expect(
102 providerErrorPresentation({
103 ...retryItem,
104 status: "completed",
105 completedAt: now,
106 }),
107 ).toMatchObject({ label: "Provider recovered (2/10 retries)" });
108 expect(
109 providerErrorPresentation({
110 ...retryItem,
111 status: "failed",
112 retry: { ...retryItem.retry, attempt: 10 },
113 completedAt: now,
114 }),
115 ).toMatchObject({ label: "Provider error after 10/10 retries" });
116 });
117​
118 it("selects the latest proposed plan for a run", () => {
119 const runId = RunId.make("run-1");
120 const planId = PlanId.make("plan-1");
121 const nodeId = NodeId.make("node-plan");
122 const now = DateTime.makeUnsafe("2026-06-20T00:00:01.000Z");
123 const baseProjection = makeThreadProjectionFixture();
124 const plan = findLatestProposedPlan(
125 {
126 ...baseProjection,
127 plans: [
128 {
129 id: planId,
130 threadId: baseProjection.thread.id,
131 nodeId,
132 kind: "proposed_plan" as const,
133 markdown: "Plan",
134 status: "active" as const,
135 runId,
136 },
137 ],
138 turnItems: [
139 {
140 id: TurnItemId.make("item-plan"),
141 threadId: baseProjection.thread.id,
142 nodeId,
143 providerThreadId: null,
144 providerTurnId: null,
145 nativeItemRef: null,
146 parentItemId: null,
147 ordinal: 0,
148 status: "completed" as const,
149 title: null,
150 startedAt: now,
151 completedAt: now,
152 updatedAt: now,
153 type: "proposed_plan" as const,
154 planId,
155 markdown: "Plan",
156 streaming: false,
157 runId,
158 },
159 ],
160 updatedAt: now,
161 },
162 runId,
163 );
164 expect(plan?.planMarkdown).toBe("Plan");
165 });
166​
167 it("assigns run rollback to the turn-start message instead of a later steer", () => {
168 const runId = RunId.make("run-steered");
169 const turnStartMessageId = MessageId.make("message-turn-start");
170 const steerMessageId = MessageId.make("message-steer");
171 const assistantMessageId = MessageId.make("message-assistant");
172 const messages: ChatMessage[] = [
173 {
174 id: turnStartMessageId,
175 role: "user",
176 text: "Start",
177 runId,
178 inputIntent: "turn_start",
179 streaming: false,
180 createdAt: "2026-06-20T00:00:00.000Z",
181 updatedAt: "2026-06-20T00:00:00.000Z",
182 },
183 {
184 id: steerMessageId,
185 role: "user",
186 text: "Steer",
187 runId,
188 inputIntent: "steer",
189 streaming: false,
190 createdAt: "2026-06-20T00:00:01.000Z",
191 updatedAt: "2026-06-20T00:00:01.000Z",
192 },
193 {
194 id: assistantMessageId,
195 role: "assistant",
196 text: "Done",
197 runId,
198 streaming: false,
199 createdAt: "2026-06-20T00:00:02.000Z",
200 updatedAt: "2026-06-20T00:00:02.000Z",
201 },
202 ];
203 const timelineEntries: TimelineEntry[] = messages.map((message): TimelineEntry => ({
204 id: message.id,
205 kind: "message",
206 createdAt: message.createdAt,
207 message,
208 }));
209​
210 const targets = deriveRevertTurnCountByUserMessageId({
211 timelineEntries,
212 checkpoints: [
213 {
214 runId,
215 checkpointTurnCount: 1,
216 checkpointRef: "checkpoint-run-1" as never,
217 status: "ready",
218 files: [],
219 assistantMessageId,
220 completedAt: "2026-06-20T00:00:03.000Z",
221 },
222 ],
223 });
224​
225 expect([...targets]).toEqual([[turnStartMessageId, 0]]);
226 expect(targets.has(steerMessageId)).toBe(false);
227 });
228​
229 it("uses visible turn item order and keeps provider errors in the work log", () => {
230 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
231 const threadId = ThreadId.make("thread-visible");
232 const runId = RunId.make("run-visible");
233 const base = (id: string, ordinal: number) => ({
234 id: TurnItemId.make(id),
235 threadId,
236 runId,
237 nodeId: null,
238 providerThreadId: null,
239 providerTurnId: null,
240 nativeItemRef: null,
241 parentItemId: null,
242 ordinal,
243 status: "completed" as const,
244 title: null,
245 startedAt: now,
246 completedAt: now,
247 updatedAt: now,
248 });
249 const userItem = {
250 ...base("item-user", 0),
251 type: "user_message" as const,
252 messageId: MessageId.make("message-user"),
253 inputIntent: "turn_start" as const,
254 text: "Start",
255 attachments: [],
256 createdBy: "user" as const,
257 creationSource: "web" as const,
258 } satisfies OrchestrationV2TurnItem;
259 const requestItem = {
260 ...base("item-interrupt-request", 1),
261 type: "run_interrupt_request" as const,
262 message: "Stopping",
263 } satisfies OrchestrationV2TurnItem;
264 const commandItem = {
265 ...base("item-command", 2),
266 type: "command_execution" as const,
267 input: "sleep 1",
268 output: "done",
269 exitCode: 0,
270 } satisfies OrchestrationV2TurnItem;
271 const resultItem = {
272 ...base("item-interrupt-result", 3),
273 type: "run_interrupt_result" as const,
274 message: "Stopped",
275 } satisfies OrchestrationV2TurnItem;
276 const todoItem = {
277 ...base("item-todo", 4),
278 type: "todo_list" as const,
279 planId: PlanId.make("plan-visible"),
280 explanation: "Keep task detail in the Tasks panel",
281 steps: [
282 { id: "step-1", text: "First", status: "completed" as const },
283 { id: "step-2", text: "Second", status: "pending" as const },
284 ],
285 } satisfies OrchestrationV2TurnItem;
286 const errorItem = {
287 ...base("item-error", 5),
288 status: "failed" as const,
289 type: "error" as const,
290 failure: {
291 class: "validation_error" as const,
292 message: "Invalid reasoning effort.",
293 code: "invalid_request",
294 retryable: false,
295 },
296 } satisfies OrchestrationV2TurnItem;
297 const threadCreatedItem = {
298 ...base("item-thread-created", 6),
299 type: "thread_created" as const,
300 title: "Follow-up thread",
301 targetThreadId: ThreadId.make("thread-follow-up"),
302 targetRunId: RunId.make("run-follow-up"),
303 targetProviderInstanceId: ProviderInstanceId.make("claude-default"),
304 targetModel: "claude-sonnet-4-6",
305 } satisfies OrchestrationV2TurnItem;
306 const workspacePreparationItem = {
307 ...base("item-workspace-preparation", 7),
308 type: "command_execution" as const,
309 title: "Workspace ready",
310 input: "Preparing workspace",
311 output: "Workspace preparation completed.",
312 exitCode: 0,
313 } satisfies OrchestrationV2TurnItem;
314 const visibleTurnItems: ReadonlyArray<OrchestrationV2ProjectedTurnItem> = [
315 userItem,
316 requestItem,
317 commandItem,
318 resultItem,
319 todoItem,
320 errorItem,
321 threadCreatedItem,
322 workspacePreparationItem,
323 ].map((item, position) => ({
324 position,
325 visibility: "local" as const,
326 sourceThreadId: threadId,
327 sourceItemId: item.id,
328 item,
329 }));
330​
331 const entries = deriveTimelineEntriesFromVisibleTurnItems({
332 visibleTurnItems,
333 optimisticMessages: [],
334 });
335​
336 expect(entries.map((entry) => [entry.kind, entry.id])).toEqual([
337 ["message", userItem.messageId],
338 ["event", requestItem.id],
339 ["work", commandItem.id],
340 ["event", resultItem.id],
341 ["work", errorItem.id],
342 ["event", threadCreatedItem.id],
343 ]);
344 const commandEntry = entries[2];
345 const userEntry = entries[0];
346 expect(userEntry?.kind).toBe("message");
347 if (userEntry?.kind === "message") {
348 expect(userEntry.projectedItem).toBe(visibleTurnItems[0]);
349 expect(userEntry.message.inputIntent).toBe("turn_start");
350 expect(userEntry.message.createdBy).toBe("user");
351 expect(userEntry.message.creationSource).toBe("web");
352 }
353 expect(commandEntry?.kind).toBe("work");
354 if (commandEntry?.kind === "work") {
355 expect(commandEntry.entry.projectedItem).toBe(visibleTurnItems[2]);
356 expect(commandEntry.entry.structuredPayload).toBe(commandItem);
357 }
358 const errorEntry = entries[4];
359 expect(errorEntry?.kind).toBe("work");
360 if (errorEntry?.kind === "work") {
361 expect(errorEntry.entry.projectedItem).toBe(visibleTurnItems[5]);
362 expect(errorEntry.entry.label).toBe("Provider error");
363 expect(errorEntry.entry.detail).toBe("Invalid reasoning effort.");
364 expect(errorEntry.entry.tone).toBe("info");
365 expect(errorEntry.entry.toolLifecycleStatus).toBe("failed");
366 }
367 const threadCreatedEntry = entries[5];
368 expect(threadCreatedEntry?.kind).toBe("event");
369 if (threadCreatedEntry?.kind === "event") {
370 expect(threadCreatedEntry.projectedItem.item.type).toBe("thread_created");
371 }
372 });
373​
374 it.each(["pending", "running", "completed"] as const)(
375 "keeps %s task progress available to the composer and out of the timeline",
376 (stepStatus) => {
377 const projection = makeThreadProjectionFixture();
378 const now = DateTime.makeUnsafe("2026-09-04T00:00:00.000Z");
379 const runId = RunId.make("run-tasks");
380 const nodeId = NodeId.make("node-tasks");
381 const planId = PlanId.make("plan-tasks");
382 const steps = [{ id: "step-1", text: "Verify the change", status: stepStatus }];
383 const item = {
384 id: TurnItemId.make("item-tasks"),
385 threadId: projection.thread.id,
386 runId,
387 nodeId,
388 providerThreadId: null,
389 providerTurnId: null,
390 nativeItemRef: null,
391 parentItemId: null,
392 ordinal: 0,
393 status: "completed" as const,
394 title: null,
395 startedAt: now,
396 completedAt: now,
397 updatedAt: now,
398 type: "todo_list" as const,
399 planId,
400 steps,
401 } satisfies OrchestrationV2TurnItem;
402 const plans = [
403 {
404 id: planId,
405 threadId: projection.thread.id,
406 runId,
407 nodeId,
408 kind: "todo_list" as const,
409 status: "active" as const,
410 steps,
411 },
412 ];
413​
414 expect(
415 deriveTimelineEntriesFromVisibleTurnItems({
416 visibleTurnItems: [
417 {
418 position: 0,
419 visibility: "local",
420 sourceThreadId: projection.thread.id,
421 sourceItemId: item.id,
422 item,
423 },
424 ],
425 optimisticMessages: [],
426 plans,
427 }),
428 ).toEqual([]);
429 expect(
430 deriveActivePlanState({ ...projection, plans, turnItems: [item] }, runId),
431 ).toMatchObject({
432 runId,
433 steps: [
434 {
435 step: "Verify the change",
436 status: stepStatus === "running" ? "inProgress" : stepStatus,
437 },
438 ],
439 });
440 },
441 );
442​
443 it("keeps failed tool items tool-toned so groups still summarize", () => {
444 const failedCommand = {
445 id: TurnItemId.make("item-failed-command"),
446 threadId: ThreadId.make("thread-1"),
447 runId: RunId.make("run-1"),
448 nodeId: null,
449 providerThreadId: null,
450 providerTurnId: null,
451 nativeItemRef: null,
452 parentItemId: null,
453 ordinal: 0,
454 status: "failed" as const,
455 title: null,
456 startedAt: null,
457 completedAt: null,
458 updatedAt: DateTime.nowUnsafe(),
459 type: "command_execution" as const,
460 input: "ssh host true",
461 output: "connection refused",
462 exitCode: 255,
463 } satisfies OrchestrationV2TurnItem;
464 const entries = deriveTimelineEntriesFromVisibleTurnItems({
465 visibleTurnItems: [
466 {
467 position: 0,
468 visibility: "local" as const,
469 sourceThreadId: ThreadId.make("thread-1"),
470 sourceItemId: failedCommand.id,
471 item: failedCommand,
472 } as never,
473 ],
474 optimisticMessages: [],
475 });
476 const entry = entries[0];
477 expect(entry?.kind).toBe("work");
478 if (entry?.kind === "work") {
479 // An exit-code failure is still an ordinary tool row: the failed
480 // lifecycle status carries the marker, and an "error" tone here would
481 // knock the whole group out of the "Ran N commands" summary.
482 expect(entry.entry.tone).toBe("tool");
483 expect(entry.entry.toolLifecycleStatus).toBe("failed");
484 }
485 });
486​
487 it("waits for a dispatched turn item before adding queued input to the timeline", () => {
488 const projection = makeThreadProjectionFixture();
489 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
490 const runId = RunId.make("run-dispatched-queued");
491 const messageId = MessageId.make("message-dispatched-queued");
492 const optimisticMessage = {
493 id: messageId,
494 role: "user" as const,
495 text: "Queued input",
496 runId: null,
497 inputIntent: "queued_turn" as const,
498 streaming: false,
499 createdAt: DateTime.formatIso(now),
500 updatedAt: DateTime.formatIso(now),
501 };
502​
503 expect(
504 deriveTimelineEntriesFromVisibleTurnItems({
505 visibleTurnItems: [],
506 optimisticMessages: [optimisticMessage],
507 }),
508 ).toEqual([]);
509​
510 const dispatchedItem = {
511 id: TurnItemId.make("item-dispatched-queued"),
512 threadId: projection.thread.id,
513 runId,
514 nodeId: null,
515 providerThreadId: null,
516 providerTurnId: null,
517 nativeItemRef: null,
518 parentItemId: null,
519 ordinal: 200,
520 status: "completed" as const,
521 title: null,
522 startedAt: now,
523 completedAt: now,
524 updatedAt: now,
525 type: "user_message" as const,
526 messageId,
527 inputIntent: "turn_start" as const,
528 text: "Queued input",
529 attachments: [],
530 createdBy: "user" as const,
531 creationSource: "web" as const,
532 } satisfies OrchestrationV2TurnItem;
533 const promotedEntries = deriveTimelineEntriesFromVisibleTurnItems({
534 visibleTurnItems: [
535 {
536 position: 0,
537 visibility: "local",
538 sourceThreadId: projection.thread.id,
539 sourceItemId: dispatchedItem.id,
540 item: dispatchedItem,
541 },
542 ],
543 optimisticMessages: [optimisticMessage],
544 });
545 expect(promotedEntries.map((entry) => entry.id)).toEqual([messageId]);
546 expect(promotedEntries[0]?.kind).toBe("message");
547 if (promotedEntries[0]?.kind === "message") {
548 expect(promotedEntries[0].message.inputIntent).toBe("turn_start");
549 }
550 });
551​
552 it("anchors feedback before later committed turns without reordering canonical history", () => {
553 const threadId = ThreadId.make("thread-feedback-order");
554 const messageItem = (input: {
555 readonly id: string;
556 readonly role: "user" | "assistant";
557 readonly createdAt: string;
558 readonly ordinal: number;
559 }): OrchestrationV2TurnItem => {
560 const timestamp = DateTime.makeUnsafe(input.createdAt);
561 const common = {
562 id: TurnItemId.make(`item-${input.id}`),
563 threadId,
564 runId: RunId.make(`run-${input.ordinal}`),
565 nodeId: null,
566 providerThreadId: null,
567 providerTurnId: null,
568 nativeItemRef: null,
569 parentItemId: null,
570 ordinal: input.ordinal,
571 status: "completed" as const,
572 title: null,
573 startedAt: timestamp,
574 completedAt: timestamp,
575 updatedAt: timestamp,
576 messageId: MessageId.make(input.id),
577 text: input.id,
578 };
579 return input.role === "user"
580 ? {
581 ...common,
582 type: "user_message",
583 inputIntent: "turn_start",
584 attachments: [],
585 createdBy: "user",
586 creationSource: "web",
587 }
588 : { ...common, type: "assistant_message", streaming: false };
589 };
590 const canonicalItems = [
591 messageItem({ id: "old-user", role: "user", createdAt: "2026-08-29T00:00:01Z", ordinal: 1 }),
592 messageItem({
593 id: "old-assistant",
594 role: "assistant",
595 createdAt: "2026-08-29T00:00:02Z",
596 ordinal: 2,
597 }),
598 messageItem({
599 id: "later-user",
600 role: "user",
601 createdAt: "2026-08-29T00:00:05Z",
602 ordinal: 3,
603 }),
604 messageItem({
605 id: "later-assistant",
606 role: "assistant",
607 createdAt: "2026-08-29T00:00:04Z",
608 ordinal: 4,
609 }),
610 ];
611 const visibleTurnItems = canonicalItems.map((item, position) => ({
612 position,
613 visibility: "local" as const,
614 sourceThreadId: threadId,
615 sourceItemId: item.id,
616 item,
617 }));
618 const feedback = (id: string, role: "user" | "assistant"): ChatMessage => ({
619 id: MessageId.make(id),
620 role,
621 text: id,
622 runId: null,
623 streaming: false,
624 createdAt: "2026-08-29T00:00:03Z",
625 updatedAt: "2026-08-29T00:00:03Z",
626 });
627 const entries = deriveTimelineEntriesFromVisibleTurnItems({
628 visibleTurnItems,
629 anchoredMessages: [
630 feedback("feedback-user", "user"),
631 feedback("feedback-assistant", "assistant"),
632 feedback("later-user", "user"),
633 ],
634 optimisticMessages: [
635 { ...feedback("optimistic-user", "user"), createdAt: "2026-08-29T00:00:00Z" },
636 ],
637 });
638​
639 expect(entries.map((entry) => entry.id)).toEqual([
640 "old-user",
641 "old-assistant",
642 "feedback-user",
643 "feedback-assistant",
644 "later-user",
645 "later-assistant",
646 "optimistic-user",
647 ]);
648 expect(
649 entries
650 .filter((entry) => entry.id.startsWith("feedback-"))
651 .every((entry) => entry.kind === "message" && entry.projectedItem === undefined),
652 ).toBe(true);
653 });
654​
655 it("uses projected plan status and file contents in timeline entries", () => {
656 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
657 const threadId = ThreadId.make("thread-timeline-artifacts");
658 const runId = RunId.make("run-timeline-artifacts");
659 const nodeId = NodeId.make("node-timeline-artifacts");
660 const planId = PlanId.make("plan-timeline-artifacts");
661 const base = {
662 threadId,
663 runId,
664 nodeId,
665 providerThreadId: null,
666 providerTurnId: null,
667 nativeItemRef: null,
668 parentItemId: null,
669 status: "completed" as const,
670 title: null,
671 startedAt: now,
672 completedAt: now,
673 updatedAt: now,
674 };
675 const planItem = {
676 ...base,
677 id: TurnItemId.make("item-proposed-plan"),
678 ordinal: 0,
679 type: "proposed_plan" as const,
680 planId,
681 markdown: "Finished plan",
682 streaming: false,
683 } satisfies OrchestrationV2TurnItem;
684 const fileItem = {
685 ...base,
686 id: TurnItemId.make("item-file-change"),
687 ordinal: 1,
688 type: "file_change" as const,
689 fileName: "src/example.ts",
690 newStr: "export const answer = 42;\n",
691 } satisfies OrchestrationV2TurnItem;
692 const visibleTurnItems: ReadonlyArray<OrchestrationV2ProjectedTurnItem> = [
693 planItem,
694 fileItem,
695 ].map((item, position) => ({
696 position,
697 visibility: "local",
698 sourceThreadId: threadId,
699 sourceItemId: item.id,
700 item,
701 }));
702​
703 const entries = deriveTimelineEntriesFromVisibleTurnItems({
704 visibleTurnItems,
705 optimisticMessages: [],
706 plans: [
707 {
708 id: planId,
709 threadId,
710 runId,
711 nodeId,
712 kind: "proposed_plan",
713 markdown: "",
714 status: "completed",
715 detailInTurnItem: true,
716 },
717 ],
718 });
719​
720 expect(entries[0]?.kind).toBe("proposed-plan");
721 if (entries[0]?.kind === "proposed-plan") {
722 expect(entries[0].proposedPlan.status).toBe("completed");
723 expect(entries[0].proposedPlan.planMarkdown).toBe("Finished plan");
724 }
725 expect(entries[1]?.kind).toBe("work");
726 if (entries[1]?.kind === "work") {
727 expect(entries[1].entry.detail).toBe(fileItem.newStr);
728 }
729 });
730​
731 it("resolves attempt identity through V2 execution nodes", () => {
732 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
733 const threadId = ThreadId.make("thread-attempts");
734 const runId = RunId.make("run-steered");
735 const supersededRootNodeId = NodeId.make("node-attempt-1-root");
736 const supersededChildNodeId = NodeId.make("node-attempt-1-child");
737 const activeRootNodeId = NodeId.make("node-attempt-2-root");
738 const supersededAttemptId = RunAttemptId.make("attempt-1");
739 const activeAttemptId = RunAttemptId.make("attempt-2");
740 const providerInstanceId = ProviderInstanceId.make("codex-default");
741 const providerThreadId = ProviderThreadId.make("provider-thread-attempts");
742 const attempts: ReadonlyArray<OrchestrationV2RunAttempt> = [
743 {
744 id: supersededAttemptId,
745 runId,
746 attemptOrdinal: 1,
747 rootNodeId: supersededRootNodeId,
748 providerInstanceId,
749 providerThreadId,
750 providerTurnId: null,
751 reason: "initial",
752 status: "superseded",
753 startedAt: now,
754 completedAt: now,
755 },
756 {
757 id: activeAttemptId,
758 runId,
759 attemptOrdinal: 2,
760 rootNodeId: activeRootNodeId,
761 providerInstanceId,
762 providerThreadId,
763 providerTurnId: null,
764 reason: "steering_restart",
765 status: "running",
766 startedAt: now,
767 completedAt: null,
768 },
769 ];
770 const node = (
771 id: OrchestrationV2ExecutionNode["id"],
772 rootNodeId: OrchestrationV2ExecutionNode["rootNodeId"],
773 parentNodeId: OrchestrationV2ExecutionNode["parentNodeId"],
774 ): OrchestrationV2ExecutionNode => ({
775 id,
776 threadId,
777 runId,
778 parentNodeId,
779 rootNodeId,
780 kind: id === rootNodeId ? "root_turn" : "assistant_message",
781 status: "running",
782 countsForRun: true,
783 providerThreadId,
784 providerTurnId: null,
785 nativeItemRef: null,
786 runtimeRequestId: null,
787 checkpointScopeId: null,
788 startedAt: now,
789 completedAt: null,
790 });
791 const nodes = [
792 node(supersededRootNodeId, supersededRootNodeId, null),
793 node(supersededChildNodeId, supersededRootNodeId, supersededRootNodeId),
794 node(activeRootNodeId, activeRootNodeId, null),
795 ];
796 const assistantItem = (
797 id: string,
798 messageId: string,
799 nodeId: NodeId,
800 text: string,
801 ordinal: number,
802 ): OrchestrationV2TurnItem => ({
803 id: TurnItemId.make(id),
804 threadId,
805 runId,
806 nodeId,
807 providerThreadId,
808 providerTurnId: null,
809 nativeItemRef: null,
810 parentItemId: null,
811 ordinal,
812 status: "running",
813 title: null,
814 startedAt: now,
815 completedAt: null,
816 updatedAt: now,
817 type: "assistant_message",
818 messageId: MessageId.make(messageId),
819 text,
820 streaming: true,
821 });
822 const items = [
823 assistantItem(
824 "item-superseded",
825 "message-superseded",
826 supersededChildNodeId,
827 "Partial old response",
828 0,
829 ),
830 assistantItem("item-active", "message-active", activeRootNodeId, "Current response", 1),
831 ];
832 const visibleTurnItems: ReadonlyArray<OrchestrationV2ProjectedTurnItem> = items.map(
833 (item, position) => ({
834 position,
835 visibility: "local",
836 sourceThreadId: threadId,
837 sourceItemId: item.id,
838 item,
839 }),
840 );
841​
842 const entries = deriveTimelineEntriesFromVisibleTurnItems({
843 visibleTurnItems,
844 optimisticMessages: [],
845 attempts,
846 nodes,
847 });
848​
849 expect(entries.map((entry) => [entry.attempt?.id, entry.attempt?.status])).toEqual([
850 [supersededAttemptId, "superseded"],
851 [activeAttemptId, "running"],
852 ]);
853 const input = { visibleTurnItems, optimisticMessages: [], attempts, nodes };
854 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
855 const nextInput = {
856 ...input,
857 attempts: attempts.map((attempt) =>
858 attempt.id === activeAttemptId ? { ...attempt, status: "superseded" as const } : attempt,
859 ),
860 };
861 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
862 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
863 expect(next.entries.at(-1)?.attempt?.status).toBe("superseded");
864 expect(previous.entries.at(-1)?.attempt?.status).toBe("running");
865 });
866});
867​
868describe("native provider presentation in the v2 timeline", () => {
869 const timestamp = DateTime.makeUnsafe("2026-09-04T12:00:00.000Z");
870 const base = {
871 id: TurnItemId.make("native-item"),
872 threadId: ThreadId.make("native-thread"),
873 runId: RunId.make("native-run"),
874 nodeId: null,
875 providerThreadId: null,
876 providerTurnId: null,
877 nativeItemRef: null,
878 parentItemId: null,
879 ordinal: 0,
880 status: "completed" as const,
881 title: null,
882 startedAt: timestamp,
883 completedAt: timestamp,
884 updatedAt: timestamp,
885 };
886 const visible = (item: OrchestrationV2TurnItem): OrchestrationV2ProjectedTurnItem => ({
887 position: 0,
888 visibility: "local",
889 sourceThreadId: item.threadId,
890 sourceItemId: item.id,
891 item,
892 });
893​
894 it("keeps browser identity and its source on a completed tool row", () => {
895 const item = {
896 ...base,
897 type: "dynamic_tool" as const,
898 toolName: "browser_snapshot",
899 input: {},
900 output: {},
901 toolSurface: "browser" as const,
902 toolIcon: { _tag: "website" as const, pageUrl: "https://example.com/checkout" },
903 toolSource: { key: "browser-use:browser", name: "Chrome", kind: "browser" as const },
904 } satisfies OrchestrationV2TurnItem;
905 const [entry] = deriveTimelineEntriesFromVisibleTurnItems({
906 visibleTurnItems: [visible(item)],
907 optimisticMessages: [],
908 });
909 expect(entry).toMatchObject({
910 kind: "work",
911 entry: {
912 toolSurface: "browser",
913 toolIcon: item.toolIcon,
914 toolSource: item.toolSource,
915 toolLifecycleStatus: "completed",
916 },
917 });
918 });
919​
920 it("shows provider-returned images on an assistant message using the environment asset URL", () => {
921 const attachment = {
922 type: "image" as const,
923 id: "assistant-image",
924 name: "screenshot.png",
925 mimeType: "image/png",
926 sizeBytes: 512,
927 };
928 const item = {
929 ...base,
930 type: "assistant_message" as const,
931 messageId: MessageId.make("assistant-native-image"),
932 text: "Here is the screenshot.",
933 streaming: false,
934 attachments: [attachment],
935 } satisfies OrchestrationV2TurnItem;
936 const [entry] = deriveTimelineEntriesFromVisibleTurnItems({
937 visibleTurnItems: [visible(item)],
938 optimisticMessages: [],
939 attachmentUrlById: new Map([[attachment.id, "https://remote.example/api/assets/screenshot"]]),
940 });
941 expect(entry).toMatchObject({
942 kind: "message",
943 message: {
944 role: "assistant",
945 attachments: [
946 { ...attachment, previewUrl: "https://remote.example/api/assets/screenshot" },
947 ],
948 },
949 });
950 });
951​
952 it("keeps an idle provider task neutral without a completion mark", () => {
953 const entry = {
954 id: "idle-tool",
955 createdAt: DateTime.formatIso(timestamp),
956 label: "Waiting for the next task",
957 tone: "tool" as const,
958 toolLifecycleStatus: "idle" as const,
959 };
960 expect(workEntryIndicatesToolSuccess(entry)).toBe(false);
961 expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
962 });
963});
964​
965describe("work-log failure policy (#7999/#7893)", () => {
966 const toolEntry = (overrides: Record<string, unknown>) =>
967 ({
968 id: "entry-1",
969 createdAt: "2026-08-27T00:00:00.000Z",
970 label: "Ran command",
971 tone: "tool",
972 ...overrides,
973 }) as never;
974​
975 it("flags success-status rows whose output text reports a failure", () => {
976 expect(
977 workEntryIndicatesToolFailure(
978 toolEntry({ toolLifecycleStatus: "completed", detail: "bash: foo: command not found" }),
979 ),
980 ).toBe(true);
981 expect(
982 workEntryIndicatesToolFailure(
983 toolEntry({ toolLifecycleStatus: "completed", detail: "<exited with exit code 2>" }),
984 ),
985 ).toBe(true);
986 });
987​
988 it("keeps the rendered row calm when only the command mentions failure text", () => {
989 const entry = toolEntry({
990 toolLifecycleStatus: "completed",
991 command: "rg 'command not found' src/",
992 });
993 expect(workEntryIndicatesToolFailure(entry)).toBe(true);
994 expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
995 });
996​
997 it("does not call a clean completed row failed", () => {
998 const entry = toolEntry({ toolLifecycleStatus: "completed", detail: "3 files changed" });
999 expect(workEntryIndicatesToolFailure(entry)).toBe(false);
1000 expect(workEntryIndicatesToolSuccess(entry)).toBe(true);
1001 });
1002​
1003 it("recovered failure text no longer counts as success", () => {
1004 const entry = toolEntry({ toolLifecycleStatus: "completed", detail: "ENOENT: no such file" });
1005 expect(workEntryIndicatesToolSuccess(entry)).toBe(false);
1006 });
1007});
1008​
1009describe("incremental v2 timeline entries", () => {
1010 it("retains history and attachment previews through decoded streaming updates", () => {
1011 const fixture = makeStreamingTimelineFixture("Partial");
1012 const attachment = {
1013 type: "image" as const,
1014 id: "stream-image",
1015 name: "image.png",
1016 mimeType: "image/png",
1017 sizeBytes: 42,
1018 };
1019 const visibleTurnItems = fixture.visibleTurnItems.map((row) =>
1020 row.item.type === "assistant_message"
1021 ? { ...row, item: { ...row.item, attachments: [attachment] } }
1022 : row,
1023 );
1024 const input = {
1025 visibleTurnItems,
1026 optimisticMessages: [],
1027 attachmentUrlById: new Map([[attachment.id, "https://server.test/image"]]),
1028 };
1029 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1030 Object.freeze(previous.entries);
1031 for (const entry of previous.entries) Object.freeze(entry);
1032 const last = visibleTurnItems.at(-1)!;
1033 if (last.item.type !== "assistant_message") throw new Error("Expected assistant fixture");
1034 const nextItem = {
1035 ...last,
1036 item: {
1037 ...last.item,
1038 text: "Next token",
1039 attachments: [{ ...attachment }],
1040 startedAt: DateTime.makeUnsafe(fixture.time(7)),
1041 updatedAt: DateTime.makeUnsafe(fixture.time(8)),
1042 },
1043 };
1044 const nextInput = {
1045 ...input,
1046 visibleTurnItems: [...visibleTurnItems.slice(0, -1), nextItem],
1047 attachmentUrlById: new Map(input.attachmentUrlById),
1048 };
1049 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1050 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1051 for (const [index, entry] of previous.entries.slice(0, -1).entries()) {
1052 expect(next.entries[index]).toBe(entry);
1054 const beforeMessage = previous.entries.at(-1)!;
1055 const nextMessage = next.entries.at(-1)!;
1056 if (beforeMessage.kind !== "message" || nextMessage.kind !== "message") {
1057 throw new Error("Expected assistant entries");
1059 expect(nextMessage.message.attachments).toBe(beforeMessage.message.attachments);
1060 expect(nextMessage.projectedItem).toBe(nextItem);
1061 expect(nextMessage.message.text).toBe("Next token");
1062 expect(beforeMessage.message.text).toBe("Partial");
1063​
1064 const renewedInput = {
1065 ...nextInput,
1066 attachmentUrlById: new Map([[attachment.id, "https://renewed.test/image"]]),
1067 };
1068 const renewed = deriveTimelineEntriesFromVisibleTurnItemsWithState(renewedInput, next);
1069 expect(renewed.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(renewedInput));
1070 expect(renewed.entries.at(-1)).toMatchObject({
1071 message: { attachments: [{ previewUrl: "https://renewed.test/image" }] },
1072 });
1073 expect(nextMessage.message.attachments?.[0]).toMatchObject({
1074 previewUrl: "https://server.test/image",
1075 });
1076 const restoredInput = { ...renewedInput, attachmentUrlById: new Map<string, string>() };
1077 const restored = deriveTimelineEntriesFromVisibleTurnItemsWithState(restoredInput, renewed);
1078 expect(restored.entries.at(-1)).toMatchObject({ message: { attachments: [attachment] } });
1079 const restoredMessage = restored.entries.at(-1)!;
1080 if (restoredMessage.kind !== "message") throw new Error("Expected assistant entry");
1081 expect(restoredMessage.message.attachments?.[0]).not.toHaveProperty("previewUrl");
1082 });
1083​
1084 it("appends committed items in canonical order even when their timestamps go backwards", () => {
1085 const fixture = makeStreamingTimelineFixture("Partial");
1086 const input = { visibleTurnItems: fixture.visibleTurnItems, optimisticMessages: [] };
1087 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1088 const last = fixture.visibleTurnItems.at(-1)!;
1089 const appended = {
1090 ...last,
1091 position: last.position + 1,
1092 sourceItemId: TurnItemId.make("late-item"),
1093 item: {
1094 ...last.item,
1095 id: TurnItemId.make("late-item"),
1096 messageId: MessageId.make("late-message"),
1097 startedAt: DateTime.makeUnsafe(fixture.time(0)),
1098 },
1099 };
1100 const nextInput = { ...input, visibleTurnItems: [...input.visibleTurnItems, appended] };
1101 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1102 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1103 expect(next.entries.at(-1)).toMatchObject({ id: "late-message" });
1104 for (const [index, entry] of previous.entries.entries())
1105 expect(next.entries[index]).toBe(entry);
1106 });
1107​
1108 it.each(["completion", "provenance", "ordering", "attachment", "run"] as const)(
1109 "rebuilds entries for a %s change instead of retaining stale v2 metadata",
1110 (change) => {
1111 const fixture = makeStreamingTimelineFixture("Partial");
1112 const input = { visibleTurnItems: fixture.visibleTurnItems, optimisticMessages: [] };
1113 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1114 const last = fixture.visibleTurnItems.at(-1)!;
1115 if (last.item.type !== "assistant_message") throw new Error("Expected assistant fixture");
1116 const changed =
1117 change === "provenance"
1118 ? { ...last, sourceThreadId: ThreadId.make("inherited-thread") }
1119 : {
1120 ...last,
1121 item:
1122 change === "completion"
1123 ? { ...last.item, streaming: false, status: "completed" as const }
1124 : change === "ordering"
1125 ? { ...last.item, startedAt: DateTime.makeUnsafe(fixture.time(0)) }
1126 : change === "run"
1127 ? { ...last.item, runId: fixture.historyRunId }
1128 : {
1129 ...last.item,
1130 attachments: [
1132 type: "image",
1133 id: "new-image",
1134 name: "new.png",
1135 mimeType: "image/png",
1136 sizeBytes: 42,
1137 },
1138 ],
1139 },
1140 };
1141 const nextInput = {
1142 ...input,
1143 visibleTurnItems: [...input.visibleTurnItems.slice(0, -1), changed],
1144 };
1145 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1146 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1147 expect(next.entries.at(-1)).not.toBe(previous.entries.at(-1));
1148 },
1149 );
1150​
1151 it("updates fallback timestamps when the provider has not supplied a message start time", () => {
1152 const fixture = makeStreamingTimelineFixture("Partial");
1153 const visibleTurnItems = fixture.visibleTurnItems.map((row) =>
1154 row.item.type === "assistant_message" && row.item.streaming
1155 ? { ...row, item: { ...row.item, startedAt: null } }
1156 : row,
1157 );
1158 const input = { visibleTurnItems, optimisticMessages: [] };
1159 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1160 const nextInput = {
1161 ...input,
1162 visibleTurnItems: visibleTurnItems.map((row) =>
1163 row.item.type === "assistant_message" && row.item.streaming
1164 ? {
1165 ...row,
1166 item: {
1167 ...row.item,
1168 text: "Next token",
1169 updatedAt: DateTime.makeUnsafe(fixture.time(8)),
1170 },
1172 : row,
1173 ),
1174 };
1175 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1176 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1177 expect(next.entries.at(-1)?.createdAt).toBe(fixture.time(8));
1178 });
1179​
1180 it("keeps unchanged message previews while tool output rebuilds the work log", () => {
1181 const fixture = makeStreamingTimelineFixture("Partial");
1182 const input = { visibleTurnItems: fixture.visibleTurnItems, optimisticMessages: [] };
1183 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1184 const nextInput = {
1185 ...input,
1186 visibleTurnItems: input.visibleTurnItems.map((row) =>
1187 row.item.type === "command_execution"
1188 ? { ...row, item: { ...row.item, output: "Additional output" } }
1189 : row,
1190 ),
1191 };
1192 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1193 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1194 for (const [index, entry] of previous.entries.entries()) {
1195 if (entry.kind === "message") expect(next.entries[index]).toBe(entry);
1197 });
1198​
1199 it("deduplicates optimistic sends when committed items arrive and retains anchored ordering", () => {
1200 const fixture = makeStreamingTimelineFixture();
1201 const input = {
1202 visibleTurnItems: fixture.visibleTurnItems.slice(0, 3),
1203 optimisticMessages: [
1205 id: MessageId.make("live-user"),
1206 runId: null,
1207 role: "user" as const,
1208 text: "Continue",
1209 streaming: false,
1210 createdAt: fixture.time(5),
1211 updatedAt: fixture.time(5),
1212 },
1213 ],
1214 anchoredMessages: [
1216 id: MessageId.make("feedback"),
1217 runId: null,
1218 role: "assistant" as const,
1219 text: "Feedback received",
1220 streaming: false,
1221 createdAt: fixture.time(4),
1222 updatedAt: fixture.time(4),
1223 },
1224 ],
1225 };
1226 const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1227 const nextInput = { ...input, visibleTurnItems: fixture.visibleTurnItems };
1228 const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(nextInput, previous);
1229 expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(nextInput));
1230 expect(next.entries.filter((entry) => entry.id === "live-user")).toHaveLength(1);
1231 expect(next.entries.map((entry) => entry.id)).toEqual([
1232 "history-user",
1233 "history-work",
1234 "history-assistant",
1235 "feedback",
1236 "live-user",
1237 "live-work",
1238 "live-assistant",
1239 ]);
1240 });
1241});
1242​
1243describe("image asset requests", () => {
1244 const image = {
1245 type: "image" as const,
1246 id: "image",
1247 name: "image.png",
1248 mimeType: "image/png",
1249 sizeBytes: 42,
1250 };
1251 const message = {
1252 id: MessageId.make("image-message"),
1253 role: "user" as const,
1254 text: "Inspect these images",
1255 runId: null,
1256 createdAt: "2026-09-04T00:00:00.000Z",
1257 updatedAt: "2026-09-04T00:00:00.000Z",
1258 streaming: false,
1259 attachments: [image],
1260 };
1261​
1262 it("requests the whole row's gallery and crops without signing local preview IDs", () => {
1263 const attachments = Object.freeze([
1264 image,
1265 { ...image, id: "second" },
1266 { ...image, id: "crop", name: "preview-annotation-1.png" },
1267 { ...image, id: "local", previewUrl: "blob:local" },
1268 { ...image, id: "inline", previewUrl: "data:image/png;base64,AA==" },
1269 { ...image, id: "provided", previewUrl: "https://preview.test/image" },
1270 { ...image, type: "file" as const, id: "file", mimeType: "application/pdf" },
1271 { ...image, type: "future", id: "unknown" },
1272 image,
1273 ]);
1274​
1275 expect(selectMessageImageResources(attachments)).toEqual([
1276 { _tag: "attachment", attachmentId: "image" },
1277 { _tag: "attachment", attachmentId: "second" },
1278 { _tag: "attachment", attachmentId: "crop" },
1279 { _tag: "attachment", attachmentId: "provided" },
1280 ]);
1281 });
1282​
1283 it("requests offscreen handoffs without signing the rest of the loaded history", () => {
1284 const history = {
1285 ...message,
1286 id: MessageId.make("history"),
1287 attachments: [{ ...image, id: "history-image" }],
1288 };
1289 const offscreen = {
1290 ...message,
1291 id: MessageId.make("offscreen"),
1292 attachments: [image, { ...image, id: "crop", name: "preview-annotation-1.png" }],
1293 };
1294 const empty = {
1295 ...message,
1296 id: MessageId.make("empty"),
1297 attachments: [{ ...image, id: "empty" }],
1298 };
1299 const assistant = {
1300 ...message,
1301 id: MessageId.make("assistant"),
1302 role: "assistant" as const,
1303 attachments: [{ ...image, id: "assistant-image" }],
1304 };
1305 expect(
1306 selectHandoffImageResources([history, message, offscreen, empty, assistant], {
1307 [message.id]: ["blob:message"],
1308 [offscreen.id]: ["blob:offscreen", "blob:crop"],
1309 [empty.id]: [],
1310 [assistant.id]: ["blob:unused"],
1311 }),
1312 ).toEqual([
1313 { _tag: "attachment", attachmentId: "image" },
1314 { _tag: "attachment", attachmentId: "crop" },
1315 ]);
1316 });
1317​
1318 it("does not scan history when no handoff is pending", () => {
1319 let reads = 0;
1320 const messages = new Proxy([message], {
1321 get(target, property, receiver) {
1322 if (property === "0") reads += 1;
1323 return Reflect.get(target, property, receiver);
1324 },
1325 });
1326 const empty = selectHandoffImageResources(messages, {});
1327 expect(reads).toBe(0);
1328 expect(empty).toHaveLength(0);
1329 expect(selectHandoffImageResources(undefined, { missing: ["blob:missing"] })).toBe(empty);
1330 expect(selectMessageImageResources(undefined)).toBe(empty);
1331 });
1332​
1333 it("hands signed URLs to a mounted row only after the local preview is released", () => {
1334 const server = createMessageAttachmentPreviewProjector();
1335 const handoff = createMessageAttachmentPreviewProjector();
1336 const row = createMessageAttachmentPreviewProjector();
1337 const pending = handoff(
1338 server(message, () => undefined),
1339 () => "blob:pending",
1340 );
1341 expect(selectMessageImageResources(pending.attachments)).toEqual([]);
1342 expect(selectHandoffImageResources([message], { [message.id]: ["blob:pending"] })).toEqual([
1343 { _tag: "attachment", attachmentId: image.id },
1344 ]);
1345​
1346 const ready = server(message, () => "https://server.test/image");
1347 expect(selectMessageImageResources(handoff(ready, () => "blob:pending").attachments)).toEqual(
1348 [],
1349 );
1350 const released = server(message, () => undefined);
1351 expect(selectMessageImageResources(released.attachments)).toEqual([
1352 { _tag: "attachment", attachmentId: image.id },
1353 ]);
1354 const displayed = row(released, () => "https://server.test/image");
1355 expect(displayed).toEqual(ready);
1356 expect(pending.attachments?.[0]).toMatchObject({ previewUrl: "blob:pending" });
1357 expect(row(released, () => "https://server.test/renewed").attachments?.[0]).toMatchObject({
1358 previewUrl: "https://server.test/renewed",
1359 });
1360 expect(displayed.attachments?.[0]).toMatchObject({ previewUrl: "https://server.test/image" });
1361 expect(row(released, () => undefined)).toBe(message);
1362 });
1363});