mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 09:22:45 +00:00
refactor(commands): centralize shared command formatting helpers
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, test } from "vitest";
|
||||
import { describe, expect, it, test, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { buildCleanupPlan } from "./cleanup-utils.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
buildCleanupPlan,
|
||||
removeStateAndLinkedPaths,
|
||||
removeWorkspaceDirs,
|
||||
} from "./cleanup-utils.js";
|
||||
import { applyAgentDefaultPrimaryModel } from "./model-default.js";
|
||||
|
||||
describe("buildCleanupPlan", () => {
|
||||
@@ -50,3 +55,47 @@ describe("applyAgentDefaultPrimaryModel", () => {
|
||||
expect(result.next).toBe(cfg);
|
||||
});
|
||||
});
|
||||
|
||||
describe("cleanup path removals", () => {
|
||||
function createRuntimeMock() {
|
||||
return {
|
||||
log: vi.fn<(message: string) => void>(),
|
||||
error: vi.fn<(message: string) => void>(),
|
||||
} as unknown as RuntimeEnv & {
|
||||
log: ReturnType<typeof vi.fn<(message: string) => void>>;
|
||||
error: ReturnType<typeof vi.fn<(message: string) => void>>;
|
||||
};
|
||||
}
|
||||
|
||||
it("removes state and only linked paths outside state", async () => {
|
||||
const runtime = createRuntimeMock();
|
||||
const tmpRoot = path.join(path.parse(process.cwd()).root, "tmp", "openclaw-cleanup");
|
||||
await removeStateAndLinkedPaths(
|
||||
{
|
||||
stateDir: path.join(tmpRoot, "state"),
|
||||
configPath: path.join(tmpRoot, "state", "openclaw.json"),
|
||||
oauthDir: path.join(tmpRoot, "oauth"),
|
||||
configInsideState: true,
|
||||
oauthInsideState: false,
|
||||
},
|
||||
runtime,
|
||||
{ dryRun: true },
|
||||
);
|
||||
|
||||
const joinedLogs = runtime.log.mock.calls.map(([line]) => line).join("\n");
|
||||
expect(joinedLogs).toContain("[dry-run] remove /tmp/openclaw-cleanup/state");
|
||||
expect(joinedLogs).toContain("[dry-run] remove /tmp/openclaw-cleanup/oauth");
|
||||
expect(joinedLogs).not.toContain("openclaw.json");
|
||||
});
|
||||
|
||||
it("removes every workspace directory", async () => {
|
||||
const runtime = createRuntimeMock();
|
||||
const workspaces = ["/tmp/openclaw-workspace-1", "/tmp/openclaw-workspace-2"];
|
||||
|
||||
await removeWorkspaceDirs(workspaces, runtime, { dryRun: true });
|
||||
|
||||
const logs = runtime.log.mock.calls.map(([line]) => line);
|
||||
expect(logs).toContain("[dry-run] remove /tmp/openclaw-workspace-1");
|
||||
expect(logs).toContain("[dry-run] remove /tmp/openclaw-workspace-2");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user