test(hooks): cover claimed inbound observer delivery

This commit is contained in:
Vincent Koc 2026-03-13 14:11:17 -07:00
parent ad1fedd6ba
commit 9246353a66
1 changed files with 29 additions and 1 deletions

View File

@ -1759,7 +1759,8 @@ describe("dispatchReplyFromConfig", () => {
it("lets a plugin claim inbound traffic before core commands and agent dispatch", async () => {
setNoAbort();
hookMocks.runner.hasHooks.mockImplementation(
((hookName?: string) => hookName === "inbound_claim") as () => boolean,
((hookName?: string) =>
hookName === "inbound_claim" || hookName === "message_received") as () => boolean,
);
hookMocks.runner.runInboundClaim.mockResolvedValue({ handled: true } as never);
const cfg = emptyConfig;
@ -1780,6 +1781,7 @@ describe("dispatchReplyFromConfig", () => {
RawBody: "who are you",
Body: "who are you",
MessageSid: "msg-claim-1",
SessionKey: "agent:main:telegram:group:-10099:77",
});
const replyResolver = vi.fn(async () => ({ text: "should not run" }) satisfies ReplyPayload);
@ -1806,6 +1808,32 @@ describe("dispatchReplyFromConfig", () => {
messageId: "msg-claim-1",
}),
);
expect(hookMocks.runner.runMessageReceived).toHaveBeenCalledWith(
expect.objectContaining({
from: ctx.From,
content: "who are you",
metadata: expect.objectContaining({
messageId: "msg-claim-1",
originatingChannel: "telegram",
originatingTo: "telegram:-10099",
senderId: "user-9",
senderUsername: "ada",
threadId: 77,
}),
}),
expect.objectContaining({
channelId: "telegram",
accountId: "default",
conversationId: "telegram:-10099",
}),
);
expect(internalHookMocks.triggerInternalHook).toHaveBeenCalledWith(
expect.objectContaining({
type: "message",
action: "received",
sessionKey: "agent:main:telegram:group:-10099:77",
}),
);
expect(replyResolver).not.toHaveBeenCalled();
expect(dispatcher.sendFinalReply).not.toHaveBeenCalled();
});