Skip to content

Commit c96871d

Browse files
committed
test(feishu): avoid runtime env union lint trap
1 parent 472bcbb commit c96871d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

extensions/feishu/src/monitor.card-action.lifecycle.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
33
import "./lifecycle.test-support.js";
4-
import type { RuntimeEnv } from "../runtime-api.js";
54
import { resetProcessedFeishuCardActionTokensForTests } from "./card-action.js";
65
import { createFeishuCardInteractionEnvelope } from "./card-interaction.js";
76
import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js";
@@ -33,7 +32,7 @@ const {
3332
} = getFeishuLifecycleTestMocks();
3433

3534
let _handlers: Record<string, (data: unknown) => Promise<void>> = {};
36-
let lastRuntime: RuntimeEnv | null = null;
35+
let lastRuntimeError: ReturnType<typeof vi.fn> | null = null;
3736
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
3837
const lifecycleConfig = createFeishuLifecycleConfig({
3938
accountId: "acct-card",
@@ -96,13 +95,14 @@ function createCardActionEvent(params: {
9695
}
9796

9897
async function setupLifecycleMonitor() {
99-
lastRuntime = createRuntimeEnv();
98+
const runtime = createRuntimeEnv();
99+
lastRuntimeError = runtime.error;
100100
return setupFeishuLifecycleHandler({
101101
createEventDispatcherMock,
102102
onRegister: (registered) => {
103103
_handlers = registered;
104104
},
105-
runtime: lastRuntime,
105+
runtime,
106106
cfg: lifecycleConfig,
107107
account: lifecycleAccount,
108108
handlerKey: "card.action.trigger",
@@ -115,7 +115,7 @@ describe("Feishu card-action lifecycle", () => {
115115
vi.useRealTimers();
116116
vi.clearAllMocks();
117117
_handlers = {};
118-
lastRuntime = null;
118+
lastRuntimeError = null;
119119
resetProcessedFeishuCardActionTokensForTests();
120120
setFeishuLifecycleStateDir("openclaw-feishu-card-action");
121121

@@ -172,7 +172,7 @@ describe("Feishu card-action lifecycle", () => {
172172
createFeishuReplyDispatcherMock,
173173
});
174174

175-
expect(lastRuntime?.error).not.toHaveBeenCalled();
175+
expect(lastRuntimeError).not.toHaveBeenCalled();
176176
expect(dispatchReplyFromConfigMock).toHaveBeenCalledTimes(1);
177177
expect(createFeishuReplyDispatcherMock).toHaveBeenCalledTimes(1);
178178
expect(createFeishuReplyDispatcherMock).toHaveBeenCalledWith(
@@ -213,10 +213,10 @@ describe("Feishu card-action lifecycle", () => {
213213
handler: onCardAction,
214214
event,
215215
dispatchReplyFromConfigMock,
216-
runtimeErrorMock: lastRuntime?.error as ReturnType<typeof vi.fn>,
216+
runtimeErrorMock: lastRuntimeError as ReturnType<typeof vi.fn>,
217217
});
218218

219-
expect(lastRuntime?.error).toHaveBeenCalledTimes(1);
219+
expect(lastRuntimeError).toHaveBeenCalledTimes(1);
220220
expect(dispatchReplyFromConfigMock).toHaveBeenCalledTimes(1);
221221
expectFeishuReplyDispatcherSentFinalReplyOnce({ createFeishuReplyDispatcherMock });
222222
});
@@ -252,7 +252,7 @@ describe("Feishu card-action lifecycle", () => {
252252
},
253253
});
254254

255-
expect(lastRuntime?.error).toHaveBeenCalledWith(
255+
expect(lastRuntimeError).toHaveBeenCalledWith(
256256
"feishu[acct-card]: ignoring malformed card action payload",
257257
);
258258
expect(dispatchReplyFromConfigMock).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)