mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 21:51:24 +00:00
perf(test): fold health + signal mention tests
This commit is contained in:
@@ -18,6 +18,7 @@ vi.mock("../../auto-reply/dispatch.js", async (importOriginal) => {
|
||||
});
|
||||
|
||||
import { createSignalEventHandler } from "./event-handler.js";
|
||||
import { renderSignalMentions } from "./mentions.js";
|
||||
|
||||
function createBaseDeps(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
@@ -270,3 +271,34 @@ describe("signal mention gating", () => {
|
||||
expect(capturedCtx?.WasMentioned).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("renderSignalMentions", () => {
|
||||
const PLACEHOLDER = "\uFFFC";
|
||||
|
||||
it("returns the original message when no mentions are provided", () => {
|
||||
const message = `${PLACEHOLDER} ping`;
|
||||
expect(renderSignalMentions(message, null)).toBe(message);
|
||||
expect(renderSignalMentions(message, [])).toBe(message);
|
||||
});
|
||||
|
||||
it("replaces placeholder code points using mention metadata", () => {
|
||||
const message = `${PLACEHOLDER} hi ${PLACEHOLDER}!`;
|
||||
const normalized = renderSignalMentions(message, [
|
||||
{ uuid: "abc-123", start: 0, length: 1 },
|
||||
{ number: "+15550005555", start: message.lastIndexOf(PLACEHOLDER), length: 1 },
|
||||
]);
|
||||
|
||||
expect(normalized).toBe("@abc-123 hi @+15550005555!");
|
||||
});
|
||||
|
||||
it("skips mentions that lack identifiers or out-of-bounds spans", () => {
|
||||
const message = `${PLACEHOLDER} hi`;
|
||||
const normalized = renderSignalMentions(message, [
|
||||
{ name: "ignored" },
|
||||
{ uuid: "valid", start: 0, length: 1 },
|
||||
{ number: "+1555", start: 999, length: 1 },
|
||||
]);
|
||||
|
||||
expect(normalized).toBe("@valid hi");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderSignalMentions } from "./mentions.js";
|
||||
|
||||
const PLACEHOLDER = "\uFFFC";
|
||||
|
||||
describe("renderSignalMentions", () => {
|
||||
it("returns the original message when no mentions are provided", () => {
|
||||
const message = `${PLACEHOLDER} ping`;
|
||||
expect(renderSignalMentions(message, null)).toBe(message);
|
||||
expect(renderSignalMentions(message, [])).toBe(message);
|
||||
});
|
||||
|
||||
it("replaces placeholder code points using mention metadata", () => {
|
||||
const message = `${PLACEHOLDER} hi ${PLACEHOLDER}!`;
|
||||
const normalized = renderSignalMentions(message, [
|
||||
{ uuid: "abc-123", start: 0, length: 1 },
|
||||
{ number: "+15550005555", start: message.lastIndexOf(PLACEHOLDER), length: 1 },
|
||||
]);
|
||||
|
||||
expect(normalized).toBe("@abc-123 hi @+15550005555!");
|
||||
});
|
||||
|
||||
it("skips mentions that lack identifiers or out-of-bounds spans", () => {
|
||||
const message = `${PLACEHOLDER} hi`;
|
||||
const normalized = renderSignalMentions(message, [
|
||||
{ name: "ignored" },
|
||||
{ uuid: "valid", start: 0, length: 1 },
|
||||
{ number: "+1555", start: 999, length: 1 },
|
||||
]);
|
||||
|
||||
expect(normalized).toBe("@valid hi");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user