Skip to content

Commit dd08097

Browse files
committed
fix(onboard): set codex primary when auth-choice is openai-codex
When onboarding explicitly chooses openai-codex, apply the codex primary model directly instead of using the conservative helper that only rewrites openai/* or empty defaults. This avoids silent intent mismatch where auth profile is codex but primary remains anthropic. Also add regression test covering anthropic->openai-codex switch when setDefaultModel=true.
1 parent 6593a57 commit dd08097

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

src/commands/auth-choice.apply.openai.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
2+
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
13
import { normalizeApiKeyInput, validateApiKeyInput } from "./auth-choice.api-key.js";
24
import {
35
createAuthChoiceAgentModelNoter,
46
ensureApiKeyFromOptionEnvOrPrompt,
57
normalizeSecretInputModeInput,
68
} from "./auth-choice.apply-helpers.js";
7-
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
89
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
10+
import { applyPrimaryModel } from "./model-picker.js";
911
import { isRemoteEnvironment } from "./oauth-env.js";
1012
import { applyAuthProfileConfig, setOpenaiApiKey, writeOAuthCredentials } from "./onboard-auth.js";
1113
import { openUrl } from "./onboard-helpers.js";
12-
import {
13-
applyOpenAICodexModelDefault,
14-
OPENAI_CODEX_DEFAULT_MODEL,
15-
} from "./openai-codex-model-default.js";
14+
import { OPENAI_CODEX_DEFAULT_MODEL } from "./openai-codex-model-default.js";
1615
import { loginOpenAICodexOAuth } from "./openai-codex-oauth.js";
1716
import {
1817
applyOpenAIConfig,
@@ -103,9 +102,10 @@ export async function applyAuthChoiceOpenAI(
103102
mode: "oauth",
104103
});
105104
if (params.setDefaultModel) {
106-
const applied = applyOpenAICodexModelDefault(nextConfig);
107-
nextConfig = applied.next;
108-
if (applied.changed) {
105+
const previousPrimary = resolveAgentModelPrimaryValue(nextConfig.agents?.defaults?.model);
106+
nextConfig = applyPrimaryModel(nextConfig, OPENAI_CODEX_DEFAULT_MODEL);
107+
const nextPrimary = resolveAgentModelPrimaryValue(nextConfig.agents?.defaults?.model);
108+
if (nextPrimary !== previousPrimary) {
109109
await params.prompter.note(
110110
`Default model set to ${OPENAI_CODEX_DEFAULT_MODEL}`,
111111
"Model configured",

src/commands/auth-choice.test.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import fs from "node:fs/promises";
21
import type { OAuthCredentials } from "@mariozechner/pi-ai";
2+
import fs from "node:fs/promises";
33
import { afterEach, describe, expect, it, vi } from "vitest";
4-
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
54
import type { WizardPrompter } from "../wizard/prompts.js";
5+
import type { AuthChoice } from "./onboard-types.js";
6+
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
67
import { applyAuthChoice, resolvePreferredProviderForAuthChoice } from "./auth-choice.js";
78
import { GOOGLE_GEMINI_DEFAULT_MODEL } from "./google-gemini-model-default.js";
89
import {
910
MINIMAX_CN_API_BASE_URL,
1011
ZAI_CODING_CN_BASE_URL,
1112
ZAI_CODING_GLOBAL_BASE_URL,
1213
} from "./onboard-auth.js";
13-
import type { AuthChoice } from "./onboard-types.js";
1414
import {
1515
authProfilePathForAgent,
1616
createAuthTestLifecycle,
@@ -189,6 +189,40 @@ describe("applyAuthChoice", () => {
189189
});
190190
});
191191

192+
it("sets openai-codex as primary model when onboarding chooses openai-codex", async () => {
193+
await setupTempState();
194+
195+
loginOpenAICodexOAuth.mockResolvedValueOnce({
196+
197+
refresh: "refresh-token",
198+
access: "access-token",
199+
expires: Date.now() + 60_000,
200+
});
201+
202+
const prompter = createPrompter({});
203+
const runtime = createExitThrowingRuntime();
204+
205+
const result = await applyAuthChoice({
206+
authChoice: "openai-codex",
207+
config: {
208+
agents: {
209+
defaults: {
210+
model: {
211+
primary: "anthropic/claude-sonnet-4-6",
212+
},
213+
},
214+
},
215+
},
216+
prompter,
217+
runtime,
218+
setDefaultModel: true,
219+
});
220+
221+
expect(resolveAgentModelPrimaryValue(result.config.agents?.defaults?.model)).toBe(
222+
"openai-codex/gpt-5.3-codex",
223+
);
224+
});
225+
192226
it("prompts and writes provider API key for common providers", async () => {
193227
const scenarios: Array<{
194228
authChoice:

0 commit comments

Comments
 (0)