Skip to content

Commit feca4aa

Browse files
committed
test(feishu): replace heavy runtime mock helper in bot tests
1 parent fbb2537 commit feca4aa

1 file changed

Lines changed: 69 additions & 70 deletions

File tree

extensions/feishu/src/bot.test.ts

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type * as ConversationRuntime from "openclaw/plugin-sdk/conversation-runtime";
22
import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
4-
import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js";
54
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
65
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
76
import type { FeishuMessageEvent } from "./bot.js";
@@ -177,6 +176,40 @@ const withReplyDispatcherMock = async ({
177176
run,
178177
}: Parameters<PluginRuntime["channel"]["reply"]["withReplyDispatcher"]>[0]) => await run();
179178

179+
function createBotTestRuntime(): PluginRuntime {
180+
return {
181+
channel: {
182+
routing: {
183+
resolveAgentRoute: resolveAgentRouteMock,
184+
},
185+
session: {
186+
readSessionUpdatedAt: readSessionUpdatedAtMock,
187+
resolveStorePath: resolveStorePathMock,
188+
},
189+
reply: {
190+
resolveEnvelopeFormatOptions:
191+
resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"],
192+
formatAgentEnvelope: vi.fn((params: { body: string }) => params.body),
193+
finalizeInboundContext: finalizeInboundContextMock as never,
194+
dispatchReplyFromConfig: vi.fn().mockResolvedValue({
195+
queuedFinal: false,
196+
counts: { final: 1 },
197+
}),
198+
withReplyDispatcher: withReplyDispatcherMock as never,
199+
},
200+
commands: {
201+
shouldComputeCommandAuthorized: vi.fn(() => false),
202+
resolveCommandAuthorizedFromAuthorizers: vi.fn(() => false),
203+
},
204+
pairing: {
205+
readAllowFromStore: vi.fn().mockResolvedValue(["ou_sender_1"]),
206+
upsertPairingRequest: vi.fn(),
207+
buildPairingReply: vi.fn(),
208+
},
209+
},
210+
} as PluginRuntime;
211+
}
212+
180213
const {
181214
mockCreateFeishuReplyDispatcher,
182215
mockSendMessageFeishu,
@@ -298,39 +331,7 @@ describe("handleFeishuMessage ACP routing", () => {
298331
markDispatchIdle: vi.fn(),
299332
});
300333

301-
setFeishuRuntime(
302-
createPluginRuntimeMock({
303-
channel: {
304-
routing: {
305-
resolveAgentRoute: resolveAgentRouteMock,
306-
},
307-
session: {
308-
readSessionUpdatedAt: readSessionUpdatedAtMock,
309-
resolveStorePath: resolveStorePathMock,
310-
},
311-
reply: {
312-
resolveEnvelopeFormatOptions:
313-
resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"],
314-
formatAgentEnvelope: vi.fn((params: { body: string }) => params.body),
315-
finalizeInboundContext: finalizeInboundContextMock as never,
316-
dispatchReplyFromConfig: vi.fn().mockResolvedValue({
317-
queuedFinal: false,
318-
counts: { final: 1 },
319-
}),
320-
withReplyDispatcher: withReplyDispatcherMock as never,
321-
},
322-
commands: {
323-
shouldComputeCommandAuthorized: vi.fn(() => false),
324-
resolveCommandAuthorizedFromAuthorizers: vi.fn(() => false),
325-
},
326-
pairing: {
327-
readAllowFromStore: vi.fn().mockResolvedValue(["ou_sender_1"]),
328-
upsertPairingRequest: vi.fn(),
329-
buildPairingReply: vi.fn(),
330-
},
331-
},
332-
}),
333-
);
334+
setFeishuRuntime(createBotTestRuntime());
334335
});
335336

336337
it("ensures configured ACP routes for Feishu DMs", async () => {
@@ -499,45 +500,43 @@ describe("handleFeishuMessage command authorization", () => {
499500
},
500501
});
501502
mockEnqueueSystemEvent.mockReset();
502-
setFeishuRuntime(
503-
createPluginRuntimeMock({
504-
system: {
505-
enqueueSystemEvent: mockEnqueueSystemEvent,
506-
},
507-
channel: {
508-
routing: {
509-
resolveAgentRoute: resolveAgentRouteMock,
510-
},
511-
session: {
512-
readSessionUpdatedAt: readSessionUpdatedAtMock,
513-
resolveStorePath: resolveStorePathMock,
514-
},
515-
reply: {
516-
resolveEnvelopeFormatOptions:
517-
resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"],
518-
formatAgentEnvelope: vi.fn((params: { body: string }) => params.body),
519-
finalizeInboundContext: mockFinalizeInboundContext as never,
520-
dispatchReplyFromConfig: mockDispatchReplyFromConfig,
521-
withReplyDispatcher: mockWithReplyDispatcher as never,
522-
},
523-
commands: {
524-
shouldComputeCommandAuthorized: mockShouldComputeCommandAuthorized,
525-
resolveCommandAuthorizedFromAuthorizers: mockResolveCommandAuthorizedFromAuthorizers,
526-
},
527-
media: {
528-
saveMediaBuffer: mockSaveMediaBuffer,
529-
},
530-
pairing: {
531-
readAllowFromStore: mockReadAllowFromStore,
532-
upsertPairingRequest: mockUpsertPairingRequest,
533-
buildPairingReply: mockBuildPairingReply,
534-
},
503+
setFeishuRuntime({
504+
system: {
505+
enqueueSystemEvent: mockEnqueueSystemEvent,
506+
},
507+
channel: {
508+
routing: {
509+
resolveAgentRoute: resolveAgentRouteMock,
510+
},
511+
session: {
512+
readSessionUpdatedAt: readSessionUpdatedAtMock,
513+
resolveStorePath: resolveStorePathMock,
514+
},
515+
reply: {
516+
resolveEnvelopeFormatOptions:
517+
resolveEnvelopeFormatOptionsMock as unknown as PluginRuntime["channel"]["reply"]["resolveEnvelopeFormatOptions"],
518+
formatAgentEnvelope: vi.fn((params: { body: string }) => params.body),
519+
finalizeInboundContext: mockFinalizeInboundContext as never,
520+
dispatchReplyFromConfig: mockDispatchReplyFromConfig,
521+
withReplyDispatcher: mockWithReplyDispatcher as never,
522+
},
523+
commands: {
524+
shouldComputeCommandAuthorized: mockShouldComputeCommandAuthorized,
525+
resolveCommandAuthorizedFromAuthorizers: mockResolveCommandAuthorizedFromAuthorizers,
535526
},
536527
media: {
537-
detectMime: vi.fn(async () => "application/octet-stream"),
528+
saveMediaBuffer: mockSaveMediaBuffer,
538529
},
539-
}),
540-
);
530+
pairing: {
531+
readAllowFromStore: mockReadAllowFromStore,
532+
upsertPairingRequest: mockUpsertPairingRequest,
533+
buildPairingReply: mockBuildPairingReply,
534+
},
535+
},
536+
media: {
537+
detectMime: vi.fn(async () => "application/octet-stream"),
538+
},
539+
} as PluginRuntime);
541540
});
542541

543542
it("does not enqueue inbound preview text as system events", async () => {

0 commit comments

Comments
 (0)