mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-29 01:52:04 +00:00
test(feishu): slim reaction monitor runtime fixtures
This commit is contained in:
@@ -4,12 +4,11 @@ import {
|
||||
resolveInboundDebounceMs,
|
||||
} from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js";
|
||||
import {
|
||||
createNonExitingTypedRuntimeEnv,
|
||||
createRuntimeEnv,
|
||||
} from "../../../test/helpers/plugins/runtime-env.js";
|
||||
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import { parseFeishuMessageEvent, type FeishuMessageEvent } from "./bot.js";
|
||||
import * as dedup from "./dedup.js";
|
||||
import { monitorSingleAccount } from "./monitor.account.js";
|
||||
@@ -230,6 +229,24 @@ function createMention(params: { openId: string; name: string; key?: string }):
|
||||
};
|
||||
}
|
||||
|
||||
function createFeishuMonitorRuntime(params?: {
|
||||
createInboundDebouncer?: PluginRuntime["channel"]["debounce"]["createInboundDebouncer"];
|
||||
resolveInboundDebounceMs?: PluginRuntime["channel"]["debounce"]["resolveInboundDebounceMs"];
|
||||
hasControlCommand?: PluginRuntime["channel"]["text"]["hasControlCommand"];
|
||||
}): PluginRuntime {
|
||||
return {
|
||||
channel: {
|
||||
debounce: {
|
||||
createInboundDebouncer: params?.createInboundDebouncer ?? createInboundDebouncer,
|
||||
resolveInboundDebounceMs: params?.resolveInboundDebounceMs ?? resolveInboundDebounceMs,
|
||||
},
|
||||
text: {
|
||||
hasControlCommand: params?.hasControlCommand ?? hasControlCommand,
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime;
|
||||
}
|
||||
|
||||
async function enqueueDebouncedMessage(
|
||||
onMessage: (data: unknown) => Promise<void>,
|
||||
event: FeishuMessageEvent,
|
||||
@@ -435,19 +452,7 @@ describe("monitorSingleAccount lifecycle", () => {
|
||||
});
|
||||
|
||||
it("stops the Feishu thread binding manager when the monitor exits", async () => {
|
||||
setFeishuRuntime(
|
||||
createPluginRuntimeMock({
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs,
|
||||
createInboundDebouncer,
|
||||
},
|
||||
text: {
|
||||
hasControlCommand,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
setFeishuRuntime(createFeishuMonitorRuntime());
|
||||
|
||||
await monitorSingleAccount({
|
||||
cfg: buildDebounceConfig(),
|
||||
@@ -466,19 +471,7 @@ describe("monitorSingleAccount lifecycle", () => {
|
||||
});
|
||||
|
||||
it("stops the Feishu thread binding manager when setup fails before transport starts", async () => {
|
||||
setFeishuRuntime(
|
||||
createPluginRuntimeMock({
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs,
|
||||
createInboundDebouncer,
|
||||
},
|
||||
text: {
|
||||
hasControlCommand,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
setFeishuRuntime(createFeishuMonitorRuntime());
|
||||
createEventDispatcherMock.mockReturnValue({
|
||||
get register() {
|
||||
throw new Error("register failed");
|
||||
@@ -509,19 +502,7 @@ describe("Feishu inbound debounce regressions", () => {
|
||||
vi.useFakeTimers();
|
||||
handlers = {};
|
||||
handleFeishuMessageMock.mockClear();
|
||||
setFeishuRuntime(
|
||||
createPluginRuntimeMock({
|
||||
channel: {
|
||||
debounce: {
|
||||
createInboundDebouncer,
|
||||
resolveInboundDebounceMs,
|
||||
},
|
||||
text: {
|
||||
hasControlCommand,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
setFeishuRuntime(createFeishuMonitorRuntime());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -693,24 +674,14 @@ describe("Feishu inbound debounce regressions", () => {
|
||||
setDedupPassThroughMocks();
|
||||
const enqueueMock = vi.fn();
|
||||
setFeishuRuntime(
|
||||
createPluginRuntimeMock({
|
||||
channel: {
|
||||
debounce: {
|
||||
createInboundDebouncer: <T>(params: {
|
||||
onError?: (err: unknown, items: T[]) => void;
|
||||
}) => ({
|
||||
enqueue: async (item: T) => {
|
||||
enqueueMock(item);
|
||||
params.onError?.(new Error("dispatch failed"), [item]);
|
||||
},
|
||||
flushKey: async () => {},
|
||||
}),
|
||||
resolveInboundDebounceMs,
|
||||
createFeishuMonitorRuntime({
|
||||
createInboundDebouncer: <T>(params: { onError?: (err: unknown, items: T[]) => void }) => ({
|
||||
enqueue: async (item: T) => {
|
||||
enqueueMock(item);
|
||||
params.onError?.(new Error("dispatch failed"), [item]);
|
||||
},
|
||||
text: {
|
||||
hasControlCommand,
|
||||
},
|
||||
},
|
||||
flushKey: async () => {},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
const onMessage = await setupDebounceMonitor();
|
||||
|
||||
Reference in New Issue
Block a user