mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:38:27 +00:00
fix(test): use path.resolve for cross-platform Windows compatibility
This commit is contained in:
committed by
Peter Steinberger
parent
90774c098a
commit
3c3a39d165
@@ -471,15 +471,17 @@ describe("sessions", () => {
|
|||||||
|
|
||||||
it("resolves cross-agent absolute sessionFile paths", () => {
|
it("resolves cross-agent absolute sessionFile paths", () => {
|
||||||
const prev = process.env.OPENCLAW_STATE_DIR;
|
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 {
|
try {
|
||||||
|
const bot2Session = path.join(stateDir, "agents", "bot2", "sessions", "sess-1.jsonl");
|
||||||
// Agent bot1 resolves a sessionFile that belongs to agent bot2
|
// Agent bot1 resolves a sessionFile that belongs to agent bot2
|
||||||
const sessionFile = resolveSessionFilePath(
|
const sessionFile = resolveSessionFilePath(
|
||||||
"sess-1",
|
"sess-1",
|
||||||
{ sessionFile: "/home/user/.openclaw/agents/bot2/sessions/sess-1.jsonl" },
|
{ sessionFile: bot2Session },
|
||||||
{ agentId: "bot1" },
|
{ agentId: "bot1" },
|
||||||
);
|
);
|
||||||
expect(sessionFile).toBe("/home/user/.openclaw/agents/bot2/sessions/sess-1.jsonl");
|
expect(sessionFile).toBe(bot2Session);
|
||||||
} finally {
|
} finally {
|
||||||
if (prev === undefined) {
|
if (prev === undefined) {
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
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", () => {
|
it("resolves cross-agent paths when OPENCLAW_STATE_DIR differs from stored paths", () => {
|
||||||
const prev = process.env.OPENCLAW_STATE_DIR;
|
const prev = process.env.OPENCLAW_STATE_DIR;
|
||||||
process.env.OPENCLAW_STATE_DIR = "/different/state";
|
process.env.OPENCLAW_STATE_DIR = path.resolve("/different/state");
|
||||||
try {
|
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
|
// sessionFile was created under a different state dir than current env
|
||||||
const sessionFile = resolveSessionFilePath(
|
const sessionFile = resolveSessionFilePath(
|
||||||
"sess-1",
|
"sess-1",
|
||||||
{ sessionFile: "/original/state/agents/bot2/sessions/sess-1.jsonl" },
|
{ sessionFile: bot2Session },
|
||||||
{ agentId: "bot1" },
|
{ agentId: "bot1" },
|
||||||
);
|
);
|
||||||
expect(sessionFile).toBe("/original/state/agents/bot2/sessions/sess-1.jsonl");
|
expect(sessionFile).toBe(bot2Session);
|
||||||
} finally {
|
} finally {
|
||||||
if (prev === undefined) {
|
if (prev === undefined) {
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
delete process.env.OPENCLAW_STATE_DIR;
|
||||||
@@ -511,10 +515,14 @@ describe("sessions", () => {
|
|||||||
|
|
||||||
it("rejects absolute sessionFile paths outside agent sessions directories", () => {
|
it("rejects absolute sessionFile paths outside agent sessions directories", () => {
|
||||||
const prev = process.env.OPENCLAW_STATE_DIR;
|
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 {
|
try {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
resolveSessionFilePath("sess-1", { sessionFile: "/etc/passwd" }, { agentId: "bot1" }),
|
resolveSessionFilePath(
|
||||||
|
"sess-1",
|
||||||
|
{ sessionFile: path.resolve("/etc/passwd") },
|
||||||
|
{ agentId: "bot1" },
|
||||||
|
),
|
||||||
).toThrow(/within sessions directory/);
|
).toThrow(/within sessions directory/);
|
||||||
} finally {
|
} finally {
|
||||||
if (prev === undefined) {
|
if (prev === undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user