test(feishu): coalesce lifecycle monitor cases

This commit is contained in:
Peter Steinberger
2026-04-23 09:25:23 +01:00
parent 2b292faece
commit 461deb8d8a
10 changed files with 56 additions and 11 deletions

View File

@@ -85,6 +85,27 @@ export function getFeishuLifecycleTestMocks(): FeishuLifecycleTestMocks {
return feishuLifecycleTestMocks;
}
export function resetFeishuLifecycleTestMocks(): void {
for (const mock of Object.values(feishuLifecycleTestMocks)) {
mock.mockReset();
}
feishuLifecycleTestMocks.monitorWebSocketMock.mockResolvedValue(undefined);
feishuLifecycleTestMocks.monitorWebhookMock.mockResolvedValue(undefined);
feishuLifecycleTestMocks.createFeishuThreadBindingManagerMock.mockReturnValue({ stop: vi.fn() });
feishuLifecycleTestMocks.resolveBoundConversationMock.mockReturnValue(null);
feishuLifecycleTestMocks.finalizeInboundContextMock.mockImplementation((ctx) => ctx);
feishuLifecycleTestMocks.getMessageFeishuMock.mockResolvedValue(null);
feishuLifecycleTestMocks.listFeishuThreadMessagesMock.mockResolvedValue([]);
feishuLifecycleTestMocks.sendMessageFeishuMock.mockResolvedValue({
messageId: "om_sent",
chatId: "chat_default",
});
feishuLifecycleTestMocks.sendCardFeishuMock.mockResolvedValue({
messageId: "om_card",
chatId: "chat_default",
});
}
const {
createEventDispatcherMock,
monitorWebSocketMock,

View File

@@ -615,6 +615,7 @@ export type MonitorSingleAccountParams = {
runtime?: RuntimeEnv;
abortSignal?: AbortSignal;
botOpenIdSource?: BotOpenIdSource;
fireAndForget?: boolean;
};
export async function monitorSingleAccount(params: MonitorSingleAccountParams): Promise<void> {
@@ -658,7 +659,7 @@ export async function monitorSingleAccount(params: MonitorSingleAccountParams):
accountId,
runtime,
chatHistories,
fireAndForget: true,
fireAndForget: params.fireAndForget ?? true,
});
if (connectionMode === "webhook") {

View File

@@ -2,7 +2,10 @@ import "./lifecycle.test-support.js";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig } from "../runtime-api.js";
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
resetFeishuLifecycleTestMocks,
} from "./lifecycle.test-support.js";
import {
createFeishuLifecycleFixture,
createFeishuTextMessageEvent,
@@ -73,7 +76,7 @@ async function setupLifecycleMonitor() {
describe("Feishu ACP-init failure lifecycle", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
setFeishuLifecycleStateDir("openclaw-feishu-acp-failure");

View File

@@ -1,7 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
resetFeishuLifecycleTestMocks,
} from "./lifecycle.test-support.js";
import {
createFeishuLifecycleConfig,
createFeishuLifecycleReplyDispatcher,
@@ -85,7 +88,7 @@ async function setupLifecycleMonitor() {
describe("Feishu bot-menu lifecycle", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
setFeishuLifecycleStateDir("openclaw-feishu-bot-menu");

View File

@@ -3,7 +3,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createNonExitingRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
import { FeishuConfigSchema } from "./config-schema.js";
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
resetFeishuLifecycleTestMocks,
} from "./lifecycle.test-support.js";
import {
createFeishuTextMessageEvent,
createFeishuLifecycleReplyDispatcher,
@@ -132,7 +135,7 @@ async function setupLifecycleMonitor(accountId: "account-A" | "account-B") {
describe("Feishu broadcast reply-once lifecycle", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
resetFeishuLifecycleTestMocks();
handlersByAccount = new Map();
runtimesByAccount = new Map();
setFeishuLifecycleStateDir("openclaw-feishu-broadcast");

View File

@@ -3,7 +3,10 @@ import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import { resetProcessedFeishuCardActionTokensForTests } from "./card-action.js";
import { createFeishuCardInteractionEnvelope } from "./card-interaction.js";
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
resetFeishuLifecycleTestMocks,
} from "./lifecycle.test-support.js";
import {
createFeishuLifecycleConfig,
createFeishuLifecycleReplyDispatcher,
@@ -112,7 +115,7 @@ async function setupLifecycleMonitor() {
describe("Feishu card-action lifecycle", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
resetProcessedFeishuCardActionTokensForTests();

View File

@@ -0,0 +1,6 @@
import "./monitor.acp-init-failure.lifecycle.test-support.js";
import "./monitor.bot-menu.lifecycle.test-support.js";
import "./monitor.broadcast.reply-once.lifecycle.test-support.js";
import "./monitor.card-action.lifecycle.test-support.js";
import "./monitor.reaction.lifecycle.test-support.js";
import "./monitor.reply-once.lifecycle.test-support.js";

View File

@@ -1,7 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
resetFeishuLifecycleTestMocks,
} from "./lifecycle.test-support.js";
import {
createFeishuLifecycleConfig,
createFeishuLifecycleReplyDispatcher,
@@ -62,7 +65,8 @@ async function setupLifecycleMonitor() {
describe("Feishu reply-once lifecycle", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
resetFeishuLifecycleTestMocks();
handleMessageMock.mockReset();
lastRuntime = null;
setFeishuLifecycleStateDir("openclaw-feishu-lifecycle");

View File

@@ -452,6 +452,7 @@ export async function setupFeishuLifecycleHandler(params: {
account: params.account,
runtime: params.runtime,
botOpenIdSource: FEISHU_PREFETCHED_BOT_OPEN_ID_SOURCE,
fireAndForget: false,
});
const handlers: Record<string, (data: unknown) => Promise<void>> = {};