fix: fix failing tests.

This commit is contained in:
Kuzey Cimen 2026-01-29 11:11:05 +00:00
parent 58c92b63c6
commit 6dbbae0d7e
5 changed files with 12 additions and 6 deletions

View File

@ -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");
});
});

View File

@ -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}`;
}

View File

@ -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();

View File

@ -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 () => {

View File

@ -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 },
});