Files
openclaw/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.reopens-fenced-blocks-splitting-inside-them.e2e.test.ts
2026-02-16 14:59:30 +00:00

40 lines
1.2 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import {
createParagraphChunkedBlockReplyHarness,
emitAssistantTextDeltaAndEnd,
expectFencedChunks,
} from "./pi-embedded-subscribe.e2e-harness.js";
describe("subscribeEmbeddedPiSession", () => {
it("reopens fenced blocks when splitting inside them", () => {
const onBlockReply = vi.fn();
const { emit } = createParagraphChunkedBlockReplyHarness({
onBlockReply,
chunking: {
minChars: 10,
maxChars: 30,
},
});
const text = `\`\`\`txt\n${"a".repeat(80)}\n\`\`\``;
emitAssistantTextDeltaAndEnd({ emit, text });
expectFencedChunks(onBlockReply.mock.calls, "```txt");
});
it("avoids splitting inside tilde fences", () => {
const onBlockReply = vi.fn();
const { emit } = createParagraphChunkedBlockReplyHarness({
onBlockReply,
chunking: {
minChars: 5,
maxChars: 25,
},
});
const text = "Intro\n\n~~~sh\nline1\nline2\n~~~\n\nOutro";
emitAssistantTextDeltaAndEnd({ emit, text });
expect(onBlockReply).toHaveBeenCalledTimes(3);
expect(onBlockReply.mock.calls[1][0].text).toBe("~~~sh\nline1\nline2\n~~~");
});
});