chore: Fix types in tests 24/N.

This commit is contained in:
cpojer
2026-02-17 14:30:36 +09:00
parent be5b28cd6b
commit 600022cdcc
11 changed files with 65 additions and 26 deletions

View File

@@ -39,13 +39,23 @@ describe("telegram bot message processor", () => {
streamMode: "partial",
textLimit: 4096,
opts: {},
};
} as unknown as Parameters<typeof createTelegramMessageProcessor>[0];
it("dispatches when context is available", async () => {
buildTelegramMessageContext.mockResolvedValue({ route: { sessionKey: "agent:main:main" } });
const processMessage = createTelegramMessageProcessor(baseDeps);
await processMessage({ message: { chat: { id: 123 }, message_id: 456 } }, [], [], {});
await processMessage(
{
message: {
chat: { id: 123, type: "private", title: "chat" },
message_id: 456,
},
} as unknown as Parameters<typeof processMessage>[0],
[],
[],
{},
);
expect(dispatchTelegramMessage).toHaveBeenCalledTimes(1);
});
@@ -53,7 +63,17 @@ describe("telegram bot message processor", () => {
it("skips dispatch when no context is produced", async () => {
buildTelegramMessageContext.mockResolvedValue(null);
const processMessage = createTelegramMessageProcessor(baseDeps);
await processMessage({ message: { chat: { id: 123 }, message_id: 456 } }, [], [], {});
await processMessage(
{
message: {
chat: { id: 123, type: "private", title: "chat" },
message_id: 456,
},
} as unknown as Parameters<typeof processMessage>[0],
[],
[],
{},
);
expect(dispatchTelegramMessage).not.toHaveBeenCalled();
});
});

View File

