mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 11:07:14 +00:00
fix(routing): unify session delivery invariants for duplicate suppression (#33786)
* Routing: unify session delivery invariants * Routing: address PR review feedback * Routing: tighten topic and session-scope suppression * fix(chat): inherit routes for per-account channel-peer sessions
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { filterMessagingToolMediaDuplicates } from "./reply-payloads.js";
|
||||
import {
|
||||
filterMessagingToolMediaDuplicates,
|
||||
shouldSuppressMessagingToolReplies,
|
||||
} from "./reply-payloads.js";
|
||||
|
||||
describe("filterMessagingToolMediaDuplicates", () => {
|
||||
it("strips mediaUrl when it matches sentMediaUrls", () => {
|
||||
@@ -75,3 +78,79 @@ describe("filterMessagingToolMediaDuplicates", () => {
|
||||
expect(result).toEqual([{ text: "hello", mediaUrl: undefined, mediaUrls: undefined }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldSuppressMessagingToolReplies", () => {
|
||||
it("suppresses when target provider is missing but target matches current provider route", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "123",
|
||||
messagingToolSentTargets: [{ tool: "message", provider: "", to: "123" }],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('suppresses when target provider uses "message" placeholder and target matches', () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "123",
|
||||
messagingToolSentTargets: [{ tool: "message", provider: "message", to: "123" }],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not suppress when providerless target does not match origin route", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "123",
|
||||
messagingToolSentTargets: [{ tool: "message", provider: "", to: "456" }],
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("suppresses telegram topic-origin replies when explicit threadId matches", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "telegram:group:-100123:topic:77",
|
||||
messagingToolSentTargets: [
|
||||
{ tool: "message", provider: "telegram", to: "-100123", threadId: "77" },
|
||||
],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not suppress telegram topic-origin replies when explicit threadId differs", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "telegram:group:-100123:topic:77",
|
||||
messagingToolSentTargets: [
|
||||
{ tool: "message", provider: "telegram", to: "-100123", threadId: "88" },
|
||||
],
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not suppress telegram topic-origin replies when target omits topic metadata", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "telegram:group:-100123:topic:77",
|
||||
messagingToolSentTargets: [{ tool: "message", provider: "telegram", to: "-100123" }],
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("suppresses telegram replies when chatId matches but target forms differ", () => {
|
||||
expect(
|
||||
shouldSuppressMessagingToolReplies({
|
||||
messageProvider: "telegram",
|
||||
originatingTo: "telegram:group:-100123",
|
||||
messagingToolSentTargets: [{ tool: "message", provider: "telegram", to: "-100123" }],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user