Files
hongjr03 bef10149a9 feat: improve outbound message chunking with code-block-aware splitting
- Increase max message length from 4000 to 8000 chars
- Add splitAtBoundary: paragraph > newline > space priority, never split
  inside fenced code blocks (move split to before opening fence)
- Add sendLongText: sends multi-chunk long messages sequentially
- Update PatchableTextStream.flush to use splitAtBoundary
- Add unit tests (6) for splitting edge cases
2026-07-08 16:57:53 +08:00

44 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { splitAtBoundary } from "../../src/feishu/textStream.js";
describe("splitAtBoundary", () => {
it("keeps short text in a single chunk", () => {
expect(splitAtBoundary("short text", 20)).toEqual(["short text"]);
});
it("keeps text at exactly maxLength in a single chunk", () => {
const text = "x".repeat(20);
expect(splitAtBoundary(text, 20)).toEqual([text]);
});
it("splits text exceeding maxLength into chunks at or below maxLength", () => {
const chunks = splitAtBoundary("x".repeat(45), 20);
expect(chunks).toHaveLength(3);
expect(chunks.every((chunk) => chunk.length <= 20)).toBe(true);
expect(chunks.join("")).toBe("x".repeat(45));
});
it("moves a split before a fenced code block when the boundary lands inside it", () => {
const prefix = "Before code starts\n";
const codeBlock = "```ts\nx\n```\n";
const text = `${prefix}${codeBlock}After`;
const chunks = splitAtBoundary(text, prefix.length + 4);
expect(chunks).toEqual([prefix, `${codeBlock}After`]);
});
it("prefers paragraph boundaries over newline boundaries", () => {
const text = "para one\n\nline two\nline three";
expect(splitAtBoundary(text, 22)).toEqual(["para one\n\n", "line two\nline three"]);
});
it("prefers newline boundaries over space boundaries", () => {
const text = "alpha beta\ngamma delta epsilon";
expect(splitAtBoundary(text, 24)).toEqual(["alpha beta\n", "gamma delta epsilon"]);
});
});