From cfdcd730bff17e32bed18bf112a3dfea0a4fc37b Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 8 May 2026 16:11:00 +0100 Subject: [PATCH] test: dedupe discord allowlist guards --- extensions/discord/src/monitor.test.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/extensions/discord/src/monitor.test.ts b/extensions/discord/src/monitor.test.ts index 540c1bea257..fba3440c173 100644 --- a/extensions/discord/src/monitor.test.ts +++ b/extensions/discord/src/monitor.test.ts @@ -38,6 +38,18 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", async () => { const fakeGuild = (id: string, name: string) => ({ id, name }) as Guild; +function expectNormalizedAllowList( + entries: string[], + prefixes: string[], +): NonNullable> { + const allow = normalizeDiscordAllowList(entries, prefixes); + expect(allow).not.toBeNull(); + if (!allow) { + throw new Error("Expected allow list to be normalized"); + } + return allow; +} + const makeEntries = ( entries: Record>, ): Record => { @@ -226,14 +238,10 @@ describe("discord allowlist helpers", () => { }); it("matches ids by default and names only when enabled", () => { - const allow = normalizeDiscordAllowList( + const allow = expectNormalizedAllowList( ["123", "steipete", "Friends of OpenClaw"], ["discord:", "user:", "guild:", "channel:"], ); - expect(allow).not.toBeNull(); - if (!allow) { - throw new Error("Expected allow list to be normalized"); - } expect(allowListMatches(allow, { id: "123" })).toBe(true); expect(allowListMatches(allow, { name: "steipete" })).toBe(false); expect(allowListMatches(allow, { name: "friends-of-openclaw" })).toBe(false); @@ -245,11 +253,7 @@ describe("discord allowlist helpers", () => { }); it("matches pk-prefixed allowlist entries", () => { - const allow = normalizeDiscordAllowList(["pk:member-123"], ["discord:", "user:", "pk:"]); - expect(allow).not.toBeNull(); - if (!allow) { - throw new Error("Expected allow list to be normalized"); - } + const allow = expectNormalizedAllowList(["pk:member-123"], ["discord:", "user:", "pk:"]); expect(allowListMatches(allow, { id: "member-123" })).toBe(true); expect(allowListMatches(allow, { id: "member-999" })).toBe(false); });