mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:40:43 +00:00
test: share cleanup command harness
This commit is contained in:
48
src/commands/cleanup-command.test-support.ts
Normal file
48
src/commands/cleanup-command.test-support.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { vi } from "vitest";
|
||||
import { createNonExitingRuntime, type RuntimeEnv } from "../runtime.js";
|
||||
|
||||
export const resolveCleanupPlanFromDisk = vi.fn();
|
||||
export const removePath = vi.fn();
|
||||
export const listAgentSessionDirs = vi.fn();
|
||||
export const removeStateAndLinkedPaths = vi.fn();
|
||||
export const removeWorkspaceDirs = vi.fn();
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
isNixMode: false,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-plan.js", () => ({
|
||||
resolveCleanupPlanFromDisk,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-utils.js", () => ({
|
||||
removePath,
|
||||
listAgentSessionDirs,
|
||||
removeStateAndLinkedPaths,
|
||||
removeWorkspaceDirs,
|
||||
}));
|
||||
|
||||
export function createCleanupCommandRuntime() {
|
||||
return createNonExitingRuntime();
|
||||
}
|
||||
|
||||
export function resetCleanupCommandMocks() {
|
||||
vi.clearAllMocks();
|
||||
resolveCleanupPlanFromDisk.mockReturnValue({
|
||||
stateDir: "/tmp/.openclaw",
|
||||
configPath: "/tmp/.openclaw/openclaw.json",
|
||||
oauthDir: "/tmp/.openclaw/credentials",
|
||||
configInsideState: true,
|
||||
oauthInsideState: true,
|
||||
workspaceDirs: ["/tmp/.openclaw/workspace"],
|
||||
});
|
||||
removePath.mockResolvedValue({ ok: true });
|
||||
listAgentSessionDirs.mockResolvedValue(["/tmp/.openclaw/agents/main/sessions"]);
|
||||
removeStateAndLinkedPaths.mockResolvedValue(undefined);
|
||||
removeWorkspaceDirs.mockResolvedValue(undefined);
|
||||
}
|
||||
|
||||
export function silenceCleanupCommandRuntime(runtime: RuntimeEnv) {
|
||||
vi.spyOn(runtime, "log").mockImplementation(() => {});
|
||||
vi.spyOn(runtime, "error").mockImplementation(() => {});
|
||||
}
|
||||
@@ -1,28 +1,12 @@
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createNonExitingRuntime } from "../runtime.js";
|
||||
const resolveCleanupPlanFromDisk = vi.fn();
|
||||
const removePath = vi.fn();
|
||||
const listAgentSessionDirs = vi.fn();
|
||||
const removeStateAndLinkedPaths = vi.fn();
|
||||
const removeWorkspaceDirs = vi.fn();
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
isNixMode: false,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-plan.js", () => ({
|
||||
resolveCleanupPlanFromDisk,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-utils.js", () => ({
|
||||
removePath,
|
||||
listAgentSessionDirs,
|
||||
removeStateAndLinkedPaths,
|
||||
removeWorkspaceDirs,
|
||||
}));
|
||||
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createCleanupCommandRuntime,
|
||||
resetCleanupCommandMocks,
|
||||
silenceCleanupCommandRuntime,
|
||||
} from "./cleanup-command.test-support.js";
|
||||
|
||||
describe("resetCommand", () => {
|
||||
const runtime = createNonExitingRuntime();
|
||||
const runtime = createCleanupCommandRuntime();
|
||||
let resetCommand: typeof import("./reset.js").resetCommand;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -30,21 +14,8 @@ describe("resetCommand", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
resolveCleanupPlanFromDisk.mockReturnValue({
|
||||
stateDir: "/tmp/.openclaw",
|
||||
configPath: "/tmp/.openclaw/openclaw.json",
|
||||
oauthDir: "/tmp/.openclaw/credentials",
|
||||
configInsideState: true,
|
||||
oauthInsideState: true,
|
||||
workspaceDirs: ["/tmp/.openclaw/workspace"],
|
||||
});
|
||||
removePath.mockResolvedValue({ ok: true });
|
||||
listAgentSessionDirs.mockResolvedValue(["/tmp/.openclaw/agents/main/sessions"]);
|
||||
removeStateAndLinkedPaths.mockResolvedValue(undefined);
|
||||
removeWorkspaceDirs.mockResolvedValue(undefined);
|
||||
vi.spyOn(runtime, "log").mockImplementation(() => {});
|
||||
vi.spyOn(runtime, "error").mockImplementation(() => {});
|
||||
resetCleanupCommandMocks();
|
||||
silenceCleanupCommandRuntime(runtime);
|
||||
});
|
||||
|
||||
it("recommends creating a backup before state-destructive reset scopes", async () => {
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createNonExitingRuntime } from "../runtime.js";
|
||||
|
||||
const resolveCleanupPlanFromDisk = vi.fn();
|
||||
const removePath = vi.fn();
|
||||
const removeStateAndLinkedPaths = vi.fn();
|
||||
const removeWorkspaceDirs = vi.fn();
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
isNixMode: false,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-plan.js", () => ({
|
||||
resolveCleanupPlanFromDisk,
|
||||
}));
|
||||
|
||||
vi.mock("./cleanup-utils.js", () => ({
|
||||
removePath,
|
||||
removeStateAndLinkedPaths,
|
||||
removeWorkspaceDirs,
|
||||
}));
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createCleanupCommandRuntime,
|
||||
resetCleanupCommandMocks,
|
||||
silenceCleanupCommandRuntime,
|
||||
} from "./cleanup-command.test-support.js";
|
||||
|
||||
const { uninstallCommand } = await import("./uninstall.js");
|
||||
|
||||
describe("uninstallCommand", () => {
|
||||
const runtime = createNonExitingRuntime();
|
||||
const runtime = createCleanupCommandRuntime();
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
resolveCleanupPlanFromDisk.mockReturnValue({
|
||||
stateDir: "/tmp/.openclaw",
|
||||
configPath: "/tmp/.openclaw/openclaw.json",
|
||||
oauthDir: "/tmp/.openclaw/credentials",
|
||||
configInsideState: true,
|
||||
oauthInsideState: true,
|
||||
workspaceDirs: ["/tmp/.openclaw/workspace"],
|
||||
});
|
||||
removePath.mockResolvedValue({ ok: true });
|
||||
removeStateAndLinkedPaths.mockResolvedValue(undefined);
|
||||
removeWorkspaceDirs.mockResolvedValue(undefined);
|
||||
vi.spyOn(runtime, "log").mockImplementation(() => {});
|
||||
vi.spyOn(runtime, "error").mockImplementation(() => {});
|
||||
resetCleanupCommandMocks();
|
||||
silenceCleanupCommandRuntime(runtime);
|
||||
});
|
||||
|
||||
it("recommends creating a backup before removing state or workspaces", async () => {
|
||||
|
||||
Reference in New Issue
Block a user