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

MessagesTimeline.test.tsx

1,500 lines48.5 KB

1import { CheckpointRef, EnvironmentId, MessageId, TurnId } from "@t3tools/contracts";
2import { codexFeedbackMessage } from "@t3tools/client-runtime/state/threads";
3import { createRef, type ReactNode, type Ref } from "react";
4import { renderToStaticMarkup } from "react-dom/server";
5import { beforeAll, describe, expect, it, vi } from "vite-plus/test";
6import type { LegendListRef } from "@legendapp/list/react";
7​
8vi.mock("@legendapp/list/react", async () => {
9 const legendListTestId = "legend-list";
10​
11 const LegendList = (props: {
12 data: Array<{ id: string }>;
13 keyExtractor: (item: { id: string }) => string;
14 renderItem: (args: { item: { id: string } }) => ReactNode;
15 ListHeaderComponent?: ReactNode;
16 ListFooterComponent?: ReactNode;
17 anchoredEndSpace?: {
18 anchorIndex: number;
19 anchorMaxSize?: number;
20 anchorOffset?: number;
21 onReady?: (info: { anchorIndex: number }) => void;
22 };
23 contentInsetEndAdjustment?: number;
24 className?: string;
25 maintainScrollAtEnd?:
26 | boolean
27 | {
28 animated?: boolean;
29 on?: {
30 dataChange?: boolean;
31 itemLayout?: boolean;
32 layout?: boolean;
33 };
34 };
35 maintainVisibleContentPosition?:
36 | boolean
37 | {
38 data?: boolean;
39 size?: boolean;
40 shouldRestorePosition?: (item: { id: string }) => boolean;
41 };
42 ref?: Ref<LegendListRef>;
43 }) => {
44 if (props.anchoredEndSpace) {
45 props.anchoredEndSpace.onReady?.({ anchorIndex: props.anchoredEndSpace.anchorIndex });
46 }
47 return (
48 <div
49 data-testid={legendListTestId}
50 data-anchor-index={props.anchoredEndSpace?.anchorIndex}
51 data-anchor-max-size={props.anchoredEndSpace?.anchorMaxSize}
52 data-anchor-offset={props.anchoredEndSpace?.anchorOffset}
53 data-anchor-on-ready={Boolean(props.anchoredEndSpace?.onReady)}
54 data-content-inset-end={props.contentInsetEndAdjustment}
55 data-class-name={props.className}
56 data-maintain-scroll-at-end={props.maintainScrollAtEnd ? "enabled" : undefined}
57 data-maintain-scroll-at-end-animated={
58 typeof props.maintainScrollAtEnd === "object"
59 ? props.maintainScrollAtEnd.animated
60 : undefined
61 }
62 data-maintain-scroll-at-end-data-change={
63 typeof props.maintainScrollAtEnd === "object"
64 ? props.maintainScrollAtEnd.on?.dataChange
65 : undefined
66 }
67 data-maintain-scroll-at-end-item-layout={
68 typeof props.maintainScrollAtEnd === "object"
69 ? props.maintainScrollAtEnd.on?.itemLayout
70 : undefined
71 }
72 data-maintain-scroll-at-end-layout={
73 typeof props.maintainScrollAtEnd === "object"
74 ? props.maintainScrollAtEnd.on?.layout
75 : undefined
76 }
77 data-maintain-visible-content-position={
78 typeof props.maintainVisibleContentPosition === "object"
79 ? "object"
80 : props.maintainVisibleContentPosition
81 }
82 data-maintain-visible-content-position-data={
83 typeof props.maintainVisibleContentPosition === "object"
84 ? props.maintainVisibleContentPosition.data
85 : undefined
86 }
87 data-maintain-visible-content-position-size={
88 typeof props.maintainVisibleContentPosition === "object"
89 ? props.maintainVisibleContentPosition.size
90 : undefined
91 }
92 data-maintain-visible-content-position-restore={
93 typeof props.maintainVisibleContentPosition === "object"
94 ? Boolean(props.maintainVisibleContentPosition.shouldRestorePosition)
95 : undefined
96 }
97 >
98 {props.ListHeaderComponent}
99 {props.data.map((item) => (
100 <div key={props.keyExtractor(item)}>{props.renderItem({ item })}</div>
101 ))}
102 {props.ListFooterComponent}
103 </div>
104 );
105 };
106​
107 return { LegendList };
108});
109​
110function MockFileDiff(props: {
111 fileDiff: { name?: string | null; prevName?: string | null };
112 renderCustomHeader?: (fileDiff: {
113 name?: string | null;
114 prevName?: string | null;
115 }) => React.ReactNode;
116}) {
117 return (
118 <div data-testid="file-diff">
119 {props.renderCustomHeader?.(props.fileDiff)}
120 {props.fileDiff.name ?? props.fileDiff.prevName ?? "diff"}
121 </div>
122 );
124​
125vi.mock("@pierre/diffs/react", () => {
126 return { FileDiff: MockFileDiff };
127});
128​
129function matchMedia() {
130 return {
131 matches: false,
132 addEventListener: () => {},
133 removeEventListener: () => {},
134 };
136​
137let MessagesTimeline: typeof import("./MessagesTimeline").MessagesTimeline;
138​
139beforeAll(async () => {
140 const classList = {
141 add: () => {},
142 remove: () => {},
143 toggle: () => {},
144 contains: () => false,
145 };
146​
147 vi.stubGlobal("localStorage", {
148 getItem: () => null,
149 setItem: () => {},
150 removeItem: () => {},
151 clear: () => {},
152 });
153 vi.stubGlobal("window", {
154 matchMedia,
155 addEventListener: () => {},
156 removeEventListener: () => {},
157 requestAnimationFrame: (callback: FrameRequestCallback) => {
158 callback(0);
159 return 0;
160 },
161 cancelAnimationFrame: () => {},
162 desktopBridge: undefined,
163 });
164 vi.stubGlobal("document", {
165 documentElement: {
166 classList,
167 offsetHeight: 0,
168 },
169 });
170​
171 ({ MessagesTimeline } = await import("./MessagesTimeline"));
172}, 30_000);
173​
174const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
175const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z";
176​
177function buildProps() {
178 return {
179 isWorking: false,
180 activeTurnStartedAt: null,
181 listRef: createRef<LegendListRef | null>(),
182 latestTurn: null,
183 runningTurnId: null,
184 turnDiffSummaryByAssistantMessageId: new Map(),
185 routeThreadKey: "environment-local:thread-1",
186 onOpenTurnDiff: () => {},
187 revertTurnCountByUserMessageId: new Map(),
188 onRevertUserMessage: () => {},
189 isRevertingCheckpoint: false,
190 openingVideoAttachmentId: null,
191 onImageExpand: () => {},
192 activeThreadEnvironmentId: ACTIVE_THREAD_ENVIRONMENT_ID,
193 markdownCwd: undefined,
194 resolvedTheme: "light" as const,
195 timestampFormat: "locale" as const,
196 workspaceRoot: undefined,
197 anchorMessageId: null,
198 onAnchorReady: () => {},
199 contentInsetEndAdjustment: 0,
200 liveFollowEnabled: true,
201 onIsAtEndChange: () => {},
202 onManualNavigation: () => {},
203 };
205​
206function buildLongUserMessageText(tail = "deep hidden detail only after expand") {
207 return Array.from({ length: 9 }, (_, index) =>
208 index === 8 ? tail : `Line ${index + 1}: ${"verbose prompt content ".repeat(8).trim()}`,
209 ).join("\n");
211​
212function buildUserTimelineEntry(text: string) {
213 return {
214 id: "entry-1",
215 kind: "message" as const,
216 createdAt: MESSAGE_CREATED_AT,
217 message: {
218 id: MessageId.make("message-1"),
219 role: "user" as const,
220 text,
221 turnId: null,
222 createdAt: MESSAGE_CREATED_AT,
223 updatedAt: MESSAGE_CREATED_AT,
224 streaming: false,
225 },
226 };
228​
229function buildAssistantTimelineEntry(text: string) {
230 const entry = buildUserTimelineEntry(text);
231 return {
232 ...entry,
233 message: {
234 ...entry.message,
235 role: "assistant" as const,
236 },
237 };
239​
240describe("MessagesTimeline", () => {
241 it("renders a feedback command and its pending response as normal thread messages", () => {
242 const submission = {
243 id: MessageId.make("feedback-command"),
244 command: "/feedback The agent stopped early.",
245 createdAt: MESSAGE_CREATED_AT,
246 status: "uploading" as const,
247 };
248 const messages = [
249 codexFeedbackMessage(submission),
250 codexFeedbackMessage(submission, "assistant"),
251 ];
252 const markup = renderToStaticMarkup(
253 <MessagesTimeline
254 {...buildProps()}
255 timelineEntries={messages.map((message) => ({
256 id: message.id,
257 kind: "message" as const,
258 createdAt: message.createdAt,
259 message,
260 }))}
261 />,
262 );
263​
264 expect(markup).toContain("/feedback The agent stopped early.");
265 expect(markup).toContain("Sending feedback to OpenAI...");
266 });
267​
268 it("renders the returned Codex thread ID in the feedback response", () => {
269 const submission = {
270 id: MessageId.make("feedback-command"),
271 command: "/feedback The agent stopped early.",
272 createdAt: MESSAGE_CREATED_AT,
273 status: "sent" as const,
274 feedbackId: "codex-thread-1",
275 };
276 const messages = [
277 codexFeedbackMessage(submission),
278 codexFeedbackMessage(submission, "assistant"),
279 ];
280 const markup = renderToStaticMarkup(
281 <MessagesTimeline
282 {...buildProps()}
283 timelineEntries={messages.map((message) => ({
284 id: message.id,
285 kind: "message" as const,
286 createdAt: message.createdAt,
287 message,
288 }))}
289 />,
290 );
291​
292 expect(markup).toContain("Feedback sent to OpenAI.");
293 expect(markup).toContain("codex-thread-1");
294 });
295​
296 it("renders the worked-for row at assistant response text size", () => {
297 const turnId = TurnId.make("turn-with-fold");
298 const assistantEntry = buildAssistantTimelineEntry("Done.");
299 const markup = renderToStaticMarkup(
300 <MessagesTimeline
301 {...buildProps()}
302 latestTurn={{
303 turnId,
304 state: "completed",
305 startedAt: "2026-03-17T19:12:20.000Z",
306 completedAt: "2026-03-17T19:12:28.000Z",
307 }}
308 timelineEntries={[
309 {
310 id: "work-entry-with-fold",
311 kind: "work",
312 createdAt: "2026-03-17T19:12:22.000Z",
313 entry: {
314 id: "work-with-fold",
315 createdAt: "2026-03-17T19:12:22.000Z",
316 turnId,
317 label: "Ran command",
318 tone: "tool",
319 toolLifecycleStatus: "completed",
320 },
321 },
322 {
323 ...assistantEntry,
324 message: { ...assistantEntry.message, turnId },
325 },
326 ]}
327 />,
328 );
329​
330 expect(markup).toContain("Worked for 8.0s");
331 expect(markup).toContain("px-1 text-sm leading-relaxed text-muted-foreground");
332 });
333​
334 it("uses the larger leading inset only when the top fade is enabled", () => {
335 const timelineEntries = [buildUserTimelineEntry("Hello")];
336​
337 const compactMarkup = renderToStaticMarkup(
338 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} />,
339 );
340 const fadedMarkup = renderToStaticMarkup(
341 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} topFadeEnabled />,
342 );
343​
344 expect(compactMarkup).toContain('class="h-3 sm:h-4"');
345 expect(compactMarkup).not.toContain("topbar-scroll-fade");
346 expect(fadedMarkup).toContain('class="h-[var(--workspace-titlebar-scroll-fade-height)]"');
347 expect(fadedMarkup).toContain("topbar-scroll-fade");
348 });
349​
350 it("keeps assistant changed-files headers sticky below the thread header", () => {
351 const assistantMessageId = MessageId.make("message-assistant-with-files");
352 const turnId = TurnId.make("turn-with-files");
353 const markup = renderToStaticMarkup(
354 <MessagesTimeline
355 {...buildProps()}
356 latestTurn={{
357 turnId,
358 state: "completed",
359 startedAt: MESSAGE_CREATED_AT,
360 completedAt: MESSAGE_CREATED_AT,
361 }}
362 timelineEntries={[
363 {
364 id: "entry-assistant-with-files",
365 kind: "message",
366 createdAt: MESSAGE_CREATED_AT,
367 message: {
368 id: assistantMessageId,
369 role: "assistant",
370 text: "Updated the fixture.",
371 turnId,
372 createdAt: MESSAGE_CREATED_AT,
373 updatedAt: MESSAGE_CREATED_AT,
374 streaming: false,
375 },
376 },
377 ]}
378 turnDiffSummaryByAssistantMessageId={
379 new Map([
380 [
381 assistantMessageId,
382 {
383 turnId,
384 checkpointTurnCount: 1,
385 checkpointRef: CheckpointRef.make("checkpoint-with-files"),
386 status: "ready",
387 files: [{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }],
388 assistantMessageId,
389 completedAt: MESSAGE_CREATED_AT,
390 },
391 ],
392 ])
393 }
394 />,
395 );
396​
397 expect(markup).toContain("sticky top-2 z-10");
398 expect(markup).not.toContain("self-start");
399 expect(markup).toContain("whitespace-nowrap");
400 expect(markup).toContain("!size-[22px]");
401 expect(markup).toContain("size-3");
402 expect(markup).toContain('aria-label="Collapse all folders"');
403 expect(markup).toContain('aria-label="Open diff"');
404 expect(markup).toContain("1 changed file");
405 });
406​
407 it("treats only the strict list end as the live edge", async () => {
408 const {
409 resolveTimelineIsAtEnd,
410 resolveTimelineMinimapHasPersistentGutter,
411 resolveTimelineMinimapHeightStyle,
412 resolveTimelineMinimapHitStripWidth,
413 resolveTimelineMinimapIndexFromPointer,
414 resolveTimelineMinimapInteractiveWidth,
415 resolveTimelineMinimapTopPercent,
416 } = await import("./MessagesTimeline.logic");
417​
418 expect(resolveTimelineIsAtEnd({ isAtEnd: true })).toBe(true);
419 expect(resolveTimelineIsAtEnd(undefined)).toBeUndefined();
420 // Within the pixel band above the content bottom counts as the end...
421 expect(
422 resolveTimelineIsAtEnd({
423 isAtEnd: false,
424 contentLength: 2000,
425 scroll: 1170,
426 scrollLength: 800,
427 }),
428 ).toBe(true);
429 // ...but half a viewport up (LegendList's isNearEnd territory) does not.
430 expect(
431 resolveTimelineIsAtEnd({
432 isAtEnd: false,
433 contentLength: 2000,
434 scroll: 900,
435 scrollLength: 800,
436 }),
437 ).toBe(false);
438 // The composer inset is part of contentLength and must not count as
439 // distance-to-end.
440 expect(
441 resolveTimelineIsAtEnd(
442 { isAtEnd: false, contentLength: 2100, scroll: 1170, scrollLength: 800 },
443 100,
444 ),
445 ).toBe(true);
446 // Geometry missing (older state shape): fall back to the strict flag.
447 expect(resolveTimelineIsAtEnd({ isAtEnd: false })).toBe(false);
448​
449 expect(resolveTimelineMinimapHeightStyle(5)).toBe("min(32px, calc(100vh - 18rem))");
450 expect(resolveTimelineMinimapTopPercent(2, 5)).toBe(50);
451 expect(
452 resolveTimelineMinimapIndexFromPointer({
453 itemCount: 101,
454 railTop: 100,
455 railHeight: 500,
456 pointerY: 350,
457 }),
458 ).toBe(50);
459 expect(
460 resolveTimelineMinimapIndexFromPointer({
461 itemCount: 101,
462 railTop: 100,
463 railHeight: 500,
464 pointerY: 999,
465 }),
466 ).toBe(100);
467 expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
468 expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
469 expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);
470​
471 // No usable gutter (zoomed in / narrow pane): the strip must go inert
472 // instead of overlaying the centered content column.
473 expect(resolveTimelineMinimapHitStripWidth(768)).toBe(0);
474 expect(resolveTimelineMinimapHitStripWidth(792)).toBe(0);
475 // Partial gutter: strip shrinks to what fits between the viewport edge
476 // and the content column.
477 expect(resolveTimelineMinimapHitStripWidth(820)).toBe(14);
478 // Full gutter: unchanged 40px-wide strip.
479 expect(resolveTimelineMinimapHitStripWidth(872)).toBe(40);
480 expect(resolveTimelineMinimapHitStripWidth(1400)).toBe(40);
481 expect(resolveTimelineMinimapHitStripWidth(0)).toBe(0);
482 expect(resolveTimelineMinimapHitStripWidth(Number.NaN)).toBe(0);
483​
484 // The collapsed target stays narrow, but an open preview keeps its full
485 // 20rem width plus the 2rem offset from the minimap rail interactive.
486 expect(resolveTimelineMinimapInteractiveWidth(0, false)).toBe(0);
487 expect(resolveTimelineMinimapInteractiveWidth(14, false)).toBe(14);
488 expect(resolveTimelineMinimapInteractiveWidth(40, false)).toBe(40);
489 expect(resolveTimelineMinimapInteractiveWidth(0, true)).toBe("22rem");
490 expect(resolveTimelineMinimapInteractiveWidth(14, true)).toBe("22rem");
491 expect(resolveTimelineMinimapInteractiveWidth(40, true)).toBe("22rem");
492 });
493​
494 it("anchors the first user message using its measured height", () => {
495 const onAnchorReady = vi.fn();
496 const firstEntry = {
497 ...buildUserTimelineEntry("First prompt."),
498 message: {
499 ...buildUserTimelineEntry("First prompt.").message,
500 attachments: [
501 {
502 type: "image" as const,
503 id: "attachment-1",
504 name: "screenshot.png",
505 mimeType: "image/png",
506 sizeBytes: 1,
507 previewUrl: "data:image/png;base64,iVBORw0KGgo=",
508 },
509 ],
510 },
511 };
512 const markup = renderToStaticMarkup(
513 <MessagesTimeline
514 {...buildProps()}
515 anchorMessageId={firstEntry.message.id}
516 onAnchorReady={onAnchorReady}
517 contentInsetEndAdjustment={144}
518 timelineEntries={[firstEntry]}
519 />,
520 );
521​
522 expect(markup).toContain('data-anchor-index="0"');
523 expect(markup).toContain('data-anchor-offset="16"');
524 expect(markup).toContain('data-anchor-on-ready="true"');
525 expect(markup).not.toContain("data-anchor-max-size=");
526 expect(markup).toContain('data-content-inset-end="144"');
527 expect(markup).toContain("[overflow-anchor:none]");
528 expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
529 expect(markup).toContain('data-maintain-visible-content-position="object"');
530 expect(markup).toContain('data-maintain-visible-content-position-data="true"');
531 expect(markup).toContain('data-maintain-visible-content-position-size="true"');
532 expect(markup).toContain('data-maintain-visible-content-position-restore="true"');
533 expect(onAnchorReady).toHaveBeenCalledOnce();
534 expect(onAnchorReady).toHaveBeenCalledWith(firstEntry.message.id, 0);
535 });
536​
537 it("does not reserve end space for a follow-up user message", () => {
538 const onAnchorReady = vi.fn();
539 const firstEntry = buildUserTimelineEntry("First prompt.");
540 const secondEntry = {
541 ...buildUserTimelineEntry("Newest prompt."),
542 id: "entry-2",
543 message: {
544 ...buildUserTimelineEntry("Newest prompt.").message,
545 id: MessageId.make("message-2"),
546 },
547 };
548 const markup = renderToStaticMarkup(
549 <MessagesTimeline
550 {...buildProps()}
551 anchorMessageId={secondEntry.message.id}
552 onAnchorReady={onAnchorReady}
553 timelineEntries={[firstEntry, secondEntry]}
554 />,
555 );
556​
557 expect(markup).not.toContain("data-anchor-index=");
558 expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
559 expect(onAnchorReady).not.toHaveBeenCalled();
560 });
561​
562 it("renders generic attachments as download links instead of image previews", () => {
563 const entry = {
564 ...buildUserTimelineEntry("Read the report."),
565 message: {
566 ...buildUserTimelineEntry("Read the report.").message,
567 attachments: [
568 {
569 type: "file" as const,
570 id: "attachment-report-pdf",
571 name: "report.pdf",
572 mimeType: "application/pdf",
573 sizeBytes: 42,
574 previewUrl: "https://environment.test/api/assets/report.pdf",
575 },
576 ],
577 },
578 };
579​
580 const markup = renderToStaticMarkup(
581 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
582 );
583​
584 expect(markup).toContain(
585 '<a href="https://environment.test/api/assets/report.pdf" download="report.pdf" class="flex min-w-0 items-center gap-2 rounded-md py-1 text-sm hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70">',
586 );
587 expect(markup).not.toContain('alt="report.pdf"');
588 });
589​
590 it("renders video attachments as play buttons", () => {
591 const entry = {
592 ...buildUserTimelineEntry("Watch the demo."),
593 message: {
594 ...buildUserTimelineEntry("Watch the demo.").message,
595 attachments: [
596 {
597 type: "file" as const,
598 id: "attachment-demo-mp4",
599 name: "demo.mp4",
600 mimeType: "video/mp4",
601 sizeBytes: 42,
602 },
603 ],
604 },
605 };
606​
607 const markup = renderToStaticMarkup(
608 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
609 );
610 const busyMarkup = renderToStaticMarkup(
611 <MessagesTimeline
612 {...buildProps()}
613 timelineEntries={[entry]}
614 openingVideoAttachmentId="attachment-demo-mp4"
615 />,
616 );
617​
618 expect(markup).toContain('aria-label="Play demo.mp4"');
619 expect(markup).toContain("min-h-[72px]");
620 expect(markup).toContain(">demo.mp4</span>");
621 expect(markup).not.toContain('aria-label="Download demo.mp4"');
622 expect(busyMarkup).toContain('aria-busy="true"');
623 expect(busyMarkup).toContain('aria-disabled="true"');
624 expect(busyMarkup).not.toContain('disabled=""');
625 expect(busyMarkup).toContain(">Loading…</span>");
626 });
627 it("renders a file download button without creating its URL in advance", () => {
628 const entry = {
629 ...buildUserTimelineEntry("Read the report."),
630 message: {
631 ...buildUserTimelineEntry("Read the report.").message,
632 attachments: [
633 {
634 type: "file" as const,
635 id: "attachment-report-pdf",
636 name: "report.pdf",
637 mimeType: "application/pdf",
638 sizeBytes: 42,
639 },
640 ],
641 },
642 };
643​
644 const markup = renderToStaticMarkup(
645 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
646 );
647​
648 expect(markup).toContain(
649 '<button type="button" aria-label="Download report.pdf" class="flex min-w-0 cursor-pointer items-center gap-2 rounded-md py-1 text-left text-sm hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70">',
650 );
651 expect(markup).not.toContain("href=");
652 });
653​
654 it("does not download an optimistic file before the server supplies its attachment ID", () => {
655 const entry = {
656 ...buildUserTimelineEntry("Read the report."),
657 message: {
658 ...buildUserTimelineEntry("Read the report.").message,
659 attachments: [
660 {
661 type: "file" as const,
662 id: "composer-local-report",
663 name: "report.pdf",
664 mimeType: "application/pdf",
665 sizeBytes: 42,
666 downloadable: false,
667 },
668 ],
669 },
670 };
671​
672 const markup = renderToStaticMarkup(
673 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
674 );
675​
676 expect(markup).toContain("report.pdf");
677 expect(markup).not.toContain('aria-label="Download report.pdf"');
678 });
679​
680 it("renders unknown attachment types as inert rows instead of crashing", () => {
681 const entry = {
682 ...buildUserTimelineEntry("Play the recording."),
683 message: {
684 ...buildUserTimelineEntry("Play the recording.").message,
685 attachments: [
686 {
687 // A newer server can introduce attachment types this build does
688 // not know. They ride the open contract member.
689 type: "recording",
690 id: "attachment-voice-memo",
691 name: "voice-memo.ogg",
692 mimeType: "audio/ogg",
693 sizeBytes: 42,
694 },
695 ],
696 },
697 };
698​
699 const markup = renderToStaticMarkup(
700 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
701 );
702​
703 expect(markup).toContain("voice-memo.ogg");
704 expect(markup).not.toContain('aria-label="Download voice-memo.ogg"');
705 expect(markup).not.toContain('alt="voice-memo.ogg"');
706 expect(markup).not.toContain("href=");
707 });
708​
709 it("keeps reserved end space when tool work starts while reading history", () => {
710 const turnId = TurnId.make("turn-with-active-tool");
711 const firstEntry = buildUserTimelineEntry("Run the command.");
712 const markup = renderToStaticMarkup(
713 <MessagesTimeline
714 {...buildProps()}
715 isWorking
716 activeTurnStartedAt={MESSAGE_CREATED_AT}
717 latestTurn={{
718 turnId,
719 state: "running",
720 startedAt: MESSAGE_CREATED_AT,
721 completedAt: null,
722 }}
723 runningTurnId={turnId}
724 anchorMessageId={firstEntry.message.id}
725 liveFollowEnabled={false}
726 timelineEntries={[
727 firstEntry,
728 {
729 id: "entry-active-tool",
730 kind: "work",
731 createdAt: MESSAGE_CREATED_AT,
732 entry: {
733 id: "work-active-tool",
734 createdAt: MESSAGE_CREATED_AT,
735 turnId,
736 toolCallId: "call-active-tool",
737 label: "Run command",
738 tone: "tool",
739 itemType: "command_execution",
740 command: "git status",
741 toolLifecycleStatus: "inProgress",
742 },
743 },
744 ]}
745 />,
746 );
747​
748 expect(markup).toContain('data-anchor-index="0"');
749 expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
750 });
751​
752 it("hands end-following back to the list once the send anchor is released", () => {
753 const firstEntry = buildUserTimelineEntry("First prompt.");
754 const secondEntry = {
755 ...buildUserTimelineEntry("Newest prompt."),
756 id: "entry-2",
757 message: {
758 ...buildUserTimelineEntry("Newest prompt.").message,
759 id: MessageId.make("message-2"),
760 },
761 };
762 const timelineEntries = [firstEntry, secondEntry];
763​
764 // While the send anchor holds the end space open, ChatView owns streaming
765 // scrolls and LegendList must not re-pin behind it.
766 expect(
767 renderToStaticMarkup(
768 <MessagesTimeline
769 {...buildProps()}
770 anchorMessageId={firstEntry.message.id}
771 timelineEntries={timelineEntries}
772 />,
773 ),
774 ).not.toContain('data-maintain-scroll-at-end="enabled"');
775​
776 // Dropping the anchor is what actually gives end-following back, so
777 // returning to the live edge has to release it — re-enabling live follow
778 // alone leaves nothing pinned to the stream.
779 expect(
780 renderToStaticMarkup(
781 <MessagesTimeline
782 {...buildProps()}
783 anchorMessageId={null}
784 timelineEntries={timelineEntries}
785 />,
786 ),
787 ).toContain('data-maintain-scroll-at-end="enabled"');
788​
789 // Reading history still wins over both.
790 expect(
791 renderToStaticMarkup(
792 <MessagesTimeline
793 {...buildProps()}
794 anchorMessageId={null}
795 liveFollowEnabled={false}
796 timelineEntries={timelineEntries}
797 />,
798 ),
799 ).not.toContain('data-maintain-scroll-at-end="enabled"');
800 });
801​
802 it("renders collapse controls for long user messages", () => {
803 const markup = renderToStaticMarkup(
804 <MessagesTimeline
805 {...buildProps()}
806 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
807 />,
808 );
809​
810 expect(markup).toContain("Show full message");
811 expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
812 expect(markup).toContain('data-maintain-scroll-at-end-animated="false"');
813 expect(markup).toContain('data-maintain-scroll-at-end-data-change="true"');
814 expect(markup).toContain('data-maintain-scroll-at-end-item-layout="true"');
815 expect(markup).toContain('data-maintain-scroll-at-end-layout="true"');
816 expect(markup).toContain('data-user-message-collapsed="true"');
817 expect(markup).toContain('data-user-message-fade="true"');
818 expect(markup).toContain('data-user-message-footer="true"');
819 });
820​
821 it("does not render collapse controls for short user messages", () => {
822 const markup = renderToStaticMarkup(
823 <MessagesTimeline
824 {...buildProps()}
825 timelineEntries={[buildUserTimelineEntry("Short prompt.")]}
826 />,
827 );
828​
829 expect(markup).not.toContain("Show full message");
830 expect(markup).toContain('data-user-message-collapsible="false"');
831 expect(markup).toContain("rounded-2xl bg-message p-3");
832 });
833​
834 it("preserves arbitrary XML-like tags and comparisons in rendered user messages", async () => {
835 const { MessagesTimeline } = await import("./MessagesTimeline");
836 const markup = renderToStaticMarkup(
837 <MessagesTimeline
838 {...buildProps()}
839 timelineEntries={[
840 buildUserTimelineEntry(
841 [
842 'Without reading a file, do you have <global-agent-instructions scope="workspace">',
843 'Before <nested data-value="a&b">inside</nested> after',
844 "</global-agent-instructions> in your context?",
845 "Comparison: 2 < 3 and 5 > 4.",
846 ].join("\n"),
847 ),
848 ]}
849 />,
850 );
851​
852 expect(markup).toContain("&lt;global-agent-instructions scope=&quot;workspace&quot;&gt;");
853 expect(markup).toContain(
854 "Before &lt;nested data-value=&quot;a&amp;b&quot;&gt;inside&lt;/nested&gt; after",
855 );
856 expect(markup).toContain("&lt;/global-agent-instructions&gt; in your context?");
857 expect(markup).toContain("Comparison: 2 &lt; 3 and 5 &gt; 4.");
858 });
859​
860 it("preserves XML-like source inside user code spans and fences", async () => {
861 const { MessagesTimeline } = await import("./MessagesTimeline");
862 const markup = renderToStaticMarkup(
863 <MessagesTimeline
864 {...buildProps()}
865 timelineEntries={[
866 buildUserTimelineEntry(
867 [
868 'Inline `<tag attr="x">`',
869 "",
870 "```xml",
871 '<root><child enabled="true" /></root>',
872 "```",
873 ].join("\n"),
874 ),
875 ]}
876 />,
877 );
878​
879 expect(markup).toContain('<code data-inline-code="">&lt;tag attr=&quot;x&quot;&gt;</code>');
880 expect(markup).toContain("&lt;root&gt;&lt;child enabled=&quot;true&quot; /&gt;&lt;/root&gt;");
881 });
882​
883 it("does not render markdown title attributes in user messages", async () => {
884 const { MessagesTimeline } = await import("./MessagesTimeline");
885 const markup = renderToStaticMarkup(
886 <MessagesTimeline
887 {...buildProps()}
888 timelineEntries={[
889 buildUserTimelineEntry(
890 '[link](https://example.com "link tip") ![image](https://example.com/image.png "image tip")',
891 ),
892 ]}
893 />,
894 );
895​
896 expect(markup).toContain('href="https://example.com"');
897 expect(markup).toContain('src="https://example.com/image.png"');
898 expect(markup).not.toContain('title="link tip"');
899 expect(markup).not.toContain('title="image tip"');
900 });
901​
902 it("renders unsafe user HTML as inert source text", async () => {
903 const { MessagesTimeline } = await import("./MessagesTimeline");
904 const markup = renderToStaticMarkup(
905 <MessagesTimeline
906 {...buildProps()}
907 timelineEntries={[
908 buildUserTimelineEntry(
909 '<script>globalThis.__t3Xss = 1</script><img src="x" onerror="globalThis.__t3Xss = 2">',
910 ),
911 ]}
912 />,
913 );
914​
915 expect(markup).toContain("&lt;script&gt;globalThis.__t3Xss = 1&lt;/script&gt;");
916 expect(markup).toContain(
917 "&lt;img src=&quot;x&quot; onerror=&quot;globalThis.__t3Xss = 2&quot;&gt;",
918 );
919 expect(markup).not.toMatch(/<script(?:\s|>)/i);
920 expect(markup).not.toMatch(/<img(?:\s|>)/i);
921 });
922​
923 it("continues to render sanitized raw HTML in assistant messages", async () => {
924 const { MessagesTimeline } = await import("./MessagesTimeline");
925 const markup = renderToStaticMarkup(
926 <MessagesTimeline
927 {...buildProps()}
928 timelineEntries={[
929 buildAssistantTimelineEntry("<details><summary>More</summary>Details</details>"),
930 ]}
931 />,
932 );
933​
934 expect(markup).toContain('data-markdown-details=""');
935 expect(markup).toContain("More");
936 expect(markup).not.toContain("&lt;details&gt;");
937 });
938​
939 it("sanitizes executable HTML while preserving supported assistant markup", async () => {
940 const { MessagesTimeline } = await import("./MessagesTimeline");
941 const markup = renderToStaticMarkup(
942 <MessagesTimeline
943 {...buildProps()}
944 timelineEntries={[
945 buildAssistantTimelineEntry(
946 [
947 '<details open onclick="globalThis.__t3Xss = 1">',
948 "<summary>Safe details</summary>",
949 "<script>globalThis.__t3Xss = 2</script>",
950 '<img src="x" onerror="globalThis.__t3Xss = 3">',
951 '<a href="javascript:globalThis.__t3Xss = 4">Unsafe link</a>',
952 "</details>",
953 ].join(""),
954 ),
955 ]}
956 />,
957 );
958​
959 expect(markup).toContain('data-markdown-details=""');
960 expect(markup).toContain("Safe details");
961 expect(markup).not.toMatch(/<script(?:\s|>)/i);
962 expect(markup).not.toContain("onclick=");
963 expect(markup).not.toContain("onerror=");
964 expect(markup).not.toContain("javascript:");
965 expect(markup).not.toContain("globalThis.__t3Xss");
966 });
967​
968 it("renders inline terminal labels with the composer chip UI", async () => {
969 const { MessagesTimeline } = await import("./MessagesTimeline");
970 const markup = renderToStaticMarkup(
971 <MessagesTimeline
972 {...buildProps()}
973 timelineEntries={[
974 buildUserTimelineEntry(
975 [
976 buildLongUserMessageText("yoo what's @terminal-1:1-5 mean"),
977 "",
978 "<terminal_context>",
979 "- Terminal 1 lines 1-5:",
980 " 1 | julius@mac effect-http-ws-cli % bun i",
981 " 2 | bun install v1.3.9 (cf6cdbbb)",
982 "</terminal_context>",
983 ].join("\n"),
984 ),
985 ]}
986 />,
987 );
988​
989 expect(markup).toContain("Terminal 1 lines 1-5");
990 expect(markup).toContain("lucide-terminal");
991 expect(markup).toContain("yoo what&#x27;s</p>");
992 expect(markup).toContain('<span aria-hidden="true"> </span>');
993 expect(markup).toContain("Show full message");
994 }, 20_000);
995​
996 it("renders chips for standalone element-pick context messages", () => {
997 const markup = renderToStaticMarkup(
998 <MessagesTimeline
999 {...buildProps()}
1000 timelineEntries={[
1001 buildUserTimelineEntry(
1003 "<element_context>",
1004 "- <SubmitButton> (Button.tsx:12):",
1005 " url: https://example.com/dashboard",
1006 " selector: button.submit",
1007 " source: /repo/src/Button.tsx:12:5",
1008 " html:",
1009 ' <button class="submit">Save</button>',
1010 "</element_context>",
1011 ].join("\n"),
1012 ),
1013 ]}
1014 />,
1015 );
1016​
1017 expect(markup).toContain("SubmitButton");
1018 expect(markup).not.toContain("&lt;element_context");
1019 expect(markup).not.toContain("<element_context");
1020 });
1021​
1022 it("keeps the copy button for collapsed long user messages", () => {
1023 const markup = renderToStaticMarkup(
1024 <MessagesTimeline
1025 {...buildProps()}
1026 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
1027 />,
1028 );
1029​
1030 expect(markup).toContain('aria-label="Copy link"');
1031 expect(markup).toContain('data-user-message-collapsed="true"');
1032 expect(markup).toContain('data-user-message-footer="true"');
1033 });
1034​
1035 it("renders context compaction entries in the normal work log", () => {
1036 const markup = renderToStaticMarkup(
1037 <MessagesTimeline
1038 {...buildProps()}
1039 timelineEntries={[
1041 id: "entry-1",
1042 kind: "work",
1043 createdAt: "2026-03-17T19:12:28.000Z",
1044 entry: {
1045 id: "work-1",
1046 createdAt: "2026-03-17T19:12:28.000Z",
1047 label: "Context compacted",
1048 tone: "info",
1049 },
1050 },
1051 ]}
1052 />,
1053 );
1054​
1055 expect(markup).toContain("Context compacted");
1056 });
1057​
1058 it("summarizes changed files in one line", () => {
1059 const markup = renderToStaticMarkup(
1060 <MessagesTimeline
1061 {...buildProps()}
1062 timelineEntries={[
1064 id: "entry-1",
1065 kind: "work",
1066 createdAt: "2026-03-17T19:12:28.000Z",
1067 entry: {
1068 id: "work-1",
1069 createdAt: "2026-03-17T19:12:28.000Z",
1070 label: "Updated files",
1071 tone: "tool",
1072 changedFiles: ["C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts"],
1073 },
1074 },
1075 ]}
1076 workspaceRoot="C:/Users/mike/dev-stuff/t3code"
1077 />,
1078 );
1079​
1080 expect(markup).toContain("Changed 1 file");
1081 expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
1082 });
1083​
1084 it("keeps mixed-success tool groups neutral", () => {
1085 const markup = renderToStaticMarkup(
1086 <MessagesTimeline
1087 {...buildProps()}
1088 timelineEntries={[
1090 id: "entry-failed",
1091 kind: "work",
1092 createdAt: "2026-03-17T19:12:28.000Z",
1093 entry: {
1094 id: "work-failed",
1095 createdAt: "2026-03-17T19:12:28.000Z",
1096 label: "Run search",
1097 tone: "tool",
1098 itemType: "command_execution",
1099 toolLifecycleStatus: "failed",
1100 },
1101 },
1103 id: "entry-completed",
1104 kind: "work",
1105 createdAt: "2026-03-17T19:12:29.000Z",
1106 entry: {
1107 id: "work-completed",
1108 createdAt: "2026-03-17T19:12:29.000Z",
1109 label: "Run tests",
1110 tone: "tool",
1111 itemType: "command_execution",
1112 toolLifecycleStatus: "completed",
1113 },
1114 },
1115 ]}
1116 />,
1117 );
1118​
1119 expect(markup).toContain("Ran 2 commands");
1120 expect(markup).not.toContain('aria-label="Tool call failed"');
1121 });
1122​
1123 it("keeps the collapsed summary icon neutral when the group ends in a failure", () => {
1124 const markup = renderToStaticMarkup(
1125 <MessagesTimeline
1126 {...buildProps()}
1127 timelineEntries={[
1129 id: "entry-completed",
1130 kind: "work",
1131 createdAt: "2026-03-17T19:12:28.000Z",
1132 entry: {
1133 id: "work-completed",
1134 createdAt: "2026-03-17T19:12:28.000Z",
1135 label: "Run tests",
1136 tone: "tool",
1137 itemType: "command_execution",
1138 toolLifecycleStatus: "completed",
1139 },
1140 },
1142 id: "entry-failed",
1143 kind: "work",
1144 createdAt: "2026-03-17T19:12:29.000Z",
1145 entry: {
1146 id: "work-failed",
1147 createdAt: "2026-03-17T19:12:29.000Z",
1148 label: "Run lint",
1149 tone: "tool",
1150 itemType: "command_execution",
1151 toolLifecycleStatus: "failed",
1152 },
1153 },
1154 ]}
1155 />,
1156 );
1157​
1158 expect(markup).toContain("Ran 2 commands");
1159 expect(markup).toContain("lucide-terminal");
1160 expect(markup).not.toContain("lucide-x");
1161 expect(markup).not.toContain("text-destructive");
1162 // The failure stays discoverable for screen readers.
1163 expect(markup).toContain("tool call failed");
1164 });
1165​
1166 it("keeps mixed work logs neutral after a later tool call succeeds", () => {
1167 const markup = renderToStaticMarkup(
1168 <MessagesTimeline
1169 {...buildProps()}
1170 timelineEntries={[
1172 id: "entry-failed",
1173 kind: "work",
1174 createdAt: "2026-03-17T19:12:28.000Z",
1175 entry: {
1176 id: "work-failed",
1177 createdAt: "2026-03-17T19:12:28.000Z",
1178 label: "Run search",
1179 tone: "tool",
1180 itemType: "command_execution",
1181 toolLifecycleStatus: "failed",
1182 },
1183 },
1185 id: "entry-info",
1186 kind: "work",
1187 createdAt: "2026-03-17T19:12:29.000Z",
1188 entry: {
1189 id: "work-info",
1190 createdAt: "2026-03-17T19:12:29.000Z",
1191 label: "Status updated",
1192 tone: "info",
1193 },
1194 },
1196 id: "entry-completed",
1197 kind: "work",
1198 createdAt: "2026-03-17T19:12:30.000Z",
1199 entry: {
1200 id: "work-completed",
1201 createdAt: "2026-03-17T19:12:30.000Z",
1202 label: "Run tests",
1203 tone: "tool",
1204 itemType: "command_execution",
1205 toolLifecycleStatus: "completed",
1206 },
1207 },
1208 ]}
1209 />,
1210 );
1211​
1212 expect(markup).toContain("Ran 2 commands and received 1 update");
1213 expect(markup).not.toContain('aria-label="Hidden work includes a failure"');
1214 });
1215​
1216 it("shows the animated one-line label for a live tool group", () => {
1217 const turnId = TurnId.make("turn-live");
1218 const markup = renderToStaticMarkup(
1219 <MessagesTimeline
1220 {...buildProps()}
1221 isWorking
1222 activeTurnStartedAt={MESSAGE_CREATED_AT}
1223 latestTurn={{
1224 turnId,
1225 state: "running",
1226 startedAt: MESSAGE_CREATED_AT,
1227 completedAt: null,
1228 }}
1229 runningTurnId={turnId}
1230 timelineEntries={[
1232 id: "entry-live",
1233 kind: "work",
1234 createdAt: MESSAGE_CREATED_AT,
1235 entry: {
1236 id: "work-live",
1237 createdAt: MESSAGE_CREATED_AT,
1238 turnId,
1239 toolCallId: "call-live",
1240 label: "Run tests",
1241 tone: "tool",
1242 itemType: "command_execution",
1243 command: "pnpm test",
1244 toolLifecycleStatus: "inProgress",
1245 },
1246 },
1247 ]}
1248 />,
1249 );
1250​
1251 expect(markup).toContain("Working for");
1252 expect(markup).toContain("Running pnpm");
1253 expect(markup).toContain("live-activity-focus");
1254 });
1255​
1256 it("scopes a live row failure to the tool named by the row", () => {
1257 const turnId = TurnId.make("turn-live");
1258 const markup = renderToStaticMarkup(
1259 <MessagesTimeline
1260 {...buildProps()}
1261 isWorking
1262 activeTurnStartedAt={MESSAGE_CREATED_AT}
1263 latestTurn={{
1264 turnId,
1265 state: "running",
1266 startedAt: MESSAGE_CREATED_AT,
1267 completedAt: null,
1268 }}
1269 runningTurnId={turnId}
1270 timelineEntries={[
1272 id: "entry-failed",
1273 kind: "work",
1274 createdAt: MESSAGE_CREATED_AT,
1275 entry: {
1276 id: "work-failed",
1277 createdAt: MESSAGE_CREATED_AT,
1278 turnId,
1279 toolCallId: "call-failed",
1280 label: "Run lint",
1281 tone: "tool",
1282 itemType: "command_execution",
1283 command: "pnpm lint",
1284 toolLifecycleStatus: "failed",
1285 },
1286 },
1288 id: "entry-running",
1289 kind: "work",
1290 createdAt: MESSAGE_CREATED_AT,
1291 entry: {
1292 id: "work-running",
1293 createdAt: MESSAGE_CREATED_AT,
1294 turnId,
1295 toolCallId: "call-running",
1296 label: "Run tests",
1297 tone: "tool",
1298 itemType: "command_execution",
1299 command: "pnpm test",
1300 toolLifecycleStatus: "inProgress",
1301 },
1302 },
1303 ]}
1304 />,
1305 );
1306​
1307 expect(markup).toContain("Running pnpm");
1308 expect(markup).not.toContain("tool call failed");
1309 });
1310​
1311 it("keeps terminal command copy live while the parent turn is active", () => {
1312 const turnId = TurnId.make("turn-live");
1313 const markup = renderToStaticMarkup(
1314 <MessagesTimeline
1315 {...buildProps()}
1316 isWorking
1317 activeTurnStartedAt={MESSAGE_CREATED_AT}
1318 latestTurn={{
1319 turnId,
1320 state: "running",
1321 startedAt: MESSAGE_CREATED_AT,
1322 completedAt: null,
1323 }}
1324 runningTurnId={turnId}
1325 timelineEntries={[
1327 id: "entry-failed",
1328 kind: "work",
1329 createdAt: MESSAGE_CREATED_AT,
1330 entry: {
1331 id: "work-failed",
1332 createdAt: MESSAGE_CREATED_AT,
1333 turnId,
1334 toolCallId: "call-failed",
1335 label: "Run lint",
1336 tone: "tool",
1337 itemType: "command_execution",
1338 command: "pnpm lint",
1339 toolLifecycleStatus: "failed",
1340 },
1341 },
1342 ]}
1343 />,
1344 );
1345​
1346 expect(markup).toContain("Running pnpm");
1347 expect(markup).toContain("tool call failed");
1348 });
1349​
1350 it("renders review comment contexts as structured cards instead of raw tags", () => {
1351 const markup = renderToStaticMarkup(
1352 <MessagesTimeline
1353 {...buildProps()}
1354 timelineEntries={[
1356 id: "entry-1",
1357 kind: "message",
1358 createdAt: "2026-03-17T19:12:28.000Z",
1359 message: {
1360 id: MessageId.make("message-2"),
1361 role: "user",
1362 text: [
1363 '<review_comment sectionId="turn:2" sectionTitle="Turn 2" filePath="apps/web/src/lib/contextWindow.test.ts" startIndex="3" endIndex="14" rangeLabel="+47 to +58">',
1364 "Wadduo",
1365 "```diff",
1366 "@@ -0,0 +47,2 @@",
1367 '+ it("keeps valid zero-usage snapshots", () => {',
1368 "+ expect(snapshot).not.toBeNull();",
1369 "```",
1370 "</review_comment>",
1371 ].join("\n"),
1372 turnId: null,
1373 createdAt: "2026-03-17T19:12:28.000Z",
1374 updatedAt: "2026-03-17T19:12:28.000Z",
1375 streaming: false,
1376 },
1377 },
1378 ]}
1379 />,
1380 );
1381​
1382 expect(markup).toContain("contextWindow.test.ts");
1383 expect(markup).toContain("Wadduo");
1384 expect(markup).toContain('data-testid="file-diff"');
1385 expect(markup).not.toContain(">Review comment<");
1386 expect(markup).not.toContain("&lt;review_comment");
1387 expect(markup).not.toContain("&lt;/review_comment&gt;");
1388 });
1389​
1390 it("renders file review comments as source code instead of diffs", () => {
1391 const markup = renderToStaticMarkup(
1392 <MessagesTimeline
1393 {...buildProps()}
1394 timelineEntries={[
1396 id: "entry-1",
1397 kind: "message",
1398 createdAt: "2026-03-17T19:12:28.000Z",
1399 message: {
1400 id: MessageId.make("message-source-comment"),
1401 role: "user",
1402 text: [
1403 '<review_comment sectionId="file:docs/plan.md" sectionTitle="File comment" filePath="docs/plan.md" startIndex="0" endIndex="1" rangeLabel="L1 to L2">',
1404 "Clarify this.",
1405 "```md",
1406 "# Plan",
1407 "- Step one",
1408 "```",
1409 "</review_comment>",
1410 ].join("\n"),
1411 turnId: null,
1412 createdAt: "2026-03-17T19:12:28.000Z",
1413 updatedAt: "2026-03-17T19:12:28.000Z",
1414 streaming: false,
1415 },
1416 },
1417 ]}
1418 />,
1419 );
1420​
1421 expect(markup).toContain("plan.md");
1422 expect(markup).toContain("Clarify this.");
1423 expect(markup).toContain("# Plan");
1424 expect(markup).not.toContain('data-testid="file-diff"');
1425 });
1426​
1427 it("keeps failed lifecycle entries discoverable in mixed activity summaries", () => {
1428 const markup = renderToStaticMarkup(
1429 <MessagesTimeline
1430 {...buildProps()}
1431 timelineEntries={[
1433 id: "entry-info",
1434 kind: "work",
1435 createdAt: "2026-03-17T19:12:27.000Z",
1436 entry: {
1437 id: "work-info",
1438 createdAt: "2026-03-17T19:12:27.000Z",
1439 label: "Status updated",
1440 tone: "info",
1441 },
1442 },
1444 id: "entry-1",
1445 kind: "work",
1446 createdAt: "2026-03-17T19:12:28.000Z",
1447 entry: {
1448 id: "work-1",
1449 createdAt: "2026-03-17T19:12:28.000Z",
1450 label: "Glob",
1451 tone: "tool",
1452 toolLifecycleStatus: "failed",
1453 detail: "No files found",
1454 },
1455 },
1456 ]}
1457 />,
1458 );
1459​
1460 expect(markup).toContain('aria-label="Received 1 update and used 1 tool, tool call failed"');
1461 // Ordinary tool failures render muted, not red.
1462 expect(markup).not.toContain("text-destructive");
1463 });
1464​
1465 it("keeps the red treatment for severe orchestration failures", () => {
1466 const markup = renderToStaticMarkup(
1467 <MessagesTimeline
1468 {...buildProps()}
1469 timelineEntries={[
1471 id: "entry-info",
1472 kind: "work",
1473 createdAt: "2026-03-17T19:12:27.000Z",
1474 entry: {
1475 id: "work-info",
1476 createdAt: "2026-03-17T19:12:27.000Z",
1477 label: "Status updated",
1478 tone: "info",
1479 },
1480 },
1482 id: "entry-turn-failed",
1483 kind: "work",
1484 createdAt: "2026-03-17T19:12:28.000Z",
1485 entry: {
1486 id: "work-turn-failed",
1487 createdAt: "2026-03-17T19:12:28.000Z",
1488 label: "Provider turn start failed",
1489 tone: "error",
1490 sourceActivityKind: "provider.turn.start.failed",
1491 },
1492 },
1493 ]}
1494 />,
1495 );
1496​
1497 expect(markup).toContain("lucide-circle-alert");
1498 expect(markup).toContain("text-destructive");
1499 });
1500});