@@ -599,6 +599,57 @@ describe("Cline", () => {
599599 expect ( Object . keys ( cleanConversationHistory [ 0 ] ! ) ) . toEqual ( [ "role" , "content" ] )
600600 } )
601601
602+ it ( "uses task-local mode and apiConfiguration in request metadata when provider state diverges" , async ( ) => {
603+ const taskApiConfiguration = {
604+ ...mockApiConfig ,
605+ apiProvider : providerIdentifiers . gemini ,
606+ } as ProviderSettings
607+
608+ vi . spyOn ( mockProvider , "getState" ) . mockResolvedValue ( {
609+ mode : "ask" ,
610+ apiConfiguration : taskApiConfiguration ,
611+ autoApprovalEnabled : true ,
612+ requestDelaySeconds : 0 ,
613+ } )
614+
615+ const cline = new Task ( {
616+ provider : mockProvider ,
617+ apiConfiguration : taskApiConfiguration ,
618+ task : "test task" ,
619+ startTask : false ,
620+ } )
621+ await cline . getTaskMode ( )
622+ vi . spyOn ( getTaskTestAccess ( cline ) , "getSystemPrompt" ) . mockResolvedValue ( "mock system prompt" )
623+ vi . spyOn ( cline . api , "getModel" ) . mockReturnValue ( {
624+ id : requireDefined ( mockApiConfig . apiModelId ) ,
625+ info : { contextWindow : 200000 , maxTokens : 4096 } as ModelInfo ,
626+ } )
627+
628+ vi . spyOn ( mockProvider , "getState" ) . mockResolvedValue ( {
629+ mode : "code" ,
630+ apiConfiguration : {
631+ ...mockApiConfig ,
632+ apiProvider : providerIdentifiers . anthropic ,
633+ } ,
634+ autoApprovalEnabled : true ,
635+ requestDelaySeconds : 0 ,
636+ } )
637+
638+ const mockStream = ( async function * ( ) {
639+ yield { type : "text" , text : "response" } as ApiStreamChunk
640+ } ) ( )
641+ const createMessageSpy = vi . spyOn ( cline . api , "createMessage" ) . mockReturnValue ( mockStream )
642+ cline . apiConversationHistory = [
643+ { role : "user" , content : [ { type : "text" , text : "test message" } ] , ts : Date . now ( ) } ,
644+ ]
645+
646+ await cline . attemptApiRequest ( 0 ) . next ( )
647+
648+ const [ , , metadata ] = requireDefined ( createMessageSpy . mock . calls [ 0 ] )
649+ expect ( metadata ?. mode ) . toBe ( "ask" )
650+ expect ( metadata ?. allowedFunctionNames ) . toBeDefined ( )
651+ } )
652+
602653 it ( "should shape image blocks for API compatibility before request construction" , async ( ) => {
603654 const conversationHistory = [
604655 {
0 commit comments