Open History to see the last commit
1import { EnvironmentId, MessageId } from "@t3tools/contracts";
2import { createRef } from "react";
3import { renderToStaticMarkup } from "react-dom/server";
4import { beforeAll, describe, expect, it, vi } from "vitest";
5import type { LegendListRef } from "@legendapp/list/react";
6
7vi.mock("@legendapp/list/react", async () => {
8 const React = await import("react");
9
10 const LegendList = React.forwardRef(function MockLegendList(
11 props: {
12 data: Array<{ id: string }>;
13 keyExtractor: (item: { id: string }) => string;
14 renderItem: (args: { item: { id: string } }) => React.ReactNode;
15 ListHeaderComponent?: React.ReactNode;
16 ListFooterComponent?: React.ReactNode;
17 },
18 _ref: React.ForwardedRef<LegendListRef>,
19 ) {
20 return (
21 <div data-testid="legend-list">
22 {props.ListHeaderComponent}
23 {props.data.map((item) => (
24 <div key={props.keyExtractor(item)}>{props.renderItem({ item })}</div>
25 ))}
26 {props.ListFooterComponent}
27 </div>
28 );
29 });
30
31 return { LegendList };
32});
33
34function matchMedia() {
35 return {
36 matches: false,
37 addEventListener: () => {},
38 removeEventListener: () => {},
39 };
40}
41
42beforeAll(() => {
43 const classList = {
44 add: () => {},
45 remove: () => {},
46 toggle: () => {},
47 contains: () => false,
48 };
49
50 vi.stubGlobal("localStorage", {
51 getItem: () => null,
52 setItem: () => {},
53 removeItem: () => {},
54 clear: () => {},
55 });
56 vi.stubGlobal("window", {
57 matchMedia,
58 addEventListener: () => {},
59 removeEventListener: () => {},
60 requestAnimationFrame: (callback: FrameRequestCallback) => {
61 callback(0);
62 return 0;
63 },
64 cancelAnimationFrame: () => {},
65 desktopBridge: undefined,
66 });
67 vi.stubGlobal("document", {
68 documentElement: {
69 classList,
70 offsetHeight: 0,
71 },
72 });
73});
74
75const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
76
77function buildProps() {
78 return {
79 isWorking: false,
80 activeTurnInProgress: false,
81 activeTurnId: null,
82 activeTurnStartedAt: null,
83 listRef: createRef<LegendListRef | null>(),
84 completionDividerBeforeEntryId: null,
85 completionSummary: null,
86 turnDiffSummaryByAssistantMessageId: new Map(),
87 routeThreadKey: "environment-local:thread-1",
88 onOpenTurnDiff: () => {},
89 revertTurnCountByUserMessageId: new Map(),
90 onRevertUserMessage: () => {},
91 isRevertingCheckpoint: false,
92 onImageExpand: () => {},
93 activeThreadEnvironmentId: ACTIVE_THREAD_ENVIRONMENT_ID,
94 markdownCwd: undefined,
95 resolvedTheme: "light" as const,
96 timestampFormat: "locale" as const,
97 workspaceRoot: undefined,
98 onIsAtEndChange: () => {},
99 };
100}
101
102describe("MessagesTimeline", () => {
103 it("renders inline terminal labels with the composer chip UI", async () => {
104 const { MessagesTimeline } = await import("./MessagesTimeline");
105 const markup = renderToStaticMarkup(
106 <MessagesTimeline
107 {...buildProps()}
108 timelineEntries={[
109 {
110 id: "entry-1",
111 kind: "message",
112 createdAt: "2026-03-17T19:12:28.000Z",
113 message: {
114 id: MessageId.make("message-2"),
115 role: "user",
116 text: [
117 "yoo what's @terminal-1:1-5 mean",
118 "",
119 "<terminal_context>",
120 "- Terminal 1 lines 1-5:",
121 " 1 | julius@mac effect-http-ws-cli % bun i",
122 " 2 | bun install v1.3.9 (cf6cdbbb)",
123 "</terminal_context>",
124 ].join("\n"),
125 createdAt: "2026-03-17T19:12:28.000Z",
126 streaming: false,
127 },
128 },
129 ]}
130 />,
131 );
132
133 expect(markup).toContain("Terminal 1 lines 1-5");
134 expect(markup).toContain("lucide-terminal");
135 expect(markup).toContain("yoo what's ");
136 }, 20_000);
137
138 it("renders context compaction entries in the normal work log", async () => {
139 const { MessagesTimeline } = await import("./MessagesTimeline");
140 const markup = renderToStaticMarkup(
141 <MessagesTimeline
142 {...buildProps()}
143 timelineEntries={[
144 {
145 id: "entry-1",
146 kind: "work",
147 createdAt: "2026-03-17T19:12:28.000Z",
148 entry: {
149 id: "work-1",
150 createdAt: "2026-03-17T19:12:28.000Z",
151 label: "Context compacted",
152 tone: "info",
153 },
154 },
155 ]}
156 />,
157 );
158
159 expect(markup).toContain("Context compacted");
160 expect(markup).toContain("Work log");
161 });
162
163 it("formats changed file paths from the workspace root", async () => {
164 const { MessagesTimeline } = await import("./MessagesTimeline");
165 const markup = renderToStaticMarkup(
166 <MessagesTimeline
167 {...buildProps()}
168 timelineEntries={[
169 {
170 id: "entry-1",
171 kind: "work",
172 createdAt: "2026-03-17T19:12:28.000Z",
173 entry: {
174 id: "work-1",
175 createdAt: "2026-03-17T19:12:28.000Z",
176 label: "Updated files",
177 tone: "tool",
178 changedFiles: ["C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts"],
179 },
180 },
181 ]}
182 workspaceRoot="C:/Users/mike/dev-stuff/t3code"
183 />,
184 );
185
186 expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
187 expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
188 });
189});