@@ -179,19 +179,24 @@ async function runMessageActionRequest(
179179 return { respond } ;
180180}
181181
182+ function deliveryCall ( index = 0 ) : Record < string , any > | undefined {
183+ const calls = mocks . deliverOutboundPayloads . mock . calls as unknown as Array < [ Record < string , any > ] > ;
184+ return calls [ index ] ?. [ 0 ] ;
185+ }
186+
187+ function firstRespondCall ( respond : ReturnType < typeof vi . fn > ) {
188+ const calls = respond . mock . calls as unknown as Array <
189+ [ boolean , Record < string , any > , unknown , Record < string , any > ]
190+ > ;
191+ return calls [ 0 ] ;
192+ }
193+
182194function expectDeliverySessionMirror ( params : { agentId : string ; sessionKey : string } ) {
183- expect ( mocks . deliverOutboundPayloads ) . toHaveBeenCalledWith (
184- expect . objectContaining ( {
185- session : expect . objectContaining ( {
186- agentId : params . agentId ,
187- key : params . sessionKey ,
188- } ) ,
189- mirror : expect . objectContaining ( {
190- sessionKey : params . sessionKey ,
191- agentId : params . agentId ,
192- } ) ,
193- } ) ,
194- ) ;
195+ const call = deliveryCall ( ) ;
196+ expect ( call ?. session ?. agentId ) . toBe ( params . agentId ) ;
197+ expect ( call ?. session ?. key ) . toBe ( params . sessionKey ) ;
198+ expect ( call ?. mirror ?. sessionKey ) . toBe ( params . sessionKey ) ;
199+ expect ( call ?. mirror ?. agentId ) . toBe ( params . agentId ) ;
195200}
196201
197202function mockDeliverySuccess ( messageId : string ) {
@@ -241,17 +246,14 @@ describe("gateway send mirroring", () => {
241246 idempotencyKey : "idem-media-only" ,
242247 } ) ;
243248
244- expect ( mocks . deliverOutboundPayloads ) . toHaveBeenCalledWith (
245- expect . objectContaining ( {
246- payloads : [ { text : "" , mediaUrl : "https://example.com/a.png" , mediaUrls : undefined } ] ,
247- } ) ,
248- ) ;
249- expect ( respond ) . toHaveBeenCalledWith (
250- true ,
251- expect . objectContaining ( { messageId : "m-media" } ) ,
252- undefined ,
253- expect . objectContaining ( { channel : "slack" } ) ,
254- ) ;
249+ expect ( deliveryCall ( ) ?. payloads ) . toEqual ( [
250+ { text : "" , mediaUrl : "https://example.com/a.png" , mediaUrls : undefined } ,
251+ ] ) ;
252+ const response = firstRespondCall ( respond ) ;
253+ expect ( response ?. [ 0 ] ) . toBe ( true ) ;
254+ expect ( response ?. [ 1 ] ?. messageId ) . toBe ( "m-media" ) ;
255+ expect ( response ?. [ 2 ] ) . toBeUndefined ( ) ;
256+ expect ( response ?. [ 3 ] ?. channel ) . toBe ( "slack" ) ;
255257 } ) ;
256258
257259 it ( "passes outbound session context for gateway media sends" , async ( ) => {
@@ -266,22 +268,16 @@ describe("gateway send mirroring", () => {
266268 idempotencyKey : "idem-whatsapp-media" ,
267269 } ) ;
268270
269- expect ( mocks . deliverOutboundPayloads ) . toHaveBeenCalledWith (
270- expect . objectContaining ( {
271- channel : "whatsapp" ,
272- payloads : [
273- {
274- text : "caption" ,
275- mediaUrl : "file:///tmp/workspace/photo.png" ,
276- mediaUrls : undefined ,
277- } ,
278- ] ,
279- session : expect . objectContaining ( {
280- agentId : "work" ,
281- key : "agent:work:whatsapp:resolved" ,
282- } ) ,
283- } ) ,
284- ) ;
271+ expect ( deliveryCall ( ) ?. channel ) . toBe ( "whatsapp" ) ;
272+ expect ( deliveryCall ( ) ?. payloads ) . toEqual ( [
273+ {
274+ text : "caption" ,
275+ mediaUrl : "file:///tmp/workspace/photo.png" ,
276+ mediaUrls : undefined ,
277+ } ,
278+ ] ) ;
279+ expect ( deliveryCall ( ) ?. session ?. agentId ) . toBe ( "work" ) ;
280+ expect ( deliveryCall ( ) ?. session ?. key ) . toBe ( "agent:work:whatsapp:resolved" ) ;
285281 } ) ;
286282
287283 it ( "maps gateway asVoice sends onto outbound audioAsVoice payloads" , async ( ) => {
@@ -296,23 +292,14 @@ describe("gateway send mirroring", () => {
296292 idempotencyKey : "idem-voice" ,
297293 } ) ;
298294
299- expect ( mocks . deliverOutboundPayloads ) . toHaveBeenCalledWith (
300- expect . objectContaining ( {
301- payloads : [
302- expect . objectContaining ( {
303- text : "voice note" ,
304- mediaUrl : "file:///tmp/openclaw-voice.ogg" ,
305- audioAsVoice : true ,
306- } ) ,
307- ] ,
308- } ) ,
309- ) ;
310- expect ( respond ) . toHaveBeenCalledWith (
311- true ,
312- expect . objectContaining ( { messageId : "m-voice" } ) ,
313- undefined ,
314- expect . objectContaining ( { channel : "slack" } ) ,
315- ) ;
295+ expect ( deliveryCall ( ) ?. payloads ?. [ 0 ] ?. text ) . toBe ( "voice note" ) ;
296+ expect ( deliveryCall ( ) ?. payloads ?. [ 0 ] ?. mediaUrl ) . toBe ( "file:///tmp/openclaw-voice.ogg" ) ;
297+ expect ( deliveryCall ( ) ?. payloads ?. [ 0 ] ?. audioAsVoice ) . toBe ( true ) ;
298+ const response = firstRespondCall ( respond ) ;
299+ expect ( response ?. [ 0 ] ) . toBe ( true ) ;
300+ expect ( response ?. [ 1 ] ?. messageId ) . toBe ( "m-voice" ) ;
301+ expect ( response ?. [ 2 ] ) . toBeUndefined ( ) ;
302+ expect ( response ?. [ 3 ] ?. channel ) . toBe ( "slack" ) ;
316303 } ) ;
317304
318305 it ( "forwards gateway client scopes into outbound delivery" , async ( ) => {
0 commit comments