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:
@@ -3,6 +3,7 @@ import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import * as connectionManager from "@oh-my-pi/pi-coding-agent/ssh/connection-manager";
|
||||
import { removeWithRetries } from "@oh-my-pi/pi-utils";
|
||||
|
||||
async function withLooseKey<T>(run: (keyPath: string) => Promise<T>): Promise<T> {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-ssh-key-"));
|
||||
@@ -12,7 +13,7 @@ async function withLooseKey<T>(run: (keyPath: string) => Promise<T>): Promise<T>
|
||||
try {
|
||||
return await run(keyPath);
|
||||
} finally {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
await removeWithRetries(dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ describe("buildRemoteCommand", () => {
|
||||
),
|
||||
).rejects.toThrow("SSH key not found");
|
||||
} finally {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
await removeWithRetries(dir);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -106,7 +107,7 @@ describe("buildRemoteCommand", () => {
|
||||
),
|
||||
).rejects.toThrow("SSH key is not a file");
|
||||
} finally {
|
||||
await fs.rm(keyPath, { recursive: true, force: true });
|
||||
await removeWithRetries(keyPath);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user