Files
openclaw/src/auto-reply/reply/inbound-dedupe.test.ts
Vincent Koc 4ca84acf24 fix(runtime): duplicate messages, share singleton state across bundled chunks (#43683)
* Tests: add fresh module import helper

* Process: share command queue runtime state

* Agents: share embedded run runtime state

* Reply: share followup queue runtime state

* Reply: share followup drain callback state

* Reply: share queued message dedupe state

* Reply: share inbound dedupe state

* Tests: cover shared command queue runtime state

* Tests: cover shared embedded run runtime state

* Tests: cover shared followup queue runtime state

* Tests: cover shared inbound dedupe state

* Tests: cover shared Slack thread participation state

* Slack: share sent thread participation state

* Tests: document fresh import helper

* Telegram: share draft stream runtime state

* Tests: cover shared Telegram draft stream state

* Telegram: share sent message cache state

* Tests: cover shared Telegram sent message cache

* Telegram: share thread binding runtime state

* Tests: cover shared Telegram thread binding state

* Tests: avoid duplicate shared queue reset

* refactor(runtime): centralize global singleton access

* refactor(runtime): preserve undefined global singleton values

* test(runtime): cover undefined global singleton values

---------

Co-authored-by: Nimrod Gutman <nimrod.gutman@gmail.com>
2026-03-12 14:59:27 -04:00

44 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { importFreshModule } from "../../../test/helpers/import-fresh.js";
import type { MsgContext } from "../templating.js";
import { resetInboundDedupe } from "./inbound-dedupe.js";
const sharedInboundContext: MsgContext = {
Provider: "discord",
Surface: "discord",
From: "discord:user-1",
To: "channel:c1",
OriginatingChannel: "discord",
OriginatingTo: "channel:c1",
SessionKey: "agent:main:discord:channel:c1",
MessageSid: "msg-1",
};
describe("inbound dedupe", () => {
afterEach(() => {
resetInboundDedupe();
});
it("shares dedupe state across distinct module instances", async () => {
const inboundA = await importFreshModule<typeof import("./inbound-dedupe.js")>(
import.meta.url,
"./inbound-dedupe.js?scope=shared-a",
);
const inboundB = await importFreshModule<typeof import("./inbound-dedupe.js")>(
import.meta.url,
"./inbound-dedupe.js?scope=shared-b",
);
inboundA.resetInboundDedupe();
inboundB.resetInboundDedupe();
try {
expect(inboundA.shouldSkipDuplicateInbound(sharedInboundContext)).toBe(false);
expect(inboundB.shouldSkipDuplicateInbound(sharedInboundContext)).toBe(true);
} finally {
inboundA.resetInboundDedupe();
inboundB.resetInboundDedupe();
}
});
});