From e3960cde3fc854c0f675bf1e509931ce8b4500e8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 12 Jan 2026 01:55:55 +0000 Subject: [PATCH] test: add normalizeConfigPaths unit test --- src/config/normalize-paths.test.ts | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/config/normalize-paths.test.ts diff --git a/src/config/normalize-paths.test.ts b/src/config/normalize-paths.test.ts new file mode 100644 index 000000000..5312337b5 --- /dev/null +++ b/src/config/normalize-paths.test.ts @@ -0,0 +1,77 @@ +import path from "node:path"; + +import { describe, expect, it, vi } from "vitest"; + +import { withTempHome } from "../../test/helpers/temp-home.js"; + +describe("normalizeConfigPaths", () => { + it("expands tilde for path-ish keys only", async () => { + await withTempHome(async (home) => { + vi.resetModules(); + const { normalizeConfigPaths } = await import("./normalize-paths.js"); + + const cfg = normalizeConfigPaths({ + plugins: { load: { paths: ["~/plugins/a"] } }, + logging: { file: "~/.clawdbot/logs/clawdbot.log" }, + hooks: { + path: "~/.clawdbot/hooks.json5", + transformsDir: "~/hooks-xform", + }, + telegram: { + accounts: { + personal: { + tokenFile: "~/.clawdbot/telegram.token", + }, + }, + }, + imessage: { + accounts: { personal: { dbPath: "~/Library/Messages/chat.db" } }, + }, + agents: { + defaults: { workspace: "~/ws-default" }, + list: [ + { + id: "main", + workspace: "~/ws-agent", + agentDir: "~/.clawdbot/agents/main", + identity: { + name: "~not-a-path", + }, + sandbox: { workspaceRoot: "~/sandbox-root" }, + }, + ], + }, + }); + + expect(cfg.plugins?.load?.paths?.[0]).toBe( + path.join(home, "plugins", "a"), + ); + expect(cfg.logging?.file).toBe( + path.join(home, ".clawdbot", "logs", "clawdbot.log"), + ); + expect(cfg.hooks?.path).toBe(path.join(home, ".clawdbot", "hooks.json5")); + expect(cfg.hooks?.transformsDir).toBe(path.join(home, "hooks-xform")); + expect(cfg.telegram?.accounts?.personal?.tokenFile).toBe( + path.join(home, ".clawdbot", "telegram.token"), + ); + expect(cfg.imessage?.accounts?.personal?.dbPath).toBe( + path.join(home, "Library", "Messages", "chat.db"), + ); + 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"), + ); + + // Non-path key => do not treat "~" as home expansion. + expect(cfg.agents?.list?.[0]?.identity?.name).toBe("~not-a-path"); + }); + }); +});