@@ -777,7 +777,16 @@ describe("Cline", () => {
777777 it ( "stops and restores history when the approved retry deletion cannot be persisted" , async ( ) => {
778778 const task = await createMidStreamRetryTask ( )
779779 task [ "saveApiConversationHistory" ] = vi . fn ( ) . mockImplementation ( async ( merge = true ) => merge )
780- vi . spyOn ( task , "ask" ) . mockResolvedValue ( { response : "yesButtonClicked" } satisfies TaskAskResult )
780+ const summaryMessage = {
781+ role : "user" as const ,
782+ content : [ { type : "text" as const , text : "context summary" } ] ,
783+ messageId : "summary-after-request" ,
784+ isSummary : true ,
785+ }
786+ vi . spyOn ( task , "ask" ) . mockImplementation ( async ( ) => {
787+ task . apiConversationHistory . push ( summaryMessage )
788+ return { response : "yesButtonClicked" } satisfies TaskAskResult
789+ } )
781790 const saySpy = vi . spyOn ( task , "say" )
782791 const attemptSpy = vi
783792 . spyOn ( task , "attemptApiRequest" )
@@ -789,7 +798,28 @@ describe("Cline", () => {
789798 expect ( attemptSpy ) . toHaveBeenCalledTimes ( 4 )
790799 expect ( task [ "saveApiConversationHistory" ] ) . toHaveBeenCalledWith ( false )
791800 expect ( saySpy ) . toHaveBeenCalledWith ( "error" , "Failed to persist conversation history before retrying." )
792- expect ( task . apiConversationHistory ) . toHaveLength ( 1 )
801+ expect ( task . apiConversationHistory ) . toHaveLength ( 2 )
802+ expect ( task . apiConversationHistory [ 0 ] ?. role ) . toBe ( "user" )
803+ expect ( task . apiConversationHistory [ 1 ] ) . toEqual ( summaryMessage )
804+ expect ( task . messageCounts . user ) . toBe ( 1 )
805+ } )
806+
807+ it ( "stops when the owned request message cannot be located by id" , async ( ) => {
808+ const task = await createMidStreamRetryTask ( )
809+ vi . spyOn ( task , "ask" ) . mockImplementation ( async ( ) => {
810+ task . apiConversationHistory [ 0 ] ! . messageId = "replaced-request-id"
811+ return { response : "yesButtonClicked" } satisfies TaskAskResult
812+ } )
813+ const saySpy = vi . spyOn ( task , "say" )
814+ const attemptSpy = vi
815+ . spyOn ( task , "attemptApiRequest" )
816+ . mockImplementation ( ( ) => midStreamFailingRequest ( new Error ( "Overloaded" ) ) )
817+
818+ const result = await task . recursivelyMakeClineRequests ( [ { type : "text" , text : "original user request" } ] )
819+
820+ expect ( result ) . toBe ( false )
821+ expect ( attemptSpy ) . toHaveBeenCalledTimes ( 4 )
822+ expect ( saySpy ) . toHaveBeenCalledWith ( "error" , "Failed to locate the API request in conversation history." )
793823 expect ( task . messageCounts . user ) . toBe ( 1 )
794824 } )
795825
0 commit comments