mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix: honor state dir override in config resolution
This commit is contained in:
@@ -5,6 +5,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
resolveDefaultConfigCandidates,
|
||||
resolveConfigPath,
|
||||
resolveOAuthDir,
|
||||
resolveOAuthPath,
|
||||
resolveStateDir,
|
||||
@@ -106,4 +107,21 @@ describe("state + config path candidates", () => {
|
||||
vi.resetModules();
|
||||
}
|
||||
});
|
||||
|
||||
it("respects state dir overrides when config is missing", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-config-override-"));
|
||||
try {
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
await fs.mkdir(legacyDir, { recursive: true });
|
||||
const legacyConfig = path.join(legacyDir, "moltbot.json");
|
||||
await fs.writeFile(legacyConfig, "{}", "utf-8");
|
||||
|
||||
const overrideDir = path.join(root, "override");
|
||||
const env = { MOLTBOT_STATE_DIR: overrideDir } as NodeJS.ProcessEnv;
|
||||
const resolved = resolveConfigPath(env, overrideDir, () => root);
|
||||
expect(resolved).toBe(path.join(overrideDir, "moltbot.json"));
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,6 +113,7 @@ export function resolveConfigPath(
|
||||
): string {
|
||||
const override = env.MOLTBOT_CONFIG_PATH?.trim() || env.CLAWDBOT_CONFIG_PATH?.trim();
|
||||
if (override) return resolveUserPath(override);
|
||||
const stateOverride = env.MOLTBOT_STATE_DIR?.trim() || env.CLAWDBOT_STATE_DIR?.trim();
|
||||
const candidates = [
|
||||
path.join(stateDir, CONFIG_FILENAME),
|
||||
path.join(stateDir, LEGACY_CONFIG_FILENAME),
|
||||
@@ -125,6 +126,7 @@ export function resolveConfigPath(
|
||||
}
|
||||
});
|
||||
if (existing) return existing;
|
||||
if (stateOverride) return path.join(stateDir, CONFIG_FILENAME);
|
||||
const defaultStateDir = resolveStateDir(env, homedir);
|
||||
if (path.resolve(stateDir) === path.resolve(defaultStateDir)) {
|
||||
return resolveConfigPathCandidate(env, homedir);
|
||||
|
||||
Reference in New Issue
Block a user