-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage-split.test.js
More file actions
35 lines (30 loc) · 1.27 KB
/
Copy pathmessage-split.test.js
File metadata and controls
35 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, expect, test } from "bun:test";
import { splitMessages, hardChunk, TG_SEGMENT_LIMIT } from "./message-split.js";
describe("splitMessages", () => {
test("空输入返回空数组", () => {
expect(splitMessages("")).toEqual([]);
expect(splitMessages(null)).toEqual([]);
});
test("双换行分段并去空白", () => {
expect(splitMessages("第一段\n\n第二段\n\n\n第三段 ")).toEqual(["第一段", "第二段", "第三段"]);
});
test("单段不超限时原样保留", () => {
const seg = "啊".repeat(TG_SEGMENT_LIMIT);
expect(splitMessages(seg)).toEqual([seg]);
});
// 回归:LLM 产出无双换行的超长段时曾整条发送失败,Alice 收不到回复
test("无双换行的超长段被硬切,每段都在限内", () => {
const long = "测".repeat(TG_SEGMENT_LIMIT * 2 + 500);
const out = splitMessages(long);
expect(out.length).toBeGreaterThan(1);
for (const seg of out) expect(seg.length).toBeLessThanOrEqual(TG_SEGMENT_LIMIT);
expect(out.join("")).toBe(long);
});
test("超长段优先在换行处断开", () => {
const part = "行".repeat(3000);
const text = `${part}\n${part}`;
const out = hardChunk(text);
expect(out[0]).toBe(part);
expect(out[1]).toBe(part);
});
});