fix: unify mention gating across providers

This commit is contained in:
Peter Steinberger
2026-01-06 01:32:17 +01:00
parent 48d52d13f1
commit 811ec8b78b
10 changed files with 253 additions and 51 deletions

View File

@@ -147,4 +147,59 @@ describe("monitorDiscordProvider tool results", () => {
expect(sendMock.mock.calls[0][1]).toBe("PFX tool update");
expect(sendMock.mock.calls[1][1]).toBe("PFX final reply");
});
it("accepts guild messages when mentionPatterns match", async () => {
config = {
messages: { responsePrefix: "PFX" },
discord: {
dm: { enabled: true },
guilds: { "*": { requireMention: true } },
},
routing: {
allowFrom: [],
groupChat: { mentionPatterns: ["\\bclawd\\b"] },
},
};
replyMock.mockResolvedValue({ text: "hi" });
const controller = new AbortController();
const run = monitorDiscordProvider({
token: "token",
abortSignal: controller.signal,
});
const discord = await import("discord.js");
const client = await waitForClient();
if (!client) throw new Error("Discord client not created");
client.emit(discord.Events.MessageCreate, {
id: "m2",
content: "clawd: hello",
author: { id: "u1", bot: false, username: "Ada", tag: "Ada#1" },
member: { displayName: "Ada" },
channelId: "c1",
channel: {
type: discord.ChannelType.GuildText,
name: "general",
isSendable: () => false,
},
guild: { id: "g1", name: "Guild" },
mentions: {
has: () => false,
everyone: false,
users: { size: 0 },
roles: { size: 0 },
},
attachments: { first: () => undefined },
type: discord.MessageType.Default,
createdTimestamp: Date.now(),
});
await flush();
controller.abort();
await run;
expect(replyMock).toHaveBeenCalledTimes(1);
expect(replyMock.mock.calls[0][0].WasMentioned).toBe(true);
});
});