@@ -49,7 +49,7 @@ describe("registerTelegramNativeCommands (plugin auth)", () => {
registerTelegramNativeCommands({
bot: bot as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg: {} as OpenClawConfig,
runtime: { log } as RuntimeEnv,
runtime: { log } as unknown as RuntimeEnv,
accountId: "default",
telegramCfg: {} as TelegramAccountConfig,
allowFrom: [],
@@ -112,7 +112,7 @@ describe("registerTelegramNativeCommands (plugin auth)", () => {
registerTelegramNativeCommands({
bot: bot as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
runtime: {} as RuntimeEnv,
runtime: {} as unknown as RuntimeEnv,
accountId: "default",
telegramCfg,
allowFrom: ["999"],

View File

@@ -56,7 +56,7 @@ describe("registerTelegramNativeCommands", () => {
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
runtime: {} as RuntimeEnv,
runtime: {} as unknown as RuntimeEnv,
accountId,
telegramCfg: {} as TelegramAccountConfig,
allowFrom: [],
@@ -132,7 +132,7 @@ describe("registerTelegramNativeCommands", () => {
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
runtime: { log: runtimeLog } as RuntimeEnv,
runtime: { log: runtimeLog } as unknown as RuntimeEnv,
telegramCfg: { customCommands } as TelegramAccountConfig,
nativeEnabled: false,
nativeSkillsEnabled: false,
@@ -164,15 +164,15 @@ describe("registerTelegramNativeCommands", () => {
name: "plug",
description: "Plugin command",
},
]);
] as never);
pluginCommandMocks.matchPluginCommand.mockReturnValue({
command: { key: "plug", requireAuth: false },
args: undefined,
});
} as never);
pluginCommandMocks.executePluginCommand.mockResolvedValue({
text: "with media",
mediaUrl: "/tmp/workspace-work/render.png",
});
} as never);
registerTelegramNativeCommands({
...buildParams(cfg),

View File

@@ -36,7 +36,7 @@ async function createBotHandlerWithOptions(options: {
}> {
const { createTelegramBot } = await import("./bot.js");
const replyModule = await import("../auto-reply/reply.js");
const replySpy = (replyModule as { __replySpy: ReturnType<typeof vi.fn> }).__replySpy;
const replySpy = (replyModule as unknown as { __replySpy: ReturnType<typeof vi.fn> }).__replySpy;
onSpy.mockReset();
replySpy.mockReset();
@@ -520,7 +520,8 @@ describe("telegram text fragments", () => {
async () => {
const { createTelegramBot } = await import("./bot.js");
const replyModule = await import("../auto-reply/reply.js");
const replySpy = (replyModule as { __replySpy: ReturnType<typeof vi.fn> }).__replySpy;
const replySpy = (replyModule as unknown as { __replySpy: ReturnType<typeof vi.fn> })
.__replySpy;
onSpy.mockReset();
replySpy.mockReset();

View File

@@ -4,7 +4,7 @@ import { onSpy } from "./bot.media.e2e-harness.js";
async function createMessageHandlerAndReplySpy() {
const { createTelegramBot } = await import("./bot.js");
const replyModule = await import("../auto-reply/reply.js");
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
const replySpy = (replyModule as unknown as { __replySpy: ReturnType<typeof vi.fn> }).__replySpy;
onSpy.mockReset();
replySpy.mockReset();

View File

@@ -26,7 +26,13 @@ const loadConfig = getLoadConfigMock();
const readChannelAllowFromStore = getReadChannelAllowFromStoreMock();
function resolveSkillCommands(config: Parameters<typeof listNativeCommandSpecsForConfig>[0]) {
return listSkillCommandsForAgents({ cfg: config });
return (
listSkillCommandsForAgents as unknown as (params: {
cfg: typeof config;
}) => Parameters<typeof listNativeCommandSpecsForConfig>[1]["skillCommands"]
)({
cfg: config,
});
}
const ORIGINAL_TZ = process.env.TZ;
@@ -1111,7 +1117,10 @@ describe("createTelegramBot", () => {
}),
);
// Verify session key does NOT contain :topic:
const sessionKey = enqueueSystemEventSpy.mock.calls[0][1].sessionKey;
const eventOptions = enqueueSystemEventSpy.mock.calls[0]?.[1] as {
sessionKey?: string;
};
const sessionKey = eventOptions.sessionKey ?? "";
expect(sessionKey).not.toContain(":topic:");
});
});

View File

@@ -50,8 +50,13 @@ function makeCtx(
msg.video = { file_id: "vid1", duration: 10, file_unique_id: "u3" };
}
return {
message: msg as Message,
me: { id: 1, is_bot: true, first_name: "bot", username: "bot" },
message: msg as unknown as Message,
me: {
id: 1,
is_bot: true,
first_name: "bot",
username: "bot",
} as unknown as TelegramContext["me"],
getFile,
};
}
@@ -154,7 +159,7 @@ describe("resolveMedia getFile retry", () => {
it("does not retry 'file is too big' GrammyError instances and returns null", async () => {
const fileTooBigError = new GrammyError(
"Call to 'getFile' failed!",
{ error_code: 400, description: "Bad Request: file is too big" },
{ ok: false, error_code: 400, description: "Bad Request: file is too big" },
"getFile",
{},
);

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveTelegramDraftStreamingChunking } from "./draft-chunking.js";
describe("resolveTelegramDraftStreamingChunking", () => {

View File

@@ -62,7 +62,7 @@ describe("resolveTelegramFetch", () => {
aborted: false,
addEventListener,
removeEventListener,
} as AbortSignal;
} as unknown as AbortSignal;
if (!resolved) {
throw new Error("expected resolved proxy fetch");

View File

@@ -3,6 +3,7 @@ import { monitorTelegramProvider } from "./monitor.js";
type MockCtx = {
message: {
message_id?: number;
chat: { id: number; type: string; title?: string };
text?: string;
caption?: string;

View File

@@ -1334,10 +1334,11 @@ describe("sendPollTelegram", () => {
expect(res).toEqual({ messageId: "123", chatId: "555", pollId: "p1" });
expect(api.sendPoll).toHaveBeenCalledTimes(1);
expect(api.sendPoll.mock.calls[0]?.[0]).toBe("123");
expect(api.sendPoll.mock.calls[0]?.[1]).toBe("Q");
expect(api.sendPoll.mock.calls[0]?.[2]).toEqual(["A", "B"]);
expect(api.sendPoll.mock.calls[0]?.[3]).toMatchObject({ open_period: 60 });
const sendPollMock = api.sendPoll as ReturnType<typeof vi.fn>;
expect(sendPollMock.mock.calls[0]?.[0]).toBe("123");
expect(sendPollMock.mock.calls[0]?.[1]).toBe("Q");
expect(sendPollMock.mock.calls[0]?.[2]).toEqual(["A", "B"]);
expect(sendPollMock.mock.calls[0]?.[3]).toMatchObject({ open_period: 60 });
});
it("defaults polls to public (is_anonymous=false)", async () => {
@@ -1352,7 +1353,8 @@ describe("sendPollTelegram", () => {
);
expect(api.sendPoll).toHaveBeenCalledTimes(1);
expect(api.sendPoll.mock.calls[0]?.[3]).toMatchObject({ is_anonymous: false });
const sendPollMock = api.sendPoll as ReturnType<typeof vi.fn>;
expect(sendPollMock.mock.calls[0]?.[3]).toMatchObject({ is_anonymous: false });
});
it("supports explicit anonymous polls", async () => {
@@ -1367,7 +1369,8 @@ describe("sendPollTelegram", () => {
);
expect(api.sendPoll).toHaveBeenCalledTimes(1);
expect(api.sendPoll.mock.calls[0]?.[3]).toMatchObject({ is_anonymous: true });
const sendPollMock = api.sendPoll as ReturnType<typeof vi.fn>;
expect(sendPollMock.mock.calls[0]?.[3]).toMatchObject({ is_anonymous: true });
});
it("retries without message_thread_id on thread-not-found", async () => {