@@ -2268,10 +2268,15 @@ describe("deliverOutboundPayloads", () => {
22682268 session : { agentId : "agent-main" } ,
22692269 } ) ;
22702270
2271- expect ( logMocks . warn ) . toHaveBeenCalledWith (
2271+ expect ( logMocks . warn . mock . calls [ 0 ] ?. [ 0 ] ) . toBe (
22722272 "deliverOutboundPayloads: session.agentId present without session key; internal message:sent hook will be skipped" ,
2273- expect . objectContaining ( { channel : "matrix" , to : "!room:example" , agentId : "agent-main" } ) ,
22742273 ) ;
2274+ const warnContext = logMocks . warn . mock . calls [ 0 ] ?. [ 1 ] as
2275+ | { agentId ?: unknown ; channel ?: unknown ; to ?: unknown }
2276+ | undefined ;
2277+ expect ( warnContext ?. channel ) . toBe ( "matrix" ) ;
2278+ expect ( warnContext ?. to ) . toBe ( "!room:example" ) ;
2279+ expect ( warnContext ?. agentId ) . toBe ( "agent-main" ) ;
22752280 } ) ;
22762281
22772282 it ( "calls failDelivery instead of ackDelivery on bestEffort partial failure" , async ( ) => {
@@ -2316,29 +2321,40 @@ describe("deliverOutboundPayloads", () => {
23162321 } ) ;
23172322
23182323 expect ( queueMocks . enqueueDelivery ) . toHaveBeenCalledTimes ( 1 ) ;
2319- expect ( queueMocks . enqueueDelivery ) . toHaveBeenCalledWith (
2320- expect . objectContaining ( {
2321- payloads : [
2322- { text : "NO_REPLY" } ,
2323- { text : '{"action":"NO_REPLY"}' } ,
2324- { text : "caption\nMEDIA:https://x.test/a.png" } ,
2325- { text : "NO_REPLY" , mediaUrl : " https://x.test/b.png " } ,
2326- ] ,
2327- renderedBatchPlan : expect . objectContaining ( {
2328- payloadCount : 4 ,
2329- textCount : 4 ,
2330- mediaCount : 1 ,
2331- items : expect . arrayContaining ( [
2332- expect . objectContaining ( {
2333- index : 3 ,
2334- kinds : [ "text" , "media" ] ,
2335- text : "NO_REPLY" ,
2336- mediaUrls : [ "https://x.test/b.png" ] ,
2337- } ) ,
2338- ] ) ,
2339- } ) ,
2340- } ) ,
2341- ) ;
2324+ const queuedDelivery = (
2325+ queueMocks . enqueueDelivery . mock . calls as unknown as Array <
2326+ [
2327+ {
2328+ payloads ?: unknown ;
2329+ renderedBatchPlan ?: {
2330+ items ?: Array < {
2331+ index ?: unknown ;
2332+ kinds ?: unknown ;
2333+ mediaUrls ?: unknown ;
2334+ text ?: unknown ;
2335+ } > ;
2336+ mediaCount ?: unknown ;
2337+ payloadCount ?: unknown ;
2338+ textCount ?: unknown ;
2339+ } ;
2340+ } ,
2341+ ]
2342+ >
2343+ ) [ 0 ] ?. [ 0 ] ;
2344+ expect ( queuedDelivery ?. payloads ) . toStrictEqual ( [
2345+ { text : "NO_REPLY" } ,
2346+ { text : '{"action":"NO_REPLY"}' } ,
2347+ { text : "caption\nMEDIA:https://x.test/a.png" } ,
2348+ { text : "NO_REPLY" , mediaUrl : " https://x.test/b.png " } ,
2349+ ] ) ;
2350+ const renderedPlan = queuedDelivery ?. renderedBatchPlan ;
2351+ expect ( renderedPlan ?. payloadCount ) . toBe ( 4 ) ;
2352+ expect ( renderedPlan ?. textCount ) . toBe ( 4 ) ;
2353+ expect ( renderedPlan ?. mediaCount ) . toBe ( 1 ) ;
2354+ const noReplyMediaItem = renderedPlan ?. items ?. find ( ( item ) => item . index === 3 ) ;
2355+ expect ( noReplyMediaItem ?. kinds ) . toStrictEqual ( [ "text" , "media" ] ) ;
2356+ expect ( noReplyMediaItem ?. text ) . toBe ( "NO_REPLY" ) ;
2357+ expect ( noReplyMediaItem ?. mediaUrls ) . toStrictEqual ( [ "https://x.test/b.png" ] ) ;
23422358 } ) ;
23432359
23442360 it ( "strips internal runtime scaffolding before queue persistence" , async ( ) => {
@@ -2374,27 +2390,31 @@ describe("deliverOutboundPayloads", () => {
23742390 deps : { matrix : sendMatrix } ,
23752391 } ) ;
23762392
2377- expect ( queueMocks . enqueueDelivery ) . toHaveBeenCalledWith (
2378- expect . objectContaining ( {
2379- payloads : [
2393+ const queuedDelivery = (
2394+ queueMocks . enqueueDelivery . mock . calls as unknown as Array <
2395+ [
23802396 {
2381- text : "visible\nafter" ,
2382- channelData : {
2383- internal : "" ,
2384- } ,
2397+ payloads ?: unknown ;
2398+ renderedBatchPlan ?: {
2399+ items ?: Array < { text ?: unknown } > ;
2400+ payloadCount ?: unknown ;
2401+ textCount ?: unknown ;
2402+ } ;
23852403 } ,
2386- ] ,
2387- renderedBatchPlan : expect . objectContaining ( {
2388- payloadCount : 1 ,
2389- textCount : 1 ,
2390- items : [
2391- expect . objectContaining ( {
2392- text : "visible\nafter" ,
2393- } ) ,
2394- ] ,
2395- } ) ,
2396- } ) ,
2397- ) ;
2404+ ]
2405+ >
2406+ ) [ 0 ] ?. [ 0 ] ;
2407+ expect ( queuedDelivery ?. payloads ) . toStrictEqual ( [
2408+ {
2409+ text : "visible\nafter" ,
2410+ channelData : {
2411+ internal : "" ,
2412+ } ,
2413+ } ,
2414+ ] ) ;
2415+ expect ( queuedDelivery ?. renderedBatchPlan ?. payloadCount ) . toBe ( 1 ) ;
2416+ expect ( queuedDelivery ?. renderedBatchPlan ?. textCount ) . toBe ( 1 ) ;
2417+ expect ( queuedDelivery ?. renderedBatchPlan ?. items ?. [ 0 ] ?. text ) . toBe ( "visible\nafter" ) ;
23982418 } ) ;
23992419
24002420 it ( "persists rendered batch plans with queued deliveries" , async ( ) => {
@@ -2422,11 +2442,10 @@ describe("deliverOutboundPayloads", () => {
24222442 renderedBatchPlan,
24232443 } ) ;
24242444
2425- expect ( queueMocks . enqueueDelivery ) . toHaveBeenCalledWith (
2426- expect . objectContaining ( {
2427- renderedBatchPlan,
2428- } ) ,
2429- ) ;
2445+ const queuedDelivery = (
2446+ queueMocks . enqueueDelivery . mock . calls as unknown as Array < [ { renderedBatchPlan ?: unknown } ] >
2447+ ) [ 0 ] ?. [ 0 ] ;
2448+ expect ( queuedDelivery ?. renderedBatchPlan ) . toBe ( renderedBatchPlan ) ;
24302449 } ) ;
24312450
24322451 it ( "applies silent-reply rewrite policy from the outbound session" , async ( ) => {
0 commit comments