@@ -241,7 +241,7 @@ describe("plugin.azure", () => { |
241 | 241 |
|
242 | 242 | test("keeps the existing API-key method and adds Entra ID", () => { |
243 | 243 | delete process.env.AZURE_RESOURCE_NAME |
244 | | - const hooks = createAzureAuthHooks(azureShell([])) |
| 244 | + const hooks = createAzureAuthHooks(azureShell([]), fetch, [], true) |
245 | 245 |
|
246 | 246 | expect(hooks.auth?.provider).toBe("azure") |
247 | 247 | expect(hooks.provider?.id).toBe("azure") |
@@ -272,10 +272,15 @@ describe("plugin.azure", () => { |
272 | 272 |
|
273 | 273 | test("lists Azure CLI resources and allows entering another resource", () => { |
274 | 274 | 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 | + ) |
279 | 284 |
|
280 | 285 | expect(oauthMethod(hooks).prompts).toEqual([ |
281 | 286 | { |
@@ -299,17 +304,25 @@ describe("plugin.azure", () => { |
299 | 304 | }) |
300 | 305 |
|
301 | 306 | 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 | + ) |
305 | 313 | const authorization = await oauthMethod(hooks).authorize({ resourceSelection: "selected-resource" }) |
306 | 314 | if (authorization.method !== "auto") throw new Error("Unexpected Azure authorization method") |
307 | 315 |
|
308 | 316 | expect(await authorization.callback()).toMatchObject({ type: "success", accountId: "selected-resource" }) |
309 | 317 | }) |
310 | 318 |
|
311 | 319 | 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 | + ) |
313 | 326 | const authorization = await oauthMethod(hooks).authorize({ |
314 | 327 | resourceSelection: "__manual__", |
315 | 328 | resourceName: "unlisted-resource", |
@@ -321,7 +334,7 @@ describe("plugin.azure", () => { |
321 | 334 |
|
322 | 335 | test("checks Azure CLI and stores the resource name", async () => { |
323 | 336 | const scopes: string[] = [] |
324 | | - const hooks = createAzureAuthHooks(azureShell(scopes)) |
| 337 | + const hooks = createAzureAuthHooks(azureShell(scopes), fetch, [], true) |
325 | 338 | const authorization = await oauthMethod(hooks).authorize({ resourceName: "test-resource" }) |
326 | 339 | if (authorization.method !== "auto") throw new Error("Unexpected Azure authorization method") |
327 | 340 |
|
@@ -335,18 +348,23 @@ describe("plugin.azure", () => { |
335 | 348 | }) |
336 | 349 |
|
337 | 350 | 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 | + ) |
342 | 360 | const authorization = await oauthMethod(hooks).authorize({ resourceName: "test-resource" }) |
343 | 361 | if (authorization.method !== "auto") throw new Error("Unexpected Azure authorization method") |
344 | 362 |
|
345 | 363 | expect(await authorization.callback()).toMatchObject({ type: "success", accountId: "test-resource" }) |
346 | 364 | }) |
347 | 365 |
|
348 | 366 | 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) |
350 | 368 | const authorization = await oauthMethod(hooks).authorize({ resourceName: "test-resource" }) |
351 | 369 | if (authorization.method !== "auto") throw new Error("Unexpected Azure authorization method") |
352 | 370 |
|
@@ -379,6 +397,9 @@ describe("plugin.azure", () => { |
379 | 397 | ], |
380 | 398 | commands, |
381 | 399 | ), |
| 400 | + fetch, |
| 401 | + [], |
| 402 | + true, |
382 | 403 | ) |
383 | 404 | const list = hooks.provider?.models |
384 | 405 | if (!list) throw new Error("Azure provider model hook is missing") |
@@ -410,6 +431,9 @@ describe("plugin.azure", () => { |
410 | 431 | [{ name: "gpt-production", properties: { model: { name: "gpt-5-mini" }, provisioningState: "Succeeded" } }], |
411 | 432 | commands, |
412 | 433 | ), |
| 434 | + fetch, |
| 435 | + [], |
| 436 | + true, |
413 | 437 | ) |
414 | 438 | const list = hooks.provider?.models |
415 | 439 | if (!list) throw new Error("Azure provider model hook is missing") |
@@ -433,6 +457,9 @@ describe("plugin.azure", () => { |
433 | 457 | ], |
434 | 458 | [], |
435 | 459 | ), |
| 460 | + fetch, |
| 461 | + [], |
| 462 | + true, |
436 | 463 | ) |
437 | 464 | const list = hooks.provider?.models |
438 | 465 | if (!list) throw new Error("Azure provider model hook is missing") |
@@ -446,19 +473,43 @@ describe("plugin.azure", () => { |
446 | 473 | }) |
447 | 474 |
|
448 | 475 | 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 | + ) |
452 | 484 | const list = hooks.provider?.models |
453 | 485 | if (!list) throw new Error("Azure provider model hook is missing") |
454 | 486 |
|
455 | 487 | const catalog = models("gpt-5-mini") |
456 | 488 | expect(await list({ ...provider, models: catalog }, { auth: oauth })).toBe(catalog) |
457 | 489 | }) |
458 | 490 |
|
| 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 | + |
459 | 510 | test("does not change API-key loading", async () => { |
460 | 511 | const scopes: string[] = [] |
461 | | - const hooks = createAzureAuthHooks(azureShell(scopes)) |
| 512 | + const hooks = createAzureAuthHooks(azureShell(scopes), fetch, [], true) |
462 | 513 | const catalog = models("gpt-5-mini") |
463 | 514 | const list = hooks.provider?.models |
464 | 515 | if (!list) throw new Error("Azure provider model hook is missing") |
@@ -471,10 +522,15 @@ describe("plugin.azure", () => { |
471 | 522 | test("uses Azure CLI bearer tokens for Azure inference endpoints", async () => { |
472 | 523 | const scopes: string[] = [] |
473 | 524 | 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 | + ) |
478 | 534 | const options = await loader(hooks)(async () => oauth, provider) |
479 | 535 | const request = customFetch(options) |
480 | 536 |
|
|