Files
hyperframes/packages/core/src/removeTree.test.ts
T
Miguel Ángel 142f246d7c fix(cli): a finished capture no longer fails when Windows refuses to delete its Chrome profile (#6505)
Chrome's profile lockfile is held for a moment after the browser exits, so removing the
capture profile threw EBUSY and a finished capture exited 1. The profile and staging
removals now go through a core helper that retries transient locks and, for cleanup of
finished work, warns instead of failing.
2026-10-27 03:10:11 +00:00

60 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import {
removeTreeBestEffort,
removeTreeBestEffortAsync,
removeTreeWithRetry,
removeTreeWithRetryAsync,
} from "./removeTree.js";
const busy = () => Object.assign(new Error("EBUSY: resource busy or locked"), { code: "EBUSY" });
const retrying = expect.objectContaining({
recursive: true,
force: true,
maxRetries: expect.any(Number),
});
describe("removeTree", () => {
it("asks for retries so a lock that clears in a moment does not fail the removal", () => {
const remove = vi.fn();
removeTreeWithRetry("/p", remove);
expect(remove).toHaveBeenCalledWith("/p", retrying);
const options = remove.mock.calls[0]![1];
expect(options.maxRetries).toBeGreaterThan(3);
expect(options.retryDelay).toBeGreaterThan(0);
});
it("still throws when a removal the caller needs keeps failing", async () => {
expect(() =>
removeTreeWithRetry("/p", () => {
throw busy();
}),
).toThrow("EBUSY");
await expect(removeTreeWithRetryAsync("/p", () => Promise.reject(busy()))).rejects.toThrow(
"EBUSY",
);
});
it("warns and returns when cleanup of finished work is refused", async () => {
const warn = vi.fn();
expect(() =>
removeTreeBestEffort("/profile", {
remove: () => {
throw busy();
},
warn,
}),
).not.toThrow();
await removeTreeBestEffortAsync("/profile", { remove: () => Promise.reject(busy()), warn });
expect(warn).toHaveBeenCalledTimes(2);
expect(warn.mock.calls[0]![0]).toContain("/profile");
expect(warn.mock.calls[0]![0]).toContain("EBUSY");
});
it("stays quiet when the removal works", async () => {
const warn = vi.fn();
removeTreeBestEffort("/p", { remove: () => {}, warn });
await removeTreeBestEffortAsync("/p", { remove: async () => {}, warn });
expect(warn).not.toHaveBeenCalled();
});
});