
























@@ -13,8 +13,9 @@ import { resolveGroupRequireMention } from "./reply/groups.js";
1313import { finalizeInboundContext } from "./reply/inbound-context.js";
1414import {
1515buildInboundDedupeKey,
16+claimInboundDedupe,
17+commitInboundDedupe,
1618resetInboundDedupe,
17-shouldSkipDuplicateInbound,
1819} from "./reply/inbound-dedupe.js";
1920import { normalizeInboundTextNewlines, sanitizeInboundSystemTags } from "./reply/inbound-text.js";
2021import {
@@ -34,6 +35,16 @@ type TestChannelGroupContext = {
3435accountId?: string | null;
3536};
363738+function commitInboundForTest(ctx: MsgContext): string {
39+const claim = claimInboundDedupe(ctx);
40+expect(claim.status).toBe("claimed");
41+if (claim.status !== "claimed") {
42+throw new Error(`expected inbound dedupe claim, got ${claim.status}`);
43+}
44+commitInboundDedupe(claim.key);
45+return claim.key;
46+}
47+3748function normalizeTestSlug(raw?: string | null): string {
3849return raw?.trim().replace(/^#/, "").toLowerCase() ?? "";
3950}
@@ -426,8 +437,8 @@ describe("inbound dedupe", () => {
426437OriginatingTo: "whatsapp:+1555",
427438MessageSid: "msg-1",
428439};
429-expect(shouldSkipDuplicateInbound(ctx, { now: 100 })).toBe(false);
430-expect(shouldSkipDuplicateInbound(ctx, { now: 200 })).toBe(true);
440+const key = commitInboundForTest(ctx);
441+expect(claimInboundDedupe(ctx)).toEqual({ status: "duplicate", key });
431442});
432443433444it("does not dedupe when the peer changes", () => {
@@ -437,12 +448,8 @@ describe("inbound dedupe", () => {
437448OriginatingChannel: "whatsapp",
438449MessageSid: "msg-1",
439450};
440-expect(
441-shouldSkipDuplicateInbound({ ...base, OriginatingTo: "whatsapp:+1000" }, { now: 100 }),
442-).toBe(false);
443-expect(
444-shouldSkipDuplicateInbound({ ...base, OriginatingTo: "whatsapp:+2000" }, { now: 200 }),
445-).toBe(false);
451+commitInboundForTest({ ...base, OriginatingTo: "whatsapp:+1000" });
452+expect(claimInboundDedupe({ ...base, OriginatingTo: "whatsapp:+2000" }).status).toBe("claimed");
446453});
447454448455it("does not dedupe across agent ids", () => {
@@ -453,20 +460,14 @@ describe("inbound dedupe", () => {
453460OriginatingTo: "whatsapp:+1555",
454461MessageSid: "msg-1",
455462};
463+const alphaKey = commitInboundForTest({ ...base, SessionKey: "agent:alpha:main" });
456464expect(
457-shouldSkipDuplicateInbound({ ...base, SessionKey: "agent:alpha:main" }, { now: 100 }),
458-).toBe(false);
459-expect(
460-shouldSkipDuplicateInbound(
461-{ ...base, SessionKey: "agent:bravo:whatsapp:direct:+1555" },
462-{
463-now: 200,
464-},
465-),
466-).toBe(false);
467-expect(
468-shouldSkipDuplicateInbound({ ...base, SessionKey: "agent:alpha:main" }, { now: 300 }),
469-).toBe(true);
465+claimInboundDedupe({ ...base, SessionKey: "agent:bravo:whatsapp:direct:+1555" }).status,
466+).toBe("claimed");
467+expect(claimInboundDedupe({ ...base, SessionKey: "agent:alpha:main" })).toEqual({
468+status: "duplicate",
469+key: alphaKey,
470+});
470471});
471472472473it("dedupes when the same agent sees the same inbound message under different session keys", () => {
@@ -477,15 +478,10 @@ describe("inbound dedupe", () => {
477478OriginatingTo: "telegram:7463849194",
478479MessageSid: "msg-1",
479480};
481+const key = commitInboundForTest({ ...base, SessionKey: "agent:main:main" });
480482expect(
481-shouldSkipDuplicateInbound({ ...base, SessionKey: "agent:main:main" }, { now: 100 }),
482-).toBe(false);
483-expect(
484-shouldSkipDuplicateInbound(
485-{ ...base, SessionKey: "agent:main:telegram:direct:7463849194" },
486-{ now: 200 },
487-),
488-).toBe(true);
483+claimInboundDedupe({ ...base, SessionKey: "agent:main:telegram:direct:7463849194" }),
484+).toEqual({ status: "duplicate", key });
489485});
490486});
491487此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。