@@ -20,7 +20,7 @@ const authProfileMocks = vi.hoisted(() => ({
2020 > ( ( ) => {
2121 throw new Error ( "unexpected auth profile load" ) ;
2222 } ) ,
23- hasAnyAuthProfileStoreSource : vi . fn ( ( ) => false ) ,
23+ hasAnyAuthProfileStoreSource : vi . fn ( ( _agentDir ?: string ) => false ) ,
2424 resolveApiKeyForProfile : vi . fn ( ) ,
2525 resolveProfileUnusableUntilForDisplay : vi . fn ( ) ,
2626} ) ) ;
@@ -87,6 +87,32 @@ describe("noteAuthProfileHealth", () => {
8787 expect ( authProfileMocks . ensureAuthProfileStore ) . not . toHaveBeenCalled ( ) ;
8888 } ) ;
8989
90+ it ( "checks the configured default agent auth store source" , async ( ) => {
91+ const defaultDir = path . join ( tempDir , "custom-default" ) ;
92+ authProfileMocks . hasAnyAuthProfileStoreSource . mockImplementation (
93+ ( agentDir ) => agentDir === defaultDir ,
94+ ) ;
95+ authProfileMocks . ensureAuthProfileStore . mockReturnValue ( {
96+ version : 1 ,
97+ profiles : { } ,
98+ } ) ;
99+
100+ await noteAuthProfileHealth ( {
101+ cfg : {
102+ agents : {
103+ list : [ { id : "main" , default : true , agentDir : defaultDir } ] ,
104+ } ,
105+ } as OpenClawConfig ,
106+ prompter : { } as DoctorPrompter ,
107+ allowKeychainPrompt : false ,
108+ } ) ;
109+
110+ expect ( authProfileMocks . hasAnyAuthProfileStoreSource ) . toHaveBeenCalledWith ( defaultDir ) ;
111+ expect ( authProfileMocks . ensureAuthProfileStore ) . toHaveBeenCalledWith ( defaultDir , {
112+ allowKeychainPrompt : false ,
113+ } ) ;
114+ } ) ;
115+
90116 it ( "labels model auth diagnostics by agent when multiple agent auth stores are checked" , async ( ) => {
91117 const now = 1_700_000_000_000 ;
92118 vi . spyOn ( Date , "now" ) . mockReturnValue ( now ) ;
@@ -129,4 +155,41 @@ describe("noteAuthProfileHealth", () => {
129155 "Model auth (agent: coder)" ,
130156 ) ;
131157 } ) ;
158+
159+ it ( "passes the target agent dir when refreshing OAuth profiles" , async ( ) => {
160+ const now = 1_700_000_000_000 ;
161+ vi . spyOn ( Date , "now" ) . mockReturnValue ( now ) ;
162+ const coderDir = path . join ( tempDir , "coder-agent" ) ;
163+ writeAuthStore ( coderDir ) ;
164+ authProfileMocks . hasAnyAuthProfileStoreSource . mockReturnValue ( false ) ;
165+ authProfileMocks . ensureAuthProfileStore . mockImplementation ( ( agentDir ) => {
166+ if ( agentDir === coderDir ) {
167+ return expiredStore ( "openai-codex:coder" , now - 60_000 ) ;
168+ }
169+ return { version : 1 , profiles : { } } ;
170+ } ) ;
171+ authProfileMocks . resolveApiKeyForProfile . mockResolvedValue ( "token" ) ;
172+
173+ await noteAuthProfileHealth ( {
174+ cfg : {
175+ agents : {
176+ list : [
177+ { id : "main" , default : true , agentDir : path . join ( tempDir , "main-agent" ) } ,
178+ { id : "coder" , agentDir : coderDir } ,
179+ ] ,
180+ } ,
181+ } as OpenClawConfig ,
182+ prompter : {
183+ confirmAutoFix : vi . fn ( async ( ) => true ) ,
184+ } as unknown as DoctorPrompter ,
185+ allowKeychainPrompt : false ,
186+ } ) ;
187+
188+ expect ( authProfileMocks . resolveApiKeyForProfile ) . toHaveBeenCalledWith (
189+ expect . objectContaining ( {
190+ agentDir : coderDir ,
191+ profileId : "openai-codex:coder" ,
192+ } ) ,
193+ ) ;
194+ } ) ;
132195} ) ;
0 commit comments