fix: patch session store updates

This commit is contained in:
Peter Steinberger
2026-01-18 22:26:01 +00:00
parent ed5ece4120
commit 9af1c8a886
2 changed files with 52 additions and 9 deletions

View File

@@ -206,6 +206,37 @@ describe("sessions", () => {
expect(store[sessionKey]?.origin?.chatType).toBe("group");
});
it("updateSessionStoreEntry preserves existing fields when patching", async () => {
const sessionKey = "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,
JSON.stringify(
{
[sessionKey]: {
sessionId: "sess-1",
updatedAt: 100,
reasoningLevel: "on",
},
},
null,
2,
),
"utf-8",
);
await updateSessionStoreEntry({
storePath,
sessionKey,
update: async () => ({ updatedAt: 200 }),
});
const store = loadSessionStore(storePath);
expect(store[sessionKey]?.updatedAt).toBeGreaterThanOrEqual(200);
expect(store[sessionKey]?.reasoningLevel).toBe("on");
});
it("updateSessionStore preserves concurrent additions", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
const storePath = path.join(dir, "sessions.json");