fix: harden iMessage echo dedupe and reasoning suppression (#25897)

This commit is contained in:
Peter Steinberger
2026-02-25 00:43:44 +00:00
parent a9ce6bd79b
commit 2a11c09a8d
13 changed files with 273 additions and 40 deletions

View File

@@ -0,0 +1,60 @@
import { describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import {
describeIMessageEchoDropLog,
resolveIMessageInboundDecision,
} from "./inbound-processing.js";
describe("resolveIMessageInboundDecision echo detection", () => {
const cfg = {} as OpenClawConfig;
it("drops inbound messages when outbound message id matches echo cache", () => {
const echoHas = vi.fn((_scope: string, lookup: { text?: string; messageId?: string }) => {
return lookup.messageId === "42";
});
const decision = resolveIMessageInboundDecision({
cfg,
accountId: "default",
message: {
id: 42,
sender: "+15555550123",
text: "Reasoning:\n_step_",
is_from_me: false,
is_group: false,
},
opts: undefined,
messageText: "Reasoning:\n_step_",
bodyText: "Reasoning:\n_step_",
allowFrom: [],
groupAllowFrom: [],
groupPolicy: "open",
dmPolicy: "open",
storeAllowFrom: [],
historyLimit: 0,
groupHistories: new Map(),
echoCache: { has: echoHas },
logVerbose: undefined,
});
expect(decision).toEqual({ kind: "drop", reason: "echo" });
expect(echoHas).toHaveBeenCalledWith(
"default:imessage:+15555550123",
expect.objectContaining({
text: "Reasoning:\n_step_",
messageId: "42",
}),
);
});
});
describe("describeIMessageEchoDropLog", () => {
it("includes message id when available", () => {
expect(
describeIMessageEchoDropLog({
messageText: "Reasoning:\n_step_",
messageId: "abc-123",
}),
).toContain("id=abc-123");
});
});