perf(wizard): keep explicit skip auth path cold

This commit is contained in:
Vincent Koc
2026-04-13 15:12:21 +01:00
parent 9763d446d9
commit bb1b30d329
2 changed files with 63 additions and 43 deletions

View File

@@ -346,6 +346,7 @@ describe("runSetupWizard", () => {
);
expect(select).not.toHaveBeenCalled();
expect(ensureAuthProfileStore).not.toHaveBeenCalled();
expect(setupChannels).not.toHaveBeenCalled();
expect(setupSkills).not.toHaveBeenCalled();
expect(healthCommand).not.toHaveBeenCalled();

View File

@@ -483,28 +483,25 @@ export async function runSetupWizard(
const { applyLocalSetupWorkspaceConfig } = await import("../commands/onboard-config.js");
let nextConfig: OpenClawConfig = applyLocalSetupWorkspaceConfig(baseConfig, workspaceDir);
const { ensureAuthProfileStore } = await import("../agents/auth-profiles.runtime.js");
const { promptAuthChoiceGrouped } = await import("../commands/auth-choice-prompt.js");
const { promptCustomApiConfig } = await import("../commands/onboard-custom.js");
const { applyAuthChoice, resolvePreferredProviderForAuthChoice, warnIfModelConfigLooksOff } =
await import("../commands/auth-choice.js");
const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js");
const authStore = ensureAuthProfileStore(undefined, {
allowKeychainPrompt: false,
});
const authChoiceFromPrompt = opts.authChoice === undefined;
const authChoice =
opts.authChoice ??
(await promptAuthChoiceGrouped({
let authChoice = opts.authChoice;
if (authChoiceFromPrompt) {
const { ensureAuthProfileStore } = await import("../agents/auth-profiles.runtime.js");
const { promptAuthChoiceGrouped } = await import("../commands/auth-choice-prompt.js");
const authStore = ensureAuthProfileStore(undefined, {
allowKeychainPrompt: false,
});
authChoice = await promptAuthChoiceGrouped({
prompter,
store: authStore,
includeSkip: true,
config: nextConfig,
workspaceDir,
}));
});
}
if (authChoice === "custom-api-key") {
const { promptCustomApiConfig } = await import("../commands/onboard-custom.js");
const customResult = await promptCustomApiConfig({
prompter,
runtime,
@@ -512,7 +509,34 @@ export async function runSetupWizard(
secretInputMode: opts.secretInputMode,
});
nextConfig = customResult.config;
} else if (authChoice === "skip") {
// Explicit skip should stay cold: do not bootstrap auth/profile machinery
// or run model/auth checks when the caller already chose to skip setup.
if (authChoiceFromPrompt) {
const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js");
const modelSelection = await promptDefaultModel({
config: nextConfig,
prompter,
allowKeep: true,
ignoreAllowlist: true,
includeProviderPluginSetups: true,
workspaceDir,
runtime,
});
if (modelSelection.config) {
nextConfig = modelSelection.config;
}
if (modelSelection.model) {
nextConfig = applyPrimaryModel(nextConfig, modelSelection.model);
}
const { warnIfModelConfigLooksOff } = await import("../commands/auth-choice.js");
await warnIfModelConfigLooksOff(nextConfig, prompter);
}
} else {
const { applyAuthChoice, resolvePreferredProviderForAuthChoice, warnIfModelConfigLooksOff } =
await import("../commands/auth-choice.js");
const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js");
const authResult = await applyAuthChoice({
authChoice,
config: nextConfig,
@@ -525,44 +549,39 @@ export async function runSetupWizard(
},
});
nextConfig = authResult.config;
if (authResult.agentModelOverride) {
nextConfig = applyPrimaryModel(nextConfig, authResult.agentModelOverride);
}
}
const authChoiceModelSelectionPolicy =
authChoice === "custom-api-key"
? undefined
: await resolveAuthChoiceModelSelectionPolicy({
authChoice,
config: nextConfig,
workspaceDir,
resolvePreferredProviderForAuthChoice,
});
const shouldPromptModelSelection =
authChoice !== "custom-api-key" &&
(authChoiceFromPrompt || authChoiceModelSelectionPolicy?.promptWhenAuthChoiceProvided === true);
if (shouldPromptModelSelection) {
const modelSelection = await promptDefaultModel({
const authChoiceModelSelectionPolicy = await resolveAuthChoiceModelSelectionPolicy({
authChoice,
config: nextConfig,
prompter,
allowKeep: authChoiceModelSelectionPolicy?.allowKeepCurrent ?? true,
ignoreAllowlist: true,
includeProviderPluginSetups: true,
preferredProvider: authChoiceModelSelectionPolicy?.preferredProvider,
workspaceDir,
runtime,
resolvePreferredProviderForAuthChoice,
});
if (modelSelection.config) {
nextConfig = modelSelection.config;
const shouldPromptModelSelection =
authChoiceFromPrompt || authChoiceModelSelectionPolicy?.promptWhenAuthChoiceProvided;
if (shouldPromptModelSelection) {
const modelSelection = await promptDefaultModel({
config: nextConfig,
prompter,
allowKeep: authChoiceModelSelectionPolicy?.allowKeepCurrent ?? true,
ignoreAllowlist: true,
includeProviderPluginSetups: true,
preferredProvider: authChoiceModelSelectionPolicy?.preferredProvider,
workspaceDir,
runtime,
});
if (modelSelection.config) {
nextConfig = modelSelection.config;
}
if (modelSelection.model) {
nextConfig = applyPrimaryModel(nextConfig, modelSelection.model);
}
}
if (modelSelection.model) {
nextConfig = applyPrimaryModel(nextConfig, modelSelection.model);
}
}
await warnIfModelConfigLooksOff(nextConfig, prompter);
await warnIfModelConfigLooksOff(nextConfig, prompter);
}
const { configureGatewayForSetup } = await import("./setup.gateway-config.js");
const gateway = await configureGatewayForSetup({