From 1794f42ac0447d6880cb65fde377f1a1c399af4e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 19:45:23 +0000 Subject: [PATCH] test(config): dedupe io fixture wiring and cover legacy config-path override --- src/config/io.compat.test.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/config/io.compat.test.ts b/src/config/io.compat.test.ts index bcb6f491b78..7da811a76e1 100644 --- a/src/config/io.compat.test.ts +++ b/src/config/io.compat.test.ts @@ -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); + }); + }); });