fix: treat reply-to-bot as implicit mention across channels
This commit is contained in:
38
src/channels/mention-gating.test.ts
Normal file
38
src/channels/mention-gating.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveMentionGating } from "./mention-gating.js";
|
||||
|
||||
describe("resolveMentionGating", () => {
|
||||
it("combines explicit, implicit, and bypass mentions", () => {
|
||||
const res = resolveMentionGating({
|
||||
requireMention: true,
|
||||
canDetectMention: true,
|
||||
wasMentioned: false,
|
||||
implicitMention: true,
|
||||
shouldBypassMention: false,
|
||||
});
|
||||
expect(res.effectiveWasMentioned).toBe(true);
|
||||
expect(res.shouldSkip).toBe(false);
|
||||
});
|
||||
|
||||
it("skips when mention required and none detected", () => {
|
||||
const res = resolveMentionGating({
|
||||
requireMention: true,
|
||||
canDetectMention: true,
|
||||
wasMentioned: false,
|
||||
implicitMention: false,
|
||||
shouldBypassMention: false,
|
||||
});
|
||||
expect(res.effectiveWasMentioned).toBe(false);
|
||||
expect(res.shouldSkip).toBe(true);
|
||||
});
|
||||
|
||||
it("does not skip when mention detection is unavailable", () => {
|
||||
const res = resolveMentionGating({
|
||||
requireMention: true,
|
||||
canDetectMention: false,
|
||||
wasMentioned: false,
|
||||
});
|
||||
expect(res.shouldSkip).toBe(false);
|
||||
});
|
||||
});
|
||||
21
src/channels/mention-gating.ts
Normal file
21
src/channels/mention-gating.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export type MentionGateParams = {
|
||||
requireMention: boolean;
|
||||
canDetectMention: boolean;
|
||||
wasMentioned: boolean;
|
||||
implicitMention?: boolean;
|
||||
shouldBypassMention?: boolean;
|
||||
};
|
||||
|
||||
export type MentionGateResult = {
|
||||
effectiveWasMentioned: boolean;
|
||||
shouldSkip: boolean;
|
||||
};
|
||||
|
||||
export function resolveMentionGating(params: MentionGateParams): MentionGateResult {
|
||||
const implicit = params.implicitMention === true;
|
||||
const bypass = params.shouldBypassMention === true;
|
||||
const effectiveWasMentioned = params.wasMentioned || implicit || bypass;
|
||||
const shouldSkip =
|
||||
params.requireMention && params.canDetectMention && !effectiveWasMentioned;
|
||||
return { effectiveWasMentioned, shouldSkip };
|
||||
}
|
||||
Reference in New Issue
Block a user