From 6dbbae0d7e20b8420776e515316d1ee3aec62a65 Mon Sep 17 00:00:00 2001 From: Kuzey Cimen Date: Thu, 29 Jan 2026 11:11:05 +0000 Subject: [PATCH] fix: fix failing tests. --- src/routing/resolve-route.test.ts | 5 +++-- src/routing/session-key.ts | 7 ++++++- ...am-bot.routes-dms-by-telegram-accountid-binding.test.ts | 2 +- src/telegram/bot.test.ts | 2 +- src/web/auto-reply.partial-reply-gating.test.ts | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/routing/resolve-route.test.ts b/src/routing/resolve-route.test.ts index aed0fa755..b67389912 100644 --- a/src/routing/resolve-route.test.ts +++ b/src/routing/resolve-route.test.ts @@ -104,7 +104,7 @@ describe("resolveAgentRoute", () => { peer: { kind: "dm", id: "+1000" }, }); expect(route.agentId).toBe("a"); - expect(route.sessionKey).toBe("agent:a:main"); + expect(route.sessionKey).toBe("agent:a:main:biz"); expect(route.matchedBy).toBe("binding.peer"); }); @@ -224,7 +224,8 @@ describe("resolveAgentRoute", () => { peer: { kind: "dm", id: "+1000" }, }); expect(route.agentId).toBe("home"); - expect(route.sessionKey).toBe("agent:home:main"); + // Updated: Non-default accounts get distinct session keys + expect(route.sessionKey).toBe("agent:home:main:biz"); }); }); diff --git a/src/routing/session-key.ts b/src/routing/session-key.ts index 9f6fa0295..29927ce87 100644 --- a/src/routing/session-key.ts +++ b/src/routing/session-key.ts @@ -151,7 +151,12 @@ export function buildAgentPeerSessionKey(params: { const accountId = normalizeAccountId(params.accountId); if (accountId && accountId !== DEFAULT_ACCOUNT_ID) { if (dmScope === "main") { - return `agent:${normalizeAgentId(params.agentId)}:dm:${peerId}:${accountId}`; + return ( + buildAgentMainSessionKey({ + agentId: params.agentId, + mainKey: params.mainKey, + }) + `:${accountId}` + ); } return `agent:${normalizeAgentId(params.agentId)}:dm:${peerId}:${accountId}`; } diff --git a/src/telegram/bot.create-telegram-bot.routes-dms-by-telegram-accountid-binding.test.ts b/src/telegram/bot.create-telegram-bot.routes-dms-by-telegram-accountid-binding.test.ts index e854d1962..b78a8ab57 100644 --- a/src/telegram/bot.create-telegram-bot.routes-dms-by-telegram-accountid-binding.test.ts +++ b/src/telegram/bot.create-telegram-bot.routes-dms-by-telegram-accountid-binding.test.ts @@ -200,7 +200,7 @@ describe("createTelegramBot", () => { expect(replySpy).toHaveBeenCalledTimes(1); const payload = replySpy.mock.calls[0][0]; expect(payload.AccountId).toBe("opie"); - expect(payload.SessionKey).toBe("agent:opie:main"); + expect(payload.SessionKey).toBe("agent:opie:main:opie"); }); it("allows per-group requireMention override", async () => { onSpy.mockReset(); diff --git a/src/telegram/bot.test.ts b/src/telegram/bot.test.ts index c075174fb..c08607bb5 100644 --- a/src/telegram/bot.test.ts +++ b/src/telegram/bot.test.ts @@ -1260,7 +1260,7 @@ describe("createTelegramBot", () => { expect(replySpy).toHaveBeenCalledTimes(1); const payload = replySpy.mock.calls[0][0]; expect(payload.AccountId).toBe("opie"); - expect(payload.SessionKey).toBe("agent:opie:main"); + expect(payload.SessionKey).toBe("agent:opie:main:opie"); }); it("allows per-group requireMention override", async () => { diff --git a/src/web/auto-reply.partial-reply-gating.test.ts b/src/web/auto-reply.partial-reply-gating.test.ts index 43bb22db1..bb90a5e90 100644 --- a/src/web/auto-reply.partial-reply-gating.test.ts +++ b/src/web/auto-reply.partial-reply-gating.test.ts @@ -242,7 +242,7 @@ describe("partial reply gating", () => { }); it("updates last-route for group chats with account id", async () => { const now = Date.now(); - const groupSessionKey = "agent:main:whatsapp:group:123@g.us"; + const groupSessionKey = "agent:main:whatsapp:group:123@g.us:work"; const store = await makeSessionStore({ [groupSessionKey]: { sessionId: "sid", updatedAt: now - 1 }, });