Skip to content

Commit e39291d

Browse files
author
SidQin-cyber
committed
fix(discord): exclude '*' wildcard from unresolvedChannels count
The channel audit counted the '*' wildcard key as an unresolved channel, producing a false positive warning in doctor/channels-status even though '*' is a valid config meaning "allow all channels in this guild". Closes #32517 Made-with: Cursor
1 parent 4ffe15c commit e39291d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/discord/audit.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ describe("discord audit", () => {
3636
expect(collected.channelIds).toEqual(["111"]);
3737
expect(collected.unresolvedChannels).toBe(1);
3838

39+
const cfgWildcard = {
40+
channels: {
41+
discord: {
42+
enabled: true,
43+
token: "t",
44+
groupPolicy: "allowlist",
45+
guilds: {
46+
"123": {
47+
channels: {
48+
"*": { allow: true },
49+
"111": { allow: true },
50+
},
51+
},
52+
},
53+
},
54+
},
55+
} as unknown as import("../config/config.js").OpenClawConfig;
56+
57+
const wildcardResult = collectDiscordAuditChannelIds({
58+
cfg: cfgWildcard,
59+
accountId: "default",
60+
});
61+
expect(wildcardResult.channelIds).toEqual(["111"]);
62+
expect(wildcardResult.unresolvedChannels).toBe(0);
63+
3964
(fetchChannelPermissionsDiscord as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
4065
channelId: "111",
4166
permissions: ["ViewChannel"],
@@ -53,4 +78,29 @@ describe("discord audit", () => {
5378
expect(audit.channels[0]?.channelId).toBe("111");
5479
expect(audit.channels[0]?.missing).toContain("SendMessages");
5580
});
81+
82+
it("does not count '*' wildcard as unresolved (#32517)", async () => {
83+
const { collectDiscordAuditChannelIds } = await import("./audit.js");
84+
85+
const cfg = {
86+
channels: {
87+
discord: {
88+
enabled: true,
89+
token: "t",
90+
groupPolicy: "allowlist",
91+
guilds: {
92+
"999": {
93+
channels: {
94+
"*": { allow: true },
95+
},
96+
},
97+
},
98+
},
99+
},
100+
} as unknown as import("../config/config.js").OpenClawConfig;
101+
102+
const result = collectDiscordAuditChannelIds({ cfg, accountId: "default" });
103+
expect(result.channelIds).toEqual([]);
104+
expect(result.unresolvedChannels).toBe(0);
105+
});
56106
});

src/discord/audit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function collectDiscordAuditChannelIds(params: {
7575
});
7676
const keys = listConfiguredGuildChannelKeys(account.config.guilds);
7777
const channelIds = keys.filter((key) => /^\d+$/.test(key));
78-
const unresolvedChannels = keys.length - channelIds.length;
78+
const wildcardCount = keys.filter((key) => key === "*").length;
79+
const unresolvedChannels = Math.max(0, keys.length - channelIds.length - wildcardCount);
7980
return { channelIds, unresolvedChannels };
8081
}
8182

0 commit comments

Comments
 (0)