1import { describe, expect, it } from "vite-plus/test";
2β
3import { limitSection, sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
4β
5describe("limitSection", () => {
6 it("cuts a long section without splitting an emoji", () => {
7 expect(limitSection(`${"a".repeat(9)}π more`, 10)).toBe(`${"a".repeat(9)}\n\n[truncated]`);
8 });
9});
10β
11describe("sanitizeCommitSubject", () => {
12 // regression: #19181 truncation split grapheme clusters at the subject limit
13 it.each([
14 { name: "an emoji", prefixLength: 71, character: "π" },
15 { name: "an accented character", prefixLength: 71, character: "e\u0301" },
16 { name: "a joined emoji", prefixLength: 65, character: "π¨βπ©βπ§βπ¦" },
17 ])("keeps $name intact at the subject limit", ({ prefixLength, character }) => {
18 const prefix = "a".repeat(prefixLength);
19β
20 expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix);
21 });
22});
23β
24describe("sanitizeThreadTitle", () => {
25 it.each([
26 { name: "a split surrogate pair", prefixLength: 116, character: "π", retained: "" },
27 { name: "a complete surrogate pair", prefixLength: 115, character: "π", retained: "π" },
28 { name: "a BMP character", prefixLength: 116, character: "η", retained: "η" },
29 ])("truncates without splitting $name", ({ prefixLength, character, retained }) => {
30 const prefix = "a".repeat(prefixLength);
31 const title = `${prefix}${character} more`;
32β
33 expect(sanitizeThreadTitle(title)).toBe(`${prefix}${retained}...`);
34 });
35});