From ac66d383e7c418008720232224d00613ce6f32b9 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Mon, 16 Mar 2026 18:51:04 +0530 Subject: [PATCH] test: mock telegram native command reply pipeline --- .../src/bot-native-commands.test-helpers.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/extensions/telegram/src/bot-native-commands.test-helpers.ts b/extensions/telegram/src/bot-native-commands.test-helpers.ts index 0b4babb180e..33c3f04f904 100644 --- a/extensions/telegram/src/bot-native-commands.test-helpers.ts +++ b/extensions/telegram/src/bot-native-commands.test-helpers.ts @@ -12,6 +12,13 @@ type GetPluginCommandSpecsFn = type MatchPluginCommandFn = typeof import("../../../src/plugins/commands.js").matchPluginCommand; type ExecutePluginCommandFn = typeof import("../../../src/plugins/commands.js").executePluginCommand; +type DispatchReplyWithBufferedBlockDispatcherFn = + typeof import("../../../src/auto-reply/reply/provider-dispatcher.js").dispatchReplyWithBufferedBlockDispatcher; +type DispatchReplyWithBufferedBlockDispatcherResult = Awaited< + ReturnType +>; +type RecordInboundSessionMetaSafeFn = + typeof import("../../../src/channels/session-meta.js").recordInboundSessionMetaSafe; type AnyMock = MockFn<(...args: unknown[]) => unknown>; type AnyAsyncMock = MockFn<(...args: unknown[]) => Promise>; type NativeCommandHarness = { @@ -43,6 +50,37 @@ vi.mock("../../../src/plugins/commands.js", () => ({ executePluginCommand: pluginCommandMocks.executePluginCommand, })); +const replyPipelineMocks = vi.hoisted(() => { + const dispatchReplyResult: DispatchReplyWithBufferedBlockDispatcherResult = { + queuedFinal: false, + counts: {} as DispatchReplyWithBufferedBlockDispatcherResult["counts"], + }; + return { + finalizeInboundContext: vi.fn((ctx: unknown) => ctx), + dispatchReplyWithBufferedBlockDispatcher: vi.fn( + async () => dispatchReplyResult, + ), + createReplyPrefixOptions: vi.fn(() => ({ onModelSelected: () => {} })), + recordInboundSessionMetaSafe: vi.fn(async () => undefined), + }; +}); +export const dispatchReplyWithBufferedBlockDispatcher = + replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher; + +vi.mock("../../../src/auto-reply/reply/inbound-context.js", () => ({ + finalizeInboundContext: replyPipelineMocks.finalizeInboundContext, +})); +vi.mock("../../../src/auto-reply/reply/provider-dispatcher.js", () => ({ + dispatchReplyWithBufferedBlockDispatcher: + replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher, +})); +vi.mock("../../../src/channels/reply-prefix.js", () => ({ + createReplyPrefixOptions: replyPipelineMocks.createReplyPrefixOptions, +})); +vi.mock("../../../src/channels/session-meta.js", () => ({ + recordInboundSessionMetaSafe: replyPipelineMocks.recordInboundSessionMetaSafe, +})); + const deliveryMocks = vi.hoisted(() => ({ deliverReplies: vi.fn(async () => {}), }));