

























@@ -162,7 +162,9 @@ vi.mock("../auth-token.js", () => ({
162162validateAnthropicSetupToken: vi.fn(() => undefined),
163163}));
164164165-vi.mock("../../plugins/provider-auth-choice-helpers.js", () => {
165+vi.mock("../../plugins/provider-auth-choice-helpers.js", async (importOriginal) => {
166+const actual =
167+await importOriginal<typeof import("../../plugins/provider-auth-choice-helpers.js")>();
166168const normalize = (value: string | undefined) => value?.trim().toLowerCase() ?? "";
167169const isRecord = (value: unknown): value is Record<string, unknown> =>
168170Boolean(value && typeof value === "object" && !Array.isArray(value));
@@ -178,6 +180,7 @@ vi.mock("../../plugins/provider-auth-choice-helpers.js", () => {
178180};
179181180182return {
183+ ...actual,
181184resolveProviderMatch: vi.fn((providers: ProviderPlugin[], rawProvider?: string) => {
182185const requested = normalize(rawProvider);
183186return (
@@ -721,6 +724,60 @@ describe("modelsAuthLoginCommand", () => {
721724});
722725});
723726727+it("keeps an existing primary when login omits --set-default and the patch recommends another", async () => {
728+const runtime = createRuntime();
729+currentConfig = {
730+agents: {
731+defaults: {
732+model: { primary: "openai-codex/gpt-5.4", fallbacks: [] },
733+models: {
734+"openai-codex/gpt-5.4": {},
735+"anthropic/claude-sonnet-4-6": {},
736+},
737+},
738+},
739+};
740+runProviderAuth.mockResolvedValue({
741+profiles: [
742+{
743+profileId: "openai:default",
744+credential: { type: "api_key", provider: "openai", key: "sk-demo" },
745+},
746+],
747+configPatch: {
748+agents: {
749+defaults: {
750+model: { primary: "openai/gpt-5.5" },
751+models: { "openai/gpt-5.5": { alias: "GPT" } },
752+},
753+},
754+},
755+defaultModel: "openai/gpt-5.5",
756+});
757+mocks.resolvePluginProviders.mockReturnValue([
758+createProvider({
759+id: "openai",
760+label: "OpenAI",
761+run: runProviderAuth as ProviderPlugin["auth"][number]["run"],
762+}),
763+]);
764+765+await modelsAuthLoginCommand({ provider: "openai" }, runtime);
766+767+expect(lastUpdatedConfig?.agents?.defaults?.model).toEqual({
768+primary: "openai-codex/gpt-5.4",
769+fallbacks: [],
770+});
771+expect(lastUpdatedConfig?.agents?.defaults?.models).toEqual({
772+"openai-codex/gpt-5.4": {},
773+"anthropic/claude-sonnet-4-6": {},
774+"openai/gpt-5.5": { alias: "GPT" },
775+});
776+expect(runtime.log).toHaveBeenCalledWith(
777+"Default model available: openai/gpt-5.5 (use --set-default to apply)",
778+);
779+});
780+724781it("overwrites an existing primary when login uses --set-default", async () => {
725782const runtime = createRuntime();
726783currentConfig = {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。