@@ -134,6 +134,34 @@ describe("resolveGitHubToken (#6116)", () => {
134134 expect ( capturedUrl ) . toBe ( "https://api.loopover.ai/v1/auth/github/token" ) ;
135135 } ) ;
136136
137+ it ( "falls back to the top-level/global config.apiUrl when the active profile has none (#8854)" , async ( ) => {
138+ dir = mkdtempSync ( join ( tmpdir ( ) , "loopover-miner-github-token-global-apiurl-" ) ) ;
139+ // apiUrl set globally (not per-profile); trailing slash proves normalization runs on the global branch too.
140+ writeConfig ( dir , { apiUrl : "https://global.example/" , profiles : { default : { session : { token : "session-token" } } } } ) ;
141+ let capturedUrl : string | undefined ;
142+ const fetchImpl = async ( url : string ) => {
143+ capturedUrl = url ;
144+ return Response . json ( { token : "live-token" } ) ;
145+ } ;
146+ await resolveGitHubToken ( configuredEnv ( dir ) , { fetchImpl } ) ;
147+ expect ( capturedUrl ) . toBe ( "https://global.example/v1/auth/github/token" ) ;
148+ } ) ;
149+
150+ it ( "prefers the active profile's apiUrl over the global config.apiUrl (#8854)" , async ( ) => {
151+ dir = mkdtempSync ( join ( tmpdir ( ) , "loopover-miner-github-token-profile-over-global-" ) ) ;
152+ writeConfig ( dir , {
153+ apiUrl : "https://global.example" ,
154+ profiles : { default : { apiUrl : "https://profile.example" , session : { token : "session-token" } } } ,
155+ } ) ;
156+ let capturedUrl : string | undefined ;
157+ const fetchImpl = async ( url : string ) => {
158+ capturedUrl = url ;
159+ return Response . json ( { token : "live-token" } ) ;
160+ } ;
161+ await resolveGitHubToken ( configuredEnv ( dir ) , { fetchImpl } ) ;
162+ expect ( capturedUrl ) . toBe ( "https://profile.example/v1/auth/github/token" ) ;
163+ } ) ;
164+
137165 it ( "treats a legacy default API URL stored in the profile as absent, falling through to the current default" , async ( ) => {
138166 dir = mkdtempSync ( join ( tmpdir ( ) , "loopover-miner-github-token-legacy-url-" ) ) ;
139167 writeConfig ( dir , { profiles : { default : { apiUrl : "https://gittensory-api.zeronode.workers.dev" , session : { token : "session-token" } } } } ) ;
0 commit comments