Fail fast for removed Codex import auth choice

This commit is contained in:
pashpashpash
2026-04-22 19:12:21 -07:00
parent 788fd14118
commit c71f07ba43
2 changed files with 44 additions and 0 deletions

View File

@@ -42,6 +42,25 @@ async function normalizeTokenProviderChoice(params: {
});
}
async function formatDeprecatedProviderChoiceError(
authChoice: AuthChoice | undefined,
params: Pick<ApplyAuthChoiceParams, "config" | "env">,
): Promise<string | undefined> {
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<ApplyAuthChoiceResult> {
@@ -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(
[

View File

@@ -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";