mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:57:40 +00:00
refactor(test): use env helper in agent paths e2e
This commit is contained in:
@@ -2,11 +2,10 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
import { withEnv } from "../test-utils/env.js";
|
||||||
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
||||||
|
|
||||||
describe("resolveOpenClawAgentDir", () => {
|
describe("resolveOpenClawAgentDir", () => {
|
||||||
const env = captureEnv(["OPENCLAW_STATE_DIR", "OPENCLAW_AGENT_DIR", "PI_CODING_AGENT_DIR"]);
|
|
||||||
let tempStateDir: string | null = null;
|
let tempStateDir: string | null = null;
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -14,28 +13,44 @@ describe("resolveOpenClawAgentDir", () => {
|
|||||||
await fs.rm(tempStateDir, { recursive: true, force: true });
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
||||||
tempStateDir = null;
|
tempStateDir = null;
|
||||||
}
|
}
|
||||||
env.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to the multi-agent path when no overrides are set", async () => {
|
it("defaults to the multi-agent path when no overrides are set", async () => {
|
||||||
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
||||||
process.env.OPENCLAW_STATE_DIR = tempStateDir;
|
const stateDir = tempStateDir;
|
||||||
delete process.env.OPENCLAW_AGENT_DIR;
|
if (!stateDir) {
|
||||||
delete process.env.PI_CODING_AGENT_DIR;
|
throw new Error("expected temp state dir");
|
||||||
|
}
|
||||||
const resolved = resolveOpenClawAgentDir();
|
withEnv(
|
||||||
|
{
|
||||||
expect(resolved).toBe(path.join(tempStateDir, "agents", "main", "agent"));
|
OPENCLAW_STATE_DIR: stateDir,
|
||||||
|
OPENCLAW_AGENT_DIR: undefined,
|
||||||
|
PI_CODING_AGENT_DIR: undefined,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
const resolved = resolveOpenClawAgentDir();
|
||||||
|
expect(resolved).toBe(path.join(stateDir, "agents", "main", "agent"));
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("honors OPENCLAW_AGENT_DIR overrides", async () => {
|
it("honors OPENCLAW_AGENT_DIR overrides", async () => {
|
||||||
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
||||||
const override = path.join(tempStateDir, "agent");
|
const stateDir = tempStateDir;
|
||||||
process.env.OPENCLAW_AGENT_DIR = override;
|
if (!stateDir) {
|
||||||
delete process.env.PI_CODING_AGENT_DIR;
|
throw new Error("expected temp state dir");
|
||||||
|
}
|
||||||
const resolved = resolveOpenClawAgentDir();
|
const override = path.join(stateDir, "agent");
|
||||||
|
withEnv(
|
||||||
expect(resolved).toBe(path.resolve(override));
|
{
|
||||||
|
OPENCLAW_STATE_DIR: undefined,
|
||||||
|
OPENCLAW_AGENT_DIR: override,
|
||||||
|
PI_CODING_AGENT_DIR: undefined,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
const resolved = resolveOpenClawAgentDir();
|
||||||
|
expect(resolved).toBe(path.resolve(override));
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user