test(config): dedupe io fixture wiring and cover legacy config-path override

This commit is contained in:
Peter Steinberger
2026-02-21 19:45:23 +00:00
parent d35a8b48f5
commit 1794f42ac0

View File

@@ -26,14 +26,18 @@ async function writeConfig(
return configPath;
}
function createIoForHome(home: string, env: NodeJS.ProcessEnv = {} as NodeJS.ProcessEnv) {
return createConfigIO({
env,
homedir: () => home,
});
}
describe("config io paths", () => {
it("uses ~/.openclaw/openclaw.json when config exists", async () => {
await withTempHome(async (home) => {
const configPath = await writeConfig(home, ".openclaw", 19001);
const io = createConfigIO({
env: {} as NodeJS.ProcessEnv,
homedir: () => home,
});
const io = createIoForHome(home);
expect(io.configPath).toBe(configPath);
expect(io.loadConfig().gateway?.port).toBe(19001);
});
@@ -41,10 +45,7 @@ describe("config io paths", () => {
it("defaults to ~/.openclaw/openclaw.json when config is missing", async () => {
await withTempHome(async (home) => {
const io = createConfigIO({
env: {} as NodeJS.ProcessEnv,
homedir: () => home,
});
const io = createIoForHome(home);
expect(io.configPath).toBe(path.join(home, ".openclaw", "openclaw.json"));
});
});
@@ -62,12 +63,18 @@ describe("config io paths", () => {
it("honors explicit OPENCLAW_CONFIG_PATH override", async () => {
await withTempHome(async (home) => {
const customPath = await writeConfig(home, ".openclaw", 20002, "custom.json");
const io = createConfigIO({
env: { OPENCLAW_CONFIG_PATH: customPath } as NodeJS.ProcessEnv,
homedir: () => home,
});
const io = createIoForHome(home, { OPENCLAW_CONFIG_PATH: customPath } as NodeJS.ProcessEnv);
expect(io.configPath).toBe(customPath);
expect(io.loadConfig().gateway?.port).toBe(20002);
});
});
it("honors legacy CLAWDBOT_CONFIG_PATH override", async () => {
await withTempHome(async (home) => {
const customPath = await writeConfig(home, ".openclaw", 20003, "legacy-custom.json");
const io = createIoForHome(home, { CLAWDBOT_CONFIG_PATH: customPath } as NodeJS.ProcessEnv);
expect(io.configPath).toBe(customPath);
expect(io.loadConfig().gateway?.port).toBe(20003);
});
});
});