


























@@ -78,6 +78,22 @@ function makePluginRegistry(overrides: Partial<PluginRegistry> = {}): PluginRegi
7878} as unknown as PluginRegistry;
7979}
808081+function callArg<T>(mock: { mock: { calls: unknown[][] } }, index = 0): T {
82+const call = mock.mock.calls[index];
83+expect(call).toBeDefined();
84+return call?.[0] as T;
85+}
86+87+function expectExternalCatalogInstallCall(index = 0) {
88+const input = callArg<{
89+entry?: { id?: string; install?: { npmSpec?: string } };
90+autoConfirmSingleSource?: boolean;
91+}>(ensureChannelSetupPluginInstalled, index);
92+expect(input.entry?.id).toBe("external-chat");
93+expect(input.entry?.install?.npmSpec).toBe("@vendor/external-chat-plugin");
94+expect(input.autoConfirmSingleSource).toBe(true);
95+}
96+8197const resolveAgentWorkspaceDir = vi.hoisted(() =>
8298vi.fn((_cfg?: unknown, _agentId?: unknown) => "/tmp/openclaw-workspace"),
8399);
@@ -237,19 +253,19 @@ describe("setupChannels workspace shadow exclusion", () => {
237253} as never,
238254);
239255240-expect(listTrustedChannelPluginCatalogEntries).toHaveBeenCalledWith(
241-expect.objectContaining({
242-cfg: {},
243-workspaceDir: "/tmp/openclaw-workspace",
244-}),
245-);
246-expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledWith(
247-expect.objectContaining({
248-channel: "external-chat",
249-pluginId: "@vendor/external-chat-plugin",
250-workspaceDir: "/tmp/openclaw-workspace",
251-}),
256+const trustedInput = callArg<{ cfg?: unknown; workspaceDir?: string }>(
257+listTrustedChannelPluginCatalogEntries,
252258);
259+expect(trustedInput.cfg).toEqual({});
260+expect(trustedInput.workspaceDir).toBe("/tmp/openclaw-workspace");
261+const registryInput = callArg<{
262+channel?: string;
263+pluginId?: string;
264+workspaceDir?: string;
265+}>(loadChannelSetupPluginRegistrySnapshotForChannel);
266+expect(registryInput.channel).toBe("external-chat");
267+expect(registryInput.pluginId).toBe("@vendor/external-chat-plugin");
268+expect(registryInput.workspaceDir).toBe("/tmp/openclaw-workspace");
253269});
254270255271it("keeps trusted workspace overrides eligible during preload", async () => {
@@ -271,13 +287,14 @@ describe("setupChannels workspace shadow exclusion", () => {
271287} as never,
272288);
273289274-expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledWith(
275-expect.objectContaining({
276-channel: "external-chat",
277-pluginId: "trusted-external-chat-shadow",
278-workspaceDir: "/tmp/openclaw-workspace",
279-}),
280-);
290+const registryInput = callArg<{
291+channel?: string;
292+pluginId?: string;
293+workspaceDir?: string;
294+}>(loadChannelSetupPluginRegistrySnapshotForChannel);
295+expect(registryInput.channel).toBe("external-chat");
296+expect(registryInput.pluginId).toBe("trusted-external-chat-shadow");
297+expect(registryInput.workspaceDir).toBe("/tmp/openclaw-workspace");
281298});
282299283300it("defers status and setup-plugin loads until a channel is selected", async () => {
@@ -298,7 +315,7 @@ describe("setupChannels workspace shadow exclusion", () => {
298315},
299316);
300317301-expect(select).toHaveBeenCalledWith(expect.objectContaining({ message: "Select a channel" }));
318+expect(callArg<{ message?: string }>(select).message).toBe("Select a channel");
302319expect(collectChannelStatus).not.toHaveBeenCalled();
303320expect(listTrustedChannelPluginCatalogEntries).not.toHaveBeenCalled();
304321expect(listChannelSetupPlugins).not.toHaveBeenCalled();
@@ -334,11 +351,9 @@ describe("setupChannels workspace shadow exclusion", () => {
334351},
335352);
336353337-expect(resolveChannelSetupEntries).toHaveBeenCalledWith(
338-expect.objectContaining({
339-installedPlugins: [activePlugin],
340-}),
341-);
354+expect(
355+callArg<{ installedPlugins?: unknown[] }>(resolveChannelSetupEntries).installedPlugins,
356+).toEqual([activePlugin]);
342357expect(listChannelSetupPlugins).not.toHaveBeenCalled();
343358expect(collectChannelStatus).not.toHaveBeenCalled();
344359});
@@ -398,11 +413,7 @@ describe("setupChannels workspace shadow exclusion", () => {
398413);
399414400415expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled();
401-expect(setupWizard.configure).toHaveBeenCalledWith(
402-expect.objectContaining({
403-cfg: {},
404-}),
405-);
416+expect(callArg<{ cfg?: unknown }>(setupWizard.configure).cfg).toEqual({});
406417expect(next).toEqual({
407418channels: {
408419"custom-chat": { token: "secret" },
@@ -472,30 +483,27 @@ describe("setupChannels workspace shadow exclusion", () => {
472483);
473484474485expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(2);
475-expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenNthCalledWith(
476-1,
477-expect.objectContaining({
478-channel: "external-chat",
479-pluginId: "external-chat",
480-workspaceDir: "/tmp/openclaw-workspace",
481-forceSetupOnlyChannelPlugins: true,
482-}),
483-);
484-expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenNthCalledWith(
485-2,
486-expect.objectContaining({
487-channel: "external-chat",
488-workspaceDir: "/tmp/openclaw-workspace",
489-forceSetupOnlyChannelPlugins: true,
490-}),
491-);
486+const firstRegistryInput = callArg<{
487+channel?: string;
488+pluginId?: string;
489+workspaceDir?: string;
490+forceSetupOnlyChannelPlugins?: boolean;
491+}>(loadChannelSetupPluginRegistrySnapshotForChannel, 0);
492+expect(firstRegistryInput.channel).toBe("external-chat");
493+expect(firstRegistryInput.pluginId).toBe("external-chat");
494+expect(firstRegistryInput.workspaceDir).toBe("/tmp/openclaw-workspace");
495+expect(firstRegistryInput.forceSetupOnlyChannelPlugins).toBe(true);
496+const secondRegistryInput = callArg<{
497+channel?: string;
498+workspaceDir?: string;
499+forceSetupOnlyChannelPlugins?: boolean;
500+}>(loadChannelSetupPluginRegistrySnapshotForChannel, 1);
501+expect(secondRegistryInput.channel).toBe("external-chat");
502+expect(secondRegistryInput.workspaceDir).toBe("/tmp/openclaw-workspace");
503+expect(secondRegistryInput.forceSetupOnlyChannelPlugins).toBe(true);
492504expect(getChannelSetupPlugin).not.toHaveBeenCalled();
493505expect(collectChannelStatus).not.toHaveBeenCalled();
494-expect(configure).toHaveBeenCalledWith(
495-expect.objectContaining({
496-cfg: {},
497-}),
498-);
506+expect(callArg<{ cfg?: unknown }>(configure).cfg).toEqual({});
499507expect(next).toEqual({
500508channels: {
501509"external-chat": { token: "secret" },
@@ -747,15 +755,7 @@ describe("setupChannels workspace shadow exclusion", () => {
747755);
748756749757expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledTimes(1);
750-expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith(
751-expect.objectContaining({
752-entry: expect.objectContaining({
753-id: "external-chat",
754-install: expect.objectContaining({ npmSpec: "@vendor/external-chat-plugin" }),
755-}),
756-autoConfirmSingleSource: true,
757-}),
758-);
758+expectExternalCatalogInstallCall();
759759expect(note).not.toHaveBeenCalledWith("external-chat plugin not available.", "Channel setup");
760760expect(configure).toHaveBeenCalledTimes(1);
761761},
@@ -909,20 +909,13 @@ describe("setupChannels workspace shadow exclusion", () => {
909909},
910910);
911911912-expect(getTrustedChannelPluginCatalogEntry).toHaveBeenCalledWith(
913-"external-chat",
914-expect.objectContaining({ workspaceDir: "/tmp/openclaw-workspace" }),
915-);
912+expect(getTrustedChannelPluginCatalogEntry.mock.calls[0]?.[0]).toBe("external-chat");
913+expect(
914+(getTrustedChannelPluginCatalogEntry.mock.calls[0]?.[1] as { workspaceDir?: string })
915+?.workspaceDir,
916+).toBe("/tmp/openclaw-workspace");
916917expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledTimes(1);
917-expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith(
918-expect.objectContaining({
919-entry: expect.objectContaining({
920-id: "external-chat",
921-install: expect.objectContaining({ npmSpec: "@vendor/external-chat-plugin" }),
922-}),
923-autoConfirmSingleSource: true,
924-}),
925-);
918+expectExternalCatalogInstallCall();
926919expect(note).not.toHaveBeenCalledWith("external-chat plugin not available.", "Channel setup");
927920expect(configure).toHaveBeenCalledTimes(1);
928921},
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。