11import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
22import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js" ;
33import "./lifecycle.test-support.js" ;
4- import type { RuntimeEnv } from "../runtime-api.js" ;
54import { resetProcessedFeishuCardActionTokensForTests } from "./card-action.js" ;
65import { createFeishuCardInteractionEnvelope } from "./card-interaction.js" ;
76import { getFeishuLifecycleTestMocks } from "./lifecycle.test-support.js" ;
@@ -33,7 +32,7 @@ const {
3332} = getFeishuLifecycleTestMocks ( ) ;
3433
3534let _handlers : Record < string , ( data : unknown ) => Promise < void > > = { } ;
36- let lastRuntime : RuntimeEnv | null = null ;
35+ let lastRuntimeError : ReturnType < typeof vi . fn > | null = null ;
3736const originalStateDir = process . env . OPENCLAW_STATE_DIR ;
3837const lifecycleConfig = createFeishuLifecycleConfig ( {
3938 accountId : "acct-card" ,
@@ -96,13 +95,14 @@ function createCardActionEvent(params: {
9695}
9796
9897async 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