From 600022cdcc0f03bc0e36ac15d48418d246b56006 Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 17 Feb 2026 14:30:36 +0900 Subject: [PATCH] chore: Fix types in tests 24/N. --- src/telegram/bot-message.test.ts | 26 ++++++++++++++++--- .../bot-native-commands.plugin-auth.test.ts | 4 +-- src/telegram/bot-native-commands.test.ts | 10 +++---- ...dia-file-path-no-file-download.e2e.test.ts | 5 ++-- ...-location-text-ctx-fields-pins.e2e.test.ts | 2 +- src/telegram/bot.test.ts | 13 ++++++++-- .../bot/delivery.resolve-media-retry.test.ts | 11 +++++--- src/telegram/draft-chunking.test.ts | 2 +- src/telegram/fetch.test.ts | 2 +- src/telegram/monitor.test.ts | 1 + src/telegram/send.test.ts | 15 ++++++----- 11 files changed, 65 insertions(+), 26 deletions(-) diff --git a/src/telegram/bot-message.test.ts b/src/telegram/bot-message.test.ts index bc3fcf5205..b3483183ae 100644 --- a/src/telegram/bot-message.test.ts +++ b/src/telegram/bot-message.test.ts @@ -39,13 +39,23 @@ describe("telegram bot message processor", () => { streamMode: "partial", textLimit: 4096, opts: {}, - }; + } as unknown as Parameters[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[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[0], + [], + [], + {}, + ); expect(dispatchTelegramMessage).not.toHaveBeenCalled(); }); }); diff --git a/src/telegram/bot-native-commands.plugin-auth.test.ts b/src/telegram/bot-native-commands.plugin-auth.test.ts index 8904fdb540..085a5af090 100644 --- a/src/telegram/bot-native-commands.plugin-auth.test.ts +++ b/src/telegram/bot-native-commands.plugin-auth.test.ts @@ -49,7 +49,7 @@ describe("registerTelegramNativeCommands (plugin auth)", () => { registerTelegramNativeCommands({ bot: bot as unknown as Parameters[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[0]["bot"], cfg, - runtime: {} as RuntimeEnv, + runtime: {} as unknown as RuntimeEnv, accountId: "default", telegramCfg, allowFrom: ["999"], diff --git a/src/telegram/bot-native-commands.test.ts b/src/telegram/bot-native-commands.test.ts index fd98fbfc83..24cf113492 100644 --- a/src/telegram/bot-native-commands.test.ts +++ b/src/telegram/bot-native-commands.test.ts @@ -56,7 +56,7 @@ describe("registerTelegramNativeCommands", () => { command: vi.fn(), } as unknown as Parameters[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[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), diff --git a/src/telegram/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts b/src/telegram/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts index 90d0a88018..e763f6bee1 100644 --- a/src/telegram/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts +++ b/src/telegram/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts @@ -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 }).__replySpy; + const replySpy = (replyModule as unknown as { __replySpy: ReturnType }).__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 }).__replySpy; + const replySpy = (replyModule as unknown as { __replySpy: ReturnType }) + .__replySpy; onSpy.mockReset(); replySpy.mockReset(); diff --git a/src/telegram/bot.media.includes-location-text-ctx-fields-pins.e2e.test.ts b/src/telegram/bot.media.includes-location-text-ctx-fields-pins.e2e.test.ts index cf43c5a277..165c000b05 100644 --- a/src/telegram/bot.media.includes-location-text-ctx-fields-pins.e2e.test.ts +++ b/src/telegram/bot.media.includes-location-text-ctx-fields-pins.e2e.test.ts @@ -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; + const replySpy = (replyModule as unknown as { __replySpy: ReturnType }).__replySpy; onSpy.mockReset(); replySpy.mockReset(); diff --git a/src/telegram/bot.test.ts b/src/telegram/bot.test.ts index 96d9bd3221..3894c81e2e 100644 --- a/src/telegram/bot.test.ts +++ b/src/telegram/bot.test.ts @@ -26,7 +26,13 @@ const loadConfig = getLoadConfigMock(); const readChannelAllowFromStore = getReadChannelAllowFromStoreMock(); function resolveSkillCommands(config: Parameters[0]) { - return listSkillCommandsForAgents({ cfg: config }); + return ( + listSkillCommandsForAgents as unknown as (params: { + cfg: typeof config; + }) => Parameters[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:"); }); }); diff --git a/src/telegram/bot/delivery.resolve-media-retry.test.ts b/src/telegram/bot/delivery.resolve-media-retry.test.ts index cb7cb078a0..7884602482 100644 --- a/src/telegram/bot/delivery.resolve-media-retry.test.ts +++ b/src/telegram/bot/delivery.resolve-media-retry.test.ts @@ -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", {}, ); diff --git a/src/telegram/draft-chunking.test.ts b/src/telegram/draft-chunking.test.ts index 1885efd94c..cc24f06962 100644 --- a/src/telegram/draft-chunking.test.ts +++ b/src/telegram/draft-chunking.test.ts @@ -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", () => { diff --git a/src/telegram/fetch.test.ts b/src/telegram/fetch.test.ts index 343908dad5..1fab6a4a56 100644 --- a/src/telegram/fetch.test.ts +++ b/src/telegram/fetch.test.ts @@ -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"); diff --git a/src/telegram/monitor.test.ts b/src/telegram/monitor.test.ts index 8b6b6b7433..7c836e1b4a 100644 --- a/src/telegram/monitor.test.ts +++ b/src/telegram/monitor.test.ts @@ -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; diff --git a/src/telegram/send.test.ts b/src/telegram/send.test.ts index 67cb5109b0..f9f191289e 100644 --- a/src/telegram/send.test.ts +++ b/src/telegram/send.test.ts @@ -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; + 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; + 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; + expect(sendPollMock.mock.calls[0]?.[3]).toMatchObject({ is_anonymous: true }); }); it("retries without message_thread_id on thread-not-found", async () => {