@@ -602,6 +602,8 @@ describe("Cline", () => {
602602 task . presentAssistantMessageLocked = true
603603 expect ( readiness ( ) ) . toBe ( false )
604604 task . presentAssistantMessageLocked = false
605+ expect ( readiness ( ) ) . toBe ( false )
606+ task . currentStreamingContentIndex = task . assistantMessageContent . length
605607 task . assistantMessageContent [ 0 ] . partial = true
606608 expect ( readiness ( ) ) . toBe ( false )
607609 task . assistantMessageContent [ 0 ] . partial = false
@@ -611,6 +613,64 @@ describe("Cline", () => {
611613 expect ( readiness ( ) ) . toBe ( true )
612614 } )
613615
616+ it ( "requires an identifiable tool call and matches sanitized result IDs" , ( ) => {
617+ const task = new Task ( {
618+ provider : mockProvider ,
619+ apiConfiguration : mockApiConfig ,
620+ task : "tool turn identity test" ,
621+ startTask : false ,
622+ } )
623+ const readiness = ( ) => getTaskTestAccess ( task ) . hasCompleteToolResultsForCurrentTurn ( )
624+ const finishPresentation = ( ) => {
625+ task . currentStreamingContentIndex = task . assistantMessageContent . length
626+ }
627+ task . didCompleteReadingStream = true
628+
629+ task . assistantMessageContent = [ { type : "text" , content : "finished" , partial : false } ]
630+ finishPresentation ( )
631+ expect ( readiness ( ) ) . toBe ( false )
632+
633+ task . assistantMessageContent = [
634+ {
635+ type : "tool_use" ,
636+ name : "read_file" ,
637+ params : { } ,
638+ partial : false ,
639+ } ,
640+ ]
641+ finishPresentation ( )
642+ expect ( readiness ( ) ) . toBe ( false )
643+
644+ task . assistantMessageContent = [
645+ {
646+ type : "mcp_tool_use" ,
647+ id : "" ,
648+ name : "mcp_server_tool" ,
649+ serverName : "server" ,
650+ toolName : "tool" ,
651+ arguments : { } ,
652+ partial : false ,
653+ } ,
654+ ]
655+ finishPresentation ( )
656+ expect ( readiness ( ) ) . toBe ( false )
657+
658+ const mcpToolUse = task . assistantMessageContent [ 0 ]
659+ if ( mcpToolUse . type !== "mcp_tool_use" ) {
660+ throw new Error ( "Expected MCP tool use fixture" )
661+ }
662+ mcpToolUse . id = "functions.read_file:0"
663+ task . userMessageContent = [
664+ { type : "tool_result" , tool_use_id : "functions.read_file:0" , content : "finished" } ,
665+ ]
666+ expect ( readiness ( ) ) . toBe ( false )
667+
668+ task . userMessageContent = [
669+ { type : "tool_result" , tool_use_id : "functions_read_file_0" , content : "finished" } ,
670+ ]
671+ expect ( readiness ( ) ) . toBe ( true )
672+ } )
673+
614674 it ( "continues after a complete read_file result when the readiness flag update is lost" , async ( ) => {
615675 const task = new Task ( {
616676 provider : mockProvider ,
@@ -633,11 +693,13 @@ describe("Cline", () => {
633693 content : "File: README.md\nfinished" ,
634694 } )
635695 // Reproduce the persisted field symptom: the tool result exists and
636- // presentation is no longer running, but the one-shot readiness latch
637- // never flips, so the old loop waits forever before the next request.
696+ // presentation consumed the completed block, but the one-shot readiness
697+ // latch never flips, so the old loop waits forever before the next request.
698+ task . currentStreamingContentIndex = task . assistantMessageContent . length
638699 task . userMessageContentReady = false
639700 } )
640701
702+ let continuationUserContent : Anthropic . Messages . ContentBlockParam [ ] | undefined
641703 const attemptApiRequestSpy = vi
642704 . spyOn ( task , "attemptApiRequest" )
643705 . mockImplementationOnce ( ( ) =>
@@ -647,6 +709,11 @@ describe("Cline", () => {
647709 ] ) ,
648710 )
649711 . mockImplementationOnce ( ( ) => {
712+ const continuationMessage = task . apiConversationHistory . at ( - 1 )
713+ continuationUserContent =
714+ continuationMessage ?. role === "user" && Array . isArray ( continuationMessage . content )
715+ ? continuationMessage . content
716+ : undefined
650717 throw new Error ( "continuation request reached" )
651718 } )
652719
@@ -659,6 +726,15 @@ describe("Cline", () => {
659726 try {
660727 await task . recursivelyMakeClineRequests ( [ { type : "text" , text : "read a file, then continue" } ] )
661728 expect ( attemptApiRequestSpy ) . toHaveBeenCalledTimes ( 2 )
729+ expect ( continuationUserContent ) . toEqual (
730+ expect . arrayContaining ( [
731+ expect . objectContaining ( {
732+ type : "tool_result" ,
733+ tool_use_id : "call_read" ,
734+ content : "File: README.md\nfinished" ,
735+ } ) ,
736+ ] ) ,
737+ )
662738 } finally {
663739 vi . mocked ( pWaitFor ) . mockImplementation ( async ( ) => { } )
664740 }
0 commit comments