From ecc6243edc5680450a1e25931e4660cf0c426e0d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 12 Jan 2026 01:53:42 +0000 Subject: [PATCH] test: cover tilde path expansion --- src/config/config.test.ts | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/config/config.test.ts b/src/config/config.test.ts index fc337bcca..94f0af9cf 100644 --- a/src/config/config.test.ts +++ b/src/config/config.test.ts @@ -676,6 +676,20 @@ describe("Nix integration (U3, U5, U9)", () => { ); }); + it("CONFIG_PATH_CLAWDBOT expands ~ in CLAWDBOT_CONFIG_PATH override", async () => { + await withTempHome(async (home) => { + await withEnvOverride( + { CLAWDBOT_CONFIG_PATH: "~/.clawdbot/custom.json" }, + async () => { + const { CONFIG_PATH_CLAWDBOT } = await import("./config.js"); + expect(CONFIG_PATH_CLAWDBOT).toBe( + path.join(home, ".clawdbot", "custom.json"), + ); + }, + ); + }); + }); + it("CONFIG_PATH_CLAWDBOT uses STATE_DIR_CLAWDBOT when only state dir is overridden", async () => { await withEnvOverride( { @@ -692,6 +706,71 @@ describe("Nix integration (U3, U5, U9)", () => { }); }); + describe("U5b: tilde expansion for config paths", () => { + it("expands ~ in common path-ish config fields", async () => { + await withTempHome(async (home) => { + const configDir = path.join(home, ".clawdbot"); + await fs.mkdir(configDir, { recursive: true }); + await fs.writeFile( + path.join(configDir, "clawdbot.json"), + JSON.stringify( + { + plugins: { + load: { + paths: ["~/plugins/demo-plugin"], + }, + }, + agents: { + defaults: { workspace: "~/ws-default" }, + list: [ + { + id: "main", + workspace: "~/ws-agent", + agentDir: "~/.clawdbot/agents/main", + sandbox: { workspaceRoot: "~/sandbox-root" }, + }, + ], + }, + whatsapp: { + accounts: { + personal: { + authDir: "~/.clawdbot/credentials/wa-personal", + }, + }, + }, + }, + null, + 2, + ), + "utf-8", + ); + + vi.resetModules(); + const { loadConfig } = await import("./config.js"); + const cfg = loadConfig(); + + expect(cfg.plugins?.load?.paths?.[0]).toBe( + path.join(home, "plugins", "demo-plugin"), + ); + expect(cfg.agents?.defaults?.workspace).toBe( + path.join(home, "ws-default"), + ); + expect(cfg.agents?.list?.[0]?.workspace).toBe( + path.join(home, "ws-agent"), + ); + expect(cfg.agents?.list?.[0]?.agentDir).toBe( + path.join(home, ".clawdbot", "agents", "main"), + ); + expect(cfg.agents?.list?.[0]?.sandbox?.workspaceRoot).toBe( + path.join(home, "sandbox-root"), + ); + expect(cfg.whatsapp?.accounts?.personal?.authDir).toBe( + path.join(home, ".clawdbot", "credentials", "wa-personal"), + ); + }); + }); + }); + describe("U6: gateway port resolution", () => { it("uses default when env and config are unset", async () => { await withEnvOverride({ CLAWDBOT_GATEWAY_PORT: undefined }, async () => {