|
1 | 1 | import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | | -import type { ClawdbotConfig } from "../runtime-api.js"; |
| 2 | +import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js"; |
3 | 3 | import { expectFirstSentCardUsesFillWidthOnly } from "./card-test-helpers.js"; |
4 | 4 | import { createFeishuBotMenuHandler } from "./monitor.bot-menu-handler.js"; |
5 | 5 | |
@@ -40,15 +40,18 @@ function createBotMenuEvent(params: { eventKey: string; timestamp: string }) {
|
40 | 40 | }; |
41 | 41 | } |
42 | 42 | |
43 | | -async function registerHandlers() { |
44 | | -return createFeishuBotMenuHandler({ |
45 | | -cfg: {} as ClawdbotConfig, |
46 | | -accountId: "default", |
47 | | -runtime: { |
| 43 | +async function registerHandlers(params: { runtime?: RuntimeEnv } = {}) { |
| 44 | +const runtime = |
| 45 | +params.runtime ?? |
| 46 | +({ |
48 | 47 | log: vi.fn(), |
49 | 48 | error: vi.fn(), |
50 | 49 | exit: vi.fn(), |
51 | | -}, |
| 50 | +} as RuntimeEnv); |
| 51 | +return createFeishuBotMenuHandler({ |
| 52 | +cfg: {} as ClawdbotConfig, |
| 53 | +accountId: "default", |
| 54 | + runtime, |
52 | 55 | chatHistories: new Map(), |
53 | 56 | fireAndForget: true, |
54 | 57 | getBotOpenId: () => "ou_bot", |
@@ -163,7 +166,8 @@ describe("Feishu bot menu handler", () => {
|
163 | 166 | }); |
164 | 167 | |
165 | 168 | it("reopens replay for explicit retryable fallback failures", async () => { |
166 | | -const onBotMenu = await registerHandlers(); |
| 169 | +const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() } as RuntimeEnv; |
| 170 | +const onBotMenu = await registerHandlers({ runtime }); |
167 | 171 | sendCardFeishuMock |
168 | 172 | .mockImplementationOnce(async () => { |
169 | 173 | throw new Error("boom"); |
@@ -180,9 +184,16 @@ describe("Feishu bot menu handler", () => {
|
180 | 184 | .mockResolvedValueOnce(undefined); |
181 | 185 | |
182 | 186 | await onBotMenu(createBotMenuEvent({ eventKey: "quick-actions", timestamp: "1700000000004" })); |
| 187 | +await vi.waitFor(() => { |
| 188 | +expect(runtime.error).toHaveBeenCalledWith( |
| 189 | +"feishu[default]: error handling bot menu event: FeishuRetryableSyntheticEventError: retry me", |
| 190 | +); |
| 191 | +}); |
183 | 192 | await onBotMenu(createBotMenuEvent({ eventKey: "quick-actions", timestamp: "1700000000004" })); |
184 | 193 | |
185 | 194 | expect(sendCardFeishuMock).toHaveBeenCalledTimes(2); |
186 | | -expect(handleFeishuMessageMock).toHaveBeenCalledTimes(1); |
| 195 | +await vi.waitFor(() => { |
| 196 | +expect(handleFeishuMessageMock).toHaveBeenCalledTimes(2); |
| 197 | +}); |
187 | 198 | }); |
188 | 199 | }); |