@@ -241,7 +241,7 @@ describe("plugin.azure", () => {
241241
242242 test ( "keeps the existing API-key method and adds Entra ID" , ( ) => {
243243 delete process . env . AZURE_RESOURCE_NAME
244- const hooks = createAzureAuthHooks ( azureShell ( [ ] ) )
244+ const hooks = createAzureAuthHooks ( azureShell ( [ ] ) , fetch , [ ] , true )
245245
246246 expect ( hooks . auth ?. provider ) . toBe ( "azure" )
247247 expect ( hooks . provider ?. id ) . toBe ( "azure" )
@@ -272,10 +272,15 @@ describe("plugin.azure", () => {
272272
273273 test ( "lists Azure CLI resources and allows entering another resource" , ( ) => {
274274 delete process . env . AZURE_RESOURCE_NAME
275- const hooks = createAzureAuthHooks ( azureShell ( [ ] ) , fetch , [
276- { name : "first-resource" , resourceGroup : "first-group" } ,
277- { name : "second-resource" , resourceGroup : "second-group" } ,
278- ] )
275+ const hooks = createAzureAuthHooks (
276+ azureShell ( [ ] ) ,
277+ fetch ,
278+ [
279+ { name : "first-resource" , resourceGroup : "first-group" } ,
280+ { name : "second-resource" , resourceGroup : "second-group" } ,
281+ ] ,
282+ true ,
283+ )
279284
280285 expect ( oauthMethod ( hooks ) . prompts ) . toEqual ( [
281286 {
@@ -299,17 +304,25 @@ describe("plugin.azure", () => {
299304 } )
300305
301306 test ( "uses the selected Azure CLI resource" , async ( ) => {
302- const hooks = createAzureAuthHooks ( azureShell ( [ ] ) , fetch , [
303- { name : "selected-resource" , resourceGroup : "selected-group" } ,
304- ] )
307+ const hooks = createAzureAuthHooks (
308+ azureShell ( [ ] ) ,
309+ fetch ,
310+ [ { name : "selected-resource" , resourceGroup : "selected-group" } ] ,
311+ true ,
312+ )
305313 const authorization = await oauthMethod ( hooks ) . authorize ( { resourceSelection : "selected-resource" } )
306314 if ( authorization . method !== "auto" ) throw new Error ( "Unexpected Azure authorization method" )
307315
308316 expect ( await authorization . callback ( ) ) . toMatchObject ( { type : "success" , accountId : "selected-resource" } )
309317 } )
310318
311319 test ( "uses a manually entered Azure resource that was not listed" , async ( ) => {
312- const hooks = createAzureAuthHooks ( azureShell ( [ ] ) , fetch , [ { name : "listed-resource" , resourceGroup : "group" } ] )
320+ const hooks = createAzureAuthHooks (
321+ azureShell ( [ ] ) ,
322+ fetch ,
323+ [ { name : "listed-resource" , resourceGroup : "group" } ] ,
324+ true ,
325+ )
313326 const authorization = await oauthMethod ( hooks ) . authorize ( {
314327 resourceSelection : "__manual__" ,
315328 resourceName : "unlisted-resource" ,
@@ -321,7 +334,7 @@ describe("plugin.azure", () => {
321334
322335 test ( "checks Azure CLI and stores the resource name" , async ( ) => {
323336 const scopes : string [ ] = [ ]
324- const hooks = createAzureAuthHooks ( azureShell ( scopes ) )
337+ const hooks = createAzureAuthHooks ( azureShell ( scopes ) , fetch , [ ] , true )
325338 const authorization = await oauthMethod ( hooks ) . authorize ( { resourceName : "test-resource" } )
326339 if ( authorization . method !== "auto" ) throw new Error ( "Unexpected Azure authorization method" )
327340
@@ -335,18 +348,23 @@ describe("plugin.azure", () => {
335348 } )
336349
337350 test ( "supports Azure CLI versions that only provide expiresOn" , async ( ) => {
338- const hooks = createAzureAuthHooks ( async ( ) => ( {
339- accessToken : "legacy-token" ,
340- expiresOn : new Date ( Date . now ( ) + 60 * 60 * 1000 ) . toISOString ( ) ,
341- } ) )
351+ const hooks = createAzureAuthHooks (
352+ async ( ) => ( {
353+ accessToken : "legacy-token" ,
354+ expiresOn : new Date ( Date . now ( ) + 60 * 60 * 1000 ) . toISOString ( ) ,
355+ } ) ,
356+ fetch ,
357+ [ ] ,
358+ true ,
359+ )
342360 const authorization = await oauthMethod ( hooks ) . authorize ( { resourceName : "test-resource" } )
343361 if ( authorization . method !== "auto" ) throw new Error ( "Unexpected Azure authorization method" )
344362
345363 expect ( await authorization . callback ( ) ) . toMatchObject ( { type : "success" , accountId : "test-resource" } )
346364 } )
347365
348366 test ( "rejects Azure CLI tokens without a usable expiration" , async ( ) => {
349- const hooks = createAzureAuthHooks ( async ( ) => ( { accessToken : "invalid-token" } ) )
367+ const hooks = createAzureAuthHooks ( async ( ) => ( { accessToken : "invalid-token" } ) , fetch , [ ] , true )
350368 const authorization = await oauthMethod ( hooks ) . authorize ( { resourceName : "test-resource" } )
351369 if ( authorization . method !== "auto" ) throw new Error ( "Unexpected Azure authorization method" )
352370
@@ -379,6 +397,9 @@ describe("plugin.azure", () => {
379397 ] ,
380398 commands ,
381399 ) ,
400+ fetch ,
401+ [ ] ,
402+ true ,
382403 )
383404 const list = hooks . provider ?. models
384405 if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
@@ -410,6 +431,9 @@ describe("plugin.azure", () => {
410431 [ { name : "gpt-production" , properties : { model : { name : "gpt-5-mini" } , provisioningState : "Succeeded" } } ] ,
411432 commands ,
412433 ) ,
434+ fetch ,
435+ [ ] ,
436+ true ,
413437 )
414438 const list = hooks . provider ?. models
415439 if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
@@ -433,6 +457,9 @@ describe("plugin.azure", () => {
433457 ] ,
434458 [ ] ,
435459 ) ,
460+ fetch ,
461+ [ ] ,
462+ true ,
436463 )
437464 const list = hooks . provider ?. models
438465 if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
@@ -446,19 +473,43 @@ describe("plugin.azure", () => {
446473 } )
447474
448475 test ( "keeps configured models available when Azure discovery fails" , async ( ) => {
449- const hooks = createAzureAuthHooks ( async ( ) => {
450- throw new Error ( "Azure CLI failed" )
451- } )
476+ const hooks = createAzureAuthHooks (
477+ async ( ) => {
478+ throw new Error ( "Azure CLI failed" )
479+ } ,
480+ fetch ,
481+ [ ] ,
482+ true ,
483+ )
452484 const list = hooks . provider ?. models
453485 if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
454486
455487 const catalog = models ( "gpt-5-mini" )
456488 expect ( await list ( { ...provider , models : catalog } , { auth : oauth } ) ) . toBe ( catalog )
457489 } )
458490
491+ test ( "skips model discovery when the Azure CLI is unavailable" , async ( ) => {
492+ const calls : string [ ] [ ] = [ ]
493+ const hooks = createAzureAuthHooks (
494+ async ( args ) => {
495+ calls . push ( args )
496+ throw new Error ( "spawn az ENOENT" )
497+ } ,
498+ fetch ,
499+ [ ] ,
500+ false ,
501+ )
502+ const list = hooks . provider ?. models
503+ if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
504+
505+ const catalog = models ( "gpt-5-mini" )
506+ expect ( await list ( { ...provider , models : catalog } , { auth : oauth } ) ) . toBe ( catalog )
507+ expect ( calls ) . toEqual ( [ ] )
508+ } )
509+
459510 test ( "does not change API-key loading" , async ( ) => {
460511 const scopes : string [ ] = [ ]
461- const hooks = createAzureAuthHooks ( azureShell ( scopes ) )
512+ const hooks = createAzureAuthHooks ( azureShell ( scopes ) , fetch , [ ] , true )
462513 const catalog = models ( "gpt-5-mini" )
463514 const list = hooks . provider ?. models
464515 if ( ! list ) throw new Error ( "Azure provider model hook is missing" )
@@ -471,10 +522,15 @@ describe("plugin.azure", () => {
471522 test ( "uses Azure CLI bearer tokens for Azure inference endpoints" , async ( ) => {
472523 const scopes : string [ ] = [ ]
473524 const requests : Headers [ ] = [ ]
474- const hooks = createAzureAuthHooks ( azureShell ( scopes ) , async ( _input , init ) => {
475- requests . push ( new Headers ( init ?. headers ) )
476- return new Response ( null , { status : 200 } )
477- } )
525+ const hooks = createAzureAuthHooks (
526+ azureShell ( scopes ) ,
527+ async ( _input , init ) => {
528+ requests . push ( new Headers ( init ?. headers ) )
529+ return new Response ( null , { status : 200 } )
530+ } ,
531+ [ ] ,
532+ true ,
533+ )
478534 const options = await loader ( hooks ) ( async ( ) => oauth , provider )
479535 const request = customFetch ( options )
480536
0 commit comments