From 4aa960bd45a3ac3a51ffd37755bc702b48cfc44b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 16:56:12 +0100 Subject: [PATCH] test: clear channel setup broad matchers --- src/flows/channel-setup.test.ts | 141 +++++++++++++++----------------- 1 file changed, 67 insertions(+), 74 deletions(-) diff --git a/src/flows/channel-setup.test.ts b/src/flows/channel-setup.test.ts index 98ed108cb63..9f13e677252 100644 --- a/src/flows/channel-setup.test.ts +++ b/src/flows/channel-setup.test.ts @@ -78,6 +78,22 @@ function makePluginRegistry(overrides: Partial = {}): PluginRegi } as unknown as PluginRegistry; } +function callArg(mock: { mock: { calls: unknown[][] } }, index = 0): T { + const call = mock.mock.calls[index]; + expect(call).toBeDefined(); + return call?.[0] as T; +} + +function expectExternalCatalogInstallCall(index = 0) { + const input = callArg<{ + entry?: { id?: string; install?: { npmSpec?: string } }; + autoConfirmSingleSource?: boolean; + }>(ensureChannelSetupPluginInstalled, index); + expect(input.entry?.id).toBe("external-chat"); + expect(input.entry?.install?.npmSpec).toBe("@vendor/external-chat-plugin"); + expect(input.autoConfirmSingleSource).toBe(true); +} + const resolveAgentWorkspaceDir = vi.hoisted(() => vi.fn((_cfg?: unknown, _agentId?: unknown) => "/tmp/openclaw-workspace"), ); @@ -237,19 +253,19 @@ describe("setupChannels workspace shadow exclusion", () => { } as never, ); - expect(listTrustedChannelPluginCatalogEntries).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - workspaceDir: "/tmp/openclaw-workspace", - }), - ); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "external-chat", - pluginId: "@vendor/external-chat-plugin", - workspaceDir: "/tmp/openclaw-workspace", - }), + const trustedInput = callArg<{ cfg?: unknown; workspaceDir?: string }>( + listTrustedChannelPluginCatalogEntries, ); + expect(trustedInput.cfg).toEqual({}); + expect(trustedInput.workspaceDir).toBe("/tmp/openclaw-workspace"); + const registryInput = callArg<{ + channel?: string; + pluginId?: string; + workspaceDir?: string; + }>(loadChannelSetupPluginRegistrySnapshotForChannel); + expect(registryInput.channel).toBe("external-chat"); + expect(registryInput.pluginId).toBe("@vendor/external-chat-plugin"); + expect(registryInput.workspaceDir).toBe("/tmp/openclaw-workspace"); }); it("keeps trusted workspace overrides eligible during preload", async () => { @@ -271,13 +287,14 @@ describe("setupChannels workspace shadow exclusion", () => { } as never, ); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "external-chat", - pluginId: "trusted-external-chat-shadow", - workspaceDir: "/tmp/openclaw-workspace", - }), - ); + const registryInput = callArg<{ + channel?: string; + pluginId?: string; + workspaceDir?: string; + }>(loadChannelSetupPluginRegistrySnapshotForChannel); + expect(registryInput.channel).toBe("external-chat"); + expect(registryInput.pluginId).toBe("trusted-external-chat-shadow"); + expect(registryInput.workspaceDir).toBe("/tmp/openclaw-workspace"); }); it("defers status and setup-plugin loads until a channel is selected", async () => { @@ -298,7 +315,7 @@ describe("setupChannels workspace shadow exclusion", () => { }, ); - expect(select).toHaveBeenCalledWith(expect.objectContaining({ message: "Select a channel" })); + expect(callArg<{ message?: string }>(select).message).toBe("Select a channel"); expect(collectChannelStatus).not.toHaveBeenCalled(); expect(listTrustedChannelPluginCatalogEntries).not.toHaveBeenCalled(); expect(listChannelSetupPlugins).not.toHaveBeenCalled(); @@ -334,11 +351,9 @@ describe("setupChannels workspace shadow exclusion", () => { }, ); - expect(resolveChannelSetupEntries).toHaveBeenCalledWith( - expect.objectContaining({ - installedPlugins: [activePlugin], - }), - ); + expect( + callArg<{ installedPlugins?: unknown[] }>(resolveChannelSetupEntries).installedPlugins, + ).toEqual([activePlugin]); expect(listChannelSetupPlugins).not.toHaveBeenCalled(); expect(collectChannelStatus).not.toHaveBeenCalled(); }); @@ -398,11 +413,7 @@ describe("setupChannels workspace shadow exclusion", () => { ); expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled(); - expect(setupWizard.configure).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - }), - ); + expect(callArg<{ cfg?: unknown }>(setupWizard.configure).cfg).toEqual({}); expect(next).toEqual({ channels: { "custom-chat": { token: "secret" }, @@ -472,30 +483,27 @@ describe("setupChannels workspace shadow exclusion", () => { ); expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(2); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenNthCalledWith( - 1, - expect.objectContaining({ - channel: "external-chat", - pluginId: "external-chat", - workspaceDir: "/tmp/openclaw-workspace", - forceSetupOnlyChannelPlugins: true, - }), - ); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - channel: "external-chat", - workspaceDir: "/tmp/openclaw-workspace", - forceSetupOnlyChannelPlugins: true, - }), - ); + const firstRegistryInput = callArg<{ + channel?: string; + pluginId?: string; + workspaceDir?: string; + forceSetupOnlyChannelPlugins?: boolean; + }>(loadChannelSetupPluginRegistrySnapshotForChannel, 0); + expect(firstRegistryInput.channel).toBe("external-chat"); + expect(firstRegistryInput.pluginId).toBe("external-chat"); + expect(firstRegistryInput.workspaceDir).toBe("/tmp/openclaw-workspace"); + expect(firstRegistryInput.forceSetupOnlyChannelPlugins).toBe(true); + const secondRegistryInput = callArg<{ + channel?: string; + workspaceDir?: string; + forceSetupOnlyChannelPlugins?: boolean; + }>(loadChannelSetupPluginRegistrySnapshotForChannel, 1); + expect(secondRegistryInput.channel).toBe("external-chat"); + expect(secondRegistryInput.workspaceDir).toBe("/tmp/openclaw-workspace"); + expect(secondRegistryInput.forceSetupOnlyChannelPlugins).toBe(true); expect(getChannelSetupPlugin).not.toHaveBeenCalled(); expect(collectChannelStatus).not.toHaveBeenCalled(); - expect(configure).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - }), - ); + expect(callArg<{ cfg?: unknown }>(configure).cfg).toEqual({}); expect(next).toEqual({ channels: { "external-chat": { token: "secret" }, @@ -747,15 +755,7 @@ describe("setupChannels workspace shadow exclusion", () => { ); expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledTimes(1); - expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith( - expect.objectContaining({ - entry: expect.objectContaining({ - id: "external-chat", - install: expect.objectContaining({ npmSpec: "@vendor/external-chat-plugin" }), - }), - autoConfirmSingleSource: true, - }), - ); + expectExternalCatalogInstallCall(); expect(note).not.toHaveBeenCalledWith("external-chat plugin not available.", "Channel setup"); expect(configure).toHaveBeenCalledTimes(1); }, @@ -909,20 +909,13 @@ describe("setupChannels workspace shadow exclusion", () => { }, ); - expect(getTrustedChannelPluginCatalogEntry).toHaveBeenCalledWith( - "external-chat", - expect.objectContaining({ workspaceDir: "/tmp/openclaw-workspace" }), - ); + expect(getTrustedChannelPluginCatalogEntry.mock.calls[0]?.[0]).toBe("external-chat"); + expect( + (getTrustedChannelPluginCatalogEntry.mock.calls[0]?.[1] as { workspaceDir?: string }) + ?.workspaceDir, + ).toBe("/tmp/openclaw-workspace"); expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledTimes(1); - expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith( - expect.objectContaining({ - entry: expect.objectContaining({ - id: "external-chat", - install: expect.objectContaining({ npmSpec: "@vendor/external-chat-plugin" }), - }), - autoConfirmSingleSource: true, - }), - ); + expectExternalCatalogInstallCall(); expect(note).not.toHaveBeenCalledWith("external-chat plugin not available.", "Channel setup"); expect(configure).toHaveBeenCalledTimes(1); },