mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:32:43 +00:00
test(signal): dedupe mention-gating handler setup
This commit is contained in:
@@ -52,15 +52,27 @@ function makeGroupEvent(opts: GroupEventOpts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMentionGatedHistoryHandler() {
|
function createMentionHandler(params: {
|
||||||
const groupHistories = new Map();
|
requireMention: boolean;
|
||||||
const handler = createSignalEventHandler(
|
mentionPattern?: string;
|
||||||
|
historyLimit?: number;
|
||||||
|
groupHistories?: Map<unknown, unknown>;
|
||||||
|
}) {
|
||||||
|
return createSignalEventHandler(
|
||||||
createBaseSignalEventHandlerDeps({
|
createBaseSignalEventHandlerDeps({
|
||||||
cfg: createSignalConfig({ requireMention: true }),
|
cfg: createSignalConfig({
|
||||||
historyLimit: 5,
|
requireMention: params.requireMention,
|
||||||
groupHistories,
|
mentionPattern: params.mentionPattern,
|
||||||
|
}),
|
||||||
|
...(typeof params.historyLimit === "number" ? { historyLimit: params.historyLimit } : {}),
|
||||||
|
...(params.groupHistories ? { groupHistories: params.groupHistories } : {}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMentionGatedHistoryHandler() {
|
||||||
|
const groupHistories = new Map();
|
||||||
|
const handler = createMentionHandler({ requireMention: true, historyLimit: 5, groupHistories });
|
||||||
return { handler, groupHistories };
|
return { handler, groupHistories };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,11 +104,7 @@ async function expectSkippedGroupHistory(opts: GroupEventOpts, expectedBody: str
|
|||||||
describe("signal mention gating", () => {
|
describe("signal mention gating", () => {
|
||||||
it("drops group messages without mention when requireMention is configured", async () => {
|
it("drops group messages without mention when requireMention is configured", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({ requireMention: true });
|
||||||
createBaseSignalEventHandlerDeps({
|
|
||||||
cfg: createSignalConfig({ requireMention: true }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await handler(makeGroupEvent({ message: "hello everyone" }));
|
await handler(makeGroupEvent({ message: "hello everyone" }));
|
||||||
expect(capturedCtx).toBeUndefined();
|
expect(capturedCtx).toBeUndefined();
|
||||||
@@ -104,11 +112,7 @@ describe("signal mention gating", () => {
|
|||||||
|
|
||||||
it("allows group messages with mention when requireMention is configured", async () => {
|
it("allows group messages with mention when requireMention is configured", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({ requireMention: true });
|
||||||
createBaseSignalEventHandlerDeps({
|
|
||||||
cfg: createSignalConfig({ requireMention: true }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await handler(makeGroupEvent({ message: "hey @bot what's up" }));
|
await handler(makeGroupEvent({ message: "hey @bot what's up" }));
|
||||||
expect(capturedCtx).toBeTruthy();
|
expect(capturedCtx).toBeTruthy();
|
||||||
@@ -117,11 +121,7 @@ describe("signal mention gating", () => {
|
|||||||
|
|
||||||
it("sets WasMentioned=false for group messages without mention when requireMention is off", async () => {
|
it("sets WasMentioned=false for group messages without mention when requireMention is off", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({ requireMention: false });
|
||||||
createBaseSignalEventHandlerDeps({
|
|
||||||
cfg: createSignalConfig({ requireMention: false }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await handler(makeGroupEvent({ message: "hello everyone" }));
|
await handler(makeGroupEvent({ message: "hello everyone" }));
|
||||||
expect(capturedCtx).toBeTruthy();
|
expect(capturedCtx).toBeTruthy();
|
||||||
@@ -152,11 +152,7 @@ describe("signal mention gating", () => {
|
|||||||
|
|
||||||
it("bypasses mention gating for authorized control commands", async () => {
|
it("bypasses mention gating for authorized control commands", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({ requireMention: true });
|
||||||
createBaseSignalEventHandlerDeps({
|
|
||||||
cfg: createSignalConfig({ requireMention: true }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await handler(makeGroupEvent({ message: "/help" }));
|
await handler(makeGroupEvent({ message: "/help" }));
|
||||||
expect(capturedCtx).toBeTruthy();
|
expect(capturedCtx).toBeTruthy();
|
||||||
@@ -164,11 +160,7 @@ describe("signal mention gating", () => {
|
|||||||
|
|
||||||
it("hydrates mention placeholders before trimming so offsets stay aligned", async () => {
|
it("hydrates mention placeholders before trimming so offsets stay aligned", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({ requireMention: false });
|
||||||
createBaseSignalEventHandlerDeps({
|
|
||||||
cfg: createSignalConfig({ requireMention: false }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const placeholder = "\uFFFC";
|
const placeholder = "\uFFFC";
|
||||||
const message = `\n${placeholder} hi ${placeholder}`;
|
const message = `\n${placeholder} hi ${placeholder}`;
|
||||||
@@ -193,11 +185,10 @@ describe("signal mention gating", () => {
|
|||||||
|
|
||||||
it("counts mention metadata replacements toward requireMention gating", async () => {
|
it("counts mention metadata replacements toward requireMention gating", async () => {
|
||||||
capturedCtx = undefined;
|
capturedCtx = undefined;
|
||||||
const handler = createSignalEventHandler(
|
const handler = createMentionHandler({
|
||||||
createBaseSignalEventHandlerDeps({
|
requireMention: true,
|
||||||
cfg: createSignalConfig({ requireMention: true, mentionPattern: "@123e4567" }),
|
mentionPattern: "@123e4567",
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const placeholder = "\uFFFC";
|
const placeholder = "\uFFFC";
|
||||||
const message = ` ${placeholder} ping`;
|
const message = ` ${placeholder} ping`;
|
||||||
|
|||||||
Reference in New Issue
Block a user