2026-01-06 21:33:53 +00:00
|
|
|
import fs from "node:fs/promises";
|
|
|
|
|
import os from "node:os";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
2026-02-15 21:31:23 +00:00
|
|
|
import { captureEnv } from "../test-utils/env.js";
|
2026-01-30 03:15:10 +01:00
|
|
|
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
2026-01-06 21:33:53 +00:00
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
describe("resolveOpenClawAgentDir", () => {
|
2026-02-15 21:31:23 +00:00
|
|
|
const env = captureEnv(["OPENCLAW_STATE_DIR", "OPENCLAW_AGENT_DIR", "PI_CODING_AGENT_DIR"]);
|
2026-01-06 21:33:53 +00:00
|
|
|
let tempStateDir: string | null = null;
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
|
if (tempStateDir) {
|
|
|
|
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
|
|
|
|
tempStateDir = null;
|
|
|
|
|
}
|
2026-02-15 21:31:23 +00:00
|
|
|
env.restore();
|
2026-01-06 21:33:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("defaults to the multi-agent path when no overrides are set", async () => {
|
2026-01-30 03:15:10 +01:00
|
|
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
|
|
|
|
process.env.OPENCLAW_STATE_DIR = tempStateDir;
|
|
|
|
|
delete process.env.OPENCLAW_AGENT_DIR;
|
2026-01-06 21:33:53 +00:00
|
|
|
delete process.env.PI_CODING_AGENT_DIR;
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
const resolved = resolveOpenClawAgentDir();
|
2026-01-06 21:33:53 +00:00
|
|
|
|
|
|
|
|
expect(resolved).toBe(path.join(tempStateDir, "agents", "main", "agent"));
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
it("honors OPENCLAW_AGENT_DIR overrides", async () => {
|
|
|
|
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
2026-01-06 21:33:53 +00:00
|
|
|
const override = path.join(tempStateDir, "agent");
|
2026-01-30 03:15:10 +01:00
|
|
|
process.env.OPENCLAW_AGENT_DIR = override;
|
2026-01-06 21:33:53 +00:00
|
|
|
delete process.env.PI_CODING_AGENT_DIR;
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
const resolved = resolveOpenClawAgentDir();
|
2026-01-06 21:33:53 +00:00
|
|
|
|
|
|
|
|
expect(resolved).toBe(path.resolve(override));
|
|
|
|
|
});
|
|
|
|
|
});
|