
























@@ -27,6 +27,56 @@ function withActivatedPluginIdsForTest<T extends Record<string, unknown>>(
2727};
2828}
292930+function expectConfiguredChannelPluginIdsParams(expected: {
31+config: unknown;
32+workspaceDir?: string;
33+}) {
34+expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledTimes(1);
35+const params = mocks.resolveConfiguredChannelPluginIds.mock.calls[0]?.[0] as
36+| { config?: unknown; env?: NodeJS.ProcessEnv; workspaceDir?: string }
37+| undefined;
38+expect(params?.config).toBe(expected.config);
39+expect(params?.env).toBe(process.env);
40+expect(params?.workspaceDir).toBe(expected.workspaceDir);
41+}
42+43+function expectLoadOpenClawPluginsCall(
44+callIndex: number,
45+expected: {
46+config?: unknown;
47+activationSourceConfig?: unknown;
48+autoEnabledReasons?: unknown;
49+onlyPluginIds: string[];
50+throwOnLoadError: boolean;
51+workspaceDir?: string;
52+},
53+) {
54+const params = mocks.loadOpenClawPlugins.mock.calls[callIndex]?.[0] as
55+| {
56+config?: unknown;
57+activationSourceConfig?: unknown;
58+autoEnabledReasons?: unknown;
59+onlyPluginIds?: string[];
60+throwOnLoadError?: boolean;
61+workspaceDir?: string;
62+}
63+| undefined;
64+if ("config" in expected) {
65+expect(params?.config).toEqual(expected.config);
66+}
67+if ("activationSourceConfig" in expected) {
68+expect(params?.activationSourceConfig).toEqual(expected.activationSourceConfig);
69+}
70+if ("autoEnabledReasons" in expected) {
71+expect(params?.autoEnabledReasons).toEqual(expected.autoEnabledReasons);
72+}
73+expect(params?.onlyPluginIds).toEqual(expected.onlyPluginIds);
74+expect(params?.throwOnLoadError).toBe(expected.throwOnLoadError);
75+if ("workspaceDir" in expected) {
76+expect(params?.workspaceDir).toBe(expected.workspaceDir);
77+}
78+}
79+3080const mocks = vi.hoisted(() => ({
3181loadOpenClawPlugins: vi.fn<typeof import("../plugins/loader.js").loadOpenClawPlugins>(),
3282resolveCompatibleRuntimePluginRegistry:
@@ -193,25 +243,21 @@ describe("ensurePluginRegistryLoaded", () => {
193243194244ensurePluginRegistryLoaded({ scope: "configured-channels" });
195245196-expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledWith(
197-expect.objectContaining({
198-config: autoEnabledConfig,
199-env: process.env,
200-workspaceDir: "/tmp/workspace",
201-}),
202-);
203-expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
204-expect.objectContaining({
205-config: autoEnabledConfig,
206-activationSourceConfig: autoEnabledConfig,
207-autoEnabledReasons: {
208-"demo-chat": ["demo-chat configured"],
209-},
210-onlyPluginIds: ["demo-chat"],
211-throwOnLoadError: true,
212-workspaceDir: "/tmp/workspace",
213-}),
214-);
246+expectConfiguredChannelPluginIdsParams({
247+config: autoEnabledConfig,
248+workspaceDir: "/tmp/workspace",
249+});
250+expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
251+expectLoadOpenClawPluginsCall(0, {
252+config: autoEnabledConfig,
253+activationSourceConfig: autoEnabledConfig,
254+autoEnabledReasons: {
255+"demo-chat": ["demo-chat configured"],
256+},
257+onlyPluginIds: ["demo-chat"],
258+throwOnLoadError: true,
259+workspaceDir: "/tmp/workspace",
260+});
215261});
216262217263it("reloads when escalating from configured-channels to channels", () => {
@@ -236,20 +282,14 @@ describe("ensurePluginRegistryLoaded", () => {
236282ensurePluginRegistryLoaded({ scope: "channels" });
237283238284expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(2);
239-expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith(
240-1,
241-expect.objectContaining({
242-onlyPluginIds: ["demo-channel-a"],
243-throwOnLoadError: true,
244-}),
245-);
246-expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith(
247-2,
248-expect.objectContaining({
249-onlyPluginIds: ["demo-channel-a", "demo-channel-b"],
250-throwOnLoadError: true,
251-}),
252-);
285+expectLoadOpenClawPluginsCall(0, {
286+onlyPluginIds: ["demo-channel-a"],
287+throwOnLoadError: true,
288+});
289+expectLoadOpenClawPluginsCall(1, {
290+onlyPluginIds: ["demo-channel-a", "demo-channel-b"],
291+throwOnLoadError: true,
292+});
253293});
254294255295it("does not treat a pre-seeded partial registry as all scope", () => {
@@ -276,14 +316,12 @@ describe("ensurePluginRegistryLoaded", () => {
276316ensurePluginRegistryLoaded({ scope: "all" });
277317278318expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
279-expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
280-expect.objectContaining({
281- config,
282-onlyPluginIds: ["demo"],
283-throwOnLoadError: true,
284-workspaceDir: "/tmp/workspace",
285-}),
286-);
319+expectLoadOpenClawPluginsCall(0, {
320+ config,
321+onlyPluginIds: ["demo"],
322+throwOnLoadError: true,
323+workspaceDir: "/tmp/workspace",
324+});
287325});
288326289327it("does not treat a tools-only pre-seeded registry as channel scope", () => {
@@ -312,15 +350,13 @@ describe("ensurePluginRegistryLoaded", () => {
312350ensurePluginRegistryLoaded({ scope: "configured-channels" });
313351314352expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
315-expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
316-expect.objectContaining({
317-config: activatedConfig,
318-activationSourceConfig: activatedConfig,
319-onlyPluginIds: ["demo-channel-a"],
320-throwOnLoadError: true,
321-workspaceDir: "/tmp/workspace",
322-}),
323-);
353+expectLoadOpenClawPluginsCall(0, {
354+config: activatedConfig,
355+activationSourceConfig: activatedConfig,
356+onlyPluginIds: ["demo-channel-a"],
357+throwOnLoadError: true,
358+workspaceDir: "/tmp/workspace",
359+});
324360});
325361326362it("reloads when a pre-seeded channel registry is missing the configured channel plugin ids", () => {
@@ -353,14 +389,12 @@ describe("ensurePluginRegistryLoaded", () => {
353389ensurePluginRegistryLoaded({ scope: "configured-channels" });
354390355391expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
356-expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
357-expect.objectContaining({
358-config: activatedConfig,
359-activationSourceConfig: activatedConfig,
360-onlyPluginIds: ["demo-channel-a"],
361-throwOnLoadError: true,
362-workspaceDir: "/tmp/workspace",
363-}),
364-);
392+expectLoadOpenClawPluginsCall(0, {
393+config: activatedConfig,
394+activationSourceConfig: activatedConfig,
395+onlyPluginIds: ["demo-channel-a"],
396+throwOnLoadError: true,
397+workspaceDir: "/tmp/workspace",
398+});
365399});
366400});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。