Files
openclaw/src/shared/chat-envelope.test.ts
2026-03-13 20:28:22 +00:00

24 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { stripEnvelope, stripMessageIdHints } from "./chat-envelope.js";
describe("shared/chat-envelope", () => {
it("strips recognized channel and timestamp envelope prefixes only", () => {
expect(stripEnvelope("[WhatsApp 2026-01-24 13:36] hello")).toBe("hello");
expect(stripEnvelope("[2026-01-24T13:36Z] hello")).toBe("hello");
expect(stripEnvelope("[Custom Sender] hello")).toBe("[Custom Sender] hello");
});
it("keeps non-envelope headers and preserves unmatched text", () => {
expect(stripEnvelope("hello")).toBe("hello");
expect(stripEnvelope("[note] hello")).toBe("[note] hello");
});
it("removes standalone message id hint lines but keeps inline mentions", () => {
expect(stripMessageIdHints("hello\n[message_id: abc123]")).toBe("hello");
expect(stripMessageIdHints("hello\n [message_id: abc123] \nworld")).toBe("hello\nworld");
expect(stripMessageIdHints("I typed [message_id: abc123] inline")).toBe(
"I typed [message_id: abc123] inline",
);
});
});