Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import { appendTerminalContextsToPrompt } from "../lib/terminalContext";
4import { buildInlineTerminalContextText } from "./chat/userMessageTerminalContexts";
5import { estimateTimelineMessageHeight } from "./timelineHeight";
6
7describe("estimateTimelineMessageHeight", () => {
8 it("uses assistant sizing rules for assistant messages", () => {
9 expect(
10 estimateTimelineMessageHeight({
11 role: "assistant",
12 text: "a".repeat(144),
13 }),
14 ).toBe(122);
15 });
16
17 it("uses assistant sizing rules for system messages", () => {
18 expect(
19 estimateTimelineMessageHeight({
20 role: "system",
21 text: "a".repeat(144),
22 }),
23 ).toBe(122);
24 });
25
26 it("adds one attachment row for one or two user attachments", () => {
27 expect(
28 estimateTimelineMessageHeight({
29 role: "user",
30 text: "hello",
31 attachments: [{ id: "1" }],
32 }),
33 ).toBe(346);
34
35 expect(
36 estimateTimelineMessageHeight({
37 role: "user",
38 text: "hello",
39 attachments: [{ id: "1" }, { id: "2" }],
40 }),
41 ).toBe(346);
42 });
43
44 it("adds a second attachment row for three or four user attachments", () => {
45 expect(
46 estimateTimelineMessageHeight({
47 role: "user",
48 text: "hello",
49 attachments: [{ id: "1" }, { id: "2" }, { id: "3" }],
50 }),
51 ).toBe(574);
52
53 expect(
54 estimateTimelineMessageHeight({
55 role: "user",
56 text: "hello",
57 attachments: [{ id: "1" }, { id: "2" }, { id: "3" }, { id: "4" }],
58 }),
59 ).toBe(574);
60 });
61
62 it("does not cap long user message estimates", () => {
63 expect(
64 estimateTimelineMessageHeight({
65 role: "user",
66 text: "a".repeat(56 * 120),
67 }),
68 ).toBe(2736);
69 });
70
71 it("counts explicit newlines for user message estimates", () => {
72 expect(
73 estimateTimelineMessageHeight({
74 role: "user",
75 text: "first\nsecond\nthird",
76 }),
77 ).toBe(162);
78 });
79
80 it("adds terminal context chrome without counting the hidden block as message text", () => {
81 const prompt = appendTerminalContextsToPrompt("Investigate this", [
82 {
83 terminalId: "default",
84 terminalLabel: "Terminal 1",
85 lineStart: 40,
86 lineEnd: 43,
87 text: [
88 "git status",
89 "M apps/web/src/components/chat/MessagesTimeline.tsx",
90 "?? tmp",
91 "",
92 ].join("\n"),
93 },
94 ]);
95
96 expect(
97 estimateTimelineMessageHeight({
98 role: "user",
99 text: prompt,
100 }),
101 ).toBe(
102 estimateTimelineMessageHeight({
103 role: "user",
104 text: `${buildInlineTerminalContextText([{ header: "Terminal 1 lines 40-43" }])} Investigate this`,
105 }),
106 );
107 });
108
109 it("uses narrower width to increase user line wrapping", () => {
110 const message = {
111 role: "user" as const,
112 text: "a".repeat(52),
113 };
114
115 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(140);
116 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(118);
117 });
118
119 it("does not clamp user wrapping too aggressively on very narrow layouts", () => {
120 const message = {
121 role: "user" as const,
122 text: "a".repeat(20),
123 };
124
125 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 100 })).toBe(184);
126 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(118);
127 });
128
129 it("uses narrower width to increase assistant line wrapping", () => {
130 const message = {
131 role: "assistant" as const,
132 text: "a".repeat(200),
133 };
134
135 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(188);
136 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(122);
137 });
138});