chore: Fix types in tests 1/N.

This commit is contained in:
cpojer
2026-02-17 10:26:25 +09:00
parent 25126d75c3
commit 0cf443afe8
5 changed files with 135 additions and 90 deletions

View File

@@ -1,27 +1,27 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../../config/config.js";
const handleDiscordAction = vi.fn(async () => ({ details: { ok: true } }));
const handleTelegramAction = vi.fn(async () => ({ ok: true }));
const sendReactionSignal = vi.fn(async () => ({ ok: true }));
const removeReactionSignal = vi.fn(async () => ({ ok: true }));
const handleSlackAction = vi.fn(async () => ({ details: { ok: true } }));
const handleDiscordAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
const handleTelegramAction = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
const sendReactionSignal = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
const removeReactionSignal = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
const handleSlackAction = vi.fn(async (..._args: unknown[]) => ({ details: { ok: true } }));
vi.mock("../../../agents/tools/discord-actions.js", () => ({
handleDiscordAction: (...args: unknown[]) => handleDiscordAction(...args),
handleDiscordAction,
}));
vi.mock("../../../agents/tools/telegram-actions.js", () => ({
handleTelegramAction: (...args: unknown[]) => handleTelegramAction(...args),
handleTelegramAction,
}));
vi.mock("../../../signal/send-reactions.js", () => ({
sendReactionSignal: (...args: unknown[]) => sendReactionSignal(...args),
removeReactionSignal: (...args: unknown[]) => removeReactionSignal(...args),
sendReactionSignal,
removeReactionSignal,
}));
vi.mock("../../../agents/tools/slack-actions.js", () => ({
handleSlackAction: (...args: unknown[]) => handleSlackAction(...args),
handleSlackAction,
}));
const { discordMessageActions } = await import("./discord.js");
@@ -136,7 +136,8 @@ describe("telegram message actions", () => {
});
it("routes poll with normalized params", async () => {
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "poll",
params: {
to: "123",
@@ -332,7 +333,7 @@ describe("handleDiscordMessageAction", () => {
describe("telegramMessageActions", () => {
it("excludes sticker actions when not enabled", () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
const actions = telegramMessageActions.listActions({ cfg });
const actions = telegramMessageActions.listActions?.({ cfg }) ?? [];
expect(actions).not.toContain("sticker");
expect(actions).not.toContain("sticker-search");
});
@@ -340,7 +341,8 @@ describe("telegramMessageActions", () => {
it("allows media-only sends and passes asVoice", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "send",
params: {
to: "123",
@@ -366,7 +368,8 @@ describe("telegramMessageActions", () => {
it("passes silent flag for silent sends", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "send",
params: {
to: "456",
@@ -391,7 +394,8 @@ describe("telegramMessageActions", () => {
it("maps edit action params into editMessage", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "edit",
params: {
chatId: "123",
@@ -421,6 +425,7 @@ describe("telegramMessageActions", () => {
await expect(
telegramMessageActions.handleAction({
channel: "telegram",
action: "edit",
params: {
chatId: "123",
@@ -445,7 +450,7 @@ describe("telegramMessageActions", () => {
},
},
} as OpenClawConfig;
const actions = telegramMessageActions.listActions({ cfg });
const actions = telegramMessageActions.listActions?.({ cfg }) ?? [];
expect(actions).toContain("sticker");
expect(actions).toContain("sticker-search");
@@ -462,7 +467,7 @@ describe("telegramMessageActions", () => {
},
},
} as OpenClawConfig;
const actions = telegramMessageActions.listActions({ cfg });
const actions = telegramMessageActions.listActions?.({ cfg }) ?? [];
expect(actions).not.toContain("sticker");
expect(actions).not.toContain("sticker-search");
@@ -471,7 +476,8 @@ describe("telegramMessageActions", () => {
it("accepts numeric messageId and channelId for reactions", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "react",
params: {
channelId: 123,
@@ -483,17 +489,22 @@ describe("telegramMessageActions", () => {
});
expect(handleTelegramAction).toHaveBeenCalledTimes(1);
const call = handleTelegramAction.mock.calls[0]?.[0] as Record<string, unknown>;
expect(call.action).toBe("react");
expect(String(call.chatId)).toBe("123");
expect(String(call.messageId)).toBe("456");
expect(call.emoji).toBe("ok");
const call = handleTelegramAction.mock.calls[0]?.[0];
if (!call) {
throw new Error("missing telegram action call");
}
const callPayload = call as Record<string, unknown>;
expect(callPayload.action).toBe("react");
expect(String(callPayload.chatId)).toBe("123");
expect(String(callPayload.messageId)).toBe("456");
expect(callPayload.emoji).toBe("ok");
});
it("routes poll action to sendPoll with question and options", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
await telegramMessageActions.handleAction({
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "poll",
params: {
to: "-100123",
@@ -519,14 +530,14 @@ describe("telegramMessageActions", () => {
describe("signalMessageActions", () => {
it("returns no actions when no configured accounts exist", () => {
const cfg = {} as OpenClawConfig;
expect(signalMessageActions.listActions({ cfg })).toEqual([]);
expect(signalMessageActions.listActions?.({ cfg }) ?? []).toEqual([]);
});
it("hides react when reactions are disabled", () => {
const cfg = {
channels: { signal: { account: "+15550001111", actions: { reactions: false } } },
} as OpenClawConfig;
expect(signalMessageActions.listActions({ cfg })).toEqual(["send"]);
expect(signalMessageActions.listActions?.({ cfg }) ?? []).toEqual(["send"]);
});
it("enables react when at least one account allows reactions", () => {
@@ -540,7 +551,7 @@ describe("signalMessageActions", () => {
},
},
} as OpenClawConfig;
expect(signalMessageActions.listActions({ cfg })).toEqual(["send", "react"]);
expect(signalMessageActions.listActions?.({ cfg }) ?? []).toEqual(["send", "react"]);
});
it("skips send for plugin dispatch", () => {
@@ -555,6 +566,7 @@ describe("signalMessageActions", () => {
await expect(
signalMessageActions.handleAction({
channel: "signal",
action: "react",
params: { to: "+15550001111", messageId: "123", emoji: "✅" },
cfg,
@@ -575,7 +587,8 @@ describe("signalMessageActions", () => {
},
} as OpenClawConfig;
await signalMessageActions.handleAction({
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: { to: "+15550001111", messageId: "123", emoji: "👍" },
cfg,
@@ -592,7 +605,8 @@ describe("signalMessageActions", () => {
channels: { signal: { account: "+15550001111" } },
} as OpenClawConfig;
await signalMessageActions.handleAction({
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: {
recipient: "uuid:123e4567-e89b-12d3-a456-426614174000",
@@ -618,6 +632,7 @@ describe("signalMessageActions", () => {
await expect(
signalMessageActions.handleAction({
channel: "signal",
action: "react",
params: { to: "signal:group:group-id", messageId: "123", emoji: "✅" },
cfg,
@@ -631,7 +646,8 @@ describe("signalMessageActions", () => {
channels: { signal: { account: "+15550001111" } },
} as OpenClawConfig;
await signalMessageActions.handleAction({
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: {
to: "signal:group:group-id",