@@ -508,13 +508,14 @@ describe("msteams messenger", () => {
508508 expect ( retryEvents ) . toEqual ( [ { nextAttempt : 2 , delayMs : 0 } ] ) ;
509509 } ) ;
510510
511- it ( "retries full activity preparation when media upload fails transiently " , async ( ) => {
511+ it ( "retries media preparation but reuses it after provider dispatch starts " , async ( ) => {
512512 const tmpDir = await mkdtemp ( path . join ( resolvePreferredOpenClawTmpDir ( ) , "msteams-retry-" ) ) ;
513513 const localFile = path . join ( tmpDir , "retry.txt" ) ;
514514 await writeFile ( localFile , "hello" ) ;
515515
516516 try {
517517 const attempts : string [ ] = [ ] ;
518+ const providerPayloads : string [ ] = [ ] ;
518519 const retryEvents : Array < { nextAttempt : number ; delayMs : number } > = [ ] ;
519520 let uploadAttempts = 0 ;
520521 graphUploadMockState . uploadAndShareSharePoint . mockImplementation ( async ( ) => {
@@ -535,8 +536,12 @@ describe("msteams messenger", () => {
535536 name : "retry.txt" ,
536537 } ) ;
537538
539+ const sendActivity = createRecordedSendActivity ( attempts , 429 ) ;
538540 const ctx = {
539- sendActivity : createRecordedSendActivity ( attempts ) ,
541+ sendActivity : async ( activity : unknown ) => {
542+ providerPayloads . push ( JSON . stringify ( activity ) ) ;
543+ return await sendActivity ( activity ) ;
544+ } ,
540545 } ;
541546 const ids = await sendMSTeamsMessages ( {
542547 replyStyle : "thread" ,
@@ -555,14 +560,18 @@ describe("msteams messenger", () => {
555560 getAccessToken : async ( ) => "token" ,
556561 } ,
557562 sharePointSiteId : "site-123" ,
558- retry : { maxAttempts : 2 , baseDelayMs : 0 , maxDelayMs : 0 } ,
563+ retry : { maxAttempts : 3 , baseDelayMs : 0 , maxDelayMs : 0 } ,
559564 onRetry : ( e ) => retryEvents . push ( { nextAttempt : e . nextAttempt , delayMs : e . delayMs } ) ,
560565 } ) ;
561566
562567 expect ( uploadAttempts ) . toBe ( 2 ) ;
563- expect ( attempts ) . toEqual ( [ "one" ] ) ;
568+ expect ( attempts ) . toEqual ( [ "one" , "one" ] ) ;
569+ expect ( providerPayloads [ 1 ] ) . toBe ( providerPayloads [ 0 ] ) ;
564570 expect ( ids ) . toEqual ( [ "id:one" ] ) ;
565- expect ( retryEvents ) . toEqual ( [ { nextAttempt : 2 , delayMs : 0 } ] ) ;
571+ expect ( retryEvents ) . toEqual ( [
572+ { nextAttempt : 2 , delayMs : 0 } ,
573+ { nextAttempt : 3 , delayMs : 0 } ,
574+ ] ) ;
566575 } finally {
567576 await rm ( tmpDir , { recursive : true , force : true } ) ;
568577 }
0 commit comments