forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessagesTimeline.logic.test.ts
More file actions
203 lines (185 loc) · 5.4 KB
/
MessagesTimeline.logic.test.ts
File metadata and controls
203 lines (185 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { describe, expect, it } from "vitest";
import {
computeMessageDurationStart,
normalizeCompactToolLabel,
resolveAssistantMessageCopyState,
} from "./MessagesTimeline.logic";
describe("computeMessageDurationStart", () => {
it("returns message createdAt when there is no preceding user message", () => {
const result = computeMessageDurationStart([
{
id: "a1",
role: "assistant",
createdAt: "2026-01-01T00:00:05Z",
completedAt: "2026-01-01T00:00:10Z",
},
]);
expect(result).toEqual(new Map([["a1", "2026-01-01T00:00:05Z"]]));
});
it("uses the user message createdAt for the first assistant response", () => {
const result = computeMessageDurationStart([
{ id: "u1", role: "user", createdAt: "2026-01-01T00:00:00Z" },
{
id: "a1",
role: "assistant",
createdAt: "2026-01-01T00:00:30Z",
completedAt: "2026-01-01T00:00:30Z",
},
]);
expect(result).toEqual(
new Map([
["u1", "2026-01-01T00:00:00Z"],
["a1", "2026-01-01T00:00:00Z"],
]),
);
});
it("uses the previous assistant completedAt for subsequent assistant responses", () => {
const result = computeMessageDurationStart([
{ id: "u1", role: "user", createdAt: "2026-01-01T00:00:00Z" },
{
id: "a1",
role: "assistant",
createdAt: "2026-01-01T00:00:30Z",
completedAt: "2026-01-01T00:00:30Z",
},
{
id: "a2",
role: "assistant",
createdAt: "2026-01-01T00:00:55Z",
completedAt: "2026-01-01T00:00:55Z",
},
]);
expect(result).toEqual(
new Map([
["u1", "2026-01-01T00:00:00Z"],
["a1", "2026-01-01T00:00:00Z"],
["a2", "2026-01-01T00:00:30Z"],
]),
);
});
it("does not advance the boundary for a streaming message without completedAt", () => {
const result = computeMessageDurationStart([
{ id: "u1", role: "user", createdAt: "2026-01-01T00:00:00Z" },
{ id: "a1", role: "assistant", createdAt: "2026-01-01T00:00:30Z" },
{
id: "a2",
role: "assistant",
createdAt: "2026-01-01T00:00:55Z",
completedAt: "2026-01-01T00:00:55Z",
},
]);
expect(result).toEqual(
new Map([
["u1", "2026-01-01T00:00:00Z"],
["a1", "2026-01-01T00:00:00Z"],
["a2", "2026-01-01T00:00:00Z"],
]),
);
});
it("resets the boundary on a new user message", () => {
const result = computeMessageDurationStart([
{ id: "u1", role: "user", createdAt: "2026-01-01T00:00:00Z" },
{
id: "a1",
role: "assistant",
createdAt: "2026-01-01T00:00:30Z",
completedAt: "2026-01-01T00:00:30Z",
},
{ id: "u2", role: "user", createdAt: "2026-01-01T00:01:00Z" },
{
id: "a2",
role: "assistant",
createdAt: "2026-01-01T00:01:20Z",
completedAt: "2026-01-01T00:01:20Z",
},
]);
expect(result).toEqual(
new Map([
["u1", "2026-01-01T00:00:00Z"],
["a1", "2026-01-01T00:00:00Z"],
["u2", "2026-01-01T00:01:00Z"],
["a2", "2026-01-01T00:01:00Z"],
]),
);
});
it("handles system messages without affecting the boundary", () => {
const result = computeMessageDurationStart([
{ id: "u1", role: "user", createdAt: "2026-01-01T00:00:00Z" },
{ id: "s1", role: "system", createdAt: "2026-01-01T00:00:01Z" },
{
id: "a1",
role: "assistant",
createdAt: "2026-01-01T00:00:30Z",
completedAt: "2026-01-01T00:00:30Z",
},
]);
expect(result).toEqual(
new Map([
["u1", "2026-01-01T00:00:00Z"],
["s1", "2026-01-01T00:00:00Z"],
["a1", "2026-01-01T00:00:00Z"],
]),
);
});
it("returns empty map for empty input", () => {
expect(computeMessageDurationStart([])).toEqual(new Map());
});
});
describe("normalizeCompactToolLabel", () => {
it("removes trailing completion wording from command labels", () => {
expect(normalizeCompactToolLabel("Ran command complete")).toBe("Ran command");
});
it("removes trailing completion wording from other labels", () => {
expect(normalizeCompactToolLabel("Read file completed")).toBe("Read file");
});
});
describe("resolveAssistantMessageCopyState", () => {
it("returns enabled copy state for completed assistant messages", () => {
expect(
resolveAssistantMessageCopyState({
text: "Ship it",
streaming: false,
}),
).toEqual({
disabled: false,
text: "Ship it",
visible: true,
});
});
it("keeps copy visible but disabled for streaming assistant messages", () => {
expect(
resolveAssistantMessageCopyState({
text: "Still streaming",
streaming: true,
}),
).toEqual({
disabled: true,
text: "Still streaming",
visible: true,
});
});
it("hides copy for empty completed assistant messages", () => {
expect(
resolveAssistantMessageCopyState({
text: " ",
streaming: false,
}),
).toEqual({
disabled: false,
text: null,
visible: false,
});
});
it("keeps copy visible while an empty assistant message is streaming", () => {
expect(
resolveAssistantMessageCopyState({
text: null,
streaming: true,
}),
).toEqual({
disabled: true,
text: null,
visible: true,
});
});
});