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

MessagesTimeline.test.tsx

1,009 lines33.0 KB

1import { EnvironmentId, MessageId, RunId, ThreadId } 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 onSizeChanged?: (size: 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.onSizeChanged?.(240);
46 props.anchoredEndSpace.onReady?.({ anchorIndex: props.anchoredEndSpace.anchorIndex });
47 }
48 return (
49 <div
50 data-testid={legendListTestId}
51 data-anchor-index={props.anchoredEndSpace?.anchorIndex}
52 data-anchor-max-size={props.anchoredEndSpace?.anchorMaxSize}
53 data-anchor-offset={props.anchoredEndSpace?.anchorOffset}
54 data-anchor-on-ready={Boolean(props.anchoredEndSpace?.onReady)}
55 data-content-inset-end={props.contentInsetEndAdjustment}
56 data-class-name={props.className}
57 data-maintain-scroll-at-end={props.maintainScrollAtEnd ? "enabled" : undefined}
58 data-maintain-scroll-at-end-animated={
59 typeof props.maintainScrollAtEnd === "object"
60 ? props.maintainScrollAtEnd.animated
61 : undefined
62 }
63 data-maintain-scroll-at-end-data-change={
64 typeof props.maintainScrollAtEnd === "object"
65 ? props.maintainScrollAtEnd.on?.dataChange
66 : undefined
67 }
68 data-maintain-scroll-at-end-item-layout={
69 typeof props.maintainScrollAtEnd === "object"
70 ? props.maintainScrollAtEnd.on?.itemLayout
71 : undefined
72 }
73 data-maintain-scroll-at-end-layout={
74 typeof props.maintainScrollAtEnd === "object"
75 ? props.maintainScrollAtEnd.on?.layout
76 : undefined
77 }
78 data-maintain-visible-content-position={
79 typeof props.maintainVisibleContentPosition === "object"
80 ? "object"
81 : props.maintainVisibleContentPosition
82 }
83 data-maintain-visible-content-position-data={
84 typeof props.maintainVisibleContentPosition === "object"
85 ? props.maintainVisibleContentPosition.data
86 : undefined
87 }
88 data-maintain-visible-content-position-size={
89 typeof props.maintainVisibleContentPosition === "object"
90 ? props.maintainVisibleContentPosition.size
91 : undefined
92 }
93 >
94 {props.ListHeaderComponent}
95 {props.data.map((item) => (
96 <div key={props.keyExtractor(item)}>{props.renderItem({ item })}</div>
97 ))}
98 {props.ListFooterComponent}
99 </div>
100 );
101 };
102​
103 return { LegendList };
104});
105​
106function MockFileDiff(props: {
107 fileDiff: { name?: string | null; prevName?: string | null };
108 renderCustomHeader?: (fileDiff: {
109 name?: string | null;
110 prevName?: string | null;
111 }) => React.ReactNode;
112}) {
113 return (
114 <div data-testid="file-diff">
115 {props.renderCustomHeader?.(props.fileDiff)}
116 {props.fileDiff.name ?? props.fileDiff.prevName ?? "diff"}
117 </div>
118 );
120​
121vi.mock("@pierre/diffs/react", () => {
122 return { FileDiff: MockFileDiff };
123});
124​
125function matchMedia() {
126 return {
127 matches: false,
128 addEventListener: () => {},
129 removeEventListener: () => {},
130 };
132​
133beforeAll(() => {
134 const classList = {
135 add: () => {},
136 remove: () => {},
137 toggle: () => {},
138 contains: () => false,
139 };
140​
141 vi.stubGlobal("localStorage", {
142 getItem: () => null,
143 setItem: () => {},
144 removeItem: () => {},
145 clear: () => {},
146 });
147 vi.stubGlobal("window", {
148 matchMedia,
149 addEventListener: () => {},
150 removeEventListener: () => {},
151 requestAnimationFrame: (callback: FrameRequestCallback) => {
152 callback(0);
153 return 0;
154 },
155 cancelAnimationFrame: () => {},
156 desktopBridge: undefined,
157 });
158 vi.stubGlobal("document", {
159 documentElement: {
160 classList,
161 offsetHeight: 0,
162 },
163 });
164});
165​
166const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
167const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z";
168​
169function buildProps() {
170 return {
171 isWorking: false,
172 activeTurnInProgress: false,
173 activeTurnStartedAt: null,
174 listRef: createRef<LegendListRef | null>(),
175 latestRun: null,
176 turnDiffSummaryByAssistantMessageId: new Map(),
177 routeThreadKey: "environment-local:thread-1",
178 onOpenTurnDiff: () => {},
179 onOpenThread: () => {},
180 onForkFromRun: async () => {},
181 onRollbackCheckpoint: () => {},
182 revertTurnCountByUserMessageId: new Map(),
183 onRevertUserMessage: () => {},
184 isRevertingCheckpoint: false,
185 onImageExpand: () => {},
186 activeThreadEnvironmentId: ACTIVE_THREAD_ENVIRONMENT_ID,
187 markdownCwd: undefined,
188 resolvedTheme: "light" as const,
189 timestampFormat: "locale" as const,
190 workspaceRoot: undefined,
191 anchorMessageId: null,
192 onAnchorReady: () => {},
193 onAnchorSizeChanged: () => {},
194 contentInsetEndAdjustment: 0,
195 onIsAtEndChange: () => {},
196 onManualNavigation: () => {},
197 };
199​
200function buildLongUserMessageText(tail = "deep hidden detail only after expand") {
201 return Array.from({ length: 9 }, (_, index) =>
202 index === 8 ? tail : `Line ${index + 1}: ${"verbose prompt content ".repeat(8).trim()}`,
203 ).join("\n");
205​
206function buildUserTimelineEntry(text: string) {
207 return {
208 id: "entry-1",
209 kind: "message" as const,
210 createdAt: MESSAGE_CREATED_AT,
211 message: {
212 id: MessageId.make("message-1"),
213 role: "user" as const,
214 text,
215 runId: null,
216 createdAt: MESSAGE_CREATED_AT,
217 updatedAt: MESSAGE_CREATED_AT,
218 streaming: false,
219 },
220 };
222​
223describe("MessagesTimeline", () => {
224 it("uses LegendList isNearEnd when deciding whether the live edge is visible", async () => {
225 const {
226 resolveTimelineIsAtEnd,
227 resolveTimelineMinimapHasPersistentGutter,
228 resolveTimelineMinimapHeightStyle,
229 resolveTimelineMinimapIndexFromPointer,
230 resolveTimelineMinimapTopPercent,
231 } = await import("./MessagesTimeline.logic");
232​
233 expect(resolveTimelineIsAtEnd({ isNearEnd: true, isAtEnd: false })).toBe(true);
234 expect(resolveTimelineIsAtEnd({ isNearEnd: false, isAtEnd: true })).toBe(false);
235 expect(resolveTimelineIsAtEnd({ isAtEnd: true })).toBe(true);
236 expect(resolveTimelineIsAtEnd(undefined)).toBeUndefined();
237​
238 expect(resolveTimelineMinimapHeightStyle(5)).toBe("min(32px, calc(100vh - 18rem))");
239 expect(resolveTimelineMinimapTopPercent(2, 5)).toBe(50);
240 expect(
241 resolveTimelineMinimapIndexFromPointer({
242 itemCount: 101,
243 railTop: 100,
244 railHeight: 500,
245 pointerY: 350,
246 }),
247 ).toBe(50);
248 expect(
249 resolveTimelineMinimapIndexFromPointer({
250 itemCount: 101,
251 railTop: 100,
252 railHeight: 500,
253 pointerY: 999,
254 }),
255 ).toBe(100);
256 expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
257 expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
258 expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);
259 });
260​
261 it("anchors a sent attachment message using its measured height", async () => {
262 const { MessagesTimeline } = await import("./MessagesTimeline");
263 const onAnchorReady = vi.fn();
264 const onAnchorSizeChanged = vi.fn();
265 const firstEntry = buildUserTimelineEntry("First prompt.");
266 const secondEntry = {
267 ...buildUserTimelineEntry("Newest prompt."),
268 id: "entry-2",
269 message: {
270 ...buildUserTimelineEntry("Newest prompt.").message,
271 id: MessageId.make("message-2"),
272 attachments: [
273 {
274 type: "image" as const,
275 id: "attachment-1",
276 name: "screenshot.png",
277 mimeType: "image/png",
278 sizeBytes: 1,
279 previewUrl: "data:image/png;base64,iVBORw0KGgo=",
280 },
281 ],
282 },
283 };
284 const markup = renderToStaticMarkup(
285 <MessagesTimeline
286 {...buildProps()}
287 anchorMessageId={secondEntry.message.id}
288 onAnchorReady={onAnchorReady}
289 onAnchorSizeChanged={onAnchorSizeChanged}
290 contentInsetEndAdjustment={144}
291 timelineEntries={[firstEntry, secondEntry]}
292 />,
293 );
294​
295 expect(markup).toContain('data-anchor-index="1"');
296 expect(markup).toContain('data-anchor-offset="16"');
297 expect(markup).toContain('data-anchor-on-ready="true"');
298 expect(markup).not.toContain("data-anchor-max-size=");
299 expect(markup).toContain('data-content-inset-end="144"');
300 expect(markup).toContain("[overflow-anchor:none]");
301 expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
302 expect(markup).toContain('data-maintain-visible-content-position="object"');
303 expect(markup).toContain('data-maintain-visible-content-position-data="true"');
304 expect(markup).toContain('data-maintain-visible-content-position-size="false"');
305 expect(onAnchorReady).toHaveBeenCalledOnce();
306 expect(onAnchorReady).toHaveBeenCalledWith(secondEntry.message.id, 1);
307 expect(onAnchorSizeChanged).toHaveBeenCalledWith(secondEntry.message.id, 240);
308 });
309​
310 it("renders collapse controls for long user messages", async () => {
311 const { MessagesTimeline } = await import("./MessagesTimeline");
312 const markup = renderToStaticMarkup(
313 <MessagesTimeline
314 {...buildProps()}
315 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
316 />,
317 );
318​
319 expect(markup).toContain("Show full message");
320 expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
321 expect(markup).toContain('data-maintain-scroll-at-end-animated="false"');
322 expect(markup).toContain('data-maintain-scroll-at-end-data-change="true"');
323 expect(markup).toContain('data-maintain-scroll-at-end-item-layout="true"');
324 expect(markup).toContain('data-maintain-scroll-at-end-layout="true"');
325 expect(markup).toContain('data-user-message-collapsed="true"');
326 expect(markup).toContain('data-user-message-fade="true"');
327 expect(markup).toContain('data-user-message-footer="true"');
328 });
329​
330 it("does not render collapse controls for short user messages", async () => {
331 const { MessagesTimeline } = await import("./MessagesTimeline");
332 const markup = renderToStaticMarkup(
333 <MessagesTimeline
334 {...buildProps()}
335 timelineEntries={[buildUserTimelineEntry("Short prompt.")]}
336 />,
337 );
338​
339 expect(markup).not.toContain("Show full message");
340 expect(markup).toContain('data-user-message-collapsible="false"');
341 });
342​
343 it("identifies user-role messages sent by another agent", async () => {
344 const { MessagesTimeline } = await import("./MessagesTimeline");
345 const entry = buildUserTimelineEntry("Review this area");
346 const agentMarkup = renderToStaticMarkup(
347 <MessagesTimeline
348 {...buildProps()}
349 timelineEntries={[
350 {
351 ...entry,
352 message: { ...entry.message, createdBy: "agent", creationSource: "provider" },
353 },
354 ]}
355 />,
356 );
357 const userMarkup = renderToStaticMarkup(
358 <MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
359 );
360​
361 expect(agentMarkup).toContain('data-user-message-attribution="agent"');
362 expect(agentMarkup).toContain("Sent by another agent");
363 expect(userMarkup).not.toContain("Sent by another agent");
364 });
365​
366 it("keeps a subagent parent-thread link at the top of an empty timeline", async () => {
367 const { MessagesTimeline } = await import("./MessagesTimeline");
368 const markup = renderToStaticMarkup(
369 <MessagesTimeline
370 {...buildProps()}
371 timelineEntries={[]}
372 parentThreadLink={{
373 threadId: ThreadId.make("thread-parent"),
374 title: "Architecture audit",
375 }}
376 />,
377 );
378​
379 expect(markup).toContain('aria-label="Open parent thread"');
380 expect(markup).toContain("Subagent of");
381 expect(markup).toContain("Architecture audit");
382 expect(markup).not.toContain("Send a message to start the conversation");
383 });
384​
385 it("keeps steer intent visible on committed user messages", async () => {
386 const { MessagesTimeline } = await import("./MessagesTimeline");
387 const entry = buildUserTimelineEntry("Adjust the current turn");
388 const markup = renderToStaticMarkup(
389 <MessagesTimeline
390 {...buildProps()}
391 timelineEntries={[
392 { ...entry, message: { ...entry.message, inputIntent: "steer" as const } },
393 ]}
394 />,
395 );
396​
397 expect(markup).toContain("Steered the active turn");
398 expect(markup).toContain(">steer<");
399 });
400​
401 it("shows a collapsed disclosure for superseded attempt output", async () => {
402 const { MessagesTimeline } = await import("./MessagesTimeline");
403 const runId = RunId.make("run-steered");
404 const supersededAttempt = {
405 id: "attempt-1" as never,
406 runId,
407 attemptOrdinal: 1,
408 rootNodeId: "node-attempt-1" as never,
409 status: "superseded" as const,
410 };
411 const activeAttempt = {
412 id: "attempt-2" as never,
413 runId,
414 attemptOrdinal: 2,
415 rootNodeId: "node-attempt-2" as never,
416 status: "running" as const,
417 };
418 const markup = renderToStaticMarkup(
419 <MessagesTimeline
420 {...buildProps()}
421 latestRun={{
422 runId,
423 status: "running",
424 startedAt: MESSAGE_CREATED_AT,
425 completedAt: null,
426 }}
427 timelineEntries={[
428 {
429 id: "superseded-response-entry",
430 kind: "message",
431 createdAt: MESSAGE_CREATED_AT,
432 attempt: supersededAttempt,
433 message: {
434 id: MessageId.make("superseded-response"),
435 role: "assistant",
436 text: "Partial response from the old attempt",
437 runId,
438 createdAt: MESSAGE_CREATED_AT,
439 updatedAt: MESSAGE_CREATED_AT,
440 streaming: false,
441 },
442 },
443 {
444 id: "active-response-entry",
445 kind: "message",
446 createdAt: "2026-03-17T19:12:29.000Z",
447 attempt: activeAttempt,
448 message: {
449 id: MessageId.make("active-response"),
450 role: "assistant",
451 text: "Current response remains visible",
452 runId,
453 createdAt: "2026-03-17T19:12:29.000Z",
454 updatedAt: "2026-03-17T19:12:29.000Z",
455 streaming: true,
456 },
457 },
458 ]}
459 />,
460 );
461​
462 expect(markup).toContain('data-superseded-attempt-id="attempt-1"');
463 expect(markup).toContain('aria-expanded="false"');
464 expect(markup).toContain("Superseded attempt");
465 expect(markup).toContain("Partial output retained");
466 expect(markup).toContain("Current response remains visible");
467 expect(markup).not.toContain("Partial response from the old attempt");
468 });
469​
470 it("exposes a per-response fork action for completed assistant items", async () => {
471 const { MessagesTimeline } = await import("./MessagesTimeline");
472 const projectedItem = {
473 position: 0,
474 visibility: "local",
475 sourceThreadId: "thread-1",
476 sourceItemId: "assistant-item-1",
477 item: {
478 id: "assistant-item-1",
479 threadId: "thread-1",
480 runId: "run-1",
481 nodeId: null,
482 providerThreadId: null,
483 providerTurnId: null,
484 nativeItemRef: null,
485 parentItemId: null,
486 ordinal: 0,
487 status: "completed",
488 title: null,
489 startedAt: null,
490 completedAt: null,
491 updatedAt: {},
492 type: "assistant_message",
493 messageId: "assistant-message-1",
494 text: "Done",
495 streaming: false,
496 },
497 } as never;
498 const markup = renderToStaticMarkup(
499 <MessagesTimeline
500 {...buildProps()}
501 timelineEntries={[
502 {
503 id: "assistant-message-1",
504 kind: "message",
505 createdAt: MESSAGE_CREATED_AT,
506 projectedItem,
507 message: {
508 id: MessageId.make("assistant-message-1"),
509 role: "assistant",
510 text: "Done",
511 runId: RunId.make("run-1"),
512 createdAt: MESSAGE_CREATED_AT,
513 updatedAt: MESSAGE_CREATED_AT,
514 streaming: false,
515 },
516 },
517 ]}
518 />,
519 );
520​
521 expect(markup).toContain('aria-label="Fork from this response"');
522 });
523​
524 it("renders inline terminal labels with the composer chip UI", async () => {
525 const { MessagesTimeline } = await import("./MessagesTimeline");
526 const markup = renderToStaticMarkup(
527 <MessagesTimeline
528 {...buildProps()}
529 timelineEntries={[
530 buildUserTimelineEntry(
531 [
532 buildLongUserMessageText("yoo what's @terminal-1:1-5 mean"),
533 "",
534 "<terminal_context>",
535 "- Terminal 1 lines 1-5:",
536 " 1 | julius@mac effect-http-ws-cli % bun i",
537 " 2 | bun install v1.3.9 (cf6cdbbb)",
538 "</terminal_context>",
539 ].join("\n"),
540 ),
541 ]}
542 />,
543 );
544​
545 expect(markup).toContain("Terminal 1 lines 1-5");
546 expect(markup).toContain("lucide-terminal");
547 expect(markup).toContain("yoo what&#x27;s</p>");
548 expect(markup).toContain('<span aria-hidden="true"> </span>');
549 expect(markup).toContain("Show full message");
550 }, 20_000);
551​
552 it("renders chips for standalone element-pick context messages", async () => {
553 const { MessagesTimeline } = await import("./MessagesTimeline");
554 const markup = renderToStaticMarkup(
555 <MessagesTimeline
556 {...buildProps()}
557 timelineEntries={[
558 buildUserTimelineEntry(
559 [
560 "<element_context>",
561 "- <SubmitButton> (Button.tsx:12):",
562 " url: https://example.com/dashboard",
563 " selector: button.submit",
564 " source: /repo/src/Button.tsx:12:5",
565 " html:",
566 ' <button class="submit">Save</button>',
567 "</element_context>",
568 ].join("\n"),
569 ),
570 ]}
571 />,
572 );
573​
574 expect(markup).toContain("SubmitButton");
575 expect(markup).not.toContain("&lt;element_context");
576 expect(markup).not.toContain("<element_context");
577 });
578​
579 it("keeps the copy button for collapsed long user messages", async () => {
580 const { MessagesTimeline } = await import("./MessagesTimeline");
581 const markup = renderToStaticMarkup(
582 <MessagesTimeline
583 {...buildProps()}
584 timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
585 />,
586 );
587​
588 expect(markup).toContain('aria-label="Copy link"');
589 expect(markup).toContain('data-user-message-collapsed="true"');
590 expect(markup).toContain('data-user-message-footer="true"');
591 });
592​
593 it("renders context compaction entries in the normal work log", async () => {
594 const { MessagesTimeline } = await import("./MessagesTimeline");
595 const markup = renderToStaticMarkup(
596 <MessagesTimeline
597 {...buildProps()}
598 timelineEntries={[
599 {
600 id: "entry-1",
601 kind: "work",
602 createdAt: "2026-03-17T19:12:28.000Z",
603 entry: {
604 id: "work-1",
605 createdAt: "2026-03-17T19:12:28.000Z",
606 label: "Context compacted",
607 tone: "info",
608 },
609 },
610 ]}
611 />,
612 );
613​
614 expect(markup).toContain("Context compacted");
615 expect(markup).toContain("Work Log");
616 });
617​
618 it("renders V2 interruption lifecycle entries as standalone rows", async () => {
619 const { MessagesTimeline } = await import("./MessagesTimeline");
620 const markup = renderToStaticMarkup(
621 <MessagesTimeline
622 {...buildProps()}
623 timelineEntries={[
624 {
625 id: "interrupt-request",
626 kind: "event",
627 createdAt: MESSAGE_CREATED_AT,
628 projectedItem: {
629 position: 0,
630 visibility: "local",
631 sourceThreadId: "thread-1",
632 sourceItemId: "interrupt-request",
633 item: {
634 id: "interrupt-request",
635 threadId: "thread-1",
636 runId: "run-1",
637 nodeId: null,
638 providerThreadId: null,
639 providerTurnId: null,
640 nativeItemRef: null,
641 parentItemId: null,
642 ordinal: 0,
643 status: "completed",
644 title: null,
645 startedAt: null,
646 completedAt: null,
647 updatedAt: {},
648 type: "run_interrupt_request",
649 message: "Waiting for the provider to stop.",
650 },
651 } as never,
652 },
653 ]}
654 />,
655 );
656​
657 expect(markup).toContain('data-v2-item-type="run_interrupt_request"');
658 expect(markup).toContain("Interrupt requested");
659 expect(markup).toContain("Waiting for the provider to stop.");
660 expect(markup).not.toContain("Structured details");
661 });
662​
663 it("renders created threads as linked cards outside the work log", async () => {
664 const { MessagesTimeline } = await import("./MessagesTimeline");
665 const markup = renderToStaticMarkup(
666 <MessagesTimeline
667 {...buildProps()}
668 timelineEntries={[
669 {
670 id: "thread-created",
671 kind: "event",
672 createdAt: MESSAGE_CREATED_AT,
673 projectedItem: {
674 position: 0,
675 visibility: "local",
676 sourceThreadId: "thread-1",
677 sourceItemId: "thread-created",
678 item: {
679 id: "thread-created",
680 threadId: "thread-1",
681 runId: "run-1",
682 nodeId: "node-1",
683 providerThreadId: null,
684 providerTurnId: null,
685 nativeItemRef: null,
686 parentItemId: null,
687 ordinal: 1,
688 status: "completed",
689 title: "Claude research thread",
690 startedAt: null,
691 completedAt: null,
692 updatedAt: {},
693 type: "thread_created",
694 targetThreadId: "thread-2",
695 targetRunId: "run-2",
696 targetProviderInstanceId: "claude-default",
697 targetModel: "claude-sonnet-4-6",
698 },
699 } as never,
700 },
701 ]}
702 />,
703 );
704​
705 expect(markup).toContain('data-v2-item-type="thread_created"');
706 expect(markup).toContain('aria-label="Open Claude research thread"');
707 expect(markup).toContain("Claude research thread");
708 expect(markup).toContain("claude-default · claude-sonnet-4-6");
709 expect(markup).not.toContain("Work Log");
710 });
711​
712 it("renders live subagent progress on the persistent linked card", async () => {
713 const { MessagesTimeline } = await import("./MessagesTimeline");
714 const markup = renderToStaticMarkup(
715 <MessagesTimeline
716 {...buildProps()}
717 timelineEntries={[
718 {
719 id: "subagent-progress",
720 kind: "event",
721 createdAt: MESSAGE_CREATED_AT,
722 projectedItem: {
723 position: 0,
724 visibility: "local",
725 sourceThreadId: "thread-1",
726 sourceItemId: "subagent-progress",
727 item: {
728 id: "subagent-progress",
729 threadId: "thread-1",
730 runId: "run-1",
731 nodeId: "node-subagent-1",
732 providerThreadId: "provider-thread-1",
733 providerTurnId: "provider-turn-1",
734 nativeItemRef: null,
735 parentItemId: null,
736 ordinal: 1,
737 status: "running",
738 title: "Package audit",
739 startedAt: null,
740 completedAt: null,
741 updatedAt: {},
742 type: "subagent",
743 subagentId: "node-subagent-1",
744 origin: "provider_native",
745 driver: "claudeAgent",
746 providerInstanceId: "claudeAgent",
747 childThreadId: "thread-subagent-1",
748 prompt: "Inspect the package",
749 progress: "Reading src/index.ts",
750 result: null,
751 },
752 } as never,
753 },
754 ]}
755 />,
756 );
757​
758 expect(markup).toContain('data-v2-item-type="subagent"');
759 expect(markup).toContain('aria-label="Open Package audit"');
760 expect(markup).toContain("Reading src/index.ts");
761 expect(markup).not.toContain("Inspect the package");
762 expect(markup).not.toContain("Work Log");
763 });
764​
765 it("renders V2 provider failures as standalone error rows", async () => {
766 const { MessagesTimeline } = await import("./MessagesTimeline");
767 const markup = renderToStaticMarkup(
768 <MessagesTimeline
769 {...buildProps()}
770 timelineEntries={[
771 {
772 id: "provider-error",
773 kind: "event",
774 createdAt: MESSAGE_CREATED_AT,
775 projectedItem: {
776 position: 0,
777 visibility: "local",
778 sourceThreadId: "thread-1",
779 sourceItemId: "provider-error",
780 item: {
781 id: "provider-error",
782 threadId: "thread-1",
783 runId: "run-1",
784 nodeId: null,
785 providerThreadId: "provider-thread-1",
786 providerTurnId: "provider-turn-1",
787 nativeItemRef: null,
788 parentItemId: null,
789 ordinal: 99,
790 status: "failed",
791 title: null,
792 startedAt: null,
793 completedAt: null,
794 updatedAt: {},
795 type: "error",
796 failure: {
797 class: "validation_error",
798 message: "Invalid reasoning effort.",
799 code: "invalid_request",
800 retryable: false,
801 },
802 },
803 } as never,
804 },
805 ]}
806 />,
807 );
808​
809 expect(markup).toContain('data-v2-item-type="error"');
810 expect(markup).toContain("Provider error");
811 expect(markup).toContain("Invalid reasoning effort.");
812 });
813​
814 it("keeps inherited V2 work provenance on the rendered row", async () => {
815 const { MessagesTimeline } = await import("./MessagesTimeline");
816 const item = {
817 id: "command-inherited",
818 threadId: "thread-source",
819 runId: null,
820 nodeId: null,
821 providerThreadId: null,
822 providerTurnId: null,
823 nativeItemRef: null,
824 parentItemId: null,
825 ordinal: 0,
826 status: "completed",
827 title: null,
828 startedAt: null,
829 completedAt: null,
830 updatedAt: {},
831 type: "command_execution",
832 input: "pwd",
833 output: "/workspace",
834 exitCode: 0,
835 } as const;
836 const projectedItem = {
837 position: 0,
838 visibility: "inherited",
839 sourceThreadId: "thread-source",
840 sourceItemId: item.id,
841 item,
842 } as const;
843 const markup = renderToStaticMarkup(
844 <MessagesTimeline
845 {...buildProps()}
846 timelineEntries={
847 [
848 {
849 id: item.id,
850 kind: "work",
851 createdAt: MESSAGE_CREATED_AT,
852 entry: {
853 id: item.id,
854 createdAt: MESSAGE_CREATED_AT,
855 runId: null,
856 label: "Ran command",
857 command: item.input,
858 tone: "tool",
859 itemType: item.type,
860 toolLifecycleStatus: "completed",
861 structuredPayload: item,
862 projectedItem,
863 },
864 },
865 ] as never
866 }
867 />,
868 );
869​
870 expect(markup).toContain('data-v2-item-type="command_execution"');
871 expect(markup).toContain('data-v2-item-visibility="inherited"');
872 expect(markup).toContain("Inherited");
873 });
874​
875 it("formats changed file paths from the workspace root", async () => {
876 const { MessagesTimeline } = await import("./MessagesTimeline");
877 const markup = renderToStaticMarkup(
878 <MessagesTimeline
879 {...buildProps()}
880 timelineEntries={[
881 {
882 id: "entry-1",
883 kind: "work",
884 createdAt: "2026-03-17T19:12:28.000Z",
885 entry: {
886 id: "work-1",
887 createdAt: "2026-03-17T19:12:28.000Z",
888 label: "Updated files",
889 tone: "tool",
890 itemType: "file_change",
891 toolLifecycleStatus: "completed",
892 changedFiles: ["C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts"],
893 },
894 },
895 ]}
896 workspaceRoot="C:/Users/mike/dev-stuff/t3code"
897 />,
898 );
899​
900 expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
901 expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
902 });
903​
904 it("renders review comment contexts as structured cards instead of raw tags", async () => {
905 const { MessagesTimeline } = await import("./MessagesTimeline");
906 const markup = renderToStaticMarkup(
907 <MessagesTimeline
908 {...buildProps()}
909 timelineEntries={[
910 {
911 id: "entry-1",
912 kind: "message",
913 createdAt: "2026-03-17T19:12:28.000Z",
914 message: {
915 id: MessageId.make("message-2"),
916 role: "user",
917 text: [
918 '<review_comment sectionId="turn:2" sectionTitle="Turn 2" filePath="apps/web/src/lib/contextWindow.test.ts" startIndex="3" endIndex="14" rangeLabel="+47 to +58">',
919 "Wadduo",
920 "```diff",
921 "@@ -0,0 +47,2 @@",
922 '+ it("keeps valid zero-usage snapshots", () => {',
923 "+ expect(snapshot).not.toBeNull();",
924 "```",
925 "</review_comment>",
926 ].join("\n"),
927 runId: null,
928 createdAt: "2026-03-17T19:12:28.000Z",
929 updatedAt: "2026-03-17T19:12:28.000Z",
930 streaming: false,
931 },
932 },
933 ]}
934 />,
935 );
936​
937 expect(markup).toContain("contextWindow.test.ts");
938 expect(markup).toContain("Wadduo");
939 expect(markup).toContain('data-testid="file-diff"');
940 expect(markup).not.toContain(">Review comment<");
941 expect(markup).not.toContain("&lt;review_comment");
942 expect(markup).not.toContain("&lt;/review_comment&gt;");
943 });
944​
945 it("renders file review comments as source code instead of diffs", async () => {
946 const { MessagesTimeline } = await import("./MessagesTimeline");
947 const markup = renderToStaticMarkup(
948 <MessagesTimeline
949 {...buildProps()}
950 timelineEntries={[
951 {
952 id: "entry-1",
953 kind: "message",
954 createdAt: "2026-03-17T19:12:28.000Z",
955 message: {
956 id: MessageId.make("message-source-comment"),
957 role: "user",
958 text: [
959 '<review_comment sectionId="file:docs/plan.md" sectionTitle="File comment" filePath="docs/plan.md" startIndex="0" endIndex="1" rangeLabel="L1 to L2">',
960 "Clarify this.",
961 "```md",
962 "# Plan",
963 "- Step one",
964 "```",
965 "</review_comment>",
966 ].join("\n"),
967 runId: null,
968 createdAt: "2026-03-17T19:12:28.000Z",
969 updatedAt: "2026-03-17T19:12:28.000Z",
970 streaming: false,
971 },
972 },
973 ]}
974 />,
975 );
976​
977 expect(markup).toContain("plan.md");
978 expect(markup).toContain("Clarify this.");
979 expect(markup).toContain("# Plan");
980 expect(markup).not.toContain('data-testid="file-diff"');
981 });
982​
983 it("renders a failure marker for failed tool lifecycle entries", async () => {
984 const { MessagesTimeline } = await import("./MessagesTimeline");
985 const markup = renderToStaticMarkup(
986 <MessagesTimeline
987 {...buildProps()}
988 timelineEntries={[
989 {
990 id: "entry-1",
991 kind: "work",
992 createdAt: "2026-03-17T19:12:28.000Z",
993 entry: {
994 id: "work-1",
995 createdAt: "2026-03-17T19:12:28.000Z",
996 label: "Glob",
997 tone: "tool",
998 toolLifecycleStatus: "failed",
999 detail: "No files found",
1000 },
1001 },
1002 ]}
1003 />,
1004 );
1005​
1006 expect(markup).toContain("lucide-x");
1007 expect(markup).toContain('aria-label="Tool call failed"');
1008 });
1009});