mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:40:43 +00:00
committed by
GitHub
parent
34ef403cb2
commit
be445dd1c1
@@ -22,12 +22,17 @@ export type SentMessageCache = {
|
||||
// duplicate delivery (noisy but not lossy) — never message loss.
|
||||
const SENT_MESSAGE_TEXT_TTL_MS = 4_000;
|
||||
const SENT_MESSAGE_ID_TTL_MS = 60_000;
|
||||
const LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS = /^[\uFEFF\uFFFD\uFFFE\uFFFF]+/u;
|
||||
|
||||
function normalizeEchoTextKey(text: string | undefined): string | null {
|
||||
if (!text) {
|
||||
return null;
|
||||
}
|
||||
const normalized = text.replace(/\r\n?/g, "\n").trim();
|
||||
const normalized = text
|
||||
.replace(/\r\n?/g, "\n")
|
||||
.trim()
|
||||
.replace(LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS, "")
|
||||
.trim();
|
||||
return normalized ? normalized : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,36 @@ describe("iMessage sent-message echo cache", () => {
|
||||
expect(cache.has("acct:imessage:+1666", { text: "Reasoning:\n_step_" })).toBe(false);
|
||||
});
|
||||
|
||||
it("matches delayed reflected echoes with leading attributedBody corruption markers", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
|
||||
const cache = createSentMessageCache();
|
||||
|
||||
cache.remember("acct:imessage:+1555", { text: "Delayed echo reply" });
|
||||
|
||||
expect(
|
||||
cache.has("acct:imessage:+1555", {
|
||||
text: "\uFFFD\uFFFE\uFFFF\uFEFFDelayed echo reply",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps attributedBody corruption cleanup leading-only", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
|
||||
const cache = createSentMessageCache();
|
||||
|
||||
cache.remember("acct:imessage:+1555", { text: "Delayed echo reply" });
|
||||
|
||||
expect(
|
||||
cache.has("acct:imessage:+1555", {
|
||||
text: "Delayed \uFFFD echo reply",
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(cache.has("acct:imessage:+1555", { text: "Delayed\techo reply" })).toBe(false);
|
||||
expect(cache.has("acct:imessage:+1555", { text: "Delayed\necho reply" })).toBe(false);
|
||||
});
|
||||
|
||||
it("matches by outbound message id and ignores placeholder ids", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
|
||||
|
||||
Reference in New Issue
Block a user