From 3a684145690cce907661592040fbfe36c9ebeae4 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 3 Apr 2026 21:09:36 +0900 Subject: [PATCH] test(feishu): slim bot runtime fixtures --- extensions/feishu/src/bot.test.ts | 100 ++++++++++++++++-------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/extensions/feishu/src/bot.test.ts b/extensions/feishu/src/bot.test.ts index 33b7631b1d3..64c6e8764bb 100644 --- a/extensions/feishu/src/bot.test.ts +++ b/extensions/feishu/src/bot.test.ts @@ -163,20 +163,13 @@ function createUnboundConfiguredRoute( return { bindingResolution: null, route }; } -const resolveAgentRouteMock: PluginRuntime["channel"]["routing"]["resolveAgentRoute"] = (params) => - mockResolveAgentRoute(params); -const readSessionUpdatedAtMock: PluginRuntime["channel"]["session"]["readSessionUpdatedAt"] = ( - params, -) => mockReadSessionUpdatedAt(params); -const resolveStorePathMock: PluginRuntime["channel"]["session"]["resolveStorePath"] = (params) => - mockResolveStorePath(params); -const resolveEnvelopeFormatOptionsMock = () => ({}); -const finalizeInboundContextMock = (ctx: Record) => ctx; -const withReplyDispatcherMock = async ({ - run, -}: Parameters[0]) => await run(); - -function createBotTestRuntime(): PluginRuntime { +function createFeishuBotRuntime( + overrides: Partial & { + channel?: Partial; + system?: Partial; + media?: Partial; + } = {}, +): PluginRuntime { return { channel: { routing: { @@ -206,10 +199,26 @@ function createBotTestRuntime(): PluginRuntime { upsertPairingRequest: vi.fn(), buildPairingReply: vi.fn(), }, + ...(overrides.channel ?? {}), }, + ...(overrides.system ? { system: overrides.system as PluginRuntime["system"] } : {}), + ...(overrides.media ? { media: overrides.media as PluginRuntime["media"] } : {}), } as unknown as PluginRuntime; } +const resolveAgentRouteMock: PluginRuntime["channel"]["routing"]["resolveAgentRoute"] = (params) => + mockResolveAgentRoute(params); +const readSessionUpdatedAtMock: PluginRuntime["channel"]["session"]["readSessionUpdatedAt"] = ( + params, +) => mockReadSessionUpdatedAt(params); +const resolveStorePathMock: PluginRuntime["channel"]["session"]["resolveStorePath"] = (params) => + mockResolveStorePath(params); +const resolveEnvelopeFormatOptionsMock = () => ({}); +const finalizeInboundContextMock = (ctx: Record) => ctx; +const withReplyDispatcherMock = async ({ + run, +}: Parameters[0]) => await run(); + const { mockCreateFeishuReplyDispatcher, mockSendMessageFeishu, @@ -331,7 +340,7 @@ describe("handleFeishuMessage ACP routing", () => { markDispatchIdle: vi.fn(), }); - setFeishuRuntime(createBotTestRuntime()); + setFeishuRuntime(createFeishuBotRuntime()); }); it("ensures configured ACP routes for Feishu DMs", async () => { @@ -500,43 +509,38 @@ describe("handleFeishuMessage command authorization", () => { }, }); mockEnqueueSystemEvent.mockReset(); - setFeishuRuntime({ - system: { - enqueueSystemEvent: mockEnqueueSystemEvent, - }, - channel: { - routing: { - resolveAgentRoute: resolveAgentRouteMock, + setFeishuRuntime( + createFeishuBotRuntime({ + system: { + enqueueSystemEvent: mockEnqueueSystemEvent, }, - session: { - readSessionUpdatedAt: readSessionUpdatedAtMock, - resolveStorePath: resolveStorePathMock, - }, - reply: { - resolveEnvelopeFormatOptions: - resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"], - formatAgentEnvelope: vi.fn((params: { body: string }) => params.body), - finalizeInboundContext: mockFinalizeInboundContext as never, - dispatchReplyFromConfig: mockDispatchReplyFromConfig, - withReplyDispatcher: mockWithReplyDispatcher as never, - }, - commands: { - shouldComputeCommandAuthorized: mockShouldComputeCommandAuthorized, - resolveCommandAuthorizedFromAuthorizers: mockResolveCommandAuthorizedFromAuthorizers, + channel: { + reply: { + resolveEnvelopeFormatOptions: + resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"], + formatAgentEnvelope: vi.fn((params: { body: string }) => params.body), + finalizeInboundContext: mockFinalizeInboundContext as never, + dispatchReplyFromConfig: mockDispatchReplyFromConfig, + withReplyDispatcher: mockWithReplyDispatcher as never, + }, + commands: { + shouldComputeCommandAuthorized: mockShouldComputeCommandAuthorized, + resolveCommandAuthorizedFromAuthorizers: mockResolveCommandAuthorizedFromAuthorizers, + }, + pairing: { + readAllowFromStore: mockReadAllowFromStore, + upsertPairingRequest: mockUpsertPairingRequest, + buildPairingReply: mockBuildPairingReply, + }, + media: { + saveMediaBuffer: mockSaveMediaBuffer, + }, }, media: { - saveMediaBuffer: mockSaveMediaBuffer, + detectMime: vi.fn(async () => "application/octet-stream"), }, - pairing: { - readAllowFromStore: mockReadAllowFromStore, - upsertPairingRequest: mockUpsertPairingRequest, - buildPairingReply: mockBuildPairingReply, - }, - }, - media: { - detectMime: vi.fn(async () => "application/octet-stream"), - }, - } as unknown as PluginRuntime); + }), + ); }); it("does not enqueue inbound preview text as system events", async () => {