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

MessagesTimeline.test.tsx

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