diff --git a/src/flows/search-setup.test.ts b/src/flows/search-setup.test.ts index e1db5425569..8ff0a72f718 100644 --- a/src/flows/search-setup.test.ts +++ b/src/flows/search-setup.test.ts @@ -322,4 +322,53 @@ describe("runSearchSetupFlow", () => { spec: "@openclaw/brave-plugin", }); }); + + it("installs an external catalog search provider when web search stays disabled", async () => { + const select = vi.fn().mockResolvedValueOnce("brave"); + const text = vi.fn().mockResolvedValue("brave-disabled-key"); + const prompter = createWizardPrompter({ + select: select as never, + text: text as never, + }); + + const next = await runSearchSetupFlow( + { + tools: { + web: { + search: { + provider: "brave", + enabled: false, + }, + }, + }, + }, + createNonExitingRuntime(), + prompter, + ); + + expect(ensureOnboardingPluginInstalled).toHaveBeenCalledWith( + expect.objectContaining({ + entry: expect.objectContaining({ + pluginId: "brave", + label: "Brave", + install: expect.objectContaining({ + npmSpec: "@openclaw/brave-plugin", + }), + }), + autoConfirmSingleSource: true, + }), + ); + expect(next.tools?.web?.search).toMatchObject({ + provider: "brave", + enabled: false, + }); + expect(next.plugins?.entries?.brave?.config?.webSearch).toMatchObject({ + apiKey: "brave-disabled-key", + }); + expect(next.plugins?.entries?.brave?.enabled).toBeUndefined(); + expect(next.plugins?.installs?.brave).toMatchObject({ + source: "npm", + spec: "@openclaw/brave-plugin", + }); + }); }); diff --git a/src/flows/search-setup.ts b/src/flows/search-setup.ts index e95cea439bf..5f80c0b81a9 100644 --- a/src/flows/search-setup.ts +++ b/src/flows/search-setup.ts @@ -342,7 +342,7 @@ async function finalizeSearchProviderSetup(params: { prompter: WizardPrompter; opts?: SetupSearchOptions; }): Promise { - let next = preserveDisabledState(params.originalConfig, params.nextConfig); + let next = params.nextConfig; const installEntry = params.entry[SEARCH_INSTALL_CATALOG_ENTRY]; if (installEntry && next.tools?.web?.search?.enabled !== false) { const { ensureOnboardingPluginInstalled } = @@ -363,6 +363,7 @@ async function finalizeSearchProviderSetup(params: { } next = installed.cfg; } + next = preserveDisabledState(params.originalConfig, next); if (!params.entry.runSetup) { return next; }