perf(test): consolidate web auto-reply suites

This commit is contained in:
Peter Steinberger
2026-02-14 23:10:06 +00:00
parent 5fd1822c7c
commit fb1d8f8361
8 changed files with 799 additions and 1524 deletions

View File

@@ -1,3 +1,6 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import type { WebInboundMsg } from "./types.js";
import { isBotMentionedFromTargets, resolveMentionTargets } from "./mentions.js";
@@ -52,4 +55,64 @@ describe("isBotMentionedFromTargets", () => {
const targets = resolveMentionTargets(msg);
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(true);
});
it("ignores JID mentions in self-chat mode", () => {
const cfg = { mentionRegexes: [/\bopenclaw\b/i], allowFrom: ["+999"] };
const msg = makeMsg({
body: "@owner ping",
mentionedJids: ["999@s.whatsapp.net"],
selfE164: "+999",
selfJid: "999@s.whatsapp.net",
});
const targets = resolveMentionTargets(msg);
expect(isBotMentionedFromTargets(msg, cfg, targets)).toBe(false);
const msgTextMention = makeMsg({
body: "openclaw ping",
selfE164: "+999",
selfJid: "999@s.whatsapp.net",
});
const targetsText = resolveMentionTargets(msgTextMention);
expect(isBotMentionedFromTargets(msgTextMention, cfg, targetsText)).toBe(true);
});
});
describe("resolveMentionTargets with @lid mapping", () => {
it("resolves mentionedJids via lid reverse mapping in authDir", async () => {
const authDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lid-mapping-"));
try {
await fs.writeFile(
path.join(authDir, "lid-mapping-777_reverse.json"),
JSON.stringify("+1777"),
);
const msg = makeMsg({
body: "ping",
mentionedJids: ["777@lid"],
selfE164: "+15551234567",
selfJid: "15551234567@s.whatsapp.net",
});
const targets = resolveMentionTargets(msg, authDir);
expect(targets.normalizedMentions).toContain("+1777");
} finally {
await fs.rm(authDir, { recursive: true, force: true });
}
});
it("derives selfE164 from selfJid when selfJid is @lid and mapping exists", async () => {
const authDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lid-mapping-"));
try {
await fs.writeFile(
path.join(authDir, "lid-mapping-777_reverse.json"),
JSON.stringify("+1777"),
);
const msg = makeMsg({
body: "ping",
selfJid: "777@lid",
});
const targets = resolveMentionTargets(msg, authDir);
expect(targets.selfE164).toBe("+1777");
} finally {
await fs.rm(authDir, { recursive: true, force: true });
}
});
});