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

MessagesTimeline.test.tsx

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