mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:31:25 +00:00
fix: newline chunking across channels
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { chunkDiscordText } from "./chunk.js";
|
||||
import { chunkDiscordText, chunkDiscordTextWithMode } from "./chunk.js";
|
||||
|
||||
function countLines(text: string) {
|
||||
return text.split("\n").length;
|
||||
@@ -51,6 +51,16 @@ describe("chunkDiscordText", () => {
|
||||
expect(chunks.at(-1)).toContain("Done.");
|
||||
});
|
||||
|
||||
it("keeps fenced blocks intact when chunkMode is newline", () => {
|
||||
const text = "```js\nconst a = 1;\nconst b = 2;\n```\nAfter";
|
||||
const chunks = chunkDiscordTextWithMode(text, {
|
||||
maxChars: 2000,
|
||||
maxLines: 50,
|
||||
chunkMode: "newline",
|
||||
});
|
||||
expect(chunks).toEqual(["```js\nconst a = 1;\nconst b = 2;\n```", "After"]);
|
||||
});
|
||||
|
||||
it("reserves space for closing fences when chunking", () => {
|
||||
const body = "a".repeat(120);
|
||||
const text = `\`\`\`txt\n${body}\n\`\`\``;
|
||||
|
||||
Reference in New Issue
Block a user