mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:08:27 +00:00
refactor: rename to openclaw
This commit is contained in:
@@ -12,10 +12,10 @@ import {
|
||||
} from "./paths.js";
|
||||
|
||||
describe("oauth paths", () => {
|
||||
it("prefers CLAWDBOT_OAUTH_DIR over CLAWDBOT_STATE_DIR", () => {
|
||||
it("prefers OPENCLAW_OAUTH_DIR over OPENCLAW_STATE_DIR", () => {
|
||||
const env = {
|
||||
CLAWDBOT_OAUTH_DIR: "/custom/oauth",
|
||||
CLAWDBOT_STATE_DIR: "/custom/state",
|
||||
OPENCLAW_OAUTH_DIR: "/custom/oauth",
|
||||
OPENCLAW_STATE_DIR: "/custom/state",
|
||||
} as NodeJS.ProcessEnv;
|
||||
|
||||
expect(resolveOAuthDir(env, "/custom/state")).toBe(path.resolve("/custom/oauth"));
|
||||
@@ -24,9 +24,9 @@ describe("oauth paths", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("derives oauth path from CLAWDBOT_STATE_DIR when unset", () => {
|
||||
it("derives oauth path from OPENCLAW_STATE_DIR when unset", () => {
|
||||
const env = {
|
||||
CLAWDBOT_STATE_DIR: "/custom/state",
|
||||
OPENCLAW_STATE_DIR: "/custom/state",
|
||||
} as NodeJS.ProcessEnv;
|
||||
|
||||
expect(resolveOAuthDir(env, "/custom/state")).toBe(path.join("/custom/state", "credentials"));
|
||||
@@ -37,28 +37,25 @@ describe("oauth paths", () => {
|
||||
});
|
||||
|
||||
describe("state + config path candidates", () => {
|
||||
it("prefers MOLTBOT_STATE_DIR over legacy state dir env", () => {
|
||||
it("uses OPENCLAW_STATE_DIR when set", () => {
|
||||
const env = {
|
||||
MOLTBOT_STATE_DIR: "/new/state",
|
||||
CLAWDBOT_STATE_DIR: "/legacy/state",
|
||||
OPENCLAW_STATE_DIR: "/new/state",
|
||||
} as NodeJS.ProcessEnv;
|
||||
|
||||
expect(resolveStateDir(env, () => "/home/test")).toBe(path.resolve("/new/state"));
|
||||
});
|
||||
|
||||
it("orders default config candidates as new then legacy", () => {
|
||||
it("orders default config candidates in a stable order", () => {
|
||||
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, ".moltbot", "clawdbot.json"));
|
||||
expect(candidates[2]).toBe(path.join(home, ".clawdbot", "moltbot.json"));
|
||||
expect(candidates[3]).toBe(path.join(home, ".clawdbot", "clawdbot.json"));
|
||||
expect(candidates[0]).toBe(path.join(home, ".openclaw", "openclaw.json"));
|
||||
expect(candidates).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("prefers ~/.moltbot when it exists and legacy dir is missing", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-state-"));
|
||||
it("prefers ~/.openclaw when it exists and legacy dir is missing", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-state-"));
|
||||
try {
|
||||
const newDir = path.join(root, ".moltbot");
|
||||
const newDir = path.join(root, ".openclaw");
|
||||
await fs.mkdir(newDir, { recursive: true });
|
||||
const resolved = resolveStateDir({} as NodeJS.ProcessEnv, () => root);
|
||||
expect(resolved).toBe(newDir);
|
||||
@@ -67,20 +64,18 @@ describe("state + config path candidates", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("CONFIG_PATH prefers existing legacy filename when present", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-config-"));
|
||||
it("CONFIG_PATH prefers existing config when present", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-config-"));
|
||||
const previousHome = process.env.HOME;
|
||||
const previousUserProfile = process.env.USERPROFILE;
|
||||
const previousHomeDrive = process.env.HOMEDRIVE;
|
||||
const previousHomePath = process.env.HOMEPATH;
|
||||
const previousMoltbotConfig = process.env.MOLTBOT_CONFIG_PATH;
|
||||
const previousClawdbotConfig = process.env.CLAWDBOT_CONFIG_PATH;
|
||||
const previousMoltbotState = process.env.MOLTBOT_STATE_DIR;
|
||||
const previousClawdbotState = process.env.CLAWDBOT_STATE_DIR;
|
||||
const previousOpenClawConfig = process.env.OPENCLAW_CONFIG_PATH;
|
||||
const previousOpenClawState = process.env.OPENCLAW_STATE_DIR;
|
||||
try {
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
const legacyDir = path.join(root, ".openclaw");
|
||||
await fs.mkdir(legacyDir, { recursive: true });
|
||||
const legacyPath = path.join(legacyDir, "clawdbot.json");
|
||||
const legacyPath = path.join(legacyDir, "openclaw.json");
|
||||
await fs.writeFile(legacyPath, "{}", "utf-8");
|
||||
|
||||
process.env.HOME = root;
|
||||
@@ -90,10 +85,8 @@ describe("state + config path candidates", () => {
|
||||
process.env.HOMEDRIVE = parsed.root.replace(/\\$/, "");
|
||||
process.env.HOMEPATH = root.slice(parsed.root.length - 1);
|
||||
}
|
||||
delete process.env.MOLTBOT_CONFIG_PATH;
|
||||
delete process.env.CLAWDBOT_CONFIG_PATH;
|
||||
delete process.env.MOLTBOT_STATE_DIR;
|
||||
delete process.env.CLAWDBOT_STATE_DIR;
|
||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
|
||||
vi.resetModules();
|
||||
const { CONFIG_PATH } = await import("./paths.js");
|
||||
@@ -110,31 +103,31 @@ describe("state + config path candidates", () => {
|
||||
else process.env.HOMEDRIVE = previousHomeDrive;
|
||||
if (previousHomePath === undefined) delete process.env.HOMEPATH;
|
||||
else process.env.HOMEPATH = previousHomePath;
|
||||
if (previousMoltbotConfig === undefined) delete process.env.MOLTBOT_CONFIG_PATH;
|
||||
else process.env.MOLTBOT_CONFIG_PATH = previousMoltbotConfig;
|
||||
if (previousClawdbotConfig === undefined) delete process.env.CLAWDBOT_CONFIG_PATH;
|
||||
else process.env.CLAWDBOT_CONFIG_PATH = previousClawdbotConfig;
|
||||
if (previousMoltbotState === undefined) delete process.env.MOLTBOT_STATE_DIR;
|
||||
else process.env.MOLTBOT_STATE_DIR = previousMoltbotState;
|
||||
if (previousClawdbotState === undefined) delete process.env.CLAWDBOT_STATE_DIR;
|
||||
else process.env.CLAWDBOT_STATE_DIR = previousClawdbotState;
|
||||
if (previousOpenClawConfig === undefined) delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
else process.env.OPENCLAW_CONFIG_PATH = previousOpenClawConfig;
|
||||
if (previousOpenClawConfig === undefined) delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
else process.env.OPENCLAW_CONFIG_PATH = previousOpenClawConfig;
|
||||
if (previousOpenClawState === undefined) delete process.env.OPENCLAW_STATE_DIR;
|
||||
else process.env.OPENCLAW_STATE_DIR = previousOpenClawState;
|
||||
if (previousOpenClawState === undefined) delete process.env.OPENCLAW_STATE_DIR;
|
||||
else process.env.OPENCLAW_STATE_DIR = previousOpenClawState;
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
vi.resetModules();
|
||||
}
|
||||
});
|
||||
|
||||
it("respects state dir overrides when config is missing", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-config-override-"));
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-config-override-"));
|
||||
try {
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
const legacyDir = path.join(root, ".openclaw");
|
||||
await fs.mkdir(legacyDir, { recursive: true });
|
||||
const legacyConfig = path.join(legacyDir, "moltbot.json");
|
||||
const legacyConfig = path.join(legacyDir, "openclaw.json");
|
||||
await fs.writeFile(legacyConfig, "{}", "utf-8");
|
||||
|
||||
const overrideDir = path.join(root, "override");
|
||||
const env = { MOLTBOT_STATE_DIR: overrideDir } as NodeJS.ProcessEnv;
|
||||
const env = { OPENCLAW_STATE_DIR: overrideDir } as NodeJS.ProcessEnv;
|
||||
const resolved = resolveConfigPath(env, overrideDir, () => root);
|
||||
expect(resolved).toBe(path.join(overrideDir, "moltbot.json"));
|
||||
expect(resolved).toBe(path.join(overrideDir, "openclaw.json"));
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user