diff --git a/src/infra/outbound/outbound-send-service.test.ts b/src/infra/outbound/outbound-send-service.test.ts index d2adb36d2cb..20705355d83 100644 --- a/src/infra/outbound/outbound-send-service.test.ts +++ b/src/infra/outbound/outbound-send-service.test.ts @@ -87,6 +87,8 @@ vi.mock("../../config/sessions.js", () => ({ })); type OutboundSendServiceModule = typeof import("./outbound-send-service.js"); +type ExecuteSendInput = Parameters[0]; +type ExecuteSendContext = ExecuteSendInput["ctx"]; let executePollAction: OutboundSendServiceModule["executePollAction"]; let executeSendAction: OutboundSendServiceModule["executeSendAction"]; @@ -145,6 +147,29 @@ describe("executeSendAction", () => { }); } + function createPluginMediaSendContext( + overrides: Partial, + ): ExecuteSendContext { + return { + cfg: {}, + channel: "demo-outbound", + params: { media: "/tmp/host.png" }, + sessionKey: "agent:main:whatsapp:group:ops", + dryRun: false, + ...overrides, + } as ExecuteSendContext; + } + + async function executePluginMediaSend(ctx: Partial) { + mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); + + await executeSendAction({ + ctx: createPluginMediaSendContext(ctx), + to: "channel:123", + message: "hello", + }); + } + beforeAll(async () => { ({ executePollAction, executeSendAction } = await import("./outbound-send-service.js")); }); @@ -288,19 +313,8 @@ describe("executeSendAction", () => { }); it("forwards requesterSenderId into outbound media access resolution", async () => { - mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); - - await executeSendAction({ - ctx: { - cfg: {}, - channel: "demo-outbound", - params: { media: "/tmp/host.png" }, - sessionKey: "agent:main:whatsapp:group:ops", - requesterSenderId: "attacker", - dryRun: false, - }, - to: "channel:123", - message: "hello", + await executePluginMediaSend({ + requesterSenderId: "attacker", }); expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith( @@ -311,21 +325,10 @@ describe("executeSendAction", () => { }); it("forwards non-id requester sender fields into outbound media access resolution", async () => { - mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); - - await executeSendAction({ - ctx: { - cfg: {}, - channel: "demo-outbound", - params: { media: "/tmp/host.png" }, - sessionKey: "agent:main:whatsapp:group:ops", - requesterSenderName: "Alice", - requesterSenderUsername: "alice_u", - requesterSenderE164: "+15551234567", - dryRun: false, - }, - to: "channel:123", - message: "hello", + await executePluginMediaSend({ + requesterSenderName: "Alice", + requesterSenderUsername: "alice_u", + requesterSenderE164: "+15551234567", }); expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith( @@ -338,19 +341,8 @@ describe("executeSendAction", () => { }); it("keeps requester session channel authoritative for media policy", async () => { - mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); - - await executeSendAction({ - ctx: { - cfg: {}, - channel: "demo-outbound", - params: { media: "/tmp/host.png" }, - sessionKey: "agent:main:whatsapp:group:ops", - requesterSenderId: "attacker", - dryRun: false, - }, - to: "channel:123", - message: "hello", + await executePluginMediaSend({ + requesterSenderId: "attacker", }); expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith( @@ -362,21 +354,10 @@ describe("executeSendAction", () => { }); it("uses requester account for media policy when session context is present", async () => { - mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); - - await executeSendAction({ - ctx: { - cfg: {}, - channel: "demo-outbound", - params: { media: "/tmp/host.png" }, - sessionKey: "agent:main:whatsapp:group:ops", - requesterAccountId: "source-account", - requesterSenderId: "attacker", - accountId: "destination-account", - dryRun: false, - }, - to: "channel:123", - message: "hello", + await executePluginMediaSend({ + requesterAccountId: "source-account", + requesterSenderId: "attacker", + accountId: "destination-account", }); expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith( @@ -388,20 +369,9 @@ describe("executeSendAction", () => { }); it("falls back to destination account for media policy when requester account is missing", async () => { - mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin")); - - await executeSendAction({ - ctx: { - cfg: {}, - channel: "demo-outbound", - params: { media: "/tmp/host.png" }, - sessionKey: "agent:main:whatsapp:group:ops", - requesterSenderId: "attacker", - accountId: "destination-account", - dryRun: false, - }, - to: "channel:123", - message: "hello", + await executePluginMediaSend({ + requesterSenderId: "attacker", + accountId: "destination-account", }); expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith(