fix: keep onboarding setup paths cold

This commit is contained in:
Shakker
2026-04-26 10:06:26 +01:00
parent 26b203e573
commit 2f81c5f580
7 changed files with 251 additions and 22 deletions

View File

@@ -118,13 +118,18 @@ const readConfigFileSnapshot = vi.hoisted(() =>
legacyIssues: [] as Array<{ path: string; message: string }>,
})),
);
const createConfigIO = vi.hoisted(() =>
vi.fn(() => ({
readConfigFileSnapshot,
})),
);
const ensureSystemdUserLingerInteractive = vi.hoisted(() => vi.fn(async () => {}));
const isSystemdUserServiceAvailable = vi.hoisted(() => vi.fn(async () => true));
const ensureControlUiAssetsBuilt = vi.hoisted(() => vi.fn(async () => ({ ok: true })));
const runTui = vi.hoisted(() => vi.fn(async (_options: unknown) => {}));
const setupWizardShellCompletion = vi.hoisted(() => vi.fn(async () => {}));
const probeGatewayReachable = vi.hoisted(() => vi.fn(async () => ({ ok: true })));
const buildPluginCompatibilityNotices = vi.hoisted(() =>
const buildPluginCompatibilitySnapshotNotices = vi.hoisted(() =>
vi.fn((): PluginCompatibilityNotice[] => []),
);
const formatPluginCompatibilityNotice = vi.hoisted(() =>
@@ -185,8 +190,8 @@ vi.mock("../commands/onboard-hooks.js", () => ({
vi.mock("../config/config.js", () => ({
DEFAULT_GATEWAY_PORT: 18789,
createConfigIO,
resolveGatewayPort,
readConfigFileSnapshot,
writeConfigFile,
}));
@@ -228,7 +233,7 @@ vi.mock("../infra/control-ui-assets.js", () => ({
}));
vi.mock("../plugins/status.js", () => ({
buildPluginCompatibilityNotices,
buildPluginCompatibilitySnapshotNotices,
formatPluginCompatibilityNotice,
}));
@@ -405,6 +410,7 @@ describe("runSetupWizard", () => {
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
const prompter = buildWizardPrompter({ select, multiselect });
const runtime = createRuntime({ throwsOnExit: true });
createConfigIO.mockClear();
ensureAuthProfileStore.mockClear();
await runSetupWizard(
@@ -423,6 +429,7 @@ describe("runSetupWizard", () => {
prompter,
);
expect(createConfigIO).toHaveBeenCalledWith({ pluginValidation: "skip" });
expect(select).not.toHaveBeenCalled();
expect(ensureAuthProfileStore).not.toHaveBeenCalled();
expect(setupChannels).not.toHaveBeenCalled();
@@ -623,6 +630,7 @@ describe("runSetupWizard", () => {
it("prompts for a model during explicit interactive Ollama setup", async () => {
promptDefaultModel.mockClear();
warnIfModelConfigLooksOff.mockClear();
resolveProviderPluginChoice.mockReturnValue({
provider: {
id: "ollama",
@@ -671,8 +679,14 @@ describe("runSetupWizard", () => {
expect(promptDefaultModel).toHaveBeenCalledWith(
expect.objectContaining({
allowKeep: false,
browseCatalogOnDemand: true,
}),
);
expect(warnIfModelConfigLooksOff).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.objectContaining({ validateCatalog: false }),
);
});
it("re-prompts for auth when applyAuthChoice requests retry selection", async () => {
@@ -744,7 +758,7 @@ describe("runSetupWizard", () => {
});
it("shows plugin compatibility notices for an existing valid config", async () => {
buildPluginCompatibilityNotices.mockReturnValue([
buildPluginCompatibilitySnapshotNotices.mockReturnValue([
{
pluginId: "legacy-plugin",
code: "legacy-before-agent-start",

View File

@@ -7,12 +7,12 @@ import type {
OnboardOptions,
ResetScope,
} from "../commands/onboard-types.js";
import { readConfigFileSnapshot, resolveGatewayPort, writeConfigFile } from "../config/config.js";
import { createConfigIO, resolveGatewayPort, writeConfigFile } from "../config/config.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { normalizeSecretInputString } from "../config/types.secrets.js";
import { formatErrorMessage } from "../infra/errors.js";
import {
buildPluginCompatibilityNotices,
buildPluginCompatibilitySnapshotNotices,
formatPluginCompatibilityNotice,
} from "../plugins/status.js";
import type { RuntimeEnv } from "../runtime.js";
@@ -61,6 +61,10 @@ async function writeWizardConfigFile(config: OpenClawConfig): Promise<OpenClawCo
return committed.config;
}
async function readSetupConfigFileSnapshot() {
return await createConfigIO({ pluginValidation: "skip" }).readConfigFileSnapshot();
}
async function resolveAuthChoiceModelSelectionPolicy(params: {
authChoice: string;
config: OpenClawConfig;
@@ -146,7 +150,7 @@ export async function runSetupWizard(
await prompter.intro("OpenClaw setup");
await requireRiskAcknowledgement({ opts, prompter });
const snapshot = await readConfigFileSnapshot();
const snapshot = await readSetupConfigFileSnapshot();
let baseConfig: OpenClawConfig = snapshot.valid
? snapshot.exists
? (snapshot.sourceConfig ?? snapshot.config)
@@ -173,7 +177,7 @@ export async function runSetupWizard(
}
const compatibilityNotices = snapshot.valid
? buildPluginCompatibilityNotices({ config: baseConfig })
? buildPluginCompatibilitySnapshotNotices({ config: baseConfig })
: [];
if (compatibilityNotices.length > 0) {
await prompter.note(
@@ -570,7 +574,7 @@ export async function runSetupWizard(
}
const { warnIfModelConfigLooksOff } = await loadAuthChoiceModule();
await warnIfModelConfigLooksOff(nextConfig, prompter);
await warnIfModelConfigLooksOff(nextConfig, prompter, { validateCatalog: false });
}
break;
}
@@ -617,6 +621,7 @@ export async function runSetupWizard(
ignoreAllowlist: true,
includeProviderPluginSetups: true,
preferredProvider: authChoiceModelSelectionPolicy?.preferredProvider,
browseCatalogOnDemand: true,
workspaceDir,
runtime,
});
@@ -628,7 +633,7 @@ export async function runSetupWizard(
}
}
await warnIfModelConfigLooksOff(nextConfig, prompter);
await warnIfModelConfigLooksOff(nextConfig, prompter, { validateCatalog: false });
break;
}