fix: load config from moltbot and legacy dirs

This commit is contained in:
Peter Steinberger
2026-01-27 12:49:07 +00:00
parent 735aea9efa
commit 58640e9ecb
6 changed files with 209 additions and 29 deletions

View File

@@ -1,7 +1,12 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import { resolveOAuthDir, resolveOAuthPath } from "./paths.js";
import {
resolveDefaultConfigCandidates,
resolveOAuthDir,
resolveOAuthPath,
resolveStateDir,
} from "./paths.js";
describe("oauth paths", () => {
it("prefers CLAWDBOT_OAUTH_DIR over CLAWDBOT_STATE_DIR", () => {
@@ -27,3 +32,21 @@ describe("oauth paths", () => {
);
});
});
describe("state + config path candidates", () => {
it("prefers MOLTBOT_STATE_DIR over legacy state dir env", () => {
const env = {
MOLTBOT_STATE_DIR: "/new/state",
CLAWDBOT_STATE_DIR: "/legacy/state",
} as NodeJS.ProcessEnv;
expect(resolveStateDir(env, () => "/home/test")).toBe(path.resolve("/new/state"));
});
it("orders default config candidates as new then legacy", () => {
const home = "/home/test";
const candidates = resolveDefaultConfigCandidates({} as NodeJS.ProcessEnv, () => home);
expect(candidates[0]).toBe(path.join(home, ".moltbot", "moltbot.json"));
expect(candidates[1]).toBe(path.join(home, ".clawdbot", "moltbot.json"));
});
});