Open History to see the last commit
1import { CheckpointRef, EnvironmentId, MessageId, TurnId } from "@t3tools/contracts";
2import { createRef, type ReactNode, type Ref } from "react";
3import { renderToStaticMarkup } from "react-dom/server";
4import { beforeAll, describe, expect, it, vi } from "vite-plus/test";
5import type { LegendListRef } from "@legendapp/list/react";
6
7vi.mock("@legendapp/list/react", async () => {
8 const legendListTestId = "legend-list";
9
10 const LegendList = (props: {
11 data: Array<{ id: string }>;
12 keyExtractor: (item: { id: string }) => string;
13 renderItem: (args: { item: { id: string } }) => ReactNode;
14 ListHeaderComponent?: ReactNode;
15 ListFooterComponent?: ReactNode;
16 anchoredEndSpace?: {
17 anchorIndex: number;
18 anchorMaxSize?: number;
19 anchorOffset?: number;
20 onReady?: (info: { anchorIndex: number }) => void;
21 };
22 contentInsetEndAdjustment?: number;
23 className?: string;
24 maintainScrollAtEnd?:
25 | boolean
26 | {
27 animated?: boolean;
28 on?: {
29 dataChange?: boolean;
30 itemLayout?: boolean;
31 layout?: boolean;
32 };
33 };
34 maintainVisibleContentPosition?:
35 | boolean
36 | {
37 data?: boolean;
38 size?: boolean;
39 shouldRestorePosition?: (item: { id: string }) => boolean;
40 };
41 ref?: Ref<LegendListRef>;
42 }) => {
43 if (props.anchoredEndSpace) {
44 props.anchoredEndSpace.onReady?.({ anchorIndex: props.anchoredEndSpace.anchorIndex });
45 }
46 return (
47 <div
48 data-testid={legendListTestId}
49 data-anchor-index={props.anchoredEndSpace?.anchorIndex}
50 data-anchor-max-size={props.anchoredEndSpace?.anchorMaxSize}
51 data-anchor-offset={props.anchoredEndSpace?.anchorOffset}
52 data-anchor-on-ready={Boolean(props.anchoredEndSpace?.onReady)}
53 data-content-inset-end={props.contentInsetEndAdjustment}
54 data-class-name={props.className}
55 data-maintain-scroll-at-end={props.maintainScrollAtEnd ? "enabled" : undefined}
56 data-maintain-scroll-at-end-animated={
57 typeof props.maintainScrollAtEnd === "object"
58 ? props.maintainScrollAtEnd.animated
59 : undefined
60 }
61 data-maintain-scroll-at-end-data-change={
62 typeof props.maintainScrollAtEnd === "object"
63 ? props.maintainScrollAtEnd.on?.dataChange
64 : undefined
65 }
66 data-maintain-scroll-at-end-item-layout={
67 typeof props.maintainScrollAtEnd === "object"
68 ? props.maintainScrollAtEnd.on?.itemLayout
69 : undefined
70 }
71 data-maintain-scroll-at-end-layout={
72 typeof props.maintainScrollAtEnd === "object"
73 ? props.maintainScrollAtEnd.on?.layout
74 : undefined
75 }
76 data-maintain-visible-content-position={
77 typeof props.maintainVisibleContentPosition === "object"
78 ? "object"
79 : props.maintainVisibleContentPosition
80 }
81 data-maintain-visible-content-position-data={
82 typeof props.maintainVisibleContentPosition === "object"
83 ? props.maintainVisibleContentPosition.data
84 : undefined
85 }
86 data-maintain-visible-content-position-size={
87 typeof props.maintainVisibleContentPosition === "object"
88 ? props.maintainVisibleContentPosition.size
89 : undefined
90 }
91 data-maintain-visible-content-position-restore={
92 typeof props.maintainVisibleContentPosition === "object"
93 ? Boolean(props.maintainVisibleContentPosition.shouldRestorePosition)
94 : undefined
95 }
96 >
97 {props.ListHeaderComponent}
98 {props.data.map((item) => (
99 <div key={props.keyExtractor(item)}>{props.renderItem({ item })}</div>
100 ))}
101 {props.ListFooterComponent}
102 </div>
103 );
104 };
105
106 return { LegendList };
107});
108
109function MockFileDiff(props: {
110 fileDiff: { name?: string | null; prevName?: string | null };
111 renderCustomHeader?: (fileDiff: {
112 name?: string | null;
113 prevName?: string | null;
114 }) => React.ReactNode;
115}) {
116 return (
117 <div data-testid="file-diff">
118 {props.renderCustomHeader?.(props.fileDiff)}
119 {props.fileDiff.name ?? props.fileDiff.prevName ?? "diff"}
120 </div>
121 );
122}
123
124vi.mock("@pierre/diffs/react", () => {
125 return { FileDiff: MockFileDiff };
126});
127
128function matchMedia() {
129 return {
130 matches: false,
131 addEventListener: () => {},
132 removeEventListener: () => {},
133 };
134}
135
136let MessagesTimeline: typeof import("./MessagesTimeline").MessagesTimeline;
137let toolCallExpandedBodyClassName: typeof import("./MessagesTimeline").toolCallExpandedBodyClassName;
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, toolCallExpandedBodyClassName } = 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 activeTurnInProgress: false,
181 activeTurnStartedAt: null,
182 listRef: createRef<LegendListRef | null>(),
183 latestTurn: null,
184 runningTurnId: null,
185 turnDiffSummaryByAssistantMessageId: new Map(),
186 routeThreadKey: "environment-local:thread-1",
187 onOpenTurnDiff: () => {},
188 revertTurnCountByUserMessageId: new Map(),
189 onRevertUserMessage: () => {},
190 isRevertingCheckpoint: false,
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 };
204}
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");
210}
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 };
227}
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 };
238}
239
240describe("MessagesTimeline", () => {
241 it("sizes expanded tool details with the configured code font size", () => {
242 expect(toolCallExpandedBodyClassName).toContain("var(--font-size-code");
243 expect(toolCallExpandedBodyClassName).not.toContain("text-[11px]");
244 });
245
246 it("uses the larger leading inset only when the top fade is enabled", () => {
247 const timelineEntries = [buildUserTimelineEntry("Hello")];
248
249 const compactMarkup = renderToStaticMarkup(
250 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} />,
251 );
252 const fadedMarkup = renderToStaticMarkup(
253 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} topFadeEnabled />,
254 );
255
256 expect(compactMarkup).toContain('class="h-3 sm:h-4"');
257 expect(compactMarkup).not.toContain("topbar-scroll-fade");
258 expect(fadedMarkup).toContain('class="h-10 sm:h-12"');
259 expect(fadedMarkup).toContain("topbar-scroll-fade");
260 });
261
262 it("keeps assistant changed-files headers sticky below the thread header", () => {
263 const assistantMessageId = MessageId.make("message-assistant-with-files");
264 const turnId = TurnId.make("turn-with-files");
265 const markup = renderToStaticMarkup(
266 <MessagesTimeline
267 {...buildProps()}
268 latestTurn={{
269 turnId,
270 state: "completed",
271 startedAt: MESSAGE_CREATED_AT,
272 completedAt: MESSAGE_CREATED_AT,
273 }}
274 timelineEntries={[
275 {
276 id: "entry-assistant-with-files",
277 kind: "message",
278 createdAt: MESSAGE_CREATED_AT,
279 message: {
280 id: assistantMessageId,
281 role: "assistant",
282 text: "Updated the fixture.",
283 turnId,
284 createdAt: MESSAGE_CREATED_AT,
285 updatedAt: MESSAGE_CREATED_AT,
286 streaming: false,
287 },
288 },
289 ]}
290 turnDiffSummaryByAssistantMessageId={
291 new Map([
292 [
293 assistantMessageId,
294 {
295 turnId,
296 checkpointTurnCount: 1,
297 checkpointRef: CheckpointRef.make("checkpoint-with-files"),
298 status: "ready",
299 files: [{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }],
300 assistantMessageId,
301 completedAt: MESSAGE_CREATED_AT,
302 },
303 ],
304 ])
305 }
306 />,
307 );
308
309 expect(markup).toContain("sticky top-2 z-10");
310 expect(markup).not.toContain("self-start");
311 expect(markup).toContain("whitespace-nowrap");
312 expect(markup).toContain("!size-[22px]");
313 expect(markup).toContain("size-3");
314 expect(markup).toContain('aria-label="Collapse all folders"');
315 expect(markup).toContain('aria-label="Open diff"');
316 expect(markup).toContain("1 changed file");
317 });
318
319 it("treats only the strict list end as the live edge", async () => {
320 const {
321 resolveTimelineIsAtEnd,
322 resolveTimelineMinimapHasPersistentGutter,
323 resolveTimelineMinimapHeightStyle,
324 resolveTimelineMinimapHitStripWidth,
325 resolveTimelineMinimapIndexFromPointer,
326 resolveTimelineMinimapInteractiveWidth,
327 resolveTimelineMinimapTopPercent,
328 } = await import("./MessagesTimeline.logic");
329
330 expect(resolveTimelineIsAtEnd({ isAtEnd: true })).toBe(true);
331 expect(resolveTimelineIsAtEnd(undefined)).toBeUndefined();
332 // Within the pixel band above the content bottom counts as the end...
333 expect(
334 resolveTimelineIsAtEnd({
335 isAtEnd: false,
336 contentLength: 2000,
337 scroll: 1170,
338 scrollLength: 800,
339 }),
340 ).toBe(true);
341 // ...but half a viewport up (LegendList's isNearEnd territory) does not.
342 expect(
343 resolveTimelineIsAtEnd({
344 isAtEnd: false,
345 contentLength: 2000,
346 scroll: 900,
347 scrollLength: 800,
348 }),
349 ).toBe(false);
350 // The composer inset is part of contentLength and must not count as
351 // distance-to-end.
352 expect(
353 resolveTimelineIsAtEnd(
354 { isAtEnd: false, contentLength: 2100, scroll: 1170, scrollLength: 800 },
355 100,
356 ),
357 ).toBe(true);
358 // Geometry missing (older state shape): fall back to the strict flag.
359 expect(resolveTimelineIsAtEnd({ isAtEnd: false })).toBe(false);
360
361 expect(resolveTimelineMinimapHeightStyle(5)).toBe("min(32px, calc(100vh - 18rem))");
362 expect(resolveTimelineMinimapTopPercent(2, 5)).toBe(50);
363 expect(
364 resolveTimelineMinimapIndexFromPointer({
365 itemCount: 101,
366 railTop: 100,
367 railHeight: 500,
368 pointerY: 350,
369 }),
370 ).toBe(50);
371 expect(
372 resolveTimelineMinimapIndexFromPointer({
373 itemCount: 101,
374 railTop: 100,
375 railHeight: 500,
376 pointerY: 999,
377 }),
378 ).toBe(100);
379 expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
380 expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
381 expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);
382
383 // No usable gutter (zoomed in / narrow pane): the strip must go inert
384 // instead of overlaying the centered content column.
385 expect(resolveTimelineMinimapHitStripWidth(768)).toBe(0);
386 expect(resolveTimelineMinimapHitStripWidth(792)).toBe(0);
387 // Partial gutter: strip shrinks to what fits between the viewport edge
388 // and the content column.
389 expect(resolveTimelineMinimapHitStripWidth(820)).toBe(14);
390 // Full gutter: unchanged 40px-wide strip.
391 expect(resolveTimelineMinimapHitStripWidth(872)).toBe(40);
392 expect(resolveTimelineMinimapHitStripWidth(1400)).toBe(40);
393 expect(resolveTimelineMinimapHitStripWidth(0)).toBe(0);
394 expect(resolveTimelineMinimapHitStripWidth(Number.NaN)).toBe(0);
395
396 // The collapsed target stays narrow, but an open preview keeps its full
397 // 20rem width plus the 2rem offset from the minimap rail interactive.
398 expect(resolveTimelineMinimapInteractiveWidth(0, false)).toBe(0);
399 expect(resolveTimelineMinimapInteractiveWidth(14, false)).toBe(14);
400 expect(resolveTimelineMinimapInteractiveWidth(40, false)).toBe(40);
401 expect(resolveTimelineMinimapInteractiveWidth(0, true)).toBe("22rem");
402 expect(resolveTimelineMinimapInteractiveWidth(14, true)).toBe("22rem");
403 expect(resolveTimelineMinimapInteractiveWidth(40, true)).toBe("22rem");
404 });
405
406 it("anchors a sent attachment message using its measured height", () => {
407 const onAnchorReady = vi.fn();
408 const firstEntry = buildUserTimelineEntry("First prompt.");
409 const secondEntry = {
410 ...buildUserTimelineEntry("Newest prompt."),
411 id: "entry-2",
412 message: {
413 ...buildUserTimelineEntry("Newest prompt.").message,
414 id: MessageId.make("message-2"),
415 attachments: [
416 {
417 type: "image" as const,
418 id: "attachment-1",
419 name: "screenshot.png",
420 mimeType: "image/png",
421 sizeBytes: 1,
422 previewUrl: "data:image/png;base64,iVBORw0KGgo=",
423 },
424 ],
425 },
426 };
427 const markup = renderToStaticMarkup(
428 <MessagesTimeline
429 {...buildProps()}
430 anchorMessageId={secondEntry.message.id}
431 onAnchorReady={onAnchorReady}
432 contentInsetEndAdjustment={144}
433 timelineEntries={[firstEntry, secondEntry]}
434 />,
435 );
436
437 expect(markup).toContain('data-anchor-index="1"');
438 expect(markup).toContain('data-anchor-offset="16"');
439 expect(markup).toContain('data-anchor-on-ready="true"');
440 expect(markup).not.toContain("data-anchor-max-size=");
441 expect(markup).toContain('data-content-inset-end="144"');
442 expect(markup).toContain("[overflow-anchor:none]");
443 expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
444 expect(markup).toContain('data-maintain-visible-content-position="object"');
445 expect(markup).toContain('data-maintain-visible-content-position-data="true"');
446 expect(markup).toContain('data-maintain-visible-content-position-size="true"');
447 expect(markup).toContain('data-maintain-visible-content-position-restore="true"');
448 expect(onAnchorReady).toHaveBeenCalledOnce();
449 expect(onAnchorReady).toHaveBeenCalledWith(secondEntry.message.id, 1);
450 });
451
452 it("renders collapse controls for long user messages", () => {
453 const markup = renderToStaticMarkup(
454 <MessagesTimeline
455 {...buildProps()}
456 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
457 />,
458 );
459
460 expect(markup).toContain("Show full message");
461 expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
462 expect(markup).toContain('data-maintain-scroll-at-end-animated="false"');
463 expect(markup).toContain('data-maintain-scroll-at-end-data-change="true"');
464 expect(markup).toContain('data-maintain-scroll-at-end-item-layout="true"');
465 expect(markup).toContain('data-maintain-scroll-at-end-layout="true"');
466 expect(markup).toContain('data-user-message-collapsed="true"');
467 expect(markup).toContain('data-user-message-fade="true"');
468 expect(markup).toContain('data-user-message-footer="true"');
469 });
470
471 it("does not render collapse controls for short user messages", () => {
472 const markup = renderToStaticMarkup(
473 <MessagesTimeline
474 {...buildProps()}
475 timelineEntries={[buildUserTimelineEntry("Short prompt.")]}
476 />,
477 );
478
479 expect(markup).not.toContain("Show full message");
480 expect(markup).toContain('data-user-message-collapsible="false"');
481 expect(markup).toContain("rounded-2xl bg-message p-3");
482 });
483
484 it("preserves arbitrary XML-like tags and comparisons in rendered user messages", async () => {
485 const { MessagesTimeline } = await import("./MessagesTimeline");
486 const markup = renderToStaticMarkup(
487 <MessagesTimeline
488 {...buildProps()}
489 timelineEntries={[
490 buildUserTimelineEntry(
491 [
492 'Without reading a file, do you have <global-agent-instructions scope="workspace">',
493 'Before <nested data-value="a&b">inside</nested> after',
494 "</global-agent-instructions> in your context?",
495 "Comparison: 2 < 3 and 5 > 4.",
496 ].join("\n"),
497 ),
498 ]}
499 />,
500 );
501
502 expect(markup).toContain("<global-agent-instructions scope="workspace">");
503 expect(markup).toContain(
504 "Before <nested data-value="a&b">inside</nested> after",
505 );
506 expect(markup).toContain("</global-agent-instructions> in your context?");
507 expect(markup).toContain("Comparison: 2 < 3 and 5 > 4.");
508 });
509
510 it("preserves XML-like source inside user code spans and fences", async () => {
511 const { MessagesTimeline } = await import("./MessagesTimeline");
512 const markup = renderToStaticMarkup(
513 <MessagesTimeline
514 {...buildProps()}
515 timelineEntries={[
516 buildUserTimelineEntry(
517 [
518 'Inline `<tag attr="x">`',
519 "",
520 "```xml",
521 '<root><child enabled="true" /></root>',
522 "```",
523 ].join("\n"),
524 ),
525 ]}
526 />,
527 );
528
529 expect(markup).toContain('<code data-inline-code=""><tag attr="x"></code>');
530 expect(markup).toContain("<root><child enabled="true" /></root>");
531 });
532
533 it("does not render markdown title attributes in user messages", async () => {
534 const { MessagesTimeline } = await import("./MessagesTimeline");
535 const markup = renderToStaticMarkup(
536 <MessagesTimeline
537 {...buildProps()}
538 timelineEntries={[
539 buildUserTimelineEntry(
540 '[link](https://example.com "link tip") ',
541 ),
542 ]}
543 />,
544 );
545
546 expect(markup).toContain('href="https://example.com"');
547 expect(markup).toContain('src="https://example.com/image.png"');
548 expect(markup).not.toContain('title="link tip"');
549 expect(markup).not.toContain('title="image tip"');
550 });
551
552 it("renders unsafe user HTML as inert source text", async () => {
553 const { MessagesTimeline } = await import("./MessagesTimeline");
554 const markup = renderToStaticMarkup(
555 <MessagesTimeline
556 {...buildProps()}
557 timelineEntries={[
558 buildUserTimelineEntry(
559 '<script>globalThis.__t3Xss = 1</script><img src="x" onerror="globalThis.__t3Xss = 2">',
560 ),
561 ]}
562 />,
563 );
564
565 expect(markup).toContain("<script>globalThis.__t3Xss = 1</script>");
566 expect(markup).toContain(
567 "<img src="x" onerror="globalThis.__t3Xss = 2">",
568 );
569 expect(markup).not.toMatch(/<script(?:\s|>)/i);
570 expect(markup).not.toMatch(/<img(?:\s|>)/i);
571 });
572
573 it("continues to render sanitized raw HTML in assistant messages", async () => {
574 const { MessagesTimeline } = await import("./MessagesTimeline");
575 const markup = renderToStaticMarkup(
576 <MessagesTimeline
577 {...buildProps()}
578 timelineEntries={[
579 buildAssistantTimelineEntry("<details><summary>More</summary>Details</details>"),
580 ]}
581 />,
582 );
583
584 expect(markup).toContain('data-markdown-details=""');
585 expect(markup).toContain("More");
586 expect(markup).not.toContain("<details>");
587 });
588
589 it("sanitizes executable HTML while preserving supported assistant markup", async () => {
590 const { MessagesTimeline } = await import("./MessagesTimeline");
591 const markup = renderToStaticMarkup(
592 <MessagesTimeline
593 {...buildProps()}
594 timelineEntries={[
595 buildAssistantTimelineEntry(
596 [
597 '<details open onclick="globalThis.__t3Xss = 1">',
598 "<summary>Safe details</summary>",
599 "<script>globalThis.__t3Xss = 2</script>",
600 '<img src="x" onerror="globalThis.__t3Xss = 3">',
601 '<a href="javascript:globalThis.__t3Xss = 4">Unsafe link</a>',
602 "</details>",
603 ].join(""),
604 ),
605 ]}
606 />,
607 );
608
609 expect(markup).toContain('data-markdown-details=""');
610 expect(markup).toContain("Safe details");
611 expect(markup).not.toMatch(/<script(?:\s|>)/i);
612 expect(markup).not.toContain("onclick=");
613 expect(markup).not.toContain("onerror=");
614 expect(markup).not.toContain("javascript:");
615 expect(markup).not.toContain("globalThis.__t3Xss");
616 });
617
618 it("renders inline terminal labels with the composer chip UI", async () => {
619 const { MessagesTimeline } = await import("./MessagesTimeline");
620 const markup = renderToStaticMarkup(
621 <MessagesTimeline
622 {...buildProps()}
623 timelineEntries={[
624 buildUserTimelineEntry(
625 [
626 buildLongUserMessageText("yoo what's @terminal-1:1-5 mean"),
627 "",
628 "<terminal_context>",
629 "- Terminal 1 lines 1-5:",
630 " 1 | julius@mac effect-http-ws-cli % bun i",
631 " 2 | bun install v1.3.9 (cf6cdbbb)",
632 "</terminal_context>",
633 ].join("\n"),
634 ),
635 ]}
636 />,
637 );
638
639 expect(markup).toContain("Terminal 1 lines 1-5");
640 expect(markup).toContain("lucide-terminal");
641 expect(markup).toContain("yoo what's</p>");
642 expect(markup).toContain('<span aria-hidden="true"> </span>');
643 expect(markup).toContain("Show full message");
644 }, 20_000);
645
646 it("renders chips for standalone element-pick context messages", () => {
647 const markup = renderToStaticMarkup(
648 <MessagesTimeline
649 {...buildProps()}
650 timelineEntries={[
651 buildUserTimelineEntry(
652 [
653 "<element_context>",
654 "- <SubmitButton> (Button.tsx:12):",
655 " url: https://example.com/dashboard",
656 " selector: button.submit",
657 " source: /repo/src/Button.tsx:12:5",
658 " html:",
659 ' <button class="submit">Save</button>',
660 "</element_context>",
661 ].join("\n"),
662 ),
663 ]}
664 />,
665 );
666
667 expect(markup).toContain("SubmitButton");
668 expect(markup).not.toContain("<element_context");
669 expect(markup).not.toContain("<element_context");
670 });
671
672 it("keeps the copy button for collapsed long user messages", () => {
673 const markup = renderToStaticMarkup(
674 <MessagesTimeline
675 {...buildProps()}
676 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
677 />,
678 );
679
680 expect(markup).toContain('aria-label="Copy link"');
681 expect(markup).toContain('data-user-message-collapsed="true"');
682 expect(markup).toContain('data-user-message-footer="true"');
683 });
684
685 it("renders context compaction entries in the normal work log", () => {
686 const markup = renderToStaticMarkup(
687 <MessagesTimeline
688 {...buildProps()}
689 timelineEntries={[
690 {
691 id: "entry-1",
692 kind: "work",
693 createdAt: "2026-03-17T19:12:28.000Z",
694 entry: {
695 id: "work-1",
696 createdAt: "2026-03-17T19:12:28.000Z",
697 label: "Context compacted",
698 tone: "info",
699 },
700 },
701 ]}
702 />,
703 );
704
705 expect(markup).toContain("Context compacted");
706 expect(markup).toContain("Work Log");
707 });
708
709 it("formats changed file paths from the workspace root", () => {
710 const markup = renderToStaticMarkup(
711 <MessagesTimeline
712 {...buildProps()}
713 timelineEntries={[
714 {
715 id: "entry-1",
716 kind: "work",
717 createdAt: "2026-03-17T19:12:28.000Z",
718 entry: {
719 id: "work-1",
720 createdAt: "2026-03-17T19:12:28.000Z",
721 label: "Updated files",
722 tone: "tool",
723 changedFiles: ["C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts"],
724 },
725 },
726 ]}
727 workspaceRoot="C:/Users/mike/dev-stuff/t3code"
728 />,
729 );
730
731 expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
732 expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
733 });
734
735 it("renders review comment contexts as structured cards instead of raw tags", () => {
736 const markup = renderToStaticMarkup(
737 <MessagesTimeline
738 {...buildProps()}
739 timelineEntries={[
740 {
741 id: "entry-1",
742 kind: "message",
743 createdAt: "2026-03-17T19:12:28.000Z",
744 message: {
745 id: MessageId.make("message-2"),
746 role: "user",
747 text: [
748 '<review_comment sectionId="turn:2" sectionTitle="Turn 2" filePath="apps/web/src/lib/contextWindow.test.ts" startIndex="3" endIndex="14" rangeLabel="+47 to +58">',
749 "Wadduo",
750 "```diff",
751 "@@ -0,0 +47,2 @@",
752 '+ it("keeps valid zero-usage snapshots", () => {',
753 "+ expect(snapshot).not.toBeNull();",
754 "```",
755 "</review_comment>",
756 ].join("\n"),
757 turnId: null,
758 createdAt: "2026-03-17T19:12:28.000Z",
759 updatedAt: "2026-03-17T19:12:28.000Z",
760 streaming: false,
761 },
762 },
763 ]}
764 />,
765 );
766
767 expect(markup).toContain("contextWindow.test.ts");
768 expect(markup).toContain("Wadduo");
769 expect(markup).toContain('data-testid="file-diff"');
770 expect(markup).not.toContain(">Review comment<");
771 expect(markup).not.toContain("<review_comment");
772 expect(markup).not.toContain("</review_comment>");
773 });
774
775 it("renders file review comments as source code instead of diffs", () => {
776 const markup = renderToStaticMarkup(
777 <MessagesTimeline
778 {...buildProps()}
779 timelineEntries={[
780 {
781 id: "entry-1",
782 kind: "message",
783 createdAt: "2026-03-17T19:12:28.000Z",
784 message: {
785 id: MessageId.make("message-source-comment"),
786 role: "user",
787 text: [
788 '<review_comment sectionId="file:docs/plan.md" sectionTitle="File comment" filePath="docs/plan.md" startIndex="0" endIndex="1" rangeLabel="L1 to L2">',
789 "Clarify this.",
790 "```md",
791 "# Plan",
792 "- Step one",
793 "```",
794 "</review_comment>",
795 ].join("\n"),
796 turnId: null,
797 createdAt: "2026-03-17T19:12:28.000Z",
798 updatedAt: "2026-03-17T19:12:28.000Z",
799 streaming: false,
800 },
801 },
802 ]}
803 />,
804 );
805
806 expect(markup).toContain("plan.md");
807 expect(markup).toContain("Clarify this.");
808 expect(markup).toContain("# Plan");
809 expect(markup).not.toContain('data-testid="file-diff"');
810 });
811
812 it("renders a failure marker for failed tool lifecycle entries", () => {
813 const markup = renderToStaticMarkup(
814 <MessagesTimeline
815 {...buildProps()}
816 timelineEntries={[
817 {
818 id: "entry-1",
819 kind: "work",
820 createdAt: "2026-03-17T19:12:28.000Z",
821 entry: {
822 id: "work-1",
823 createdAt: "2026-03-17T19:12:28.000Z",
824 label: "Glob",
825 tone: "tool",
826 toolLifecycleStatus: "failed",
827 detail: "No files found",
828 },
829 },
830 ]}
831 />,
832 );
833
834 expect(markup).toContain("lucide-x");
835 expect(markup).toContain('aria-label="Tool call failed"');
836 });
837});