[STG-2477] test(cli): fix flaky Windows EBUSY temp-dir cleanup in functions dev test#2321
Merged
Merged
Conversation
…ions dev test
The functions dev test spawns `browse functions dev`, which itself spawns a
runtime subprocess (a grandchild). afterEach kills only the direct child via
SIGTERM, so on Windows the grandchild runtime can still hold open handles inside
the temp dir when `rm(path, { recursive, force })` runs. `force: true` ignores
missing paths but does NOT retry EBUSY, so Windows CI intermittently fails with
`EBUSY: resource busy or locked, rmdir`.
Add fs.rm's maxRetries/retryDelay options, which exist specifically to retry
transient Windows EBUSY/EPERM/ENOTEMPTY errors during recursive removal.
Test-only change; no runtime/source impact.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
ajmcquilkin
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an intermittent Windows-only CI failure in
packages/cli/tests/cli-functions-contract.test.ts.Failing test:
functions scaffolding and local dev > runs a local dev server and invokes a functionObserved error (Windows CI only):
Root cause
The test spawns
browse functions dev, which in turn spawns a runtime subprocess (a grandchild of the test). TheafterEachcleanup doeschild.kill("SIGTERM")+waitForExit(child)— but on Windowskillonly terminates the direct child, not the grandchild runtime. That grandchild can still hold open file handles inside the per-test temp dir when cleanup runs.The subsequent
rm(path, { recursive: true, force: true })then hits a directory with live handles, and Windows refuses to remove it →EBUSY. Critically,force: trueonly ignores missing paths; it does not retry onEBUSY. Node'sfs.rmexposesmaxRetries/retryDelayprecisely to retry transient WindowsEBUSY/EPERM/ENOTEMPTYerrors during recursive removal.Fix
Add retry options to the temp-dir cleanup
rm(...)call inafterEach:This is the only
rm/rmdircall in the file that removes temp dirs.Scope / impact
E2E Test Matrix
pnpm vitest run tests/cli-functions-contract.test.ts(in<worktree>/packages/cli, afterpnpm install --frozen-lockfile+pnpm turbo run build --filter=browse...)Test Files 1 passed (1)/Tests 13 passed (13); verbose shows✓ ... runs a local dev server and invokes a function 626msEBUSYpath can't be reproduced on macOS (POSIX unlinks directories with open handles), so this run cannot exercise the retry itself; themaxRetries/retryDelayoptions are the canonical, documented Node remedy for WindowsEBUSY/EPERM/ENOTEMPTYon recursiverm.npx prettier --check tests/cli-functions-contract.test.tsAll matched files use Prettier code style!npx eslint tests/cli-functions-contract.test.tsLinear
STG-2477
🤖 Generated with Claude Code
Summary by cubic
Fixes a Windows-only flaky test by retrying temp-dir cleanup in
packages/cli/tests/cli-functions-contract.test.tsto avoidEBUSYduring thefunctions devtest. Addresses STG-2477 and stabilizes CI without touching production code.maxRetries: 5andretryDelay: 100tofs.rmin the testafterEachcleanup.EBUSY/EPERM/ENOTEMPTYerrors when a grandchild process holds open handles on Windows.Written for commit c17987a. Summary will update on new commits.