From 5e3766b4d13f403c752c202c59dbca481e5efd50 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 23:22:38 +0100 Subject: [PATCH] test: tighten web search provider runtime assertions --- .../web-search-providers.runtime.test.ts | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/plugins/web-search-providers.runtime.test.ts b/src/plugins/web-search-providers.runtime.test.ts index 5b310d1f164..f7e2b201f55 100644 --- a/src/plugins/web-search-providers.runtime.test.ts +++ b/src/plugins/web-search-providers.runtime.test.ts @@ -207,13 +207,32 @@ function expectLoaderCallCount(count: number) { expect(loadOpenClawPluginsMock).toHaveBeenCalledTimes(count); } +function requireRecord(value: unknown): Record { + expect(value).toBeTruthy(); + expect(typeof value).toBe("object"); + expect(Array.isArray(value)).toBe(false); + return value as Record; +} + +function requireLastCallFirstArg( + mock: { mock: { calls: readonly (readonly unknown[])[] } }, + label: string, +): Record { + const call = mock.mock.calls.at(-1); + expect(call, `${label} should have been called`).toBeTruthy(); + return requireRecord(call?.[0]); +} + +function requirePluginsConfig(params: Record): Record { + const config = requireRecord(params.config); + return requireRecord(config.plugins); +} + function expectScopedWebSearchCandidates(pluginIds: readonly string[]) { expect(loadInstalledPluginManifestRegistryMock).toHaveBeenCalled(); - expect(loadOpenClawPluginsMock).toHaveBeenCalledWith( - expect.objectContaining({ - onlyPluginIds: [...pluginIds], - }), - ); + expect( + requireLastCallFirstArg(loadOpenClawPluginsMock, "loadOpenClawPlugins").onlyPluginIds, + ).toEqual([...pluginIds]); } function expectAutoEnabledWebSearchLoad(params: { @@ -224,15 +243,9 @@ function expectAutoEnabledWebSearchLoad(params: { config: params.rawConfig, env: createWebSearchEnv(), }); - expect(loadOpenClawPluginsMock).toHaveBeenCalledWith( - expect.objectContaining({ - config: expect.objectContaining({ - plugins: expect.objectContaining({ - allow: expect.arrayContaining([...params.expectedAllow]), - }), - }), - }), - ); + const loaderParams = requireLastCallFirstArg(loadOpenClawPluginsMock, "loadOpenClawPlugins"); + const plugins = requirePluginsConfig(loaderParams); + expect(plugins.allow).toEqual([...params.expectedAllow]); } function expectSnapshotLoaderCalls(params: { @@ -505,17 +518,12 @@ describe("resolvePluginWebSearchProviders", () => { expect(toRuntimeProviderKeys(providers)).toEqual(["brave:brave"]); expectScopedWebSearchCandidates(["brave"]); - expect(loadOpenClawPluginsMock).toHaveBeenCalledWith( - expect.objectContaining({ - config: expect.objectContaining({ - plugins: expect.objectContaining({ - allow: ["brave"], - bundledDiscovery: "allowlist", - entries: { brave: { enabled: true } }, - }), - }), - }), - ); + const loaderParams = requireLastCallFirstArg(loadOpenClawPluginsMock, "loadOpenClawPlugins"); + expect(requirePluginsConfig(loaderParams)).toEqual({ + allow: ["brave"], + bundledDiscovery: "allowlist", + entries: { brave: { enabled: true } }, + }); }); it("uses the active registry workspace for candidate discovery and snapshot loads when workspaceDir is omitted", () => { @@ -535,17 +543,14 @@ describe("resolvePluginWebSearchProviders", () => { env, }); - expect(loadInstalledPluginManifestRegistryMock).toHaveBeenCalledWith( - expect.objectContaining({ - workspaceDir: "/tmp/runtime-workspace", - }), - ); - expect(loadOpenClawPluginsMock).toHaveBeenCalledWith( - expect.objectContaining({ - workspaceDir: "/tmp/runtime-workspace", - onlyPluginIds: ["brave"], - }), + const manifestParams = requireLastCallFirstArg( + loadInstalledPluginManifestRegistryMock, + "loadPluginManifestRegistryForInstalledIndex", ); + expect(manifestParams.workspaceDir).toBe("/tmp/runtime-workspace"); + const loaderParams = requireLastCallFirstArg(loadOpenClawPluginsMock, "loadOpenClawPlugins"); + expect(loaderParams.workspaceDir).toBe("/tmp/runtime-workspace"); + expect(loaderParams.onlyPluginIds).toEqual(["brave"]); }); it("reuses a compatible active registry for snapshot resolution when config is provided", () => { const { env, rawConfig } = createActiveBraveRegistryFixture();