@@ -3905,11 +3905,18 @@ describe("Cline", () => {
39053905 } )
39063906
39073907 const payloads : string [ ] = [ ]
3908+ // As the real say does, the message is added to the conversation: the request keeps hold of that one.
39083909 vi . spyOn ( task , "say" ) . mockImplementation ( async ( type , text ) => {
39093910 if ( type === "api_req_started" ) payloads . push ( String ( text ) )
3911+ task . clineMessages . push ( {
3912+ ts : Date . now ( ) ,
3913+ type : "say" ,
3914+ say : type as "api_req_started" ,
3915+ text : String ( text ) ,
3916+ } )
39103917 return undefined as never
39113918 } )
3912- task . clineMessages = [ { ts : Date . now ( ) , type : "say" , say : "api_req_started" , text : "{}" } ]
3919+ task . clineMessages = [ { ts : Date . now ( ) - 1 , type : "say" , say : "api_req_started" , text : "{}" } ]
39133920
39143921 // Only the stop that the test asks for is expected: any other failure is a failure of the test.
39153922 await task . recursivelyMakeClineRequests ( [ { type : "text" , text : "hello" } ] ) . catch ( ( error : unknown ) => {
@@ -3992,6 +3999,47 @@ describe("Cline", () => {
39923999 expect ( older . text ) . toBe ( '{"apiProvider":"older"}' ) // not relabelled in its place
39934000 expect ( attempt ) . not . toHaveBeenCalled ( ) // and nothing was sent
39944001 } )
4002+
4003+ it ( "stops, and takes no older request in its place, when the placeholder is deleted while it is being written" , async ( ) => {
4004+ const task = new Task ( {
4005+ provider : mockProvider ,
4006+ apiConfiguration : {
4007+ apiProvider : providerIdentifiers . anthropic ,
4008+ apiKey : "k" ,
4009+ apiModelId : "claude-sonnet-5" ,
4010+ } ,
4011+ task : "test task" ,
4012+ startTask : false ,
4013+ } )
4014+ Object . assign ( task . api , { ensureModelFetched : vi . fn ( ) . mockResolvedValue ( undefined ) } )
4015+ vi . mocked ( processUserContentMentions ) . mockResolvedValueOnce ( {
4016+ content : [ { type : "text" , text : "hello" } ] ,
4017+ mode : undefined ,
4018+ } )
4019+ vi . spyOn ( getTaskTestAccess ( task ) , "saveClineMessages" ) . mockResolvedValue ( true )
4020+ vi . spyOn ( getTaskTestAccess ( task ) , "addToApiConversationHistory" ) . mockResolvedValue ( undefined )
4021+ const attempt = vi . spyOn ( task , "attemptApiRequest" )
4022+ // An older request, and the placeholder that this request adds.
4023+ const older = {
4024+ ts : 1 ,
4025+ type : "say" as const ,
4026+ say : "api_req_started" as const ,
4027+ text : '{"apiProvider":"older"}' ,
4028+ }
4029+ task . clineMessages = [ older ]
4030+ // A delete that is confirmed while the say waits: the placeholder is gone when it returns.
4031+ vi . spyOn ( task , "say" ) . mockImplementation ( async ( ) => undefined as never )
4032+ // A deletion that is confirmed while the request is being prepared removes its placeholder.
4033+ vi . mocked ( getEnvironmentDetails ) . mockClear ( )
4034+
4035+ // The loop ends the request there, as it does for an abort.
4036+ await expect ( task . recursivelyMakeClineRequests ( [ { type : "text" , text : "hello" } ] ) ) . rejects . toThrow (
4037+ "request was removed from the conversation" ,
4038+ )
4039+
4040+ expect ( older . text ) . toBe ( '{"apiProvider":"older"}' ) // not relabelled in its place
4041+ expect ( attempt ) . not . toHaveBeenCalled ( ) // and nothing was sent
4042+ } )
39954043 } )
39964044
39974045 describe ( "Subtask Rate Limiting" , ( ) => {
0 commit comments