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

MessagesTimeline.test.tsx

853 lines28.6 KB

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 );
123​
124vi.mock("@pierre/diffs/react", () => {
125 return { FileDiff: MockFileDiff };
126});
127​
128function matchMedia() {
129 return {
130 matches: false,
131 addEventListener: () => {},
132 removeEventListener: () => {},
133 };
135​
136let MessagesTimeline: typeof import("./MessagesTimeline").MessagesTimeline;
137​
138beforeAll(async () => {
139 const classList = {
140 add: () => {},
141 remove: () => {},
142 toggle: () => {},
143 contains: () => false,
144 };
145​
146 vi.stubGlobal("localStorage", {
147 getItem: () => null,
148 setItem: () => {},
149 removeItem: () => {},
150 clear: () => {},
151 });
152 vi.stubGlobal("window", {
153 matchMedia,
154 addEventListener: () => {},
155 removeEventListener: () => {},
156 requestAnimationFrame: (callback: FrameRequestCallback) => {
157 callback(0);
158 return 0;
159 },
160 cancelAnimationFrame: () => {},
161 desktopBridge: undefined,
162 });
163 vi.stubGlobal("document", {
164 documentElement: {
165 classList,
166 offsetHeight: 0,
167 },
168 });
169​
170 ({ MessagesTimeline } = await import("./MessagesTimeline"));
171}, 30_000);
172​
173const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
174const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z";
175​
176function buildProps() {
177 return {
178 isWorking: false,
179 activeTurnInProgress: 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 onCancelQueuedMessage: () => {},
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 };
205​
206function buildLongUserMessageText(tail = "deep hidden detail only after expand") {
207 return Array.from({ length: 9 }, (_, index) =>
208 index === 8 ? tail : `Line ${index + 1}: ${"verbose prompt content ".repeat(8).trim()}`,
209 ).join("\n");
211​
212function buildUserTimelineEntry(text: string) {
213 return {
214 id: "entry-1",
215 kind: "message" as const,
216 createdAt: MESSAGE_CREATED_AT,
217 message: {
218 id: MessageId.make("message-1"),
219 role: "user" as const,
220 text,
221 turnId: null,
222 createdAt: MESSAGE_CREATED_AT,
223 updatedAt: MESSAGE_CREATED_AT,
224 streaming: false,
225 },
226 };
228​
229function buildAssistantTimelineEntry(text: string) {
230 const entry = buildUserTimelineEntry(text);
231 return {
232 ...entry,
233 message: {
234 ...entry.message,
235 role: "assistant" as const,
236 },
237 };
239​
240describe("MessagesTimeline", () => {
241 it("uses the larger leading inset only when the top fade is enabled", () => {
242 const timelineEntries = [buildUserTimelineEntry("Hello")];
243​
244 const compactMarkup = renderToStaticMarkup(
245 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} />,
246 );
247 const fadedMarkup = renderToStaticMarkup(
248 <MessagesTimeline {...buildProps()} timelineEntries={timelineEntries} topFadeEnabled />,
249 );
250​
251 expect(compactMarkup).toContain('class="h-3 sm:h-4"');
252 expect(compactMarkup).not.toContain("topbar-scroll-fade");
253 expect(fadedMarkup).toContain('class="h-10 sm:h-12"');
254 expect(fadedMarkup).toContain("topbar-scroll-fade");
255 });
256​
257 it("keeps assistant changed-files headers sticky below the thread header", () => {
258 const assistantMessageId = MessageId.make("message-assistant-with-files");
259 const turnId = TurnId.make("turn-with-files");
260 const markup = renderToStaticMarkup(
261 <MessagesTimeline
262 {...buildProps()}
263 latestTurn={{
264 turnId,
265 state: "completed",
266 startedAt: MESSAGE_CREATED_AT,
267 completedAt: MESSAGE_CREATED_AT,
268 }}
269 timelineEntries={[
270 {
271 id: "entry-assistant-with-files",
272 kind: "message",
273 createdAt: MESSAGE_CREATED_AT,
274 message: {
275 id: assistantMessageId,
276 role: "assistant",
277 text: "Updated the fixture.",
278 turnId,
279 createdAt: MESSAGE_CREATED_AT,
280 updatedAt: MESSAGE_CREATED_AT,
281 streaming: false,
282 },
283 },
284 ]}
285 turnDiffSummaryByAssistantMessageId={
286 new Map([
287 [
288 assistantMessageId,
289 {
290 turnId,
291 checkpointTurnCount: 1,
292 checkpointRef: CheckpointRef.make("checkpoint-with-files"),
293 status: "ready",
294 files: [{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }],
295 assistantMessageId,
296 completedAt: MESSAGE_CREATED_AT,
297 },
298 ],
299 ])
300 }
301 />,
302 );
303​
304 expect(markup).toContain("sticky top-2 z-10");
305 expect(markup).not.toContain("self-start");
306 expect(markup).toContain("whitespace-nowrap");
307 expect(markup).toContain("!size-[22px]");
308 expect(markup).toContain("size-3");
309 expect(markup).toContain('aria-label="Collapse all folders"');
310 expect(markup).toContain('aria-label="Open diff"');
311 expect(markup).toContain("1 changed file");
312 });
313​
314 it("treats only the strict list end as the live edge", async () => {
315 const {
316 resolveTimelineIsAtEnd,
317 resolveTimelineMinimapHasPersistentGutter,
318 resolveTimelineMinimapHeightStyle,
319 resolveTimelineMinimapHitStripWidth,
320 resolveTimelineMinimapIndexFromPointer,
321 resolveTimelineMinimapInteractiveWidth,
322 resolveTimelineMinimapTopPercent,
323 } = await import("./MessagesTimeline.logic");
324​
325 expect(resolveTimelineIsAtEnd({ isAtEnd: true })).toBe(true);
326 expect(resolveTimelineIsAtEnd(undefined)).toBeUndefined();
327 // Within the pixel band above the content bottom counts as the end...
328 expect(
329 resolveTimelineIsAtEnd({
330 isAtEnd: false,
331 contentLength: 2000,
332 scroll: 1170,
333 scrollLength: 800,
334 }),
335 ).toBe(true);
336 // ...but half a viewport up (LegendList's isNearEnd territory) does not.
337 expect(
338 resolveTimelineIsAtEnd({
339 isAtEnd: false,
340 contentLength: 2000,
341 scroll: 900,
342 scrollLength: 800,
343 }),
344 ).toBe(false);
345 // The composer inset is part of contentLength and must not count as
346 // distance-to-end.
347 expect(
348 resolveTimelineIsAtEnd(
349 { isAtEnd: false, contentLength: 2100, scroll: 1170, scrollLength: 800 },
350 100,
351 ),
352 ).toBe(true);
353 // Geometry missing (older state shape): fall back to the strict flag.
354 expect(resolveTimelineIsAtEnd({ isAtEnd: false })).toBe(false);
355​
356 expect(resolveTimelineMinimapHeightStyle(5)).toBe("min(32px, calc(100vh - 18rem))");
357 expect(resolveTimelineMinimapTopPercent(2, 5)).toBe(50);
358 expect(
359 resolveTimelineMinimapIndexFromPointer({
360 itemCount: 101,
361 railTop: 100,
362 railHeight: 500,
363 pointerY: 350,
364 }),
365 ).toBe(50);
366 expect(
367 resolveTimelineMinimapIndexFromPointer({
368 itemCount: 101,
369 railTop: 100,
370 railHeight: 500,
371 pointerY: 999,
372 }),
373 ).toBe(100);
374 expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
375 expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
376 expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);
377​
378 // No usable gutter (zoomed in / narrow pane): the strip must go inert
379 // instead of overlaying the centered content column.
380 expect(resolveTimelineMinimapHitStripWidth(768)).toBe(0);
381 expect(resolveTimelineMinimapHitStripWidth(792)).toBe(0);
382 // Partial gutter: strip shrinks to what fits between the viewport edge
383 // and the content column.
384 expect(resolveTimelineMinimapHitStripWidth(820)).toBe(14);
385 // Full gutter: unchanged 40px-wide strip.
386 expect(resolveTimelineMinimapHitStripWidth(872)).toBe(40);
387 expect(resolveTimelineMinimapHitStripWidth(1400)).toBe(40);
388 expect(resolveTimelineMinimapHitStripWidth(0)).toBe(0);
389 expect(resolveTimelineMinimapHitStripWidth(Number.NaN)).toBe(0);
390​
391 // The collapsed target stays narrow, but an open preview keeps its full
392 // 20rem width plus the 2rem offset from the minimap rail interactive.
393 expect(resolveTimelineMinimapInteractiveWidth(0, false)).toBe(0);
394 expect(resolveTimelineMinimapInteractiveWidth(14, false)).toBe(14);
395 expect(resolveTimelineMinimapInteractiveWidth(40, false)).toBe(40);
396 expect(resolveTimelineMinimapInteractiveWidth(0, true)).toBe("22rem");
397 expect(resolveTimelineMinimapInteractiveWidth(14, true)).toBe("22rem");
398 expect(resolveTimelineMinimapInteractiveWidth(40, true)).toBe("22rem");
399 });
400​
401 it("anchors a sent attachment message using its measured height", () => {
402 const onAnchorReady = vi.fn();
403 const firstEntry = buildUserTimelineEntry("First prompt.");
404 const secondEntry = {
405 ...buildUserTimelineEntry("Newest prompt."),
406 id: "entry-2",
407 message: {
408 ...buildUserTimelineEntry("Newest prompt.").message,
409 id: MessageId.make("message-2"),
410 attachments: [
411 {
412 type: "image" as const,
413 id: "attachment-1",
414 name: "screenshot.png",
415 mimeType: "image/png",
416 sizeBytes: 1,
417 previewUrl: "data:image/png;base64,iVBORw0KGgo=",
418 },
419 ],
420 },
421 };
422 const markup = renderToStaticMarkup(
423 <MessagesTimeline
424 {...buildProps()}
425 anchorMessageId={secondEntry.message.id}
426 onAnchorReady={onAnchorReady}
427 contentInsetEndAdjustment={144}
428 timelineEntries={[firstEntry, secondEntry]}
429 />,
430 );
431​
432 expect(markup).toContain('data-anchor-index="1"');
433 expect(markup).toContain('data-anchor-offset="16"');
434 expect(markup).toContain('data-anchor-on-ready="true"');
435 expect(markup).not.toContain("data-anchor-max-size=");
436 expect(markup).toContain('data-content-inset-end="144"');
437 expect(markup).toContain("[overflow-anchor:none]");
438 expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
439 expect(markup).toContain('data-maintain-visible-content-position="object"');
440 expect(markup).toContain('data-maintain-visible-content-position-data="true"');
441 expect(markup).toContain('data-maintain-visible-content-position-size="true"');
442 expect(markup).toContain('data-maintain-visible-content-position-restore="true"');
443 expect(onAnchorReady).toHaveBeenCalledOnce();
444 expect(onAnchorReady).toHaveBeenCalledWith(secondEntry.message.id, 1);
445 });
446​
447 it("renders collapse controls for long user messages", () => {
448 const markup = renderToStaticMarkup(
449 <MessagesTimeline
450 {...buildProps()}
451 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
452 />,
453 );
454​
455 expect(markup).toContain("Show full message");
456 expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
457 expect(markup).toContain('data-maintain-scroll-at-end-animated="false"');
458 expect(markup).toContain('data-maintain-scroll-at-end-data-change="true"');
459 expect(markup).toContain('data-maintain-scroll-at-end-item-layout="true"');
460 expect(markup).toContain('data-maintain-scroll-at-end-layout="true"');
461 expect(markup).toContain('data-user-message-collapsed="true"');
462 expect(markup).toContain('data-user-message-fade="true"');
463 expect(markup).toContain('data-user-message-footer="true"');
464 });
465​
466 it("does not render collapse controls for short user messages", () => {
467 const markup = renderToStaticMarkup(
468 <MessagesTimeline
469 {...buildProps()}
470 timelineEntries={[buildUserTimelineEntry("Short prompt.")]}
471 />,
472 );
473​
474 expect(markup).not.toContain("Show full message");
475 expect(markup).toContain('data-user-message-collapsible="false"');
476 expect(markup).toContain("rounded-2xl bg-message p-3");
477 });
478​
479 it("keeps server-queued messages visibly cancellable", () => {
480 const entry = buildUserTimelineEntry("Run this next");
481 const markup = renderToStaticMarkup(
482 <MessagesTimeline
483 {...buildProps()}
484 timelineEntries={[
485 {
486 ...entry,
487 message: { ...entry.message, deliveryState: "queued" },
488 },
489 ]}
490 />,
491 );
492​
493 expect(markup).toContain("Queued");
494 expect(markup).toContain("Cancel");
495 expect(markup).toContain('aria-label="Cancel queued message"');
496 expect(markup).toContain('data-slot="button"');
497 expect(markup).toContain("opacity-100");
498 });
499​
500 it("preserves arbitrary XML-like tags and comparisons in rendered user messages", async () => {
501 const { MessagesTimeline } = await import("./MessagesTimeline");
502 const markup = renderToStaticMarkup(
503 <MessagesTimeline
504 {...buildProps()}
505 timelineEntries={[
506 buildUserTimelineEntry(
507 [
508 'Without reading a file, do you have <global-agent-instructions scope="workspace">',
509 'Before <nested data-value="a&b">inside</nested> after',
510 "</global-agent-instructions> in your context?",
511 "Comparison: 2 < 3 and 5 > 4.",
512 ].join("\n"),
513 ),
514 ]}
515 />,
516 );
517​
518 expect(markup).toContain("&lt;global-agent-instructions scope=&quot;workspace&quot;&gt;");
519 expect(markup).toContain(
520 "Before &lt;nested data-value=&quot;a&amp;b&quot;&gt;inside&lt;/nested&gt; after",
521 );
522 expect(markup).toContain("&lt;/global-agent-instructions&gt; in your context?");
523 expect(markup).toContain("Comparison: 2 &lt; 3 and 5 &gt; 4.");
524 });
525​
526 it("preserves XML-like source inside user code spans and fences", async () => {
527 const { MessagesTimeline } = await import("./MessagesTimeline");
528 const markup = renderToStaticMarkup(
529 <MessagesTimeline
530 {...buildProps()}
531 timelineEntries={[
532 buildUserTimelineEntry(
533 [
534 'Inline `<tag attr="x">`',
535 "",
536 "```xml",
537 '<root><child enabled="true" /></root>',
538 "```",
539 ].join("\n"),
540 ),
541 ]}
542 />,
543 );
544​
545 expect(markup).toContain('<code data-inline-code="">&lt;tag attr=&quot;x&quot;&gt;</code>');
546 expect(markup).toContain("&lt;root&gt;&lt;child enabled=&quot;true&quot; /&gt;&lt;/root&gt;");
547 });
548​
549 it("does not render markdown title attributes in user messages", async () => {
550 const { MessagesTimeline } = await import("./MessagesTimeline");
551 const markup = renderToStaticMarkup(
552 <MessagesTimeline
553 {...buildProps()}
554 timelineEntries={[
555 buildUserTimelineEntry(
556 '[link](https://example.com "link tip") ![image](https://example.com/image.png "image tip")',
557 ),
558 ]}
559 />,
560 );
561​
562 expect(markup).toContain('href="https://example.com"');
563 expect(markup).toContain('src="https://example.com/image.png"');
564 expect(markup).not.toContain('title="link tip"');
565 expect(markup).not.toContain('title="image tip"');
566 });
567​
568 it("renders unsafe user HTML as inert source text", async () => {
569 const { MessagesTimeline } = await import("./MessagesTimeline");
570 const markup = renderToStaticMarkup(
571 <MessagesTimeline
572 {...buildProps()}
573 timelineEntries={[
574 buildUserTimelineEntry(
575 '<script>globalThis.__t3Xss = 1</script><img src="x" onerror="globalThis.__t3Xss = 2">',
576 ),
577 ]}
578 />,
579 );
580​
581 expect(markup).toContain("&lt;script&gt;globalThis.__t3Xss = 1&lt;/script&gt;");
582 expect(markup).toContain(
583 "&lt;img src=&quot;x&quot; onerror=&quot;globalThis.__t3Xss = 2&quot;&gt;",
584 );
585 expect(markup).not.toMatch(/<script(?:\s|>)/i);
586 expect(markup).not.toMatch(/<img(?:\s|>)/i);
587 });
588​
589 it("continues to render sanitized raw HTML in assistant messages", async () => {
590 const { MessagesTimeline } = await import("./MessagesTimeline");
591 const markup = renderToStaticMarkup(
592 <MessagesTimeline
593 {...buildProps()}
594 timelineEntries={[
595 buildAssistantTimelineEntry("<details><summary>More</summary>Details</details>"),
596 ]}
597 />,
598 );
599​
600 expect(markup).toContain('data-markdown-details=""');
601 expect(markup).toContain("More");
602 expect(markup).not.toContain("&lt;details&gt;");
603 });
604​
605 it("sanitizes executable HTML while preserving supported assistant markup", async () => {
606 const { MessagesTimeline } = await import("./MessagesTimeline");
607 const markup = renderToStaticMarkup(
608 <MessagesTimeline
609 {...buildProps()}
610 timelineEntries={[
611 buildAssistantTimelineEntry(
612 [
613 '<details open onclick="globalThis.__t3Xss = 1">',
614 "<summary>Safe details</summary>",
615 "<script>globalThis.__t3Xss = 2</script>",
616 '<img src="x" onerror="globalThis.__t3Xss = 3">',
617 '<a href="javascript:globalThis.__t3Xss = 4">Unsafe link</a>',
618 "</details>",
619 ].join(""),
620 ),
621 ]}
622 />,
623 );
624​
625 expect(markup).toContain('data-markdown-details=""');
626 expect(markup).toContain("Safe details");
627 expect(markup).not.toMatch(/<script(?:\s|>)/i);
628 expect(markup).not.toContain("onclick=");
629 expect(markup).not.toContain("onerror=");
630 expect(markup).not.toContain("javascript:");
631 expect(markup).not.toContain("globalThis.__t3Xss");
632 });
633​
634 it("renders inline terminal labels with the composer chip UI", async () => {
635 const { MessagesTimeline } = await import("./MessagesTimeline");
636 const markup = renderToStaticMarkup(
637 <MessagesTimeline
638 {...buildProps()}
639 timelineEntries={[
640 buildUserTimelineEntry(
641 [
642 buildLongUserMessageText("yoo what's @terminal-1:1-5 mean"),
643 "",
644 "<terminal_context>",
645 "- Terminal 1 lines 1-5:",
646 " 1 | julius@mac effect-http-ws-cli % bun i",
647 " 2 | bun install v1.3.9 (cf6cdbbb)",
648 "</terminal_context>",
649 ].join("\n"),
650 ),
651 ]}
652 />,
653 );
654​
655 expect(markup).toContain("Terminal 1 lines 1-5");
656 expect(markup).toContain("lucide-terminal");
657 expect(markup).toContain("yoo what&#x27;s</p>");
658 expect(markup).toContain('<span aria-hidden="true"> </span>');
659 expect(markup).toContain("Show full message");
660 }, 20_000);
661​
662 it("renders chips for standalone element-pick context messages", () => {
663 const markup = renderToStaticMarkup(
664 <MessagesTimeline
665 {...buildProps()}
666 timelineEntries={[
667 buildUserTimelineEntry(
668 [
669 "<element_context>",
670 "- <SubmitButton> (Button.tsx:12):",
671 " url: https://example.com/dashboard",
672 " selector: button.submit",
673 " source: /repo/src/Button.tsx:12:5",
674 " html:",
675 ' <button class="submit">Save</button>',
676 "</element_context>",
677 ].join("\n"),
678 ),
679 ]}
680 />,
681 );
682​
683 expect(markup).toContain("SubmitButton");
684 expect(markup).not.toContain("&lt;element_context");
685 expect(markup).not.toContain("<element_context");
686 });
687​
688 it("keeps the copy button for collapsed long user messages", () => {
689 const markup = renderToStaticMarkup(
690 <MessagesTimeline
691 {...buildProps()}
692 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
693 />,
694 );
695​
696 expect(markup).toContain('aria-label="Copy link"');
697 expect(markup).toContain('data-user-message-collapsed="true"');
698 expect(markup).toContain('data-user-message-footer="true"');
699 });
700​
701 it("renders context compaction entries in the normal work log", () => {
702 const markup = renderToStaticMarkup(
703 <MessagesTimeline
704 {...buildProps()}
705 timelineEntries={[
706 {
707 id: "entry-1",
708 kind: "work",
709 createdAt: "2026-03-17T19:12:28.000Z",
710 entry: {
711 id: "work-1",
712 createdAt: "2026-03-17T19:12:28.000Z",
713 label: "Context compacted",
714 tone: "info",
715 },
716 },
717 ]}
718 />,
719 );
720​
721 expect(markup).toContain("Context compacted");
722 expect(markup).toContain("Work Log");
723 });
724​
725 it("formats changed file paths from the workspace root", () => {
726 const markup = renderToStaticMarkup(
727 <MessagesTimeline
728 {...buildProps()}
729 timelineEntries={[
730 {
731 id: "entry-1",
732 kind: "work",
733 createdAt: "2026-03-17T19:12:28.000Z",
734 entry: {
735 id: "work-1",
736 createdAt: "2026-03-17T19:12:28.000Z",
737 label: "Updated files",
738 tone: "tool",
739 changedFiles: ["C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts"],
740 },
741 },
742 ]}
743 workspaceRoot="C:/Users/mike/dev-stuff/t3code"
744 />,
745 );
746​
747 expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
748 expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
749 });
750​
751 it("renders review comment contexts as structured cards instead of raw tags", () => {
752 const markup = renderToStaticMarkup(
753 <MessagesTimeline
754 {...buildProps()}
755 timelineEntries={[
756 {
757 id: "entry-1",
758 kind: "message",
759 createdAt: "2026-03-17T19:12:28.000Z",
760 message: {
761 id: MessageId.make("message-2"),
762 role: "user",
763 text: [
764 '<review_comment sectionId="turn:2" sectionTitle="Turn 2" filePath="apps/web/src/lib/contextWindow.test.ts" startIndex="3" endIndex="14" rangeLabel="+47 to +58">',
765 "Wadduo",
766 "```diff",
767 "@@ -0,0 +47,2 @@",
768 '+ it("keeps valid zero-usage snapshots", () => {',
769 "+ expect(snapshot).not.toBeNull();",
770 "```",
771 "</review_comment>",
772 ].join("\n"),
773 turnId: null,
774 createdAt: "2026-03-17T19:12:28.000Z",
775 updatedAt: "2026-03-17T19:12:28.000Z",
776 streaming: false,
777 },
778 },
779 ]}
780 />,
781 );
782​
783 expect(markup).toContain("contextWindow.test.ts");
784 expect(markup).toContain("Wadduo");
785 expect(markup).toContain('data-testid="file-diff"');
786 expect(markup).not.toContain(">Review comment<");
787 expect(markup).not.toContain("&lt;review_comment");
788 expect(markup).not.toContain("&lt;/review_comment&gt;");
789 });
790​
791 it("renders file review comments as source code instead of diffs", () => {
792 const markup = renderToStaticMarkup(
793 <MessagesTimeline
794 {...buildProps()}
795 timelineEntries={[
796 {
797 id: "entry-1",
798 kind: "message",
799 createdAt: "2026-03-17T19:12:28.000Z",
800 message: {
801 id: MessageId.make("message-source-comment"),
802 role: "user",
803 text: [
804 '<review_comment sectionId="file:docs/plan.md" sectionTitle="File comment" filePath="docs/plan.md" startIndex="0" endIndex="1" rangeLabel="L1 to L2">',
805 "Clarify this.",
806 "```md",
807 "# Plan",
808 "- Step one",
809 "```",
810 "</review_comment>",
811 ].join("\n"),
812 turnId: null,
813 createdAt: "2026-03-17T19:12:28.000Z",
814 updatedAt: "2026-03-17T19:12:28.000Z",
815 streaming: false,
816 },
817 },
818 ]}
819 />,
820 );
821​
822 expect(markup).toContain("plan.md");
823 expect(markup).toContain("Clarify this.");
824 expect(markup).toContain("# Plan");
825 expect(markup).not.toContain('data-testid="file-diff"');
826 });
827​
828 it("renders a failure marker for failed tool lifecycle entries", () => {
829 const markup = renderToStaticMarkup(
830 <MessagesTimeline
831 {...buildProps()}
832 timelineEntries={[
833 {
834 id: "entry-1",
835 kind: "work",
836 createdAt: "2026-03-17T19:12:28.000Z",
837 entry: {
838 id: "work-1",
839 createdAt: "2026-03-17T19:12:28.000Z",
840 label: "Glob",
841 tone: "tool",
842 toolLifecycleStatus: "failed",
843 detail: "No files found",
844 },
845 },
846 ]}
847 />,
848 );
849​
850 expect(markup).toContain("lucide-x");
851 expect(markup).toContain('aria-label="Tool call failed"');
852 });
853});