fix: persist deliveryContext on last-route updates
Co-authored-by: Adam Holt <mail@adamholt.co.nz>
This commit is contained in:
@@ -121,8 +121,10 @@ describe("sessions", () => {
|
||||
await updateLastRoute({
|
||||
storePath,
|
||||
sessionKey: mainSessionKey,
|
||||
channel: "telegram",
|
||||
to: " 12345 ",
|
||||
deliveryContext: {
|
||||
channel: "telegram",
|
||||
to: " 12345 ",
|
||||
},
|
||||
});
|
||||
|
||||
const store = loadSessionStore(storePath);
|
||||
@@ -142,6 +144,36 @@ describe("sessions", () => {
|
||||
expect(store[mainSessionKey]?.compactionCount).toBe(2);
|
||||
});
|
||||
|
||||
it("updateLastRoute prefers explicit deliveryContext", async () => {
|
||||
const mainSessionKey = "agent:main:main";
|
||||
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: mainSessionKey,
|
||||
channel: "whatsapp",
|
||||
to: "111",
|
||||
accountId: "legacy",
|
||||
deliveryContext: {
|
||||
channel: "telegram",
|
||||
to: "222",
|
||||
accountId: "primary",
|
||||
},
|
||||
});
|
||||
|
||||
const store = loadSessionStore(storePath);
|
||||
expect(store[mainSessionKey]?.lastChannel).toBe("telegram");
|
||||
expect(store[mainSessionKey]?.lastTo).toBe("222");
|
||||
expect(store[mainSessionKey]?.lastAccountId).toBe("primary");
|
||||
expect(store[mainSessionKey]?.deliveryContext).toEqual({
|
||||
channel: "telegram",
|
||||
to: "222",
|
||||
accountId: "primary",
|
||||
});
|
||||
});
|
||||
|
||||
it("updateSessionStore preserves concurrent additions", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
|
||||
const storePath = path.join(dir, "sessions.json");
|
||||
|
||||
Reference in New Issue
Block a user