import { Command } from "commander"; import { afterEach, describe, expect, it, vi } from "vitest"; import { managedWorktrees } from "../agents/worktrees/service.js"; import { resetConfigRuntimeState, setRuntimeConfigSnapshot } from "../config/config.js"; import type { OpenClawConfig } from "../config/config.js"; import { defaultRuntime } from "../runtime.js"; import { registerWorktreesCli } from "./worktrees-cli.js"; afterEach(() => { vi.restoreAllMocks(); resetConfigRuntimeState(); }); describe("worktrees cli", () => { it("passes session owner activity and configured limits to gc", async () => { const cfg: OpenClawConfig = { worktrees: { cleanup: { maxCount: 25, maxTotalSizeGb: 50 } }, }; setRuntimeConfigSnapshot(cfg, cfg); const gc = vi.spyOn(managedWorktrees, "gc").mockResolvedValue({ removed: [], orphansDeleted: 0, snapshotsPruned: 0, }); vi.spyOn(defaultRuntime, "log").mockImplementation(() => undefined); const program = new Command().name("openclaw"); registerWorktreesCli(program); await program.parseAsync(["worktrees", "gc"], { from: "user" }); expect(gc).toHaveBeenCalledWith({ limits: { maxCount: 25, maxTotalSizeBytes: 50 * 1024 ** 3 }, shouldProtectOwner: expect.any(Function), }); }); });