From d2dae50a753fe8716734ccffde42399ac855e613 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 3 Apr 2026 13:10:24 +0100 Subject: [PATCH] test: trim telegram bot import graph --- .../src/bot-message-dispatch.runtime.ts | 12 ++++ .../telegram/src/bot-message-dispatch.test.ts | 32 +++++----- .../telegram/src/bot-message-dispatch.ts | 19 +++--- .../bot.create-telegram-bot.test-harness.ts | 58 ++----------------- 4 files changed, 42 insertions(+), 79 deletions(-) create mode 100644 extensions/telegram/src/bot-message-dispatch.runtime.ts diff --git a/extensions/telegram/src/bot-message-dispatch.runtime.ts b/extensions/telegram/src/bot-message-dispatch.runtime.ts new file mode 100644 index 00000000000..70944cd2791 --- /dev/null +++ b/extensions/telegram/src/bot-message-dispatch.runtime.ts @@ -0,0 +1,12 @@ +export { + loadSessionStore, + resolveMarkdownTableMode, + resolveSessionStoreEntry, + resolveStorePath, +} from "openclaw/plugin-sdk/config-runtime"; +export { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime"; +export { + generateTopicLabel, + resolveAutoTopicLabelConfig, + resolveChunkMode, +} from "openclaw/plugin-sdk/reply-runtime"; diff --git a/extensions/telegram/src/bot-message-dispatch.test.ts b/extensions/telegram/src/bot-message-dispatch.test.ts index fe050877aa8..5e66c82b0ea 100644 --- a/extensions/telegram/src/bot-message-dispatch.test.ts +++ b/extensions/telegram/src/bot-message-dispatch.test.ts @@ -1,5 +1,10 @@ import type { Bot } from "grammy"; import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { resolveChunkMode as resolveChunkModeRuntime } from "../../../src/auto-reply/chunk.js"; +import { resolveAutoTopicLabelConfig as resolveAutoTopicLabelConfigRuntime } from "../../../src/auto-reply/reply/auto-topic-label-config.js"; +import { resolveMarkdownTableMode as resolveMarkdownTableModeRuntime } from "../../../src/config/markdown-tables.js"; +import { resolveSessionStoreEntry as resolveSessionStoreEntryRuntime } from "../../../src/config/sessions/store.js"; +import { getAgentScopedMediaLocalRoots as getAgentScopedMediaLocalRootsRuntime } from "../../../src/media/local-roots.js"; import type { TelegramBotDeps } from "./bot-deps.js"; import { createSequencedTestDraftStream, @@ -59,14 +64,6 @@ vi.mock("./draft-stream.js", () => ({ createTelegramDraftStream, })); -vi.mock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - generateTopicLabel, - }; -}); - vi.mock("./bot/delivery.js", () => ({ deliverReplies, emitInternalMessageSentHook, @@ -88,15 +85,16 @@ vi.mock("./send.js", () => ({ sendStickerTelegram, })); -vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - loadConfig, - loadSessionStore, - resolveStorePath, - }; -}); +vi.mock("./bot-message-dispatch.runtime.js", () => ({ + generateTopicLabel, + getAgentScopedMediaLocalRoots: getAgentScopedMediaLocalRootsRuntime, + loadSessionStore, + resolveAutoTopicLabelConfig: resolveAutoTopicLabelConfigRuntime, + resolveChunkMode: resolveChunkModeRuntime, + resolveMarkdownTableMode: resolveMarkdownTableModeRuntime, + resolveSessionStoreEntry: resolveSessionStoreEntryRuntime, + resolveStorePath, +})); vi.mock("./sticker-cache.js", () => ({ cacheSticker: vi.fn(), diff --git a/extensions/telegram/src/bot-message-dispatch.ts b/extensions/telegram/src/bot-message-dispatch.ts index 0fb3f74c16f..7529a9cfcbb 100644 --- a/extensions/telegram/src/bot-message-dispatch.ts +++ b/extensions/telegram/src/bot-message-dispatch.ts @@ -12,28 +12,29 @@ import { removeAckReactionAfterReply, } from "openclaw/plugin-sdk/channel-feedback"; import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline"; -import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/config-runtime"; -import { - loadSessionStore, - resolveSessionStoreEntry, - resolveStorePath, -} from "openclaw/plugin-sdk/config-runtime"; import type { OpenClawConfig, ReplyToMode, TelegramAccountConfig, TelegramDirectConfig, } from "openclaw/plugin-sdk/config-runtime"; -import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime"; import { clearHistoryEntriesIfEnabled } from "openclaw/plugin-sdk/reply-history"; import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload"; -import { resolveChunkMode } from "openclaw/plugin-sdk/reply-runtime"; import type { ReplyPayload } from "openclaw/plugin-sdk/reply-runtime"; -import { resolveAutoTopicLabelConfig, generateTopicLabel } from "openclaw/plugin-sdk/reply-runtime"; import { danger, logVerbose } from "openclaw/plugin-sdk/runtime-env"; import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env"; import { defaultTelegramBotDeps, type TelegramBotDeps } from "./bot-deps.js"; import type { TelegramMessageContext } from "./bot-message-context.js"; +import { + loadSessionStore, + resolveMarkdownTableMode, + resolveSessionStoreEntry, + resolveStorePath, + getAgentScopedMediaLocalRoots, + resolveChunkMode, + resolveAutoTopicLabelConfig, + generateTopicLabel, +} from "./bot-message-dispatch.runtime.js"; import type { TelegramBotOptions } from "./bot.js"; import { deliverReplies, emitInternalMessageSentHook } from "./bot/delivery.js"; import type { TelegramStreamMode } from "./bot/types.js"; diff --git a/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts b/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts index d41f1bf7f60..214a2132f8c 100644 --- a/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts +++ b/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts @@ -1,11 +1,11 @@ import { resolveDefaultModelForAgent } from "openclaw/plugin-sdk/agent-runtime"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; -import { resetInboundDedupe } from "openclaw/plugin-sdk/reply-runtime"; -import type { MsgContext } from "openclaw/plugin-sdk/reply-runtime"; -import type { GetReplyOptions, ReplyPayload } from "openclaw/plugin-sdk/reply-runtime"; -import { createReplyDispatcher } from "openclaw/plugin-sdk/reply-runtime"; import type { MockFn } from "openclaw/plugin-sdk/testing"; import { beforeEach, vi } from "vitest"; +import { resetInboundDedupe } from "../../../src/auto-reply/reply/inbound-dedupe.js"; +import { createReplyDispatcher } from "../../../src/auto-reply/reply/reply-dispatcher.js"; +import type { MsgContext } from "../../../src/auto-reply/templating.js"; +import type { GetReplyOptions, ReplyPayload } from "../../../src/auto-reply/types.js"; import type { TelegramBotDeps } from "./bot-deps.js"; type AnyMock = ReturnType; @@ -18,7 +18,7 @@ type TelegramBotRuntimeForTest = NonNullable< Parameters[0] >; type DispatchReplyWithBufferedBlockDispatcherFn = - typeof import("openclaw/plugin-sdk/reply-runtime").dispatchReplyWithBufferedBlockDispatcher; + typeof import("openclaw/plugin-sdk/reply-dispatch-runtime").dispatchReplyWithBufferedBlockDispatcher; type DispatchReplyWithBufferedBlockDispatcherResult = Awaited< ReturnType >; @@ -79,16 +79,6 @@ export function setSessionStoreEntriesForTest(entries: SessionStore) { sessionStoreEntries.value = JSON.parse(JSON.stringify(entries)) as SessionStore; } -vi.doMock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - loadConfig, - loadSessionStore: loadSessionStoreMock, - resolveStorePath: resolveStorePathMock, - }; -}); - const { readChannelAllowFromStore, upsertChannelPairingRequest } = vi.hoisted( (): { readChannelAllowFromStore: MockFn; @@ -110,23 +100,6 @@ export function getUpsertChannelPairingRequestMock(): AnyAsyncMock { return upsertChannelPairingRequest; } -vi.doMock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - readChannelAllowFromStore, - upsertChannelPairingRequest, - }; -}); -vi.doMock("openclaw/plugin-sdk/conversation-runtime.js", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - readChannelAllowFromStore, - upsertChannelPairingRequest, - }; -}); - const skillCommandListHoisted = vi.hoisted(() => ({ listSkillCommandsForAgents: vi.fn(() => []), })); @@ -249,27 +222,6 @@ function createModelsProviderDataFromConfig(cfg: OpenClawConfig): { return { byProvider, providers, resolvedDefault, modelNames: new Map() }; } -vi.doMock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - getReplyFromConfig: replySpyHoisted.replySpy, - __replySpy: replySpyHoisted.replySpy, - dispatchReplyWithBufferedBlockDispatcher: - dispatchReplyHoisted.dispatchReplyWithBufferedBlockDispatcher, - }; -}); -vi.doMock("openclaw/plugin-sdk/reply-runtime.js", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - getReplyFromConfig: replySpyHoisted.replySpy, - __replySpy: replySpyHoisted.replySpy, - dispatchReplyWithBufferedBlockDispatcher: - dispatchReplyHoisted.dispatchReplyWithBufferedBlockDispatcher, - }; -}); - const systemEventsHoisted = vi.hoisted(() => ({ enqueueSystemEventSpy: vi.fn(() => false), }));