mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:51:25 +00:00
fix: harden iMessage echo dedupe and reasoning suppression (#25897)
This commit is contained in:
60
src/imessage/monitor/inbound-processing.test.ts
Normal file
60
src/imessage/monitor/inbound-processing.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user