refactor(outbound): share plugin send/poll dispatch path

This commit is contained in:
Peter Steinberger
2026-02-18 22:39:49 +00:00
parent fc5bcebd0a
commit a117e9fed6
2 changed files with 139 additions and 50 deletions

View File

@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
dispatchChannelMessageAction: vi.fn(),
sendMessage: vi.fn(),
sendPoll: vi.fn(),
}));
vi.mock("../../channels/plugins/message-actions.js", () => ({
@@ -11,15 +12,16 @@ vi.mock("../../channels/plugins/message-actions.js", () => ({
vi.mock("./message.js", () => ({
sendMessage: (...args: unknown[]) => mocks.sendMessage(...args),
sendPoll: vi.fn(),
sendPoll: (...args: unknown[]) => mocks.sendPoll(...args),
}));
import { executeSendAction } from "./outbound-send-service.js";
import { executePollAction, executeSendAction } from "./outbound-send-service.js";
describe("executeSendAction", () => {
beforeEach(() => {
mocks.dispatchChannelMessageAction.mockReset();
mocks.sendMessage.mockReset();
mocks.sendPoll.mockReset();
});
it("forwards ctx.agentId to sendMessage on core outbound path", async () => {
@@ -52,4 +54,77 @@ describe("executeSendAction", () => {
}),
);
});
it("uses plugin poll action when available", async () => {
mocks.dispatchChannelMessageAction.mockResolvedValue({
ok: true,
value: { messageId: "poll-plugin" },
continuePrompt: "",
output: "",
sessionId: "s1",
model: "gpt-5.2",
usage: {},
});
const result = await executePollAction({
ctx: {
cfg: {},
channel: "discord",
params: {},
dryRun: false,
},
to: "channel:123",
question: "Lunch?",
options: ["Pizza", "Sushi"],
maxSelections: 1,
});
expect(result.handledBy).toBe("plugin");
expect(mocks.sendPoll).not.toHaveBeenCalled();
});
it("forwards poll args to sendPoll on core outbound path", async () => {
mocks.dispatchChannelMessageAction.mockResolvedValue(null);
mocks.sendPoll.mockResolvedValue({
channel: "discord",
to: "channel:123",
question: "Lunch?",
options: ["Pizza", "Sushi"],
maxSelections: 1,
durationSeconds: null,
durationHours: null,
via: "gateway",
});
await executePollAction({
ctx: {
cfg: {},
channel: "discord",
params: {},
accountId: "acc-1",
dryRun: false,
},
to: "channel:123",
question: "Lunch?",
options: ["Pizza", "Sushi"],
maxSelections: 1,
durationSeconds: 300,
threadId: "thread-1",
isAnonymous: true,
});
expect(mocks.sendPoll).toHaveBeenCalledWith(
expect.objectContaining({
channel: "discord",
accountId: "acc-1",
to: "channel:123",
question: "Lunch?",
options: ["Pizza", "Sushi"],
maxSelections: 1,
durationSeconds: 300,
threadId: "thread-1",
isAnonymous: true,
}),
);
});
});