test(feishu): coalesce lifecycle monitor cases · openclaw/openclaw@461deb8
steipete
·
2026-04-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,27 @@ export function getFeishuLifecycleTestMocks(): FeishuLifecycleTestMocks {
|
85 | 85 | return feishuLifecycleTestMocks; |
86 | 86 | } |
87 | 87 | |
| 88 | +export function resetFeishuLifecycleTestMocks(): void { |
| 89 | +for (const mock of Object.values(feishuLifecycleTestMocks)) { |
| 90 | +mock.mockReset(); |
| 91 | +} |
| 92 | +feishuLifecycleTestMocks.monitorWebSocketMock.mockResolvedValue(undefined); |
| 93 | +feishuLifecycleTestMocks.monitorWebhookMock.mockResolvedValue(undefined); |
| 94 | +feishuLifecycleTestMocks.createFeishuThreadBindingManagerMock.mockReturnValue({ stop: vi.fn() }); |
| 95 | +feishuLifecycleTestMocks.resolveBoundConversationMock.mockReturnValue(null); |
| 96 | +feishuLifecycleTestMocks.finalizeInboundContextMock.mockImplementation((ctx) => ctx); |
| 97 | +feishuLifecycleTestMocks.getMessageFeishuMock.mockResolvedValue(null); |
| 98 | +feishuLifecycleTestMocks.listFeishuThreadMessagesMock.mockResolvedValue([]); |
| 99 | +feishuLifecycleTestMocks.sendMessageFeishuMock.mockResolvedValue({ |
| 100 | +messageId: "om_sent", |
| 101 | +chatId: "chat_default", |
| 102 | +}); |
| 103 | +feishuLifecycleTestMocks.sendCardFeishuMock.mockResolvedValue({ |
| 104 | +messageId: "om_card", |
| 105 | +chatId: "chat_default", |
| 106 | +}); |
| 107 | +} |
| 108 | + |
88 | 109 | const { |
89 | 110 | createEventDispatcherMock, |
90 | 111 | monitorWebSocketMock, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -615,6 +615,7 @@ export type MonitorSingleAccountParams = {
|
615 | 615 | runtime?: RuntimeEnv; |
616 | 616 | abortSignal?: AbortSignal; |
617 | 617 | botOpenIdSource?: BotOpenIdSource; |
| 618 | +fireAndForget?: boolean; |
618 | 619 | }; |
619 | 620 | |
620 | 621 | export async function monitorSingleAccount(params: MonitorSingleAccountParams): Promise<void> { |
@@ -658,7 +659,7 @@ export async function monitorSingleAccount(params: MonitorSingleAccountParams):
|
658 | 659 | accountId, |
659 | 660 | runtime, |
660 | 661 | chatHistories, |
661 | | -fireAndForget: true, |
| 662 | +fireAndForget: params.fireAndForget ?? true, |
662 | 663 | }); |
663 | 664 | |
664 | 665 | if (connectionMode === "webhook") { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,10 @@ import "./lifecycle.test-support.js";
|
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js"; |
4 | 4 | import type { ClawdbotConfig } from "../runtime-api.js"; |
5 | | -import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js"; |
| 5 | +import { |
| 6 | +getFeishuLifecycleTestMocks, |
| 7 | +resetFeishuLifecycleTestMocks, |
| 8 | +} from "./lifecycle.test-support.js"; |
6 | 9 | import { |
7 | 10 | createFeishuLifecycleFixture, |
8 | 11 | createFeishuTextMessageEvent, |
@@ -73,7 +76,7 @@ async function setupLifecycleMonitor() {
|
73 | 76 | describe("Feishu ACP-init failure lifecycle", () => { |
74 | 77 | beforeEach(() => { |
75 | 78 | vi.useRealTimers(); |
76 | | -vi.clearAllMocks(); |
| 79 | +resetFeishuLifecycleTestMocks(); |
77 | 80 | _handlers = {}; |
78 | 81 | lastRuntime = null; |
79 | 82 | setFeishuLifecycleStateDir("openclaw-feishu-acp-failure"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js"; |
3 | 3 | import "./lifecycle.test-support.js"; |
4 | | -import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js"; |
| 4 | +import { |
| 5 | +getFeishuLifecycleTestMocks, |
| 6 | +resetFeishuLifecycleTestMocks, |
| 7 | +} from "./lifecycle.test-support.js"; |
5 | 8 | import { |
6 | 9 | createFeishuLifecycleConfig, |
7 | 10 | createFeishuLifecycleReplyDispatcher, |
@@ -85,7 +88,7 @@ async function setupLifecycleMonitor() {
|
85 | 88 | describe("Feishu bot-menu lifecycle", () => { |
86 | 89 | beforeEach(() => { |
87 | 90 | vi.useRealTimers(); |
88 | | -vi.clearAllMocks(); |
| 91 | +resetFeishuLifecycleTestMocks(); |
89 | 92 | _handlers = {}; |
90 | 93 | lastRuntime = null; |
91 | 94 | setFeishuLifecycleStateDir("openclaw-feishu-bot-menu"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
3 | 3 | import { createNonExitingRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js"; |
4 | 4 | import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js"; |
5 | 5 | import { FeishuConfigSchema } from "./config-schema.js"; |
6 | | -import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js"; |
| 6 | +import { |
| 7 | +getFeishuLifecycleTestMocks, |
| 8 | +resetFeishuLifecycleTestMocks, |
| 9 | +} from "./lifecycle.test-support.js"; |
7 | 10 | import { |
8 | 11 | createFeishuTextMessageEvent, |
9 | 12 | createFeishuLifecycleReplyDispatcher, |
@@ -132,7 +135,7 @@ async function setupLifecycleMonitor(accountId: "account-A" | "account-B") {
|
132 | 135 | describe("Feishu broadcast reply-once lifecycle", () => { |
133 | 136 | beforeEach(() => { |
134 | 137 | vi.useRealTimers(); |
135 | | -vi.clearAllMocks(); |
| 138 | +resetFeishuLifecycleTestMocks(); |
136 | 139 | handlersByAccount = new Map(); |
137 | 140 | runtimesByAccount = new Map(); |
138 | 141 | setFeishuLifecycleStateDir("openclaw-feishu-broadcast"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,10 @@ import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
|
3 | 3 | import "./lifecycle.test-support.js"; |
4 | 4 | import { resetProcessedFeishuCardActionTokensForTests } from "./card-action.js"; |
5 | 5 | import { createFeishuCardInteractionEnvelope } from "./card-interaction.js"; |
6 | | -import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js"; |
| 6 | +import { |
| 7 | +getFeishuLifecycleTestMocks, |
| 8 | +resetFeishuLifecycleTestMocks, |
| 9 | +} from "./lifecycle.test-support.js"; |
7 | 10 | import { |
8 | 11 | createFeishuLifecycleConfig, |
9 | 12 | createFeishuLifecycleReplyDispatcher, |
@@ -112,7 +115,7 @@ async function setupLifecycleMonitor() {
|
112 | 115 | describe("Feishu card-action lifecycle", () => { |
113 | 116 | beforeEach(() => { |
114 | 117 | vi.useRealTimers(); |
115 | | -vi.clearAllMocks(); |
| 118 | +resetFeishuLifecycleTestMocks(); |
116 | 119 | _handlers = {}; |
117 | 120 | lastRuntime = null; |
118 | 121 | resetProcessedFeishuCardActionTokensForTests(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import "./monitor.acp-init-failure.lifecycle.test-support.js"; |
| 2 | +import "./monitor.bot-menu.lifecycle.test-support.js"; |
| 3 | +import "./monitor.broadcast.reply-once.lifecycle.test-support.js"; |
| 4 | +import "./monitor.card-action.lifecycle.test-support.js"; |
| 5 | +import "./monitor.reaction.lifecycle.test-support.js"; |
| 6 | +import "./monitor.reply-once.lifecycle.test-support.js"; |
File renamed without changes.
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js"; |
3 | 3 | import "./lifecycle.test-support.js"; |
4 | | -import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js"; |
| 4 | +import { |
| 5 | +getFeishuLifecycleTestMocks, |
| 6 | +resetFeishuLifecycleTestMocks, |
| 7 | +} from "./lifecycle.test-support.js"; |
5 | 8 | import { |
6 | 9 | createFeishuLifecycleConfig, |
7 | 10 | createFeishuLifecycleReplyDispatcher, |
@@ -62,7 +65,8 @@ async function setupLifecycleMonitor() {
|
62 | 65 | describe("Feishu reply-once lifecycle", () => { |
63 | 66 | beforeEach(() => { |
64 | 67 | vi.useRealTimers(); |
65 | | -vi.clearAllMocks(); |
| 68 | +resetFeishuLifecycleTestMocks(); |
| 69 | +handleMessageMock.mockReset(); |
66 | 70 | lastRuntime = null; |
67 | 71 | setFeishuLifecycleStateDir("openclaw-feishu-lifecycle"); |
68 | 72 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -452,6 +452,7 @@ export async function setupFeishuLifecycleHandler(params: {
|
452 | 452 | account: params.account, |
453 | 453 | runtime: params.runtime, |
454 | 454 | botOpenIdSource: FEISHU_PREFETCHED_BOT_OPEN_ID_SOURCE, |
| 455 | +fireAndForget: false, |
455 | 456 | }); |
456 | 457 | |
457 | 458 | const handlers: Record<string, (data: unknown) => Promise<void>> = {}; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。