|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | | -import { filterMessagingToolMediaDuplicates } from "./reply-payloads.js"; |
| 2 | +import { |
| 3 | + filterMessagingToolMediaDuplicates, |
| 4 | + shouldSuppressMessagingToolReplies, |
| 5 | +} from "./reply-payloads.js"; |
3 | 6 |
|
4 | 7 | describe("filterMessagingToolMediaDuplicates", () => { |
5 | 8 | it("strips mediaUrl when it matches sentMediaUrls", () => { |
@@ -75,3 +78,79 @@ describe("filterMessagingToolMediaDuplicates", () => { |
75 | 78 | expect(result).toEqual([{ text: "hello", mediaUrl: undefined, mediaUrls: undefined }]); |
76 | 79 | }); |
77 | 80 | }); |
| 81 | + |
| 82 | +describe("shouldSuppressMessagingToolReplies", () => { |
| 83 | + it("suppresses when target provider is missing but target matches current provider route", () => { |
| 84 | + expect( |
| 85 | + shouldSuppressMessagingToolReplies({ |
| 86 | + messageProvider: "telegram", |
| 87 | + originatingTo: "123", |
| 88 | + messagingToolSentTargets: [{ tool: "message", provider: "", to: "123" }], |
| 89 | + }), |
| 90 | + ).toBe(true); |
| 91 | + }); |
| 92 | + |
| 93 | + it('suppresses when target provider uses "message" placeholder and target matches', () => { |
| 94 | + expect( |
| 95 | + shouldSuppressMessagingToolReplies({ |
| 96 | + messageProvider: "telegram", |
| 97 | + originatingTo: "123", |
| 98 | + messagingToolSentTargets: [{ tool: "message", provider: "message", to: "123" }], |
| 99 | + }), |
| 100 | + ).toBe(true); |
| 101 | + }); |
| 102 | + |
| 103 | + it("does not suppress when providerless target does not match origin route", () => { |
| 104 | + expect( |
| 105 | + shouldSuppressMessagingToolReplies({ |
| 106 | + messageProvider: "telegram", |
| 107 | + originatingTo: "123", |
| 108 | + messagingToolSentTargets: [{ tool: "message", provider: "", to: "456" }], |
| 109 | + }), |
| 110 | + ).toBe(false); |
| 111 | + }); |
| 112 | + |
| 113 | + it("suppresses telegram topic-origin replies when explicit threadId matches", () => { |
| 114 | + expect( |
| 115 | + shouldSuppressMessagingToolReplies({ |
| 116 | + messageProvider: "telegram", |
| 117 | + originatingTo: "telegram:group:-100123:topic:77", |
| 118 | + messagingToolSentTargets: [ |
| 119 | + { tool: "message", provider: "telegram", to: "-100123", threadId: "77" }, |
| 120 | + ], |
| 121 | + }), |
| 122 | + ).toBe(true); |
| 123 | + }); |
| 124 | + |
| 125 | + it("does not suppress telegram topic-origin replies when explicit threadId differs", () => { |
| 126 | + expect( |
| 127 | + shouldSuppressMessagingToolReplies({ |
| 128 | + messageProvider: "telegram", |
| 129 | + originatingTo: "telegram:group:-100123:topic:77", |
| 130 | + messagingToolSentTargets: [ |
| 131 | + { tool: "message", provider: "telegram", to: "-100123", threadId: "88" }, |
| 132 | + ], |
| 133 | + }), |
| 134 | + ).toBe(false); |
| 135 | + }); |
| 136 | + |
| 137 | + it("does not suppress telegram topic-origin replies when target omits topic metadata", () => { |
| 138 | + expect( |
| 139 | + shouldSuppressMessagingToolReplies({ |
| 140 | + messageProvider: "telegram", |
| 141 | + originatingTo: "telegram:group:-100123:topic:77", |
| 142 | + messagingToolSentTargets: [{ tool: "message", provider: "telegram", to: "-100123" }], |
| 143 | + }), |
| 144 | + ).toBe(false); |
| 145 | + }); |
| 146 | + |
| 147 | + it("suppresses telegram replies when chatId matches but target forms differ", () => { |
| 148 | + expect( |
| 149 | + shouldSuppressMessagingToolReplies({ |
| 150 | + messageProvider: "telegram", |
| 151 | + originatingTo: "telegram:group:-100123", |
| 152 | + messagingToolSentTargets: [{ tool: "message", provider: "telegram", to: "-100123" }], |
| 153 | + }), |
| 154 | + ).toBe(true); |
| 155 | + }); |
| 156 | +}); |
0 commit comments