openclaw/src/commands/message.test.ts

497 lines
13 KiB
TypeScript
Raw Normal View History

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type {
ChannelMessageActionAdapter,
ChannelOutboundAdapter,
ChannelPlugin,
} from "../channels/plugins/types.js";
import type { CliDeps } from "../cli/deps.js";
import type { RuntimeEnv } from "../runtime.js";
import { createTestRegistry } from "../test-utils/channel-plugins.js";
import { captureEnv } from "../test-utils/env.js";
2026-01-01 21:22:59 +01:00
let testConfig: Record<string, unknown> = {};
vi.mock("../config/config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/config.js")>();
return {
...actual,
loadConfig: () => testConfig,
};
});
2026-01-01 21:22:59 +01:00
feat(secrets): expand SecretRef coverage across user-supplied credentials (#29580) * feat(secrets): expand secret target coverage and gateway tooling * docs(secrets): align gateway and CLI secret docs * chore(protocol): regenerate swift gateway models for secrets methods * fix(config): restore talk apiKey fallback and stabilize runner test * ci(windows): reduce test worker count for shard stability * ci(windows): raise node heap for test shard stability * test(feishu): make proxy env precedence assertion windows-safe * fix(gateway): resolve auth password SecretInput refs for clients * fix(gateway): resolve remote SecretInput credentials for clients * fix(secrets): skip inactive refs in command snapshot assignments * fix(secrets): scope gateway.remote refs to effective auth surfaces * fix(secrets): ignore memory defaults when enabled agents disable search * fix(secrets): honor Google Chat serviceAccountRef inheritance * fix(secrets): address tsgo errors in command and gateway collectors * fix(secrets): avoid auth-store load in providers-only configure * fix(gateway): defer local password ref resolution by precedence * fix(secrets): gate telegram webhook secret refs by webhook mode * fix(secrets): gate slack signing secret refs to http mode * fix(secrets): skip telegram botToken refs when tokenFile is set * fix(secrets): gate discord pluralkit refs by enabled flag * fix(secrets): gate discord voice tts refs by voice enabled * test(secrets): make runtime fixture modes explicit * fix(cli): resolve local qr password secret refs * fix(cli): fail when gateway leaves command refs unresolved * fix(gateway): fail when local password SecretRef is unresolved * fix(gateway): fail when required remote SecretRefs are unresolved * fix(gateway): resolve local password refs only when password can win * fix(cli): skip local password SecretRef resolution on qr token override * test(gateway): cast SecretRef fixtures to OpenClawConfig * test(secrets): activate mode-gated targets in runtime coverage fixture * fix(cron): support SecretInput webhook tokens safely * fix(bluebubbles): support SecretInput passwords across config paths * fix(msteams): make appPassword SecretInput-safe in onboarding/token paths * fix(bluebubbles): align SecretInput schema helper typing * fix(cli): clarify secrets.resolve version-skew errors * refactor(secrets): return structured inactive paths from secrets.resolve * refactor(gateway): type onboarding secret writes as SecretInput * chore(protocol): regenerate swift models for secrets.resolve * feat(secrets): expand extension credential secretref support * fix(secrets): gate web-search refs by active provider * fix(onboarding): detect SecretRef credentials in extension status * fix(onboarding): allow keeping existing ref in secret prompt * fix(onboarding): resolve gateway password SecretRefs for probe and tui * fix(onboarding): honor secret-input-mode for local gateway auth * fix(acp): resolve gateway SecretInput credentials * fix(secrets): gate gateway.remote refs to remote surfaces * test(secrets): cover pattern matching and inactive array refs * docs(secrets): clarify secrets.resolve and remote active surfaces * fix(bluebubbles): keep existing SecretRef during onboarding * fix(tests): resolve CI type errors in new SecretRef coverage * fix(extensions): replace raw fetch with SSRF-guarded fetch * test(secrets): mark gateway remote targets active in runtime coverage * test(infra): normalize home-prefix expectation across platforms * fix(cli): only resolve local qr password refs in password mode * test(cli): cover local qr token mode with unresolved password ref * docs(cli): clarify local qr password ref resolution behavior * refactor(extensions): reuse sdk SecretInput helpers * fix(wizard): resolve onboarding env-template secrets before plaintext * fix(cli): surface secrets.resolve diagnostics in memory and qr * test(secrets): repair post-rebase runtime and fixtures * fix(gateway): skip remote password ref resolution when token wins * fix(secrets): treat tailscale remote gateway refs as active * fix(gateway): allow remote password fallback when token ref is unresolved * fix(gateway): ignore stale local password refs for none and trusted-proxy * fix(gateway): skip remote secret ref resolution on local call paths * test(cli): cover qr remote tailscale secret ref resolution * fix(secrets): align gateway password active-surface with auth inference * fix(cli): resolve inferred local gateway password refs in qr * fix(gateway): prefer resolvable remote password over token ref pre-resolution * test(gateway): cover none and trusted-proxy stale password refs * docs(secrets): sync qr and gateway active-surface behavior * fix: restore stability blockers from pre-release audit * Secrets: fix collector/runtime precedence contradictions * docs: align secrets and web credential docs * fix(rebase): resolve integration regressions after main rebase * fix(node-host): resolve gateway secret refs for auth * fix(secrets): harden secretinput runtime readers * gateway: skip inactive auth secretref resolution * cli: avoid gateway preflight for inactive secret refs * extensions: allow unresolved refs in onboarding status * tests: fix qr-cli module mock hoist ordering * Security: align audit checks with SecretInput resolution * Gateway: resolve local-mode remote fallback secret refs * Node host: avoid resolving inactive password secret refs * Secrets runtime: mark Slack appToken inactive for HTTP mode * secrets: keep inactive gateway remote refs non-blocking * cli: include agent memory secret targets in runtime resolution * docs(secrets): sync docs with active-surface and web search behavior * fix(secrets): keep telegram top-level token refs active for blank account tokens * fix(daemon): resolve gateway password secret refs for probe auth * fix(secrets): skip IRC NickServ ref resolution when NickServ is disabled * fix(secrets): align token inheritance and exec timeout defaults * docs(secrets): clarify active-surface notes in cli docs * cli: require secrets.resolve gateway capability * gateway: log auth secret surface diagnostics * secrets: remove dead provider resolver module * fix(secrets): restore gateway auth precedence and fallback resolution * fix(tests): align plugin runtime mock typings --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-03-02 20:58:20 -06:00
const resolveCommandSecretRefsViaGateway = vi.fn(async ({ config }: { config: unknown }) => ({
resolvedConfig: config,
diagnostics: [] as string[],
}));
vi.mock("../cli/command-secret-gateway.js", () => ({
resolveCommandSecretRefsViaGateway,
}));
2025-12-09 20:18:50 +00:00
const callGatewayMock = vi.fn();
vi.mock("../gateway/call.js", () => ({
2026-02-17 11:59:29 +09:00
callGateway: callGatewayMock,
callGatewayLeastPrivilege: callGatewayMock,
2025-12-09 20:18:50 +00:00
randomIdempotencyKey: () => "idem-1",
}));
2026-01-09 08:27:17 +01:00
const webAuthExists = vi.fn(async () => false);
vi.mock("../../extensions/whatsapp/src/session.js", () => ({
2026-02-17 11:59:29 +09:00
webAuthExists,
2026-01-09 08:27:17 +01:00
}));
2026-02-17 14:32:43 +09:00
const handleDiscordAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
2026-01-09 08:27:17 +01:00
vi.mock("../agents/tools/discord-actions.js", () => ({
2026-02-17 11:59:29 +09:00
handleDiscordAction,
2026-01-09 08:27:17 +01:00
}));
2026-02-17 14:32:43 +09:00
const handleSlackAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
2026-01-09 08:27:17 +01:00
vi.mock("../agents/tools/slack-actions.js", () => ({
2026-02-17 11:59:29 +09:00
handleSlackAction,
2026-01-09 08:27:17 +01:00
}));
2026-02-17 14:32:43 +09:00
const handleTelegramAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
2026-01-09 08:27:17 +01:00
vi.mock("../agents/tools/telegram-actions.js", () => ({
2026-02-17 11:59:29 +09:00
handleTelegramAction,
2026-01-09 08:27:17 +01:00
}));
2026-02-17 14:32:43 +09:00
const handleWhatsAppAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
2026-01-09 08:27:17 +01:00
vi.mock("../agents/tools/whatsapp-actions.js", () => ({
2026-02-17 11:59:29 +09:00
handleWhatsAppAction,
2026-01-09 08:27:17 +01:00
}));
let envSnapshot: ReturnType<typeof captureEnv>;
const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
const { setActivePluginRegistry } = await import("../plugins/runtime.js");
setActivePluginRegistry(registry);
};
beforeEach(async () => {
envSnapshot = captureEnv(["TELEGRAM_BOT_TOKEN", "DISCORD_BOT_TOKEN"]);
2026-01-09 08:27:17 +01:00
process.env.TELEGRAM_BOT_TOKEN = "";
process.env.DISCORD_BOT_TOKEN = "";
2026-01-01 21:22:59 +01:00
testConfig = {};
await setRegistry(createTestRegistry([]));
callGatewayMock.mockClear();
webAuthExists.mockClear().mockResolvedValue(false);
handleDiscordAction.mockClear();
handleSlackAction.mockClear();
handleTelegramAction.mockClear();
handleWhatsAppAction.mockClear();
feat(secrets): expand SecretRef coverage across user-supplied credentials (#29580) * feat(secrets): expand secret target coverage and gateway tooling * docs(secrets): align gateway and CLI secret docs * chore(protocol): regenerate swift gateway models for secrets methods * fix(config): restore talk apiKey fallback and stabilize runner test * ci(windows): reduce test worker count for shard stability * ci(windows): raise node heap for test shard stability * test(feishu): make proxy env precedence assertion windows-safe * fix(gateway): resolve auth password SecretInput refs for clients * fix(gateway): resolve remote SecretInput credentials for clients * fix(secrets): skip inactive refs in command snapshot assignments * fix(secrets): scope gateway.remote refs to effective auth surfaces * fix(secrets): ignore memory defaults when enabled agents disable search * fix(secrets): honor Google Chat serviceAccountRef inheritance * fix(secrets): address tsgo errors in command and gateway collectors * fix(secrets): avoid auth-store load in providers-only configure * fix(gateway): defer local password ref resolution by precedence * fix(secrets): gate telegram webhook secret refs by webhook mode * fix(secrets): gate slack signing secret refs to http mode * fix(secrets): skip telegram botToken refs when tokenFile is set * fix(secrets): gate discord pluralkit refs by enabled flag * fix(secrets): gate discord voice tts refs by voice enabled * test(secrets): make runtime fixture modes explicit * fix(cli): resolve local qr password secret refs * fix(cli): fail when gateway leaves command refs unresolved * fix(gateway): fail when local password SecretRef is unresolved * fix(gateway): fail when required remote SecretRefs are unresolved * fix(gateway): resolve local password refs only when password can win * fix(cli): skip local password SecretRef resolution on qr token override * test(gateway): cast SecretRef fixtures to OpenClawConfig * test(secrets): activate mode-gated targets in runtime coverage fixture * fix(cron): support SecretInput webhook tokens safely * fix(bluebubbles): support SecretInput passwords across config paths * fix(msteams): make appPassword SecretInput-safe in onboarding/token paths * fix(bluebubbles): align SecretInput schema helper typing * fix(cli): clarify secrets.resolve version-skew errors * refactor(secrets): return structured inactive paths from secrets.resolve * refactor(gateway): type onboarding secret writes as SecretInput * chore(protocol): regenerate swift models for secrets.resolve * feat(secrets): expand extension credential secretref support * fix(secrets): gate web-search refs by active provider * fix(onboarding): detect SecretRef credentials in extension status * fix(onboarding): allow keeping existing ref in secret prompt * fix(onboarding): resolve gateway password SecretRefs for probe and tui * fix(onboarding): honor secret-input-mode for local gateway auth * fix(acp): resolve gateway SecretInput credentials * fix(secrets): gate gateway.remote refs to remote surfaces * test(secrets): cover pattern matching and inactive array refs * docs(secrets): clarify secrets.resolve and remote active surfaces * fix(bluebubbles): keep existing SecretRef during onboarding * fix(tests): resolve CI type errors in new SecretRef coverage * fix(extensions): replace raw fetch with SSRF-guarded fetch * test(secrets): mark gateway remote targets active in runtime coverage * test(infra): normalize home-prefix expectation across platforms * fix(cli): only resolve local qr password refs in password mode * test(cli): cover local qr token mode with unresolved password ref * docs(cli): clarify local qr password ref resolution behavior * refactor(extensions): reuse sdk SecretInput helpers * fix(wizard): resolve onboarding env-template secrets before plaintext * fix(cli): surface secrets.resolve diagnostics in memory and qr * test(secrets): repair post-rebase runtime and fixtures * fix(gateway): skip remote password ref resolution when token wins * fix(secrets): treat tailscale remote gateway refs as active * fix(gateway): allow remote password fallback when token ref is unresolved * fix(gateway): ignore stale local password refs for none and trusted-proxy * fix(gateway): skip remote secret ref resolution on local call paths * test(cli): cover qr remote tailscale secret ref resolution * fix(secrets): align gateway password active-surface with auth inference * fix(cli): resolve inferred local gateway password refs in qr * fix(gateway): prefer resolvable remote password over token ref pre-resolution * test(gateway): cover none and trusted-proxy stale password refs * docs(secrets): sync qr and gateway active-surface behavior * fix: restore stability blockers from pre-release audit * Secrets: fix collector/runtime precedence contradictions * docs: align secrets and web credential docs * fix(rebase): resolve integration regressions after main rebase * fix(node-host): resolve gateway secret refs for auth * fix(secrets): harden secretinput runtime readers * gateway: skip inactive auth secretref resolution * cli: avoid gateway preflight for inactive secret refs * extensions: allow unresolved refs in onboarding status * tests: fix qr-cli module mock hoist ordering * Security: align audit checks with SecretInput resolution * Gateway: resolve local-mode remote fallback secret refs * Node host: avoid resolving inactive password secret refs * Secrets runtime: mark Slack appToken inactive for HTTP mode * secrets: keep inactive gateway remote refs non-blocking * cli: include agent memory secret targets in runtime resolution * docs(secrets): sync docs with active-surface and web search behavior * fix(secrets): keep telegram top-level token refs active for blank account tokens * fix(daemon): resolve gateway password secret refs for probe auth * fix(secrets): skip IRC NickServ ref resolution when NickServ is disabled * fix(secrets): align token inheritance and exec timeout defaults * docs(secrets): clarify active-surface notes in cli docs * cli: require secrets.resolve gateway capability * gateway: log auth secret surface diagnostics * secrets: remove dead provider resolver module * fix(secrets): restore gateway auth precedence and fallback resolution * fix(tests): align plugin runtime mock typings --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-03-02 20:58:20 -06:00
resolveCommandSecretRefsViaGateway.mockClear();
});
afterEach(() => {
envSnapshot.restore();
});
const runtime: RuntimeEnv = {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(() => {
throw new Error("exit");
}),
};
2025-12-05 19:03:59 +00:00
const makeDeps = (overrides: Partial<CliDeps> = {}): CliDeps => ({
sendMessageWhatsApp: vi.fn(),
sendMessageTelegram: vi.fn(),
2025-12-15 10:11:18 -06:00
sendMessageDiscord: vi.fn(),
sendMessageSlack: vi.fn(),
2026-01-01 15:43:15 +01:00
sendMessageSignal: vi.fn(),
2026-01-02 01:19:13 +01:00
sendMessageIMessage: vi.fn(),
2025-12-05 19:03:59 +00:00
...overrides,
});
const createStubPlugin = (params: {
id: ChannelPlugin["id"];
label?: string;
actions?: ChannelMessageActionAdapter;
outbound?: ChannelOutboundAdapter;
}): ChannelPlugin => ({
id: params.id,
meta: {
id: params.id,
label: params.label ?? String(params.id),
selectionLabel: params.label ?? String(params.id),
docsPath: `/channels/${params.id}`,
blurb: "test stub.",
},
capabilities: { chatTypes: ["direct"] },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({}),
isConfigured: async () => true,
},
actions: params.actions,
outbound: params.outbound,
});
2026-02-17 15:48:16 +09:00
type ChannelActionParams = Parameters<
NonNullable<NonNullable<ChannelPlugin["actions"]>["handleAction"]>
>[0];
const createDiscordPollPluginRegistration = () => ({
pluginId: "discord",
source: "test",
plugin: createStubPlugin({
id: "discord",
label: "Discord",
actions: {
listActions: () => ["poll"],
2026-02-17 15:48:16 +09:00
handleAction: (async ({ action, params, cfg, accountId }: ChannelActionParams) => {
return await handleDiscordAction(
{ action, to: params.to, accountId: accountId ?? undefined },
cfg,
2026-02-17 15:48:16 +09:00
);
}) as unknown as NonNullable<ChannelPlugin["actions"]>["handleAction"],
},
}),
});
const createTelegramSendPluginRegistration = () => ({
pluginId: "telegram",
source: "test",
plugin: createStubPlugin({
id: "telegram",
label: "Telegram",
actions: {
listActions: () => ["send"],
2026-02-17 15:48:16 +09:00
handleAction: (async ({ action, params, cfg, accountId }: ChannelActionParams) => {
return await handleTelegramAction(
{ action, to: params.to, accountId: accountId ?? undefined },
cfg,
2026-02-17 15:48:16 +09:00
);
}) as unknown as NonNullable<ChannelPlugin["actions"]>["handleAction"],
},
}),
});
const createTelegramPollPluginRegistration = () => ({
pluginId: "telegram",
source: "test",
plugin: createStubPlugin({
id: "telegram",
label: "Telegram",
actions: {
listActions: () => ["poll"],
handleAction: (async ({ action, params, cfg, accountId }: ChannelActionParams) => {
return await handleTelegramAction(
{ action, to: params.to, accountId: accountId ?? undefined },
cfg,
);
}) as unknown as NonNullable<ChannelPlugin["actions"]>["handleAction"],
},
}),
});
const { messageCommand } = await import("./message.js");
function createTelegramSecretRawConfig() {
return {
channels: {
telegram: {
token: { $secret: "vault://telegram/token" }, // pragma: allowlist secret
},
},
};
}
function createTelegramResolvedTokenConfig(token: string) {
return {
channels: {
telegram: {
token,
},
},
};
}
function mockResolvedCommandConfig(params: {
rawConfig: Record<string, unknown>;
resolvedConfig: Record<string, unknown>;
diagnostics?: string[];
}) {
testConfig = params.rawConfig;
resolveCommandSecretRefsViaGateway.mockResolvedValueOnce({
resolvedConfig: params.resolvedConfig,
diagnostics: params.diagnostics ?? ["resolved channels.telegram.token"],
});
}
async function runTelegramDirectOutboundSend(params: {
rawConfig: Record<string, unknown>;
resolvedConfig: Record<string, unknown>;
diagnostics?: string[];
}) {
mockResolvedCommandConfig(params);
const sendText = vi.fn(async (_ctx: { cfg?: unknown; to?: string; text?: string }) => ({
channel: "telegram" as const,
messageId: "msg-1",
chatId: "123456",
}));
const sendMedia = vi.fn(async (_ctx: { cfg?: unknown }) => ({
channel: "telegram" as const,
messageId: "msg-2",
chatId: "123456",
}));
await setRegistry(
createTestRegistry([
{
pluginId: "telegram",
source: "test",
plugin: createStubPlugin({
id: "telegram",
label: "Telegram",
outbound: {
deliveryMode: "direct",
sendText,
sendMedia,
},
}),
},
]),
);
const deps = makeDeps();
await messageCommand(
{
action: "send",
channel: "telegram",
target: "123456",
message: "hi",
},
deps,
runtime,
);
return { sendText };
}
describe("messageCommand", () => {
it("threads resolved SecretRef config into outbound send actions", async () => {
const rawConfig = createTelegramSecretRawConfig();
const resolvedConfig = createTelegramResolvedTokenConfig("12345:resolved-token");
mockResolvedCommandConfig({
rawConfig: rawConfig as unknown as Record<string, unknown>,
resolvedConfig: resolvedConfig as unknown as Record<string, unknown>,
});
await setRegistry(
createTestRegistry([
{
...createTelegramSendPluginRegistration(),
},
]),
);
const deps = makeDeps();
await messageCommand(
{
action: "send",
channel: "telegram",
target: "123456",
message: "hi",
},
deps,
runtime,
);
expect(resolveCommandSecretRefsViaGateway).toHaveBeenCalledWith(
expect.objectContaining({
config: rawConfig,
commandName: "message",
}),
);
expect(handleTelegramAction).toHaveBeenCalledWith(
expect.objectContaining({ action: "send", to: "123456", accountId: undefined }),
resolvedConfig,
);
});
it("threads resolved SecretRef config into outbound adapter sends", async () => {
const rawConfig = createTelegramSecretRawConfig();
const resolvedConfig = createTelegramResolvedTokenConfig("12345:resolved-token");
const { sendText } = await runTelegramDirectOutboundSend({
rawConfig: rawConfig as unknown as Record<string, unknown>,
resolvedConfig: resolvedConfig as unknown as Record<string, unknown>,
});
expect(sendText).toHaveBeenCalledWith(
expect.objectContaining({
cfg: resolvedConfig,
to: "123456",
text: "hi",
}),
);
expect(sendText.mock.calls[0]?.[0]?.cfg).not.toBe(rawConfig);
});
it("keeps local-fallback resolved cfg in outbound adapter sends", async () => {
const rawConfig = {
channels: {
telegram: {
token: { source: "env", provider: "default", id: "TELEGRAM_BOT_TOKEN" },
},
},
};
const locallyResolvedConfig = {
channels: {
telegram: {
token: "12345:local-fallback-token",
},
},
};
const { sendText } = await runTelegramDirectOutboundSend({
rawConfig: rawConfig as unknown as Record<string, unknown>,
resolvedConfig: locallyResolvedConfig as unknown as Record<string, unknown>,
diagnostics: ["gateway secrets.resolve unavailable; used local resolver fallback."],
});
expect(sendText).toHaveBeenCalledWith(
expect.objectContaining({
cfg: locallyResolvedConfig,
}),
);
expect(sendText.mock.calls[0]?.[0]?.cfg).not.toBe(rawConfig);
expect(runtime.log).toHaveBeenCalledWith(
expect.stringContaining("[secrets] gateway secrets.resolve unavailable"),
);
});
it("defaults channel when only one configured", async () => {
2026-01-09 08:27:17 +01:00
process.env.TELEGRAM_BOT_TOKEN = "token-abc";
await setRegistry(
createTestRegistry([
{
...createTelegramSendPluginRegistration(),
},
]),
);
2025-12-05 19:03:59 +00:00
const deps = makeDeps();
2026-01-09 08:27:17 +01:00
await messageCommand(
{
target: "123456",
message: "hi",
},
deps,
runtime,
);
2026-01-09 08:27:17 +01:00
expect(handleTelegramAction).toHaveBeenCalled();
});
it("requires channel when multiple configured", async () => {
2026-01-09 08:27:17 +01:00
process.env.TELEGRAM_BOT_TOKEN = "token-abc";
process.env.DISCORD_BOT_TOKEN = "token-discord";
await setRegistry(
createTestRegistry([
{
...createTelegramSendPluginRegistration(),
},
{
...createDiscordPollPluginRegistration(),
},
]),
);
2025-12-05 19:03:59 +00:00
const deps = makeDeps();
2026-01-09 08:27:17 +01:00
await expect(
messageCommand(
{
target: "123",
2026-01-09 08:27:17 +01:00
message: "hi",
},
deps,
runtime,
),
).rejects.toThrow(/Channel is required/);
});
2026-01-09 08:27:17 +01:00
it("sends via gateway for WhatsApp", async () => {
callGatewayMock.mockResolvedValueOnce({ messageId: "g1" });
await setRegistry(
createTestRegistry([
{
pluginId: "whatsapp",
source: "test",
plugin: createStubPlugin({
id: "whatsapp",
label: "WhatsApp",
outbound: {
deliveryMode: "gateway",
},
}),
},
]),
);
const deps = makeDeps();
2026-01-09 08:27:17 +01:00
await messageCommand(
{
2026-01-09 08:27:17 +01:00
action: "send",
channel: "whatsapp",
target: "+15551234567",
message: "hi",
},
deps,
runtime,
);
2026-01-09 08:27:17 +01:00
expect(callGatewayMock).toHaveBeenCalled();
});
2026-01-09 08:27:17 +01:00
it("routes discord polls through message action", async () => {
await setRegistry(
createTestRegistry([
{
...createDiscordPollPluginRegistration(),
},
]),
);
2026-01-03 23:57:43 +00:00
const deps = makeDeps();
2026-01-09 08:27:17 +01:00
await messageCommand(
2026-01-03 23:57:43 +00:00
{
2026-01-09 08:27:17 +01:00
action: "poll",
channel: "discord",
target: "channel:123456789",
2026-01-09 08:27:17 +01:00
pollQuestion: "Snack?",
pollOption: ["Pizza", "Sushi"],
2026-01-03 23:57:43 +00:00
},
deps,
runtime,
);
2026-01-09 08:27:17 +01:00
expect(handleDiscordAction).toHaveBeenCalledWith(
2026-01-03 23:57:43 +00:00
expect.objectContaining({
2026-01-09 08:27:17 +01:00
action: "poll",
to: "channel:123456789",
2026-01-03 23:57:43 +00:00
}),
2026-01-09 08:27:17 +01:00
expect.any(Object),
2026-01-03 23:57:43 +00:00
);
});
it("routes telegram polls through message action", async () => {
await setRegistry(
createTestRegistry([
{
...createTelegramPollPluginRegistration(),
},
]),
);
const deps = makeDeps();
await messageCommand(
{
action: "poll",
channel: "telegram",
target: "123456789",
pollQuestion: "Ship it?",
pollOption: ["Yes", "No"],
pollDurationSeconds: 120,
},
deps,
runtime,
);
expect(handleTelegramAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "poll",
to: "123456789",
}),
expect.any(Object),
);
});
2026-01-09 06:43:40 +01:00
});