fix: migrate coding-agent tests from fs.rm to removeWithRetries

Migrate 203 test files (356 call sites) from fs.rm/fs.rmSync to
removeWithRetries/removeSyncWithRetries to reduce EBUSY test failures
on Windows. removeWithRetries is now exported from @oh-my-pi/pi-utils.

The migration uses a regex-based approach that:
- Replaces fs.rm(path, { recursive, force }) → removeWithRetries(path)
- Replaces fs.rmSync(path, { recursive, force }) → removeSyncWithRetries(path)
- Replaces fs.rm(path) → removeWithRetries(path) (no options)
- Skips fs.rm/fs.rmSync inside template literals (bun --eval scripts)
- Adds imports to existing @oh-my-pi/pi-utils import or creates new one
- Removes unused fs imports where fs.rm was the only fs usage (4 files)
This commit is contained in:
oldschoola
2026-06-23 15:21:27 -07:00
parent 93d730c01d
commit a2854ba768
204 changed files with 572 additions and 439 deletions
@@ -14,6 +14,7 @@ import type {
} from "@oh-my-pi/pi-coding-agent/dap/types";
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
import { DebugTool } from "@oh-my-pi/pi-coding-agent/tools/debug";
import { removeWithRetries } from "@oh-my-pi/pi-utils";
const TEST_ADAPTER: DapResolvedAdapter = {
name: "lldb-dap",
@@ -339,7 +340,7 @@ describe("DAP launch failure handling", () => {
expect(client.isAlive()).toBe(true);
} finally {
await client?.dispose();
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
});
});
@@ -364,7 +365,7 @@ describe("DebugTool launch validation", () => {
/launch program resolves to a directory.*python/,
);
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
launchSpy.mockRestore();
@@ -407,7 +408,7 @@ describe("DebugTool launch validation", () => {
expect(opts.extraLaunchArguments).toEqual({ mode: "debug" });
expect(opts.program).toBe(path.join(cwd, "cmd"));
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
sessionLaunchSpy.mockRestore();
@@ -444,7 +445,7 @@ describe("DebugTool launch validation", () => {
expect(opts.adapter.name).toBe("dlv");
expect(opts.extraLaunchArguments).toEqual({ mode: "debug" });
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
sessionLaunchSpy.mockRestore();
@@ -483,7 +484,7 @@ describe("DebugTool launch validation", () => {
const [opts] = sessionLaunchSpy.mock.calls[0]!;
expect(opts.extraLaunchArguments).toEqual({ mode: "exec" });
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
sessionLaunchSpy.mockRestore();
@@ -510,7 +511,7 @@ describe("DebugTool launch validation", () => {
tool.execute("call", { action: "launch", program: "main.py", adapter: "debugpy" }),
).rejects.toThrow(/debugpy.*python not found in PATH/);
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
launchSpy.mockRestore();
@@ -535,7 +536,7 @@ describe("DebugTool launch validation", () => {
/debugpy.*python not found in PATH/,
);
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
attachSpy.mockRestore();
@@ -561,7 +562,7 @@ describe("DebugTool launch validation", () => {
/No debugger adapter available/,
);
} finally {
await fs.rm(cwd, { recursive: true, force: true });
await removeWithRetries(cwd);
}
} finally {
launchSpy.mockRestore();
@@ -6,7 +6,7 @@ import type { Model } from "@oh-my-pi/pi-ai";
import { buildModel } from "@oh-my-pi/pi-catalog/build";
import { RawSseDebugBuffer } from "@oh-my-pi/pi-coding-agent/debug/raw-sse-buffer";
import { createReportBundle } from "@oh-my-pi/pi-coding-agent/debug/report-bundle";
import { getConfigRootDir, setAgentDir } from "@oh-my-pi/pi-utils";
import { getConfigRootDir, removeWithRetries, setAgentDir } from "@oh-my-pi/pi-utils";
const model: Model<"anthropic-messages"> = buildModel({
id: "claude-test",
@@ -39,7 +39,7 @@ afterEach(async () => {
delete process.env.PI_CODING_AGENT_DIR;
}
if (cleanupRoot) {
await fs.rm(cleanupRoot, { recursive: true, force: true });
await removeWithRetries(cleanupRoot);
cleanupRoot = undefined;
}
});