@@ -877,6 +877,80 @@ describe("CLI attempt execution", () => {
877877 expect ( firstRunCliAgentArg ( ) . authProfileId ) . toBe ( "google:api-key" ) ;
878878 } ) ;
879879
880+ it ( "selects canonical Google API-key auth order for Google models routed through Gemini CLI" , async ( ) => {
881+ const sessionKey = "agent:main:direct:gemini-cli-google-api-key-order" ;
882+ const sessionEntry : SessionEntry = {
883+ sessionId : "openclaw-session-gemini-api-key-order" ,
884+ updatedAt : Date . now ( ) ,
885+ } ;
886+ const sessionStore : Record < string , SessionEntry > = { [ sessionKey ] : sessionEntry } ;
887+ await fs . writeFile ( storePath , JSON . stringify ( sessionStore , null , 2 ) , "utf-8" ) ;
888+ saveAuthProfileStore (
889+ {
890+ version : 1 ,
891+ profiles : {
892+ "google:api-key" : {
893+ type : "api_key" ,
894+ provider : "google" ,
895+ key : "gemini-api-key" ,
896+ } ,
897+ } ,
898+ } ,
899+ tmpDir ,
900+ { filterExternalAuthProfiles : false , syncExternalCli : false } ,
901+ ) ;
902+ runCliAgentMock . mockResolvedValueOnce ( makeCliResult ( "gemini cli api-key response" ) ) ;
903+
904+ await runAgentAttempt ( {
905+ providerOverride : "google" ,
906+ originalProvider : "google" ,
907+ modelOverride : "gemini-3.1-pro-preview" ,
908+ cfg : {
909+ auth : {
910+ order : {
911+ google : [ "google:api-key" ] ,
912+ } ,
913+ } ,
914+ agents : {
915+ defaults : {
916+ models : {
917+ "google/gemini-3.1-pro-preview" : {
918+ agentRuntime : { id : "google-gemini-cli" } ,
919+ } ,
920+ } ,
921+ } ,
922+ } ,
923+ } as OpenClawConfig ,
924+ sessionEntry,
925+ sessionId : sessionEntry . sessionId ,
926+ sessionKey,
927+ sessionAgentId : "main" ,
928+ sessionFile : path . join ( tmpDir , "session.jsonl" ) ,
929+ workspaceDir : tmpDir ,
930+ body : "continue" ,
931+ isFallbackRetry : false ,
932+ resolvedThinkLevel : "medium" ,
933+ timeoutMs : 1_000 ,
934+ runId : "run-gemini-cli-google-api-key-order" ,
935+ opts : { } as Parameters < typeof runAgentAttempt > [ 0 ] [ "opts" ] ,
936+ runContext : { } as Parameters < typeof runAgentAttempt > [ 0 ] [ "runContext" ] ,
937+ spawnedBy : undefined ,
938+ messageChannel : undefined ,
939+ skillsSnapshot : undefined ,
940+ resolvedVerboseLevel : undefined ,
941+ agentDir : tmpDir ,
942+ onAgentEvent : vi . fn ( ) ,
943+ authProfileProvider : "google" ,
944+ sessionStore,
945+ storePath,
946+ sessionHasHistory : false ,
947+ } ) ;
948+
949+ expect ( runCliAgentMock ) . toHaveBeenCalledTimes ( 1 ) ;
950+ expect ( firstRunCliAgentArg ( ) . provider ) . toBe ( "google-gemini-cli" ) ;
951+ expect ( firstRunCliAgentArg ( ) . authProfileId ) . toBe ( "google:api-key" ) ;
952+ } ) ;
953+
880954 it ( "persists CLI replies into the session transcript" , async ( ) => {
881955 const sessionKey = "agent:main:subagent:cli-transcript" ;
882956 const sessionFile = path . join ( tmpDir , "session-cli-transcript.jsonl" ) ;
0 commit comments