fix: preserve discord chunk whitespace

This commit is contained in:
Peter Steinberger
2026-01-17 07:11:15 +00:00
parent 3a6ee5ee00
commit 86a46874da
3 changed files with 24 additions and 2 deletions

View File

@@ -63,6 +63,27 @@ describe("chunkDiscordText", () => {
}
});
it("preserves whitespace when splitting long lines", () => {
const text = Array.from({ length: 40 }, () => "word").join(" ");
const chunks = chunkDiscordText(text, { maxChars: 20, maxLines: 50 });
expect(chunks.length).toBeGreaterThan(1);
expect(chunks.join("")).toBe(text);
});
it("preserves mixed whitespace across chunk boundaries", () => {
const text = "alpha beta\tgamma delta epsilon zeta";
const chunks = chunkDiscordText(text, { maxChars: 12, maxLines: 50 });
expect(chunks.length).toBeGreaterThan(1);
expect(chunks.join("")).toBe(text);
});
it("keeps leading whitespace when splitting long lines", () => {
const text = " indented line with words that force splits";
const chunks = chunkDiscordText(text, { maxChars: 14, maxLines: 50 });
expect(chunks.length).toBeGreaterThan(1);
expect(chunks.join("")).toBe(text);
});
it("keeps reasoning italics balanced across chunks", () => {
const body = Array.from({ length: 25 }, (_, i) => `${i + 1}. line`).join("\n");
const text = `Reasoning:\n_${body}_`;