fix(mentions): check mentionPatterns even when explicit mention is available
This commit is contained in:
parent
fcc53bcf1b
commit
22b59d24ce
@ -4,7 +4,7 @@ import { matchesMentionWithExplicit } from "./mentions.js";
|
|||||||
describe("matchesMentionWithExplicit", () => {
|
describe("matchesMentionWithExplicit", () => {
|
||||||
const mentionRegexes = [/\bclawd\b/i];
|
const mentionRegexes = [/\bclawd\b/i];
|
||||||
|
|
||||||
it("prefers explicit mentions when other mentions are present", () => {
|
it("checks mentionPatterns even when explicit mention is available", () => {
|
||||||
const result = matchesMentionWithExplicit({
|
const result = matchesMentionWithExplicit({
|
||||||
text: "@clawd hello",
|
text: "@clawd hello",
|
||||||
mentionRegexes,
|
mentionRegexes,
|
||||||
@ -14,6 +14,19 @@ describe("matchesMentionWithExplicit", () => {
|
|||||||
canResolveExplicit: true,
|
canResolveExplicit: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when explicit is false and no regex match", () => {
|
||||||
|
const result = matchesMentionWithExplicit({
|
||||||
|
text: "<@999999> hello",
|
||||||
|
mentionRegexes,
|
||||||
|
explicit: {
|
||||||
|
hasAnyMention: true,
|
||||||
|
isExplicitlyMentioned: false,
|
||||||
|
canResolveExplicit: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,9 @@ export function matchesMentionWithExplicit(params: {
|
|||||||
const explicit = params.explicit?.isExplicitlyMentioned === true;
|
const explicit = params.explicit?.isExplicitlyMentioned === true;
|
||||||
const explicitAvailable = params.explicit?.canResolveExplicit === true;
|
const explicitAvailable = params.explicit?.canResolveExplicit === true;
|
||||||
const hasAnyMention = params.explicit?.hasAnyMention === true;
|
const hasAnyMention = params.explicit?.hasAnyMention === true;
|
||||||
if (hasAnyMention && explicitAvailable) return explicit;
|
if (hasAnyMention && explicitAvailable) {
|
||||||
|
return explicit || params.mentionRegexes.some((re) => re.test(cleaned));
|
||||||
|
}
|
||||||
if (!cleaned) return explicit;
|
if (!cleaned) return explicit;
|
||||||
return explicit || params.mentionRegexes.some((re) => re.test(cleaned));
|
return explicit || params.mentionRegexes.some((re) => re.test(cleaned));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -135,7 +135,7 @@ describe("discord tool result dispatch", () => {
|
|||||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||||
}, 20_000);
|
}, 20_000);
|
||||||
|
|
||||||
it("skips guild messages when another user is explicitly mentioned", async () => {
|
it("accepts guild messages when mentionPatterns match even if another user is mentioned", async () => {
|
||||||
const { createDiscordMessageHandler } = await import("./monitor.js");
|
const { createDiscordMessageHandler } = await import("./monitor.js");
|
||||||
const cfg = {
|
const cfg = {
|
||||||
agents: {
|
agents: {
|
||||||
@ -211,8 +211,8 @@ describe("discord tool result dispatch", () => {
|
|||||||
client,
|
client,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(dispatchMock).not.toHaveBeenCalled();
|
expect(dispatchMock).toHaveBeenCalledTimes(1);
|
||||||
expect(sendMock).not.toHaveBeenCalled();
|
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||||
}, 20_000);
|
}, 20_000);
|
||||||
|
|
||||||
it("accepts guild reply-to-bot messages as implicit mentions", async () => {
|
it("accepts guild reply-to-bot messages as implicit mentions", async () => {
|
||||||
|
|||||||
@ -392,7 +392,7 @@ describe("monitorSlackProvider tool results", () => {
|
|||||||
expect(replyMock.mock.calls[0][0].WasMentioned).toBe(true);
|
expect(replyMock.mock.calls[0][0].WasMentioned).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips channel messages when another user is explicitly mentioned", async () => {
|
it("accepts channel messages when mentionPatterns match even if another user is mentioned", async () => {
|
||||||
slackTestState.config = {
|
slackTestState.config = {
|
||||||
messages: {
|
messages: {
|
||||||
responsePrefix: "PFX",
|
responsePrefix: "PFX",
|
||||||
@ -433,8 +433,8 @@ describe("monitorSlackProvider tool results", () => {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
await run;
|
await run;
|
||||||
|
|
||||||
expect(replyMock).not.toHaveBeenCalled();
|
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||||
expect(sendMock).not.toHaveBeenCalled();
|
expect(replyMock.mock.calls[0][0].WasMentioned).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("treats replies to bot threads as implicit mentions", async () => {
|
it("treats replies to bot threads as implicit mentions", async () => {
|
||||||
|
|||||||
@ -212,7 +212,7 @@ describe("createTelegramBot", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips group messages when another user is explicitly mentioned", async () => {
|
it("accepts group messages when mentionPatterns match even if another user is mentioned", async () => {
|
||||||
onSpy.mockReset();
|
onSpy.mockReset();
|
||||||
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
||||||
replySpy.mockReset();
|
replySpy.mockReset();
|
||||||
@ -249,7 +249,8 @@ describe("createTelegramBot", () => {
|
|||||||
getFile: async () => ({ download: async () => new Uint8Array() }),
|
getFile: async () => ({ download: async () => new Uint8Array() }),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(replySpy.mock.calls[0][0].WasMentioned).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps group envelope headers stable (sender identity is separate)", async () => {
|
it("keeps group envelope headers stable (sender identity is separate)", async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user