mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:38:28 +00:00
test(agents): dedupe agent-path fixtures and cover env override precedence
This commit is contained in:
@@ -1,56 +1,85 @@
|
|||||||
import fs from "node:fs/promises";
|
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 { describe, expect, it } from "vitest";
|
||||||
import { withEnv } 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", () => {
|
||||||
let tempStateDir: string | null = null;
|
const withTempStateDir = async (run: (stateDir: string) => void) => {
|
||||||
|
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
|
||||||
afterEach(async () => {
|
try {
|
||||||
if (tempStateDir) {
|
run(stateDir);
|
||||||
await fs.rm(tempStateDir, { recursive: true, force: true });
|
} finally {
|
||||||
tempStateDir = null;
|
await fs.rm(stateDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
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-"));
|
await withTempStateDir((stateDir) => {
|
||||||
const stateDir = tempStateDir;
|
withEnv(
|
||||||
if (!stateDir) {
|
{
|
||||||
throw new Error("expected temp state dir");
|
OPENCLAW_STATE_DIR: stateDir,
|
||||||
}
|
OPENCLAW_AGENT_DIR: undefined,
|
||||||
withEnv(
|
PI_CODING_AGENT_DIR: undefined,
|
||||||
{
|
},
|
||||||
OPENCLAW_STATE_DIR: stateDir,
|
() => {
|
||||||
OPENCLAW_AGENT_DIR: undefined,
|
const resolved = resolveOpenClawAgentDir();
|
||||||
PI_CODING_AGENT_DIR: undefined,
|
expect(resolved).toBe(path.join(stateDir, "agents", "main", "agent"));
|
||||||
},
|
},
|
||||||
() => {
|
);
|
||||||
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-"));
|
await withTempStateDir((stateDir) => {
|
||||||
const stateDir = tempStateDir;
|
const override = path.join(stateDir, "agent");
|
||||||
if (!stateDir) {
|
withEnv(
|
||||||
throw new Error("expected temp state dir");
|
{
|
||||||
}
|
OPENCLAW_STATE_DIR: undefined,
|
||||||
const override = path.join(stateDir, "agent");
|
OPENCLAW_AGENT_DIR: override,
|
||||||
withEnv(
|
PI_CODING_AGENT_DIR: undefined,
|
||||||
{
|
},
|
||||||
OPENCLAW_STATE_DIR: undefined,
|
() => {
|
||||||
OPENCLAW_AGENT_DIR: override,
|
const resolved = resolveOpenClawAgentDir();
|
||||||
PI_CODING_AGENT_DIR: undefined,
|
expect(resolved).toBe(path.resolve(override));
|
||||||
},
|
},
|
||||||
() => {
|
);
|
||||||
const resolved = resolveOpenClawAgentDir();
|
});
|
||||||
expect(resolved).toBe(path.resolve(override));
|
});
|
||||||
},
|
|
||||||
);
|
it("honors PI_CODING_AGENT_DIR when OPENCLAW_AGENT_DIR is unset", async () => {
|
||||||
|
await withTempStateDir((stateDir) => {
|
||||||
|
const override = path.join(stateDir, "pi-agent");
|
||||||
|
withEnv(
|
||||||
|
{
|
||||||
|
OPENCLAW_STATE_DIR: undefined,
|
||||||
|
OPENCLAW_AGENT_DIR: undefined,
|
||||||
|
PI_CODING_AGENT_DIR: override,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
const resolved = resolveOpenClawAgentDir();
|
||||||
|
expect(resolved).toBe(path.resolve(override));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers OPENCLAW_AGENT_DIR over PI_CODING_AGENT_DIR when both are set", async () => {
|
||||||
|
await withTempStateDir((stateDir) => {
|
||||||
|
const primaryOverride = path.join(stateDir, "primary-agent");
|
||||||
|
const fallbackOverride = path.join(stateDir, "fallback-agent");
|
||||||
|
withEnv(
|
||||||
|
{
|
||||||
|
OPENCLAW_STATE_DIR: undefined,
|
||||||
|
OPENCLAW_AGENT_DIR: primaryOverride,
|
||||||
|
PI_CODING_AGENT_DIR: fallbackOverride,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
const resolved = resolveOpenClawAgentDir();
|
||||||
|
expect(resolved).toBe(path.resolve(primaryOverride));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user