mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 19:44:59 +00:00
refactor: rename to openclaw
This commit is contained in:
@@ -4,7 +4,7 @@ import path from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
autoMigrateLegacyStateDir,
|
||||
autoMigrateLegacyState,
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
let tempRoot: string | null = null;
|
||||
|
||||
async function makeTempRoot() {
|
||||
const root = await fs.promises.mkdtemp(path.join(os.tmpdir(), "moltbot-doctor-"));
|
||||
const root = await fs.promises.mkdtemp(path.join(os.tmpdir(), "openclaw-doctor-"));
|
||||
tempRoot = root;
|
||||
return root;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ function writeJson5(filePath: string, value: unknown) {
|
||||
describe("doctor legacy state migrations", () => {
|
||||
it("migrates legacy sessions into agents/<id>/sessions", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
const legacySessionsDir = path.join(root, "sessions");
|
||||
fs.mkdirSync(legacySessionsDir, { recursive: true });
|
||||
|
||||
@@ -54,7 +54,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
const result = await runLegacyStateMigrations({
|
||||
detected,
|
||||
@@ -82,7 +82,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("migrates legacy agent dir with conflict fallback", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
const legacyAgentDir = path.join(root, "agent");
|
||||
fs.mkdirSync(legacyAgentDir, { recursive: true });
|
||||
@@ -95,7 +95,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -106,7 +106,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("auto-migrates legacy agent dir on startup", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
const legacyAgentDir = path.join(root, "agent");
|
||||
fs.mkdirSync(legacyAgentDir, { recursive: true });
|
||||
@@ -116,7 +116,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const result = await autoMigrateLegacyState({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
log,
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("auto-migrates legacy sessions on startup", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
const legacySessionsDir = path.join(root, "sessions");
|
||||
fs.mkdirSync(legacySessionsDir, { recursive: true });
|
||||
@@ -141,7 +141,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const result = await autoMigrateLegacyState({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
log,
|
||||
now: () => 123,
|
||||
});
|
||||
@@ -157,7 +157,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("migrates legacy WhatsApp auth files without touching oauth.json", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
const oauthDir = path.join(root, "credentials");
|
||||
fs.mkdirSync(oauthDir, { recursive: true });
|
||||
@@ -167,7 +167,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -180,10 +180,10 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("no-ops when nothing detected", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
const result = await runLegacyStateMigrations({ detected });
|
||||
expect(result.changes).toEqual([]);
|
||||
@@ -191,7 +191,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("routes legacy state to the default agent entry", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: { list: [{ id: "alpha", default: true }] },
|
||||
};
|
||||
const legacySessionsDir = path.join(root, "sessions");
|
||||
@@ -202,7 +202,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -215,7 +215,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("honors session.mainKey when seeding the direct-chat bucket", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = { session: { mainKey: "work" } };
|
||||
const cfg: OpenClawConfig = { session: { mainKey: "work" } };
|
||||
const legacySessionsDir = path.join(root, "sessions");
|
||||
fs.mkdirSync(legacySessionsDir, { recursive: true });
|
||||
writeJson5(path.join(legacySessionsDir, "sessions.json"), {
|
||||
@@ -225,7 +225,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -239,7 +239,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("canonicalizes legacy main keys inside the target sessions store", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
const targetDir = path.join(root, "agents", "main", "sessions");
|
||||
writeJson5(path.join(targetDir, "sessions.json"), {
|
||||
main: { sessionId: "legacy", updatedAt: 10 },
|
||||
@@ -248,7 +248,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -261,7 +261,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("prefers the newest entry when collapsing main aliases", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = { session: { mainKey: "work" } };
|
||||
const cfg: OpenClawConfig = { session: { mainKey: "work" } };
|
||||
const targetDir = path.join(root, "agents", "main", "sessions");
|
||||
writeJson5(path.join(targetDir, "sessions.json"), {
|
||||
"agent:main:main": { sessionId: "legacy", updatedAt: 50 },
|
||||
@@ -270,7 +270,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -283,7 +283,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("lowercases agent session keys during canonicalization", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
const targetDir = path.join(root, "agents", "main", "sessions");
|
||||
writeJson5(path.join(targetDir, "sessions.json"), {
|
||||
"agent:main:slack:channel:C123": { sessionId: "legacy", updatedAt: 10 },
|
||||
@@ -291,7 +291,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
|
||||
@@ -304,7 +304,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
it("auto-migrates when only target sessions contain legacy keys", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: MoltbotConfig = {};
|
||||
const cfg: OpenClawConfig = {};
|
||||
const targetDir = path.join(root, "agents", "main", "sessions");
|
||||
writeJson5(path.join(targetDir, "sessions.json"), {
|
||||
main: { sessionId: "legacy", updatedAt: 10 },
|
||||
@@ -314,7 +314,7 @@ describe("doctor legacy state migrations", () => {
|
||||
|
||||
const result = await autoMigrateLegacyState({
|
||||
cfg,
|
||||
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
log,
|
||||
});
|
||||
|
||||
@@ -327,48 +327,25 @@ describe("doctor legacy state migrations", () => {
|
||||
expect(store["agent:main:main"]?.sessionId).toBe("legacy");
|
||||
});
|
||||
|
||||
it("auto-migrates legacy state dir to ~/.moltbot", async () => {
|
||||
it("does nothing when no legacy state dir exists", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
fs.mkdirSync(legacyDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(legacyDir, "foo.txt"), "legacy", "utf-8");
|
||||
|
||||
const result = await autoMigrateLegacyStateDir({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
homedir: () => root,
|
||||
});
|
||||
|
||||
const targetDir = path.join(root, ".moltbot");
|
||||
expect(fs.existsSync(path.join(targetDir, "foo.txt"))).toBe(true);
|
||||
const legacyStat = fs.lstatSync(legacyDir);
|
||||
expect(legacyStat.isSymbolicLink()).toBe(true);
|
||||
expect(fs.realpathSync(legacyDir)).toBe(fs.realpathSync(targetDir));
|
||||
expect(result.migrated).toBe(true);
|
||||
});
|
||||
|
||||
it("skips state dir migration when target exists", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
const targetDir = path.join(root, ".moltbot");
|
||||
fs.mkdirSync(legacyDir, { recursive: true });
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
|
||||
const result = await autoMigrateLegacyStateDir({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
homedir: () => root,
|
||||
});
|
||||
|
||||
expect(result.migrated).toBe(false);
|
||||
expect(result.warnings.length).toBeGreaterThan(0);
|
||||
expect(result.skipped).toBe(false);
|
||||
expect(result.warnings).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("skips state dir migration when env override is set", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const legacyDir = path.join(root, ".clawdbot");
|
||||
const legacyDir = path.join(root, ".openclaw");
|
||||
fs.mkdirSync(legacyDir, { recursive: true });
|
||||
|
||||
const result = await autoMigrateLegacyStateDir({
|
||||
env: { MOLTBOT_STATE_DIR: "/custom/state" } as NodeJS.ProcessEnv,
|
||||
env: { OPENCLAW_STATE_DIR: "/custom/state" } as NodeJS.ProcessEnv,
|
||||
homedir: () => root,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user