fix(foundry): avoid stale setup metadata

This commit is contained in:
Vincent Koc
2026-06-10 23:00:38 +09:00
parent 2031603542
commit 9db8601235
2 changed files with 50 additions and 2 deletions

View File

@@ -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),

View File

@@ -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 }) => {