From 93ad783c1bee8f416e53ceaeca1186ce1b56957a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 09:34:35 +0000 Subject: [PATCH] test: remove redundant slash channel-policy integration case --- src/slack/monitor/slash.test.ts | 120 -------------------------------- 1 file changed, 120 deletions(-) diff --git a/src/slack/monitor/slash.test.ts b/src/slack/monitor/slash.test.ts index f394208376..2f9e9c69cf 100644 --- a/src/slack/monitor/slash.test.ts +++ b/src/slack/monitor/slash.test.ts @@ -188,123 +188,3 @@ describe("Slack native command argument menus", () => { }); }); }); - -function createPolicyHarness() { - const commands = new Map Promise>(); - const postEphemeral = vi.fn().mockResolvedValue({ ok: true }); - const app = { - client: { chat: { postEphemeral } }, - command: (name: unknown, handler: (args: unknown) => Promise) => { - commands.set(name, handler); - }, - }; - - const ctx = { - cfg: { commands: { native: false } }, - runtime: {}, - botToken: "bot-token", - botUserId: "bot", - teamId: "T1", - allowFrom: ["*"], - dmEnabled: true, - dmPolicy: "open", - groupDmEnabled: false, - groupDmChannels: [], - defaultRequireMention: true, - groupPolicy: "open", - useAccessGroups: true, - channelsConfig: undefined, - slashCommand: { - enabled: true, - name: "openclaw", - ephemeral: true, - sessionPrefix: "slack:slash", - }, - textLimit: 4000, - app, - isChannelAllowed: () => true, - resolveChannelName: async () => ({ name: "unlisted", type: "channel" }), - resolveUserName: async () => ({ name: "Ada" }), - } as Record; - - const account = { accountId: "acct", config: { commands: { native: false } } } as unknown; - - return { commands, ctx, account, postEphemeral }; -} - -function resetPolicyHarness(harness: ReturnType) { - harness.ctx.allowFrom = ["*"]; - harness.ctx.groupPolicy = "open"; - harness.ctx.useAccessGroups = true; - harness.ctx.channelsConfig = undefined; - harness.ctx.resolveChannelName = async () => ({ name: "unlisted", type: "channel" }); -} - -async function runSlashHandler(params: { - commands: Map Promise>; - command: Partial<{ - user_id: string; - user_name: string; - channel_id: string; - channel_name: string; - text: string; - trigger_id: string; - }> & - Pick<{ channel_id: string; channel_name: string }, "channel_id" | "channel_name">; -}): Promise<{ respond: ReturnType; ack: ReturnType }> { - const handler = [...params.commands.values()][0]; - if (!handler) { - throw new Error("Missing slash handler"); - } - - const respond = vi.fn().mockResolvedValue(undefined); - const ack = vi.fn().mockResolvedValue(undefined); - - await handler({ - command: { - user_id: "U1", - user_name: "Ada", - text: "hello", - trigger_id: "t1", - ...params.command, - }, - ack, - respond, - }); - - return { respond, ack }; -} - -describe("slack slash commands channel policy", () => { - let harness: ReturnType; - - beforeAll(async () => { - harness = createPolicyHarness(); - await registerCommands(harness.ctx, harness.account); - }); - - beforeEach(() => { - harness.postEphemeral.mockClear(); - resetPolicyHarness(harness); - }); - - it("blocks unlisted channels when groupPolicy is allowlist", async () => { - harness.ctx.groupPolicy = "allowlist"; - harness.ctx.channelsConfig = { C_LISTED: { requireMention: true } }; - harness.ctx.resolveChannelName = async () => ({ name: "unlisted", type: "channel" }); - - const { respond } = await runSlashHandler({ - commands: harness.commands, - command: { - channel_id: "C_UNLISTED", - channel_name: "unlisted", - }, - }); - - expect(dispatchMock).not.toHaveBeenCalled(); - expect(respond).toHaveBeenCalledWith({ - text: "This channel is not allowed.", - response_type: "ephemeral", - }); - }); -});