fix: persist session origin metadata

This commit is contained in:
Peter Steinberger
2026-01-18 03:40:35 +00:00
parent dad69afc84
commit 0d9172d761
13 changed files with 102 additions and 23 deletions

View File

@@ -176,6 +176,36 @@ describe("sessions", () => {
});
});
it("updateLastRoute records origin + group metadata when ctx is provided", async () => {
const sessionKey = "agent:main:whatsapp:group:123@g.us";
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
const storePath = path.join(dir, "sessions.json");
await fs.writeFile(storePath, "{}", "utf-8");
await updateLastRoute({
storePath,
sessionKey,
deliveryContext: {
channel: "whatsapp",
to: "123@g.us",
},
ctx: {
Provider: "whatsapp",
ChatType: "group",
GroupSubject: "Family",
From: "123@g.us",
},
});
const store = loadSessionStore(storePath);
expect(store[sessionKey]?.subject).toBe("Family");
expect(store[sessionKey]?.channel).toBe("whatsapp");
expect(store[sessionKey]?.groupId).toBe("123@g.us");
expect(store[sessionKey]?.origin?.label).toBe("Family id:123@g.us");
expect(store[sessionKey]?.origin?.provider).toBe("whatsapp");
expect(store[sessionKey]?.origin?.chatType).toBe("group");
});
it("updateSessionStore preserves concurrent additions", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
const storePath = path.join(dir, "sessions.json");