refactor: canonicalize gateway session store keys

This commit is contained in:
Peter Steinberger
2026-01-17 07:41:06 +00:00
parent d5fdda8e28
commit c92265a51b
13 changed files with 449 additions and 650 deletions

View File

@@ -11,6 +11,7 @@ import {
rpcReq,
startServerWithClient,
testState,
writeSessionStore,
} from "./test-helpers.js";
installGatewayTestHooks();
@@ -96,7 +97,7 @@ describe("gateway server chat", () => {
test("chat.abort returns aborted=false for unknown runId", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(testState.sessionStorePath, JSON.stringify({}, null, 2), "utf-8");
await writeSessionStore({ entries: {} });
const { server, ws } = await startServerWithClient();
await connectOk(ws);
@@ -116,20 +117,14 @@ describe("gateway server chat", () => {
test("chat.abort rejects mismatched sessionKey", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(
testState.sessionStorePath,
JSON.stringify(
{
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
await writeSessionStore({
entries: {
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
null,
2,
),
"utf-8",
);
},
});
const { server, ws } = await startServerWithClient();
await connectOk(ws);
@@ -189,20 +184,14 @@ describe("gateway server chat", () => {
test("chat.abort is a no-op after chat.send completes", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(
testState.sessionStorePath,
JSON.stringify(
{
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
await writeSessionStore({
entries: {
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
null,
2,
),
"utf-8",
);
},
});
const { server, ws } = await startServerWithClient();
await connectOk(ws);
@@ -259,20 +248,14 @@ describe("gateway server chat", () => {
test("chat.send preserves run ordering for queued runs", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(
testState.sessionStorePath,
JSON.stringify(
{
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
await writeSessionStore({
entries: {
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
null,
2,
),
"utf-8",
);
},
});
const { server, ws } = await startServerWithClient();
await connectOk(ws);