


























@@ -1,3 +1,4 @@
1+import type { DiscordAccountConfig } from "openclaw/plugin-sdk/config-types";
12import { createNonExitingRuntimeEnv } from "openclaw/plugin-sdk/plugin-test-runtime";
23import { beforeEach, describe, expect, it, vi } from "vitest";
34import * as resolveChannelsModule from "../resolve-channels.js";
@@ -44,6 +45,7 @@ describe("resolveDiscordAllowlistConfig", () => {
4445},
4546fetcher: vi.fn() as unknown as typeof fetch,
4647 runtime,
48+discordConfig: { dangerouslyAllowNameMatching: true } as DiscordAccountConfig,
4749});
48504951expect(result.allowFrom).toEqual(["111", "*"]);
@@ -76,6 +78,7 @@ describe("resolveDiscordAllowlistConfig", () => {
7678},
7779fetcher: vi.fn() as unknown as typeof fetch,
7880 runtime,
81+discordConfig: { dangerouslyAllowNameMatching: true } as DiscordAccountConfig,
7982});
80838184const logs = (runtime.log as ReturnType<typeof vi.fn>).mock.calls
@@ -135,6 +138,7 @@ describe("resolveDiscordAllowlistConfig", () => {
135138},
136139fetcher: vi.fn() as unknown as typeof fetch,
137140 runtime,
141+discordConfig: {} as DiscordAccountConfig,
138142});
139143140144const logs = (runtime.log as ReturnType<typeof vi.fn>).mock.calls
@@ -146,4 +150,68 @@ describe("resolveDiscordAllowlistConfig", () => {
146150"1456350064065904867/1456744319972282449 (guild:Friends of the Crustacean 🦞🤝; channel:maintainers)",
147151);
148152});
153+154+it("keeps user allowlist names unresolved unless name matching is enabled", async () => {
155+const runtime = createNonExitingRuntimeEnv();
156+const result = await resolveDiscordAllowlistConfig({
157+token: "token",
158+allowFrom: ["Alice", "111", "*"],
159+guildEntries: {
160+"*": {
161+users: ["Bob", "999"],
162+channels: {
163+"*": {
164+users: ["Carol", "888"],
165+},
166+},
167+},
168+},
169+fetcher: vi.fn() as unknown as typeof fetch,
170+ runtime,
171+discordConfig: {} as DiscordAccountConfig,
172+});
173+174+expect(result.allowFrom).toEqual(["Alice", "111", "*"]);
175+expect(result.guildEntries?.["*"]?.users).toEqual(["Bob", "999"]);
176+expect(result.guildEntries?.["*"]?.channels?.["*"]?.users).toEqual(["Carol", "888"]);
177+expect(resolveUsersModule.resolveDiscordUserAllowlist).not.toHaveBeenCalled();
178+});
179+180+it("still resolves guild and channel ids when name matching is disabled", async () => {
181+vi.spyOn(resolveChannelsModule, "resolveDiscordChannelAllowlist").mockResolvedValueOnce([
182+{
183+input: "ops/general",
184+resolved: true,
185+guildId: "145",
186+guildName: "Ops",
187+channelId: "246",
188+channelName: "general",
189+},
190+]);
191+const runtime = createNonExitingRuntimeEnv();
192+193+const result = await resolveDiscordAllowlistConfig({
194+token: "token",
195+allowFrom: ["Alice"],
196+guildEntries: {
197+ops: {
198+users: ["Bob"],
199+channels: {
200+general: {
201+users: ["Carol"],
202+},
203+},
204+},
205+},
206+fetcher: vi.fn() as unknown as typeof fetch,
207+ runtime,
208+discordConfig: {} as DiscordAccountConfig,
209+});
210+211+expect(result.allowFrom).toEqual(["Alice"]);
212+expect(result.guildEntries?.["145"]?.channels?.["246"]?.users).toEqual(["Carol"]);
213+expect(result.guildEntries?.ops?.users).toEqual(["Bob"]);
214+expect(resolveChannelsModule.resolveDiscordChannelAllowlist).toHaveBeenCalledTimes(1);
215+expect(resolveUsersModule.resolveDiscordUserAllowlist).not.toHaveBeenCalled();
216+});
149217});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。