@@ -332,6 +332,53 @@ describe("runHeartbeatOnce ack handling", () => {
332332 } ) ;
333333 } ) ;
334334
335+ it ( "preserves heartbeat mirror text when notifications include media URLs" , async ( ) => {
336+ await withTempHeartbeatSandbox ( async ( { tmpDir, storePath, replySpy } ) => {
337+ const cfg = createWhatsAppHeartbeatConfig ( {
338+ tmpDir,
339+ storePath,
340+ } ) ;
341+ const sessionKey = "agent:main:whatsapp:direct:test-user" ;
342+ await seedSessionStore ( storePath , sessionKey , {
343+ sessionId : "direct-sid" ,
344+ lastChannel : "whatsapp" ,
345+ lastProvider : "whatsapp" ,
346+ lastTo : "test-user" ,
347+ } ) ;
348+
349+ replySpy . mockResolvedValue ( {
350+ text : "Deepali sent the programme attachment." ,
351+ mediaUrls : [ "file:///tmp/programme.pdf" ] ,
352+ } ) ;
353+ const sendWhatsApp = createMessageSendSpy ( ) ;
354+
355+ await runHeartbeatOnce ( {
356+ cfg,
357+ sessionKey,
358+ deps : {
359+ ...makeWhatsAppDeps ( { sendWhatsApp } ) ,
360+ getReplyFromConfig : replySpy ,
361+ } ,
362+ } ) ;
363+
364+ expect ( sendWhatsApp ) . toHaveBeenCalledWith (
365+ "test-user" ,
366+ "Deepali sent the programme attachment." ,
367+ expect . any ( Object ) ,
368+ ) ;
369+ expect ( transcriptMocks . appendAssistantMessageToSessionTranscript ) . toHaveBeenCalledTimes ( 1 ) ;
370+ const appendCall =
371+ transcriptMocks . appendAssistantMessageToSessionTranscript . mock . calls [ 0 ] ?. [ 0 ] ;
372+ expect ( appendCall ) . toMatchObject ( {
373+ agentId : "main" ,
374+ sessionKey,
375+ text : "Deepali sent the programme attachment." ,
376+ } ) ;
377+ expect ( appendCall ?. text ) . not . toBe ( "programme.pdf" ) ;
378+ expect ( appendCall ?. idempotencyKey ) . toMatch ( / ^ h e a r t b e a t - d e l i v e r y - m i r r o r : v 1 : / ) ;
379+ } ) ;
380+ } ) ;
381+
335382 it . each ( [
336383 {
337384 title : "does not deliver HEARTBEAT_OK to telegram when showOk is false" ,
0 commit comments