diff --git a/src/commands/auth-choice.apply.ts b/src/commands/auth-choice.apply.ts index a330d364e55..1674b30ba92 100644 --- a/src/commands/auth-choice.apply.ts +++ b/src/commands/auth-choice.apply.ts @@ -42,6 +42,25 @@ async function normalizeTokenProviderChoice(params: { }); } +async function formatDeprecatedProviderChoiceError( + authChoice: AuthChoice | undefined, + params: Pick, +): Promise { + if (typeof authChoice !== "string") { + return undefined; + } + const { resolveManifestDeprecatedProviderAuthChoice } = + await import("../plugins/provider-auth-choices.js"); + const deprecatedChoice = resolveManifestDeprecatedProviderAuthChoice(authChoice, { + config: params.config, + env: params.env, + }); + if (!deprecatedChoice) { + return undefined; + } + return `Auth choice "${authChoice}" is no longer supported. Use "${deprecatedChoice.choiceId}" instead.`; +} + export async function applyAuthChoice( params: ApplyAuthChoiceParams, ): Promise { @@ -63,6 +82,17 @@ export async function applyAuthChoice( return result; } + const deprecatedProviderChoiceError = await formatDeprecatedProviderChoiceError( + normalizedParams.authChoice, + { + config: normalizedParams.config, + env: normalizedParams.env, + }, + ); + if (deprecatedProviderChoiceError) { + throw new Error(deprecatedProviderChoiceError); + } + if (normalizedParams.authChoice === "token" || normalizedParams.authChoice === "setup-token") { throw new Error( [ diff --git a/src/commands/auth-choice.test.ts b/src/commands/auth-choice.test.ts index d2fce6de550..f8305b5ffce 100644 --- a/src/commands/auth-choice.test.ts +++ b/src/commands/auth-choice.test.ts @@ -691,6 +691,20 @@ describe("applyAuthChoice", () => { ); }); + it("fails fast when a removed provider auth choice is passed to the interactive flow", async () => { + await expect( + applyAuthChoice({ + authChoice: "openai-codex-import", + config: {}, + prompter: createPrompter({}), + runtime: createExitThrowingRuntime(), + setDefaultModel: true, + }), + ).rejects.toThrow( + 'Auth choice "openai-codex-import" is no longer supported. Use "openai-codex" instead.', + ); + }); + it("prompts and writes provider API key profiles for common providers", async () => { const scenarios: Array<{ authChoice: "huggingface-api-key";