@@ -1353,9 +1353,21 @@ describe('createOpenAIAdapter — OIDC auth', () => {
13531353 expect ( probe . reason ) . toMatch ( / O I D C / i) ;
13541354 } ) ;
13551355
1356- it ( 'getModelsFetchConfig() returns null when OIDC is enabled (deferred to runtime)' , ( ) => {
1357- const adapter = createOpenAIAdapter ( { } , { oidcAuth : makeMockOidcManager ( { enabled : true } ) } ) ;
1358- expect ( adapter . getModelsFetchConfig ( ) ) . toBeNull ( ) ;
1356+ it ( 'getModelsFetchConfig() returns async config with Bearer token when OIDC is enabled' , async ( ) => {
1357+ const adapter = createOpenAIAdapter (
1358+ { OPENAI_API_TARGET : 'myaccount.openai.azure.com' , OPENAI_API_BASE_PATH : '/openai/deployments/gpt-4' } ,
1359+ { oidcAuth : makeMockOidcManager ( { token : 'az-token-abc' } ) }
1360+ ) ;
1361+ const config = await adapter . getModelsFetchConfig ( ) ;
1362+ expect ( config ) . not . toBeNull ( ) ;
1363+ expect ( config . cacheKey ) . toBe ( 'openai' ) ;
1364+ expect ( config . url ) . toBe ( 'https://myaccount.openai.azure.com/openai/deployments/gpt-4/models' ) ;
1365+ expect ( config . opts . headers . Authorization ) . toBe ( 'Bearer az-token-abc' ) ;
1366+ } ) ;
1367+
1368+ it ( 'getModelsFetchConfig() propagates OIDC token errors' , async ( ) => {
1369+ const adapter = createOpenAIAdapter ( { } , { oidcAuth : makeMockOidcManager ( { error : 'token expired' } ) } ) ;
1370+ await expect ( adapter . getModelsFetchConfig ( ) ) . rejects . toThrow ( 'token expired' ) ;
13591371 } ) ;
13601372
13611373 it ( 'getReflectionInfo().configured is true when OIDC is enabled' , ( ) => {
@@ -1949,6 +1961,34 @@ describe('fetchStartupModels', () => {
19491961 const reflect = reflectEndpoints ( ) ;
19501962 expect ( reflect . models_fetch_complete ) . toBe ( true ) ;
19511963 } ) ;
1964+
1965+ it ( 'adapter-based: supports async getModelsFetchConfig (e.g. OIDC)' , async ( ) => {
1966+ mockHttpsRequestWithBody ( 200 , '{"data":[{"id":"gpt-4o"},{"id":"gpt-4o-mini"}]}' ) ;
1967+
1968+ // Adapter with async getModelsFetchConfig simulating OIDC token acquisition
1969+ const oidcAdapter = {
1970+ name : 'openai-oidc' ,
1971+ getModelsFetchConfig : async ( ) => ( {
1972+ url : 'https://myaccount.openai.azure.com/openai/deployments/gpt-4/models' ,
1973+ opts : { method : 'GET' , headers : { 'Authorization' : 'Bearer az-oidc-token' } } ,
1974+ cacheKey : 'openai' ,
1975+ } ) ,
1976+ } ;
1977+
1978+ await fetchStartupModels ( [ oidcAdapter ] ) ;
1979+ expect ( cachedModels . openai ) . toEqual ( [ 'gpt-4o' , 'gpt-4o-mini' ] ) ;
1980+ } ) ;
1981+
1982+ it ( 'adapter-based: handles null from async getModelsFetchConfig gracefully' , async ( ) => {
1983+ const spy = jest . spyOn ( https , 'request' ) ;
1984+ const adapter = {
1985+ name : 'no-config' ,
1986+ getModelsFetchConfig : async ( ) => null ,
1987+ } ;
1988+ await fetchStartupModels ( [ adapter ] ) ;
1989+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1990+ expect ( cachedModels ) . toEqual ( { } ) ;
1991+ } ) ;
19521992} ) ;
19531993
19541994// ── reflectEndpoints ───────────────────────────────────────────────────────
0 commit comments