Files
oh-my-pi/packages/coding-agent/test/helpers/temp-home-cleanup.ts
T
oldschoola fa903b2b2c fix(test): migrate fs.rmSync to removeSyncWithRetries for EBUSY-safe cleanup
Export removeSyncWithRetries from @oh-my-pi/pi-utils as a standalone
function, then migrate the highest-impact fs.rmSync call sites:

- test/helpers/temp-home-cleanup.ts: 2 fs.rmSync → removeSyncWithRetries
  (affects all tests using the cleanupTempHome helper)
- test/core/apply-patch-regression.test.ts: 16 fs.rmSync → removeSyncWithRetries
  (the most fs.rmSync calls of any test file)

removeSyncWithRetries retries on EBUSY/EPERM/ENOTEMPTY (40x25ms on
Windows), matching TempDir.removeSync's retry logic. On Linux/macOS
(CI) the retries are a no-op — fs.rmSync succeeds immediately.
2026-06-19 17:27:54 -07:00

25 lines
567 B
TypeScript

import { removeSyncWithRetries } from "@oh-my-pi/pi-utils";
export interface TempHomeState {
tempDir: string;
tempHomeDir: string;
originalHome: string | undefined;
}
export function cleanupTempHome(getState: () => TempHomeState): () => void {
return () => {
const { tempDir, tempHomeDir, originalHome } = getState();
if (tempDir) {
removeSyncWithRetries(tempDir);
}
if (tempHomeDir) {
removeSyncWithRetries(tempHomeDir);
}
if (originalHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = originalHome;
}
};
}