test: cover explicit mention gating across channels

This commit is contained in:
Peter Steinberger
2026-01-24 11:09:20 +00:00
parent d905ca0e02
commit dbf139d14e
5 changed files with 266 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
import { describe, expect, it } from "vitest";
import type { WebInboundMsg } from "./types.js";
import { isBotMentionedFromTargets, resolveMentionTargets } from "./mentions.js";
const makeMsg = (overrides: Partial<WebInboundMsg>): WebInboundMsg =>
({
id: "m1",
from: "120363401234567890@g.us",
conversationId: "120363401234567890@g.us",
to: "15551234567@s.whatsapp.net",
accountId: "default",
body: "",
chatType: "group",
chatId: "120363401234567890@g.us",
sendComposing: async () => {},
reply: async () => {},
sendMedia: async () => {},
...overrides,
}) as WebInboundMsg;
describe("isBotMentionedFromTargets", () => {
const mentionCfg = { mentionRegexes: [/\bclawd\b/i] };
it("ignores regex matches when other mentions are present", () => {
const msg = makeMsg({
body: "@Clawd please help",
mentionedJids: ["19998887777@s.whatsapp.net"],
selfE164: "+15551234567",
selfJid: "15551234567@s.whatsapp.net",
});
const targets = resolveMentionTargets(msg);
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(false);
});
it("matches explicit self mentions", () => {
const msg = makeMsg({
body: "hey",
mentionedJids: ["15551234567@s.whatsapp.net"],
selfE164: "+15551234567",
selfJid: "15551234567@s.whatsapp.net",
});
const targets = resolveMentionTargets(msg);
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(true);
});
it("falls back to regex when no mentions are present", () => {
const msg = makeMsg({
body: "clawd can you help?",
selfE164: "+15551234567",
selfJid: "15551234567@s.whatsapp.net",
});
const targets = resolveMentionTargets(msg);
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(true);
});
});