fix: ignore discord wildcard audit keys (#33125) (thanks @thewilloftheshadow) (#33125)

This commit is contained in:
Shadow
2026-03-03 09:28:30 -06:00
committed by GitHub
parent c8b45a4c5c
commit 8e2e4b2ed5
3 changed files with 57 additions and 0 deletions

View File

@@ -53,4 +53,55 @@ describe("discord audit", () => {
expect(audit.channels[0]?.channelId).toBe("111");
expect(audit.channels[0]?.missing).toContain("SendMessages");
});
it("does not count '*' wildcard key as unresolved channel", async () => {
const { collectDiscordAuditChannelIds } = await import("./audit.js");
const cfg = {
channels: {
discord: {
enabled: true,
token: "t",
groupPolicy: "allowlist",
guilds: {
"123": {
channels: {
"111": { allow: true },
"*": { allow: true },
},
},
},
},
},
} as unknown as import("../config/config.js").OpenClawConfig;
const collected = collectDiscordAuditChannelIds({ cfg, accountId: "default" });
expect(collected.channelIds).toEqual(["111"]);
expect(collected.unresolvedChannels).toBe(0);
});
it("handles guild with only '*' wildcard and no numeric channel ids", async () => {
const { collectDiscordAuditChannelIds } = await import("./audit.js");
const cfg = {
channels: {
discord: {
enabled: true,
token: "t",
groupPolicy: "allowlist",
guilds: {
"123": {
channels: {
"*": { allow: true },
},
},
},
},
},
} as unknown as import("../config/config.js").OpenClawConfig;
const collected = collectDiscordAuditChannelIds({ cfg, accountId: "default" });
expect(collected.channelIds).toEqual([]);
expect(collected.unresolvedChannels).toBe(0);
});
});

View File

@@ -56,6 +56,11 @@ function listConfiguredGuildChannelKeys(
if (!channelId) {
continue;
}
// Skip wildcard keys (e.g. "*" meaning "all channels") — they are valid
// config but are not real channel IDs and should not be audited.
if (channelId === "*") {
continue;
}
if (!shouldAuditChannelConfig(value as DiscordGuildChannelConfig | undefined)) {
continue;
}