CLI: lazy-load auth choice provider fallback (#47495)

* CLI: lazy-load auth choice provider fallback

* CLI: cover lazy auth choice provider fallback
This commit is contained in:
Vincent Koc
2026-03-15 10:29:31 -07:00
committed by GitHub
parent d88da9f5f8
commit 756d9b5782
7 changed files with 16 additions and 14 deletions

View File

@@ -1,6 +1,4 @@
import type { OpenClawConfig } from "../config/config.js";
import { resolveProviderPluginChoice } from "../plugins/provider-wizard.js";
import { resolvePluginProviders } from "../plugins/providers.js";
import type { AuthChoice } from "./onboard-types.js";
const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
@@ -53,17 +51,21 @@ const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
vllm: "vllm",
};
export function resolvePreferredProviderForAuthChoice(params: {
export async function resolvePreferredProviderForAuthChoice(params: {
choice: AuthChoice;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
}): string | undefined {
}): Promise<string | undefined> {
const preferred = PREFERRED_PROVIDER_BY_AUTH_CHOICE[params.choice];
if (preferred) {
return preferred;
}
const [{ resolveProviderPluginChoice }, { resolvePluginProviders }] = await Promise.all([
import("../plugins/provider-wizard.js"),
import("../plugins/providers.js"),
]);
const providers = resolvePluginProviders({
config: params.config,
workspaceDir: params.workspaceDir,

View File

@@ -1352,7 +1352,7 @@ describe("applyAuthChoice", () => {
});
describe("resolvePreferredProviderForAuthChoice", () => {
it("maps known and unknown auth choices", () => {
it("maps known and unknown auth choices", async () => {
const scenarios = [
{ authChoice: "github-copilot" as const, expectedProvider: "github-copilot" },
{ authChoice: "qwen-portal" as const, expectedProvider: "qwen-portal" },
@@ -1361,9 +1361,9 @@ describe("resolvePreferredProviderForAuthChoice", () => {
{ authChoice: "unknown" as AuthChoice, expectedProvider: undefined },
] as const;
for (const scenario of scenarios) {
expect(resolvePreferredProviderForAuthChoice({ choice: scenario.authChoice })).toBe(
scenario.expectedProvider,
);
await expect(
resolvePreferredProviderForAuthChoice({ choice: scenario.authChoice }),
).resolves.toBe(scenario.expectedProvider);
}
});
});

View File

@@ -23,7 +23,7 @@ vi.mock("./auth-choice-prompt.js", () => ({
vi.mock("./auth-choice.js", () => ({
applyAuthChoice: mocks.applyAuthChoice,
resolvePreferredProviderForAuthChoice: vi.fn(() => undefined),
resolvePreferredProviderForAuthChoice: vi.fn(async () => undefined),
}));
vi.mock("./model-picker.js", async (importActual) => {

View File

@@ -110,7 +110,7 @@ export async function promptAuthConfig(
allowKeep: true,
ignoreAllowlist: true,
includeProviderPluginSetups: true,
preferredProvider: resolvePreferredProviderForAuthChoice({
preferredProvider: await resolvePreferredProviderForAuthChoice({
choice: authChoice,
config: next,
}),

View File

@@ -64,11 +64,11 @@ export async function applyNonInteractivePluginProviderChoice(params: {
: undefined;
const preferredProviderId =
prefixedProviderId ||
resolvePreferredProviderForAuthChoice({
(await resolvePreferredProviderForAuthChoice({
choice: params.authChoice,
config: params.nextConfig,
workspaceDir,
});
}));
const resolutionConfig = buildIsolatedProviderResolutionConfig(
params.nextConfig,
preferredProviderId,

View File

@@ -11,7 +11,7 @@ import type { WizardPrompter, WizardSelectParams } from "./prompts.js";
const ensureAuthProfileStore = vi.hoisted(() => vi.fn(() => ({ profiles: {} })));
const promptAuthChoiceGrouped = vi.hoisted(() => vi.fn(async () => "skip"));
const applyAuthChoice = vi.hoisted(() => vi.fn(async (args) => ({ config: args.config })));
const resolvePreferredProviderForAuthChoice = vi.hoisted(() => vi.fn(() => "openai"));
const resolvePreferredProviderForAuthChoice = vi.hoisted(() => vi.fn(async () => "openai"));
const warnIfModelConfigLooksOff = vi.hoisted(() => vi.fn(async () => {}));
const applyPrimaryModel = vi.hoisted(() => vi.fn((cfg) => cfg));
const promptDefaultModel = vi.hoisted(() => vi.fn(async () => ({ config: null, model: null })));

View File

@@ -464,7 +464,7 @@ export async function runOnboardingWizard(
allowKeep: true,
ignoreAllowlist: true,
includeProviderPluginSetups: true,
preferredProvider: resolvePreferredProviderForAuthChoice({
preferredProvider: await resolvePreferredProviderForAuthChoice({
choice: authChoice,
config: nextConfig,
workspaceDir,