mirror of https://github.com/openclaw/openclaw.git
test: tighten shared text chunking coverage
This commit is contained in:
parent
56299effe9
commit
cdde51c608
|
|
@ -12,6 +12,7 @@ describe("shared/chat-content", () => {
|
|||
{ type: "text", text: " hello " },
|
||||
{ type: "image_url", image_url: "https://example.com" },
|
||||
{ type: "text", text: "world" },
|
||||
{ text: "ignored without type" },
|
||||
null,
|
||||
]),
|
||||
).toBe("hello world");
|
||||
|
|
@ -37,6 +38,18 @@ describe("shared/chat-content", () => {
|
|||
},
|
||||
),
|
||||
).toBe("hello\nworld");
|
||||
|
||||
expect(
|
||||
extractTextFromChatContent(
|
||||
[
|
||||
{ type: "text", text: "keep" },
|
||||
{ type: "text", text: "drop" },
|
||||
],
|
||||
{
|
||||
sanitizeText: (text) => (text === "drop" ? " " : text),
|
||||
},
|
||||
),
|
||||
).toBe("keep");
|
||||
});
|
||||
|
||||
it("returns null for unsupported or empty content", () => {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ describe("shared/text-chunking", () => {
|
|||
it("returns empty for blank input and the full text when under limit", () => {
|
||||
expect(chunkTextByBreakResolver("", 10, () => 5)).toEqual([]);
|
||||
expect(chunkTextByBreakResolver("hello", 10, () => 2)).toEqual(["hello"]);
|
||||
expect(chunkTextByBreakResolver("hello", 0, () => 2)).toEqual(["hello"]);
|
||||
});
|
||||
|
||||
it("splits at resolver-provided breakpoints and trims separator boundaries", () => {
|
||||
expect(
|
||||
chunkTextByBreakResolver("alpha beta gamma", 10, (window) => window.lastIndexOf(" ")),
|
||||
).toEqual(["alpha", "beta gamma"]);
|
||||
expect(chunkTextByBreakResolver("abcd efgh", 4, () => 4)).toEqual(["abcd", "efgh"]);
|
||||
});
|
||||
|
||||
it("falls back to hard limits for invalid break indexes", () => {
|
||||
|
|
@ -28,4 +30,11 @@ describe("shared/text-chunking", () => {
|
|||
chunkTextByBreakResolver("word next", 5, (window) => window.lastIndexOf(" ")),
|
||||
).toEqual(["word", "next"]);
|
||||
});
|
||||
|
||||
it("trims trailing whitespace from emitted chunks before continuing", () => {
|
||||
expect(chunkTextByBreakResolver("abc def", 6, (window) => window.lastIndexOf(" "))).toEqual([
|
||||
"abc",
|
||||
"def",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue