Tests: cover shared Telegram thread binding state

This commit is contained in:
Vincent Koc
2026-03-12 01:27:46 -04:00
parent f1e03eafee
commit 4da19eed83

View File

@@ -2,6 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { importFreshModule } from "../../test/helpers/import-fresh.js";
import { resolveStateDir } from "../config/paths.js";
import { getSessionBindingService } from "../infra/outbound/session-binding-service.js";
import {
@@ -79,6 +80,53 @@ describe("telegram thread bindings", () => {
});
});
it("shares binding state across distinct module instances", async () => {
const bindingsA = await importFreshModule<typeof import("./thread-bindings.js")>(
import.meta.url,
"./thread-bindings.js?scope=shared-a",
);
const bindingsB = await importFreshModule<typeof import("./thread-bindings.js")>(
import.meta.url,
"./thread-bindings.js?scope=shared-b",
);
bindingsA.__testing.resetTelegramThreadBindingsForTests();
try {
const managerA = bindingsA.createTelegramThreadBindingManager({
accountId: "shared-runtime",
persist: false,
enableSweeper: false,
});
const managerB = bindingsB.createTelegramThreadBindingManager({
accountId: "shared-runtime",
persist: false,
enableSweeper: false,
});
expect(managerB).toBe(managerA);
await getSessionBindingService().bind({
targetSessionKey: "agent:main:subagent:child-shared",
targetKind: "subagent",
conversation: {
channel: "telegram",
accountId: "shared-runtime",
conversationId: "-100200300:topic:44",
},
placement: "current",
});
expect(
bindingsB
.getTelegramThreadBindingManager("shared-runtime")
?.getByConversationId("-100200300:topic:44")?.targetSessionKey,
).toBe("agent:main:subagent:child-shared");
} finally {
bindingsA.__testing.resetTelegramThreadBindingsForTests();
}
});
it("updates lifecycle windows by session key", async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-03-06T10:00:00.000Z"));