|
1 | 1 | import type * as ConversationRuntime from "openclaw/plugin-sdk/conversation-runtime"; |
2 | 2 | import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing"; |
3 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
4 | | -import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js"; |
5 | 4 | import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js"; |
6 | 5 | import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js"; |
7 | 6 | import type { FeishuMessageEvent } from "./bot.js"; |
@@ -177,6 +176,40 @@ const withReplyDispatcherMock = async ({ |
177 | 176 | run, |
178 | 177 | }: Parameters<PluginRuntime["channel"]["reply"]["withReplyDispatcher"]>[0]) => await run(); |
179 | 178 |
|
| 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 | + |
180 | 213 | const { |
181 | 214 | mockCreateFeishuReplyDispatcher, |
182 | 215 | mockSendMessageFeishu, |
@@ -298,39 +331,7 @@ describe("handleFeishuMessage ACP routing", () => { |
298 | 331 | markDispatchIdle: vi.fn(), |
299 | 332 | }); |
300 | 333 |
|
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()); |
334 | 335 | }); |
335 | 336 |
|
336 | 337 | it("ensures configured ACP routes for Feishu DMs", async () => { |
@@ -499,45 +500,43 @@ describe("handleFeishuMessage command authorization", () => { |
499 | 500 | }, |
500 | 501 | }); |
501 | 502 | 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, |
535 | 526 | }, |
536 | 527 | media: { |
537 | | - detectMime: vi.fn(async () => "application/octet-stream"), |
| 528 | + saveMediaBuffer: mockSaveMediaBuffer, |
538 | 529 | }, |
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); |
541 | 540 | }); |
542 | 541 |
|
543 | 542 | it("does not enqueue inbound preview text as system events", async () => { |
|
0 commit comments