test(feishu): slim bot runtime fixtures

This commit is contained in:
Vincent Koc 2026-04-03 21:09:36 +09:00
parent 99397254a1
commit 3a68414569
1 changed files with 52 additions and 48 deletions

View File

@ -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<string, unknown>) => ctx;
const withReplyDispatcherMock = async ({
run,
}: Parameters<PluginRuntime["channel"]["reply"]["withReplyDispatcher"]>[0]) => await run();
function createBotTestRuntime(): PluginRuntime {
function createFeishuBotRuntime(
overrides: Partial<PluginRuntime> & {
channel?: Partial<PluginRuntime["channel"]>;
system?: Partial<PluginRuntime["system"]>;
media?: Partial<PluginRuntime["media"]>;
} = {},
): 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<string, unknown>) => ctx;
const withReplyDispatcherMock = async ({
run,
}: Parameters<PluginRuntime["channel"]["reply"]["withReplyDispatcher"]>[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 () => {