From 48739ab9ec8cf1799e90bad844a1ff0e6029d27f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 04:20:38 +0100 Subject: [PATCH] test: tighten plugin registry assertions --- src/cli/plugin-registry.test.ts | 152 +++++++++++++++++++------------- 1 file changed, 93 insertions(+), 59 deletions(-) diff --git a/src/cli/plugin-registry.test.ts b/src/cli/plugin-registry.test.ts index c8ade757fbc..f05eb473541 100644 --- a/src/cli/plugin-registry.test.ts +++ b/src/cli/plugin-registry.test.ts @@ -27,6 +27,56 @@ function withActivatedPluginIdsForTest>( }; } +function expectConfiguredChannelPluginIdsParams(expected: { + config: unknown; + workspaceDir?: string; +}) { + expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledTimes(1); + const params = mocks.resolveConfiguredChannelPluginIds.mock.calls[0]?.[0] as + | { config?: unknown; env?: NodeJS.ProcessEnv; workspaceDir?: string } + | undefined; + expect(params?.config).toBe(expected.config); + expect(params?.env).toBe(process.env); + expect(params?.workspaceDir).toBe(expected.workspaceDir); +} + +function expectLoadOpenClawPluginsCall( + callIndex: number, + expected: { + config?: unknown; + activationSourceConfig?: unknown; + autoEnabledReasons?: unknown; + onlyPluginIds: string[]; + throwOnLoadError: boolean; + workspaceDir?: string; + }, +) { + const params = mocks.loadOpenClawPlugins.mock.calls[callIndex]?.[0] as + | { + config?: unknown; + activationSourceConfig?: unknown; + autoEnabledReasons?: unknown; + onlyPluginIds?: string[]; + throwOnLoadError?: boolean; + workspaceDir?: string; + } + | undefined; + if ("config" in expected) { + expect(params?.config).toEqual(expected.config); + } + if ("activationSourceConfig" in expected) { + expect(params?.activationSourceConfig).toEqual(expected.activationSourceConfig); + } + if ("autoEnabledReasons" in expected) { + expect(params?.autoEnabledReasons).toEqual(expected.autoEnabledReasons); + } + expect(params?.onlyPluginIds).toEqual(expected.onlyPluginIds); + expect(params?.throwOnLoadError).toBe(expected.throwOnLoadError); + if ("workspaceDir" in expected) { + expect(params?.workspaceDir).toBe(expected.workspaceDir); + } +} + const mocks = vi.hoisted(() => ({ loadOpenClawPlugins: vi.fn(), resolveCompatibleRuntimePluginRegistry: @@ -193,25 +243,21 @@ describe("ensurePluginRegistryLoaded", () => { ensurePluginRegistryLoaded({ scope: "configured-channels" }); - expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledWith( - expect.objectContaining({ - config: autoEnabledConfig, - env: process.env, - workspaceDir: "/tmp/workspace", - }), - ); - expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith( - expect.objectContaining({ - config: autoEnabledConfig, - activationSourceConfig: autoEnabledConfig, - autoEnabledReasons: { - "demo-chat": ["demo-chat configured"], - }, - onlyPluginIds: ["demo-chat"], - throwOnLoadError: true, - workspaceDir: "/tmp/workspace", - }), - ); + expectConfiguredChannelPluginIdsParams({ + config: autoEnabledConfig, + workspaceDir: "/tmp/workspace", + }); + expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1); + expectLoadOpenClawPluginsCall(0, { + config: autoEnabledConfig, + activationSourceConfig: autoEnabledConfig, + autoEnabledReasons: { + "demo-chat": ["demo-chat configured"], + }, + onlyPluginIds: ["demo-chat"], + throwOnLoadError: true, + workspaceDir: "/tmp/workspace", + }); }); it("reloads when escalating from configured-channels to channels", () => { @@ -236,20 +282,14 @@ describe("ensurePluginRegistryLoaded", () => { ensurePluginRegistryLoaded({ scope: "channels" }); expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(2); - expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith( - 1, - expect.objectContaining({ - onlyPluginIds: ["demo-channel-a"], - throwOnLoadError: true, - }), - ); - expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - onlyPluginIds: ["demo-channel-a", "demo-channel-b"], - throwOnLoadError: true, - }), - ); + expectLoadOpenClawPluginsCall(0, { + onlyPluginIds: ["demo-channel-a"], + throwOnLoadError: true, + }); + expectLoadOpenClawPluginsCall(1, { + onlyPluginIds: ["demo-channel-a", "demo-channel-b"], + throwOnLoadError: true, + }); }); it("does not treat a pre-seeded partial registry as all scope", () => { @@ -276,14 +316,12 @@ describe("ensurePluginRegistryLoaded", () => { ensurePluginRegistryLoaded({ scope: "all" }); expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1); - expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith( - expect.objectContaining({ - config, - onlyPluginIds: ["demo"], - throwOnLoadError: true, - workspaceDir: "/tmp/workspace", - }), - ); + expectLoadOpenClawPluginsCall(0, { + config, + onlyPluginIds: ["demo"], + throwOnLoadError: true, + workspaceDir: "/tmp/workspace", + }); }); it("does not treat a tools-only pre-seeded registry as channel scope", () => { @@ -312,15 +350,13 @@ describe("ensurePluginRegistryLoaded", () => { ensurePluginRegistryLoaded({ scope: "configured-channels" }); expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1); - expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith( - expect.objectContaining({ - config: activatedConfig, - activationSourceConfig: activatedConfig, - onlyPluginIds: ["demo-channel-a"], - throwOnLoadError: true, - workspaceDir: "/tmp/workspace", - }), - ); + expectLoadOpenClawPluginsCall(0, { + config: activatedConfig, + activationSourceConfig: activatedConfig, + onlyPluginIds: ["demo-channel-a"], + throwOnLoadError: true, + workspaceDir: "/tmp/workspace", + }); }); it("reloads when a pre-seeded channel registry is missing the configured channel plugin ids", () => { @@ -353,14 +389,12 @@ describe("ensurePluginRegistryLoaded", () => { ensurePluginRegistryLoaded({ scope: "configured-channels" }); expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1); - expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith( - expect.objectContaining({ - config: activatedConfig, - activationSourceConfig: activatedConfig, - onlyPluginIds: ["demo-channel-a"], - throwOnLoadError: true, - workspaceDir: "/tmp/workspace", - }), - ); + expectLoadOpenClawPluginsCall(0, { + config: activatedConfig, + activationSourceConfig: activatedConfig, + onlyPluginIds: ["demo-channel-a"], + throwOnLoadError: true, + workspaceDir: "/tmp/workspace", + }); }); });