mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
test(whatsapp): cover group generated media delivery
This commit is contained in:
@@ -378,7 +378,7 @@ describe("whatsapp inbound dispatch", () => {
|
||||
expect(groupHistories.get("whatsapp:default:group:123@g.us") ?? []).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("delivers block and final WhatsApp payloads; suppresses text-only tool payloads but delivers tool media", async () => {
|
||||
it("delivers block and final WhatsApp payloads; suppresses text-only tool payloads but delivers media", async () => {
|
||||
const deliverReply = vi.fn(async () => undefined);
|
||||
const rememberSentText = vi.fn();
|
||||
|
||||
@@ -411,10 +411,27 @@ describe("whatsapp inbound dispatch", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
await deliver?.(
|
||||
{ text: "generated image", mediaUrls: ["/tmp/generated.jpg"] },
|
||||
{
|
||||
kind: "block",
|
||||
},
|
||||
);
|
||||
expect(deliverReply).toHaveBeenCalledTimes(2);
|
||||
expect(rememberSentText).toHaveBeenCalledTimes(2);
|
||||
expect(deliverReply).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
replyResult: expect.objectContaining({
|
||||
mediaUrls: ["/tmp/generated.jpg"],
|
||||
text: "generated image",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
await deliver?.({ text: "block payload" }, { kind: "block" });
|
||||
await deliver?.({ text: "final payload" }, { kind: "final" });
|
||||
expect(deliverReply).toHaveBeenCalledTimes(3);
|
||||
expect(rememberSentText).toHaveBeenCalledTimes(3);
|
||||
expect(deliverReply).toHaveBeenCalledTimes(4);
|
||||
expect(rememberSentText).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
|
||||
it("suppresses reasoning and compaction payloads before WhatsApp delivery", async () => {
|
||||
|
||||
@@ -3241,6 +3241,37 @@ describe("dispatchReplyFromConfig", () => {
|
||||
expect(blockReplySentTexts).toContain("The answer is 42");
|
||||
});
|
||||
|
||||
it("forwards generated-media block replies in WhatsApp group sessions", async () => {
|
||||
setNoAbort();
|
||||
const dispatcher = createDispatcher();
|
||||
const ctx = buildTestCtx({
|
||||
Provider: "whatsapp",
|
||||
Surface: "whatsapp",
|
||||
ChatType: "group",
|
||||
From: "whatsapp:120363111111111@g.us",
|
||||
To: "whatsapp:120363111111111@g.us",
|
||||
SessionKey: "agent:main:whatsapp:group:120363111111111@g.us",
|
||||
});
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts?: GetReplyOptions,
|
||||
): Promise<ReplyPayload> => {
|
||||
await opts?.onBlockReply?.({
|
||||
text: "generated",
|
||||
mediaUrls: ["https://example.com/generated.png"],
|
||||
});
|
||||
return { text: "NO_REPLY" };
|
||||
};
|
||||
|
||||
await dispatchReplyFromConfig({ ctx, cfg: emptyConfig, dispatcher, replyResolver });
|
||||
|
||||
expect(dispatcher.sendBlockReply).toHaveBeenCalledTimes(1);
|
||||
expect(dispatcher.sendBlockReply).toHaveBeenCalledWith({
|
||||
text: "generated",
|
||||
mediaUrls: ["https://example.com/generated.png"],
|
||||
});
|
||||
});
|
||||
|
||||
it("signals block boundaries before async block delivery is queued", async () => {
|
||||
setNoAbort();
|
||||
const dispatcher = createDispatcher();
|
||||
|
||||
Reference in New Issue
Block a user