fix(auto-reply): RawBody commands + locked session updates (#643)

This commit is contained in:
Peter Steinberger
2026-01-10 17:32:19 +01:00
parent e2ea02160d
commit e3cd431551
17 changed files with 566 additions and 89 deletions

View File

@@ -11,6 +11,7 @@ import {
resolveSessionTranscriptPath,
resolveSessionTranscriptsDir,
updateLastRoute,
updateSessionStoreEntry,
} from "./sessions.js";
describe("sessions", () => {
@@ -187,4 +188,52 @@ describe("sessions", () => {
}
}
});
it("updateSessionStoreEntry merges concurrent patches", 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,
JSON.stringify(
{
[mainSessionKey]: {
sessionId: "sess-1",
updatedAt: 123,
thinkingLevel: "low",
},
},
null,
2,
),
"utf-8",
);
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
await Promise.all([
updateSessionStoreEntry({
storePath,
sessionKey: mainSessionKey,
update: async () => {
await sleep(50);
return { modelOverride: "anthropic/claude-opus-4-5" };
},
}),
updateSessionStoreEntry({
storePath,
sessionKey: mainSessionKey,
update: async () => {
await sleep(10);
return { thinkingLevel: "high" };
},
}),
]);
const store = loadSessionStore(storePath);
expect(store[mainSessionKey]?.modelOverride).toBe(
"anthropic/claude-opus-4-5",
);
expect(store[mainSessionKey]?.thinkingLevel).toBe("high");
await expect(fs.stat(`${storePath}.lock`)).rejects.toThrow();
});
});