Skip to content

Commit 1e80d05

Browse files
[AI] test(feishu): add channelRuntime guard tests for monitorSingleAccount
Three test cases for the channelRuntime guard at monitor.account.ts:489: 1. Partial channelRuntime (no inbound) → falls back to local runtime 2. Full channelRuntime with inbound → uses provided runtime 3. No channelRuntime (undefined) → falls back to local runtime Related to #92595
1 parent 03b3b4b commit 1e80d05

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

extensions/feishu/src/monitor.reaction.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,4 +769,67 @@ describe("Feishu inbound debounce regressions", () => {
769769

770770
expect(handleFeishuMessageMock).toHaveBeenCalledTimes(1);
771771
});
772+
773+
describe("monitorSingleAccount channelRuntime guard", () => {
774+
it("falls back to local runtime when channelRuntime is partial (no inbound)", async () => {
775+
setFeishuRuntime(createFeishuMonitorRuntime());
776+
const register = vi.fn();
777+
createEventDispatcherMock.mockReturnValue({ register });
778+
779+
await expect(
780+
monitorSingleAccount({
781+
cfg: buildDebounceConfig(),
782+
account: buildDebounceAccount(),
783+
runtime: createNonExitingRuntimeEnv(),
784+
channelRuntime: { runtimeContexts: {} } as unknown as PluginRuntime["channel"],
785+
botOpenIdSource: { kind: "prefetched", botOpenId: "ou_bot" },
786+
}),
787+
).resolves.toBeUndefined();
788+
789+
expect(register).toHaveBeenCalled();
790+
});
791+
792+
it("uses provided channelRuntime when it has inbound", async () => {
793+
setFeishuRuntime(createFeishuMonitorRuntime());
794+
const register = vi.fn();
795+
createEventDispatcherMock.mockReturnValue({ register });
796+
797+
await expect(
798+
monitorSingleAccount({
799+
cfg: buildDebounceConfig(),
800+
account: buildDebounceAccount(),
801+
runtime: createNonExitingRuntimeEnv(),
802+
channelRuntime: {
803+
runtimeContexts: {} as never,
804+
inbound: { run: vi.fn() },
805+
debounce: {
806+
resolveInboundDebounceMs: vi.fn().mockReturnValue(2000),
807+
createInboundDebouncer: vi.fn(),
808+
},
809+
} as unknown as PluginRuntime["channel"],
810+
botOpenIdSource: { kind: "prefetched", botOpenId: "ou_bot" },
811+
}),
812+
).resolves.toBeUndefined();
813+
814+
expect(register).toHaveBeenCalled();
815+
});
816+
817+
it("falls back to local runtime when channelRuntime is undefined", async () => {
818+
setFeishuRuntime(createFeishuMonitorRuntime());
819+
const register = vi.fn();
820+
createEventDispatcherMock.mockReturnValue({ register });
821+
822+
await expect(
823+
monitorSingleAccount({
824+
cfg: buildDebounceConfig(),
825+
account: buildDebounceAccount(),
826+
runtime: createNonExitingRuntimeEnv(),
827+
channelRuntime: undefined,
828+
botOpenIdSource: { kind: "prefetched", botOpenId: "ou_bot" },
829+
}),
830+
).resolves.toBeUndefined();
831+
832+
expect(register).toHaveBeenCalled();
833+
});
834+
});
772835
});

0 commit comments

Comments
 (0)