test(reply): add block delivery normalization regressions

This commit is contained in:
Sebastian
2026-02-14 22:59:54 -05:00
parent eefb2f8fb3
commit 769661a4a2
2 changed files with 52 additions and 2 deletions

View File

@@ -261,4 +261,54 @@ describe("block streaming", () => {
expect(seen).toEqual(["Hello from stream"]);
});
});
it("still parses media directives for direct block payloads", async () => {
await withTempHome(async (home) => {
const onBlockReply = vi.fn();
piEmbeddedMock.runEmbeddedPiAgent.mockImplementation(
async (params: RunEmbeddedPiAgentParams) => {
void params.onBlockReply?.({ text: "Result\nMEDIA: ./image.png" });
return {
payloads: [{ text: "Result\nMEDIA: ./image.png" }],
meta: {
durationMs: 5,
agentMeta: { sessionId: "s", provider: "p", model: "m" },
},
};
},
);
const res = await getReplyFromConfig(
{
Body: "ping",
From: "+1004",
To: "+2000",
MessageSid: "msg-129",
Provider: "telegram",
},
{
onBlockReply,
disableBlockStreaming: false,
},
{
agents: {
defaults: {
model: "anthropic/claude-opus-4-5",
workspace: path.join(home, "openclaw"),
},
},
channels: { telegram: { allowFrom: ["*"] } },
session: { store: path.join(home, "sessions.json") },
},
);
expect(res).toBeUndefined();
expect(onBlockReply).toHaveBeenCalledTimes(1);
expect(onBlockReply.mock.calls[0][0]).toMatchObject({
text: "Result",
mediaUrls: ["./image.png"],
});
});
});
});

View File

@@ -181,10 +181,10 @@ describe("runReplyAgent typing (heartbeat)", () => {
expect(typing.startTypingLoop).not.toHaveBeenCalled();
});
it("signals typing on block replies", async () => {
it("signals typing on normalized block replies", async () => {
const onBlockReply = vi.fn();
runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => {
await params.onBlockReply?.({ text: "chunk", mediaUrls: [] });
await params.onBlockReply?.({ text: "\n\nchunk", mediaUrls: [] });
return { payloads: [{ text: "final" }], meta: {} };
});