refactor: unify markdown formatting pipeline
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
import { markdownToSignalTextChunks } from "../../signal/format.js";
|
||||
import { deliverOutboundPayloads, normalizeOutboundPayloads } from "./deliver.js";
|
||||
|
||||
describe("deliverOutboundPayloads", () => {
|
||||
@@ -22,7 +23,9 @@ describe("deliverOutboundPayloads", () => {
|
||||
|
||||
expect(sendTelegram).toHaveBeenCalledTimes(2);
|
||||
for (const call of sendTelegram.mock.calls) {
|
||||
expect(call[2]).toEqual(expect.objectContaining({ accountId: undefined, verbose: false }));
|
||||
expect(call[2]).toEqual(
|
||||
expect.objectContaining({ accountId: undefined, verbose: false, textMode: "html" }),
|
||||
);
|
||||
}
|
||||
expect(results).toHaveLength(2);
|
||||
expect(results[0]).toMatchObject({ channel: "telegram", chatId: "c1" });
|
||||
@@ -53,7 +56,7 @@ describe("deliverOutboundPayloads", () => {
|
||||
expect(sendTelegram).toHaveBeenCalledWith(
|
||||
"123",
|
||||
"hi",
|
||||
expect.objectContaining({ accountId: "default", verbose: false }),
|
||||
expect.objectContaining({ accountId: "default", verbose: false, textMode: "html" }),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -75,11 +78,46 @@ describe("deliverOutboundPayloads", () => {
|
||||
expect.objectContaining({
|
||||
mediaUrl: "https://x.test/a.jpg",
|
||||
maxBytes: 2 * 1024 * 1024,
|
||||
textMode: "plain",
|
||||
textStyles: [],
|
||||
}),
|
||||
);
|
||||
expect(results[0]).toMatchObject({ channel: "signal", messageId: "s1" });
|
||||
});
|
||||
|
||||
it("chunks Signal markdown using the format-first chunker", async () => {
|
||||
const sendSignal = vi
|
||||
.fn()
|
||||
.mockResolvedValue({ messageId: "s1", timestamp: 123 });
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: { signal: { textChunkLimit: 20 } },
|
||||
};
|
||||
const text = `Intro\\n\\n\`\`\`\`md\\n${"y".repeat(60)}\\n\`\`\`\\n\\nOutro`;
|
||||
const expectedChunks = markdownToSignalTextChunks(text, 20);
|
||||
|
||||
await deliverOutboundPayloads({
|
||||
cfg,
|
||||
channel: "signal",
|
||||
to: "+1555",
|
||||
payloads: [{ text }],
|
||||
deps: { sendSignal },
|
||||
});
|
||||
|
||||
expect(sendSignal).toHaveBeenCalledTimes(expectedChunks.length);
|
||||
expectedChunks.forEach((chunk, index) => {
|
||||
expect(sendSignal).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
"+1555",
|
||||
chunk.text,
|
||||
expect.objectContaining({
|
||||
accountId: undefined,
|
||||
textMode: "plain",
|
||||
textStyles: chunk.styles,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("chunks WhatsApp text and returns all results", async () => {
|
||||
const sendWhatsApp = vi
|
||||
.fn()
|
||||
|
||||
Reference in New Issue
Block a user