From 9db8601235cf38b623deac14c41fc3ccc427bce1 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 10 Jun 2026 23:00:38 +0900 Subject: [PATCH] fix(foundry): avoid stale setup metadata --- extensions/microsoft-foundry/auth.ts | 7 +++- extensions/microsoft-foundry/index.test.ts | 45 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/extensions/microsoft-foundry/auth.ts b/extensions/microsoft-foundry/auth.ts index a0af6dcb3131..cc25f674e50a 100644 --- a/extensions/microsoft-foundry/auth.ts +++ b/extensions/microsoft-foundry/auth.ts @@ -251,14 +251,17 @@ export const apiKeyAuthMethod: ProviderAuthMethod = { throw new Error("Missing Azure OpenAI API key."); } const selection = await promptApiKeyEndpointAndModel(ctx); + const existingModelNameHint = + existingMetadata?.modelId === selection.modelId + ? (existingMetadata.modelName ?? existingMetadata.modelId) + : undefined; return buildFoundryAuthResult({ profileId: `${PROVIDER_ID}:default`, apiKey: capturedSecretInput ?? "", ...(capturedMode ? { secretInputMode: capturedMode } : {}), endpoint: selection.endpoint, modelId: selection.modelId, - modelNameHint: - selection.modelNameHint ?? existingMetadata?.modelName ?? existingMetadata?.modelId, + modelNameHint: selection.modelNameHint ?? existingModelNameHint, api: selection.api, authMethod: "api-key", currentProviderProfileIds: listConfiguredFoundryProfileIds(ctx.config), diff --git a/extensions/microsoft-foundry/index.test.ts b/extensions/microsoft-foundry/index.test.ts index 4440eff7bad5..864a04b83660 100644 --- a/extensions/microsoft-foundry/index.test.ts +++ b/extensions/microsoft-foundry/index.test.ts @@ -963,6 +963,51 @@ describe("microsoft-foundry plugin", () => { }); }); + it("does not reuse stale API-key model metadata when selecting a different deployment", async () => { + const provider = registerProvider(); + ensureAuthProfileStoreMock.mockReturnValueOnce({ + profiles: { + "microsoft-foundry:default": { + type: "api_key", + provider: "microsoft-foundry", + metadata: { + authMethod: "api-key", + endpoint: "https://example.services.ai.azure.com", + modelId: "prod-fable", + modelName: "claude-fable-5", + api: "anthropic-messages", + }, + }, + }, + }); + const text = vi + .fn() + .mockResolvedValueOnce("https://example.services.ai.azure.com") + .mockResolvedValueOnce("prod-gpt"); + const select = vi + .fn() + .mockResolvedValueOnce("other-chat") + .mockResolvedValueOnce("openai-completions"); + const apiKeyAuth = provider.auth.find((method) => method.id === "api-key"); + + const result = await apiKeyAuth?.run({ + config: {}, + opts: { azureOpenaiApiKey: "test-api-key" }, + prompter: { text, select }, + agentDir: defaultFoundryAgentDir, + secretInputMode: "plaintext", + } as never); + + const model = result?.configPatch?.models?.providers?.["microsoft-foundry"]?.models[0]; + expect(model).toMatchObject({ + id: "prod-gpt", + name: "prod-gpt", + api: "openai-completions", + reasoning: false, + }); + expect(model?.thinkingLevelMap).toBeUndefined(); + }); + it("rejects Entra-only Claude Mythos deployments during API-key manual setup", async () => { const text = vi.fn( async (params: { message: string; validate?: (value: string) => string | undefined }) => {