



















@@ -1,5 +1,5 @@
11import { describe, expect, it, vi } from "vitest";
2-import { matchesMessagingToolDeliveryTarget } from "./delivery-dispatch.js";
2+import { sourceDeliveryTargetsMatch } from "../../infra/outbound/source-delivery-plan.js";
3344// Mock the announce flow dependencies to test the fallback behavior.
55vi.mock("../../agents/subagent-announce.js", () => ({
@@ -9,10 +9,10 @@ vi.mock("../../agents/subagent-registry-read.js", () => ({
99countActiveDescendantRuns: vi.fn().mockReturnValue(0),
1010}));
111112-describe("matchesMessagingToolDeliveryTarget", () => {
12+describe("sourceDeliveryTargetsMatch", () => {
1313it("matches when channel and to agree", () => {
1414expect(
15-matchesMessagingToolDeliveryTarget(
15+sourceDeliveryTargetsMatch(
1616{ provider: "telegram", to: "123456" },
1717{ channel: "telegram", to: "123456" },
1818),
@@ -21,7 +21,7 @@ describe("matchesMessagingToolDeliveryTarget", () => {
21212222it("rejects when channel differs", () => {
2323expect(
24-matchesMessagingToolDeliveryTarget(
24+sourceDeliveryTargetsMatch(
2525{ provider: "whatsapp", to: "123456" },
2626{ channel: "telegram", to: "123456" },
2727),
@@ -30,7 +30,7 @@ describe("matchesMessagingToolDeliveryTarget", () => {
30303131it("rejects when to is missing from delivery", () => {
3232expect(
33-matchesMessagingToolDeliveryTarget(
33+sourceDeliveryTargetsMatch(
3434{ provider: "telegram", to: "123456" },
3535{ channel: "telegram", to: undefined },
3636),
@@ -39,25 +39,34 @@ describe("matchesMessagingToolDeliveryTarget", () => {
39394040it("rejects when channel is missing from delivery", () => {
4141expect(
42-matchesMessagingToolDeliveryTarget(
42+sourceDeliveryTargetsMatch(
4343{ provider: "telegram", to: "123456" },
4444{ channel: undefined, to: "123456" },
4545),
4646).toBe(false);
4747});
484849-it("strips :topic:NNN suffix from target.to before comparing", () => {
49+it("matches topic suffixes against the resolved delivery thread", () => {
5050expect(
51-matchesMessagingToolDeliveryTarget(
51+sourceDeliveryTargetsMatch(
5252{ provider: "telegram", to: "-1003597428309:topic:462" },
53-{ channel: "telegram", to: "-1003597428309" },
53+{ channel: "telegram", to: "-1003597428309", threadId: 462 },
5454),
5555).toBe(true);
5656});
575758+it("rejects matching room targets when thread ids differ", () => {
59+expect(
60+sourceDeliveryTargetsMatch(
61+{ provider: "telegram", to: "-1003597428309", threadId: "111" },
62+{ channel: "telegram", to: "-1003597428309", threadId: 462 },
63+),
64+).toBe(false);
65+});
66+5867it("matches when provider is 'message' (generic)", () => {
5968expect(
60-matchesMessagingToolDeliveryTarget(
69+sourceDeliveryTargetsMatch(
6170{ provider: "message", to: "123456" },
6271{ channel: "telegram", to: "123456" },
6372),
@@ -66,7 +75,7 @@ describe("matchesMessagingToolDeliveryTarget", () => {
66756776it("rejects when accountIds differ", () => {
6877expect(
69-matchesMessagingToolDeliveryTarget(
78+sourceDeliveryTargetsMatch(
7079{ provider: "telegram", to: "123456", accountId: "bot-a" },
7180{ channel: "telegram", to: "123456", accountId: "bot-b" },
7281),
@@ -75,7 +84,7 @@ describe("matchesMessagingToolDeliveryTarget", () => {
75847685it("matches when delivery has accountId and target omits it (tool fills accountId at exec)", () => {
7786expect(
78-matchesMessagingToolDeliveryTarget(
87+sourceDeliveryTargetsMatch(
7988{ provider: "message", to: "123456" },
8089{ channel: "telegram", to: "123456", accountId: "bot-a" },
8190),
@@ -84,7 +93,7 @@ describe("matchesMessagingToolDeliveryTarget", () => {
84938594it("matches when delivery and target carry the same accountId", () => {
8695expect(
87-matchesMessagingToolDeliveryTarget(
96+sourceDeliveryTargetsMatch(
8897{ provider: "telegram", to: "123456", accountId: "bot-a" },
8998{ channel: "telegram", to: "123456", accountId: "bot-a" },
9099),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。