test: add tests for onToolResult in DM vs group sessions

- provides onToolResult in DM sessions (ChatType=direct)
- does not provide onToolResult in group sessions (ChatType=group)
- sends tool results via dispatcher in DM sessions

Replaces the old cross-provider test that expected onToolResult to
always be undefined.
This commit is contained in:
Clawdbot 2026-01-27 09:43:38 +01:00 committed by Ayaan Zaidi
parent 05f1cfd0ad
commit 9a1ba96e94

View File

@ -138,7 +138,7 @@ describe("dispatchReplyFromConfig", () => {
); );
}); });
it("does not provide onToolResult when routing cross-provider", async () => { it("provides onToolResult in DM sessions", async () => {
mocks.tryFastAbortFromMessage.mockResolvedValue({ mocks.tryFastAbortFromMessage.mockResolvedValue({
handled: false, handled: false,
aborted: false, aborted: false,
@ -147,9 +147,34 @@ describe("dispatchReplyFromConfig", () => {
const cfg = {} as MoltbotConfig; const cfg = {} as MoltbotConfig;
const dispatcher = createDispatcher(); const dispatcher = createDispatcher();
const ctx = buildTestCtx({ const ctx = buildTestCtx({
Provider: "slack", Provider: "telegram",
OriginatingChannel: "telegram", ChatType: "direct",
OriginatingTo: "telegram:999", });
const replyResolver = async (
_ctx: MsgContext,
opts: GetReplyOptions | undefined,
_cfg: ClawdbotConfig,
) => {
expect(opts?.onToolResult).toBeDefined();
expect(typeof opts?.onToolResult).toBe("function");
return { text: "hi" } satisfies ReplyPayload;
};
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(dispatcher.sendFinalReply).toHaveBeenCalledTimes(1);
});
it("does not provide onToolResult in group sessions", async () => {
mocks.tryFastAbortFromMessage.mockResolvedValue({
handled: false,
aborted: false,
});
const cfg = {} as ClawdbotConfig;
const dispatcher = createDispatcher();
const ctx = buildTestCtx({
Provider: "telegram",
ChatType: "group",
}); });
const replyResolver = async ( const replyResolver = async (
@ -162,12 +187,36 @@ describe("dispatchReplyFromConfig", () => {
}; };
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver }); await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(dispatcher.sendFinalReply).toHaveBeenCalledTimes(1);
});
expect(mocks.routeReply).toHaveBeenCalledWith( it("sends tool results via dispatcher in DM sessions", async () => {
expect.objectContaining({ mocks.tryFastAbortFromMessage.mockResolvedValue({
payload: expect.objectContaining({ text: "hi" }), handled: false,
}), aborted: false,
});
const cfg = {} as ClawdbotConfig;
const dispatcher = createDispatcher();
const ctx = buildTestCtx({
Provider: "telegram",
ChatType: "direct",
});
const replyResolver = async (
_ctx: MsgContext,
opts: GetReplyOptions | undefined,
_cfg: ClawdbotConfig,
) => {
// Simulate tool result emission
await opts?.onToolResult?.({ text: "🔧 exec: ls" });
return { text: "done" } satisfies ReplyPayload;
};
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(dispatcher.sendToolResult).toHaveBeenCalledWith(
expect.objectContaining({ text: "🔧 exec: ls" }),
); );
expect(dispatcher.sendFinalReply).toHaveBeenCalledTimes(1);
}); });
it("fast-aborts without calling the reply resolver", async () => { it("fast-aborts without calling the reply resolver", async () => {