|
1 | 1 | import { describe, expect, test } from "vitest"; |
2 | 2 | import { projectSessionDisplayMessage } from "./session-display-projection.js"; |
3 | 3 |
|
4 | | -const SESSION_LAST_MESSAGE_PREVIEW_MAX_CHARS = 240; |
| 4 | +const SESSION_LAST_MESSAGE_PREVIEW_DEFAULT_CHARS = 240; |
5 | 5 |
|
6 | 6 | describe("projectSessionDisplayMessage", () => { |
7 | 7 | test("keeps visible user and assistant text while excluding non-display rows", () => { |
@@ -37,26 +37,27 @@ describe("projectSessionDisplayMessage", () => { |
37 | 37 | }); |
38 | 38 |
|
39 | 39 | test("bounds previews without splitting surrogate pairs", () => { |
40 | | - const longReply = `${"a".repeat(SESSION_LAST_MESSAGE_PREVIEW_MAX_CHARS - 2)}😊tail`; |
| 40 | + const longReply = `${"a".repeat(SESSION_LAST_MESSAGE_PREVIEW_DEFAULT_CHARS - 2)}😊tail`; |
41 | 41 | const preview = projectSessionDisplayMessage({ role: "assistant", content: longReply }); |
42 | 42 |
|
43 | | - expect(preview?.text).toHaveLength(SESSION_LAST_MESSAGE_PREVIEW_MAX_CHARS); |
44 | | - expect(preview?.text).toBe(`${"a".repeat(SESSION_LAST_MESSAGE_PREVIEW_MAX_CHARS - 3)}...`); |
| 43 | + expect(preview?.text).toHaveLength(SESSION_LAST_MESSAGE_PREVIEW_DEFAULT_CHARS); |
| 44 | + expect(preview?.text).toBe(`${"a".repeat(SESSION_LAST_MESSAGE_PREVIEW_DEFAULT_CHARS - 3)}...`); |
45 | 45 | }); |
46 | 46 |
|
47 | | - test("honors an explicit preview budget above the default", () => { |
| 47 | + test("honors explicit preview budgets up to the shared cap", () => { |
48 | 48 | const maxChars = 800; |
49 | | - const preview = projectSessionDisplayMessage( |
50 | | - { role: "assistant", content: "a".repeat(maxChars + 20) }, |
51 | | - { maxChars }, |
52 | | - ); |
| 49 | + const message = { role: "assistant", content: "a".repeat(maxChars + 20) }; |
| 50 | + const preview = projectSessionDisplayMessage(message, { maxChars }); |
53 | 51 |
|
54 | 52 | expect(preview?.text).toHaveLength(maxChars); |
55 | 53 | expect(preview?.text).toBe(`${"a".repeat(maxChars - 3)}...`); |
| 54 | + expect(projectSessionDisplayMessage(message, { maxChars: Number.MAX_SAFE_INTEGER })?.text).toBe( |
| 55 | + `${"a".repeat(maxChars - 3)}...`, |
| 56 | + ); |
56 | 57 | }); |
57 | 58 |
|
58 | 59 | test("flattens Markdown before bounding a preview", () => { |
59 | | - const longUrl = `https://example.com/${"x".repeat(SESSION_LAST_MESSAGE_PREVIEW_MAX_CHARS)}`; |
| 60 | + const longUrl = `https://example.com/${"x".repeat(SESSION_LAST_MESSAGE_PREVIEW_DEFAULT_CHARS)}`; |
60 | 61 | const preview = projectSessionDisplayMessage( |
61 | 62 | { role: "assistant", content: `Read the [deployment guide](${longUrl})` }, |
62 | 63 | { flattenMarkdown: true }, |
|
0 commit comments