|
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,15 +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 | + }); |
| 46 | + |
| 47 | + test("honors explicit preview budgets up to the shared cap", () => { |
| 48 | + const maxChars = 800; |
| 49 | + const message = { role: "assistant", content: "a".repeat(maxChars + 20) }; |
| 50 | + const preview = projectSessionDisplayMessage(message, { maxChars }); |
| 51 | + |
| 52 | + expect(preview?.text).toHaveLength(maxChars); |
| 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 | + ); |
45 | 57 | }); |
46 | 58 |
|
47 | 59 | test("flattens Markdown before bounding a preview", () => { |
48 | | - 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)}`; |
49 | 61 | const preview = projectSessionDisplayMessage( |
50 | 62 | { role: "assistant", content: `Read the [deployment guide](${longUrl})` }, |
51 | 63 | { flattenMarkdown: true }, |
|
0 commit comments