@@ -631,11 +631,11 @@ describe("Cline", () => {
631631
632632 // 5 is MAX_MID_STREAM_AUTO_RETRIES: the first attempt plus 5 automatic retries.
633633 it . each ( [
634- { autoApprovalEnabled : true , expectedAttempts : 6 , expectedBackoffs : 5 } ,
635- { autoApprovalEnabled : false , expectedAttempts : 1 , expectedBackoffs : 0 } ,
634+ { autoApprovalEnabled : true , expectedAttempts : 6 , expectedBackoffAttempts : [ 0 , 1 , 2 , 3 , 4 ] } ,
635+ { autoApprovalEnabled : false , expectedAttempts : 1 , expectedBackoffAttempts : [ ] } ,
636636 ] ) (
637637 "asks the user instead of retrying forever (autoApprovalEnabled=$autoApprovalEnabled)" ,
638- async ( { autoApprovalEnabled, expectedAttempts, expectedBackoffs } ) => {
638+ async ( { autoApprovalEnabled, expectedAttempts, expectedBackoffAttempts } ) => {
639639 vi . spyOn ( mockProvider , "getState" ) . mockResolvedValue (
640640 providerStateWith ( { autoApprovalEnabled, requestDelaySeconds : 0 } ) ,
641641 )
@@ -656,14 +656,54 @@ describe("Cline", () => {
656656 . spyOn ( task , "attemptApiRequest" )
657657 . mockImplementation ( ( ) => idleTimeoutStream ( ) )
658658
659- await task . recursivelyMakeClineRequests ( [ { type : "text" , text : "long request" } ] ) . catch ( ( ) => { } )
659+ // Declining ends the turn: the "API request failed" error is handled inside the loop,
660+ // so the call resolves rather than rejecting.
661+ await expect ( task . recursivelyMakeClineRequests ( [ { type : "text" , text : "long request" } ] ) ) . resolves . toBe (
662+ true ,
663+ )
660664
661665 expect ( attemptApiRequestSpy ) . toHaveBeenCalledTimes ( expectedAttempts )
662- expect ( backoffSpy ) . toHaveBeenCalledTimes ( expectedBackoffs )
666+ expect ( backoffSpy . mock . calls . map ( ( [ attempt ] ) => attempt ) ) . toEqual ( expectedBackoffAttempts )
663667 expect ( askSpy ) . toHaveBeenCalledOnce ( )
664668 expect ( askSpy ) . toHaveBeenCalledWith ( "api_req_failed" , expect . stringContaining ( "idle timeout" ) )
665669 } ,
666670 )
671+
672+ it ( "does not add the user message to history again when the user confirms a retry" , async ( ) => {
673+ vi . spyOn ( mockProvider , "getState" ) . mockResolvedValue (
674+ providerStateWith ( { autoApprovalEnabled : false , requestDelaySeconds : 0 } ) ,
675+ )
676+ const task = new Task ( {
677+ provider : mockProvider ,
678+ apiConfiguration : mockApiConfig ,
679+ task : "test task" ,
680+ startTask : false ,
681+ } )
682+ vi . spyOn ( task . diffViewProvider , "reset" ) . mockResolvedValue ( undefined )
683+ vi . spyOn ( getTaskTestAccess ( task ) , "safeEnsureModelFetched" ) . mockResolvedValue ( stubModelInfo )
684+ vi . spyOn ( getTaskTestAccess ( task ) , "presentAssistantMessageSafe" ) . mockImplementation ( ( ) => { } )
685+ const historySpy = vi
686+ . spyOn ( getTaskTestAccess ( task ) , "addToApiConversationHistory" )
687+ . mockResolvedValue ( undefined )
688+ const askSpy = vi
689+ . spyOn ( task , "ask" )
690+ . mockResolvedValueOnce ( { response : "yesButtonClicked" } satisfies TaskAskResult )
691+ . mockResolvedValue ( { response : "noButtonClicked" } satisfies TaskAskResult )
692+ const attemptApiRequestSpy = vi
693+ . spyOn ( task , "attemptApiRequest" )
694+ . mockImplementation ( ( ) => idleTimeoutStream ( ) )
695+
696+ await expect ( task . recursivelyMakeClineRequests ( [ { type : "text" , text : "long request" } ] ) ) . resolves . toBe (
697+ true ,
698+ )
699+
700+ expect ( askSpy ) . toHaveBeenCalledTimes ( 2 )
701+ expect ( attemptApiRequestSpy ) . toHaveBeenCalledTimes ( 2 )
702+ const userMessages = historySpy . mock . calls . filter (
703+ ( [ message ] ) => ( message as { role : string } ) . role === "user" ,
704+ )
705+ expect ( userMessages ) . toHaveLength ( 1 )
706+ } )
667707 } )
668708
669709 describe ( "native tool-call request isolation" , ( ) => {
0 commit comments