139 lines
3.8 KiB
TypeScript
139 lines
3.8 KiB
TypeScript
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(346);
|
|
|
|
expect(
|
|
estimateTimelineMessageHeight({
|
|
role: "user",
|
|
text: "hello",
|
|
attachments: [{ id: "1" }, { id: "2" }],
|
|
}),
|
|
).toBe(346);
|
|
});
|
|
|
|
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(574);
|
|
|
|
expect(
|
|
estimateTimelineMessageHeight({
|
|
role: "user",
|
|
text: "hello",
|
|
attachments: [{ id: "1" }, { id: "2" }, { id: "3" }, { id: "4" }],
|
|
}),
|
|
).toBe(574);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|