diff --git a/packages/cli/test/acp/subprocess.ts b/packages/cli/test/acp/subprocess.ts index 9ca913371f8..c0265fb5dd3 100644 --- a/packages/cli/test/acp/subprocess.ts +++ b/packages/cli/test/acp/subprocess.ts @@ -97,9 +97,7 @@ export async function createAcpFixture( [...processes].map((process) => process.close().catch(() => process[Symbol.asyncDispose]())), ) const serverResults = await Promise.allSettled([llm.stop(true)]) - const directoryResults = await Promise.allSettled([ - fs.rm(root, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 }), - ]) + const directoryResults = await Promise.allSettled([removeRoot(root)]) const failure = [...processResults, ...serverResults, ...directoryResults].find( (result): result is PromiseRejectedResult => result.status === "rejected", ) @@ -108,6 +106,19 @@ export async function createAcpFixture( } } +// ACP exits without waiting for its standalone server, which holds files under root until its own teardown ends. +// On Windows removal fails with EBUSY until then, which can outlast fs.rm's own retries, so retry for longer. +async function removeRoot(root: string, deadline = Date.now() + 15_000): Promise { + try { + await fs.rm(root, { recursive: true, force: true }) + } catch (error) { + const busy = !!error && typeof error === "object" && "code" in error && error.code === "EBUSY" + if (!busy || Date.now() >= deadline) throw error + await Bun.sleep(100) + return removeRoot(root, deadline) + } +} + export function initialize(acp: AcpProcess) { return acp .request("initialize", {