From 7cbe9deca9b7fc9efa5d2320acb058bc9fbea48c Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Sat, 14 Feb 2026 13:43:18 -0500 Subject: [PATCH] test(gateway): cover chat-history session file recovery --- src/gateway/session-utils.fs.test.ts | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/gateway/session-utils.fs.test.ts b/src/gateway/session-utils.fs.test.ts index 42f6bf43366..d7cf781f5ff 100644 --- a/src/gateway/session-utils.fs.test.ts +++ b/src/gateway/session-utils.fs.test.ts @@ -475,6 +475,58 @@ describe("readSessionMessages", () => { expect(marker.__openclaw?.id).toBe("comp-1"); expect(typeof marker.timestamp).toBe("number"); }); + + test("reads cross-agent absolute sessionFile when storePath points to another agent dir", () => { + const sessionId = "cross-agent-default-root"; + const sessionFile = path.join(tmpDir, "agents", "ops", "sessions", `${sessionId}.jsonl`); + fs.mkdirSync(path.dirname(sessionFile), { recursive: true }); + fs.writeFileSync( + sessionFile, + [ + JSON.stringify({ type: "session", version: 1, id: sessionId }), + JSON.stringify({ message: { role: "user", content: "from-ops" } }), + ].join("\n"), + "utf-8", + ); + + const wrongStorePath = path.join(tmpDir, "agents", "main", "sessions", "sessions.json"); + const out = readSessionMessages(sessionId, wrongStorePath, sessionFile); + + expect(out).toEqual([{ role: "user", content: "from-ops" }]); + }); + + test("reads cross-agent absolute sessionFile for custom per-agent store roots", () => { + const sessionId = "cross-agent-custom-root"; + const sessionFile = path.join( + tmpDir, + "custom", + "agents", + "ops", + "sessions", + `${sessionId}.jsonl`, + ); + fs.mkdirSync(path.dirname(sessionFile), { recursive: true }); + fs.writeFileSync( + sessionFile, + [ + JSON.stringify({ type: "session", version: 1, id: sessionId }), + JSON.stringify({ message: { role: "assistant", content: "from-custom-ops" } }), + ].join("\n"), + "utf-8", + ); + + const wrongStorePath = path.join( + tmpDir, + "custom", + "agents", + "main", + "sessions", + "sessions.json", + ); + const out = readSessionMessages(sessionId, wrongStorePath, sessionFile); + + expect(out).toEqual([{ role: "assistant", content: "from-custom-ops" }]); + }); }); describe("readSessionPreviewItemsFromTranscript", () => {