test(gateway): cover chat-history session file recovery

This commit is contained in:
Gustavo Madeira Santana 2026-02-14 13:43:18 -05:00
parent 8ce7cfdc12
commit 7cbe9deca9
1 changed files with 52 additions and 0 deletions

View File

@ -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", () => {