@@ -25,8 +25,6 @@ type SlackProviderMonitor = (params: {
2525 setStatus ?: ( next : Record < string , unknown > ) => void ;
2626} ) => Promise < unknown > ;
2727type SlackStartupAuthClientFactory = typeof import ( "./client.js" ) . createSlackStartupAuthClient ;
28- type SlackChannelInboundDispatch =
29- typeof import ( "openclaw/plugin-sdk/channel-inbound" ) . dispatchChannelInboundTurn ;
3028
3129const SLACK_INGRESS_LIFECYCLE_CONTEXT_KEY = "openclawIngressLifecycle" ;
3230
@@ -79,7 +77,6 @@ type SlackTestState = {
7977 > ;
8078 socketModeLogger ?: { error : ( ...args : unknown [ ] ) => void } ;
8179 createSlackStartupAuthClientMock : Mock < SlackStartupAuthClientFactory > ;
82- channelInboundDispatchOnce ?: SlackChannelInboundDispatch ;
8380} ;
8481
8582// globalThis-backed singleton: with isolate=false, a vi.resetModules() in any
@@ -106,7 +103,6 @@ const slackTestState: SlackTestState = vi.hoisted(() => {
106103 resolveSlackUserAllowlistMock : vi . fn ( ) ,
107104 socketModeLogger : undefined ,
108105 createSlackStartupAuthClientMock : vi . fn ( ) ,
109- channelInboundDispatchOnce : undefined ,
110106 } as SlackTestState ;
111107 return globalState [ "__slackTestState" ] ;
112108} ) ;
@@ -117,8 +113,11 @@ export function useSlackStartupAuthClientOnce(factory: SlackStartupAuthClientFac
117113 slackTestState . createSlackStartupAuthClientMock . mockImplementationOnce ( factory ) ;
118114}
119115
120- export function useSlackChannelInboundDispatchOnce ( dispatch : SlackChannelInboundDispatch ) : void {
121- slackTestState . channelInboundDispatchOnce = dispatch ;
116+ export async function runSlackHandlerWithDispatch (
117+ handler : SlackHandler ,
118+ args : unknown ,
119+ ) : Promise < void > {
120+ await handler ( withSlackDispatchLifecycle ( args ) ) ;
122121}
123122
124123type SlackClient = {
@@ -279,9 +278,12 @@ async function runSlackEventOnce(
279278 const handler = await getSlackHandlerOrThrow ( name ) ;
280279 // Normal Bolt handlers return after queue admission. Terminal-state tests use the
281280 // durable-ingress lifecycle so this helper can await the actual dispatch boundary.
282- const handlerArgs = opts ?. awaitDispatch ? withSlackDispatchLifecycle ( args ) : args ;
283281 try {
284- await handler ( handlerArgs ) ;
282+ if ( opts ?. awaitDispatch ) {
283+ await runSlackHandlerWithDispatch ( handler , args ) ;
284+ } else {
285+ await handler ( args ) ;
286+ }
285287 } finally {
286288 await stopSlackMonitor ( { controller, run } ) ;
287289 }
@@ -348,7 +350,6 @@ export function resetSlackTestState(config: Record<string, unknown> = defaultSla
348350 slackTestState . config = config ;
349351 slackTestState . appConstructorArgs = undefined ;
350352 slackTestState . socketModeLogger = undefined ;
351- slackTestState . channelInboundDispatchOnce = undefined ;
352353 slackTestState . appStartMock . mockReset ( ) . mockResolvedValue ( undefined ) ;
353354 slackTestState . appStopMock . mockReset ( ) . mockResolvedValue ( undefined ) ;
354355 slackTestState . interactionRegistrations . length = 0 ;
@@ -413,15 +414,8 @@ vi.mock("openclaw/plugin-sdk/channel-inbound", async (importOriginal) => {
413414 slackTestState . replyMock ( ...args ) as ReturnType < ReplyResolver > ;
414415 return {
415416 ...actual ,
416- dispatchChannelInboundTurn : ( params : DispatchParams ) => {
417- const enrichedParams = { ...params , replyResolver } ;
418- const dispatchOnce = slackTestState . channelInboundDispatchOnce ;
419- if ( dispatchOnce ) {
420- slackTestState . channelInboundDispatchOnce = undefined ;
421- return dispatchOnce ( enrichedParams ) ;
422- }
423- return actual . dispatchChannelInboundTurn ( enrichedParams ) ;
424- } ,
417+ dispatchChannelInboundTurn : ( params : DispatchParams ) =>
418+ actual . dispatchChannelInboundTurn ( { ...params , replyResolver } ) ,
425419 } ;
426420} ) ;
427421
0 commit comments