From 3c3a39d1650feea71b779d6dcb77758346e2801c Mon Sep 17 00:00:00 2001 From: Xinhua Gu Date: Mon, 16 Feb 2026 12:54:07 +0100 Subject: [PATCH] fix(test): use path.resolve for cross-platform Windows compatibility --- src/config/sessions.test.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/config/sessions.test.ts b/src/config/sessions.test.ts index 8711f8da1..94d628dcd 100644 --- a/src/config/sessions.test.ts +++ b/src/config/sessions.test.ts @@ -471,15 +471,17 @@ describe("sessions", () => { it("resolves cross-agent absolute sessionFile paths", () => { const prev = process.env.OPENCLAW_STATE_DIR; - process.env.OPENCLAW_STATE_DIR = "/home/user/.openclaw"; + const stateDir = path.resolve("/home/user/.openclaw"); + process.env.OPENCLAW_STATE_DIR = stateDir; try { + const bot2Session = path.join(stateDir, "agents", "bot2", "sessions", "sess-1.jsonl"); // Agent bot1 resolves a sessionFile that belongs to agent bot2 const sessionFile = resolveSessionFilePath( "sess-1", - { sessionFile: "/home/user/.openclaw/agents/bot2/sessions/sess-1.jsonl" }, + { sessionFile: bot2Session }, { agentId: "bot1" }, ); - expect(sessionFile).toBe("/home/user/.openclaw/agents/bot2/sessions/sess-1.jsonl"); + expect(sessionFile).toBe(bot2Session); } finally { if (prev === undefined) { delete process.env.OPENCLAW_STATE_DIR; @@ -491,15 +493,17 @@ describe("sessions", () => { it("resolves cross-agent paths when OPENCLAW_STATE_DIR differs from stored paths", () => { const prev = process.env.OPENCLAW_STATE_DIR; - process.env.OPENCLAW_STATE_DIR = "/different/state"; + process.env.OPENCLAW_STATE_DIR = path.resolve("/different/state"); try { + const originalBase = path.resolve("/original/state"); + const bot2Session = path.join(originalBase, "agents", "bot2", "sessions", "sess-1.jsonl"); // sessionFile was created under a different state dir than current env const sessionFile = resolveSessionFilePath( "sess-1", - { sessionFile: "/original/state/agents/bot2/sessions/sess-1.jsonl" }, + { sessionFile: bot2Session }, { agentId: "bot1" }, ); - expect(sessionFile).toBe("/original/state/agents/bot2/sessions/sess-1.jsonl"); + expect(sessionFile).toBe(bot2Session); } finally { if (prev === undefined) { delete process.env.OPENCLAW_STATE_DIR; @@ -511,10 +515,14 @@ describe("sessions", () => { it("rejects absolute sessionFile paths outside agent sessions directories", () => { const prev = process.env.OPENCLAW_STATE_DIR; - process.env.OPENCLAW_STATE_DIR = "/home/user/.openclaw"; + process.env.OPENCLAW_STATE_DIR = path.resolve("/home/user/.openclaw"); try { expect(() => - resolveSessionFilePath("sess-1", { sessionFile: "/etc/passwd" }, { agentId: "bot1" }), + resolveSessionFilePath( + "sess-1", + { sessionFile: path.resolve("/etc/passwd") }, + { agentId: "bot1" }, + ), ).toThrow(/within sessions directory/); } finally { if (prev === undefined) {