forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimelineHeight.test.ts
More file actions
151 lines (132 loc) · 4.27 KB
/
timelineHeight.test.ts
File metadata and controls
151 lines (132 loc) · 4.27 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
import { describe, expect, it } from "vitest";
import { appendTerminalContextsToPrompt } from "../lib/terminalContext";
import { buildInlineTerminalContextText } from "./chat/userMessageTerminalContexts";
import { estimateTimelineMessageHeight } from "./timelineHeight";
describe("estimateTimelineMessageHeight", () => {
it("uses assistant sizing rules for assistant messages", () => {
expect(
estimateTimelineMessageHeight({
role: "assistant",
text: "a".repeat(144),
}),
).toBe(86.5);
});
it("uses assistant sizing rules for system messages", () => {
expect(
estimateTimelineMessageHeight({
role: "system",
text: "a".repeat(144),
}),
).toBe(86.5);
});
it("adds one attachment row for one or two user attachments", () => {
expect(
estimateTimelineMessageHeight({
role: "user",
text: "hello",
attachments: [{ id: "1" }],
}),
).toBe(234);
expect(
estimateTimelineMessageHeight({
role: "user",
text: "hello",
attachments: [{ id: "1" }, { id: "2" }],
}),
).toBe(234);
});
it("adds a second attachment row for three or four user attachments", () => {
expect(
estimateTimelineMessageHeight({
role: "user",
text: "hello",
attachments: [{ id: "1" }, { id: "2" }, { id: "3" }],
}),
).toBe(350);
expect(
estimateTimelineMessageHeight({
role: "user",
text: "hello",
attachments: [{ id: "1" }, { id: "2" }, { id: "3" }, { id: "4" }],
}),
).toBe(350);
});
it("does not cap long user message estimates", () => {
expect(
estimateTimelineMessageHeight({
role: "user",
text: "a".repeat(56 * 120),
}),
).toBe(2736);
});
it("counts explicit newlines for user message estimates", () => {
expect(
estimateTimelineMessageHeight({
role: "user",
text: "first\nsecond\nthird",
}),
).toBe(162);
});
it("adds terminal context chrome without counting the hidden block as message text", () => {
const prompt = appendTerminalContextsToPrompt("Investigate this", [
{
terminalId: "default",
terminalLabel: "Terminal 1",
lineStart: 40,
lineEnd: 43,
text: [
"git status",
"M apps/web/src/components/chat/MessagesTimeline.tsx",
"?? tmp",
"",
].join("\n"),
},
]);
expect(
estimateTimelineMessageHeight({
role: "user",
text: prompt,
}),
).toBe(
estimateTimelineMessageHeight({
role: "user",
text: `${buildInlineTerminalContextText([{ header: "Terminal 1 lines 40-43" }])} Investigate this`,
}),
);
});
it("uses narrower width to increase user line wrapping", () => {
const message = {
role: "user" as const,
text: "a".repeat(52),
};
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(140);
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(118);
});
it("does not clamp user wrapping too aggressively on very narrow layouts", () => {
const message = {
role: "user" as const,
text: "a".repeat(20),
};
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 100 })).toBe(184);
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(118);
});
it("uses narrower width to increase assistant line wrapping", () => {
const message = {
role: "assistant" as const,
text: "a".repeat(200),
};
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(154.75);
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(86.5);
});
it("treats inline code as wider when estimating assistant markdown wrapping", () => {
const message = {
role: "assistant" as const,
text: [
"Typecheck found one exact-optional-property issue in the browser harness:",
"I was always passing `onVirtualizerSnapshot`, including `undefined`.",
"I'm tightening that object construction and rerunning the checks.",
].join(" "),
};
expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(109.25);
});
});