fix(tests): ensure temp test files are cleaned up on failure - #3385
Draft
nitsuah wants to merge 1 commit into
Draft
fix(tests): ensure temp test files are cleaned up on failure#3385nitsuah wants to merge 1 commit into
nitsuah wants to merge 1 commit into
Conversation
nitsuah
marked this pull request as draft
August 16, 2026 21:23
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.
Problem: Stale Artifact Pollution
The output shows a failed atomic operation (Write(c.txt) failure) followed by the creation of an orphaned, unmanaged worktree (add-c-txt).
Why it happens:
The system attempts a task, fails mid-process, and lacks a "rollback" mechanism to clean up the partially created state. Because the cleanup logic is external (run only upon success or explicitly called), the error aborts the flow, leaving the stale file (c.txt) and the orphaned directory (worktree) permanently polluting the environment.
tl;dr - Non-Atomic Sequencing. The system doesn't treat the sequence as one transactional unit. A failure in step 1 doesn't abort the entire process; step 2 proceeds anyway. Result: orphaned artifacts from subsequent, should-not-have-run steps, even though the initial step was flagged as an error. Partial success is incorrectly reported as a failure, or the process is continuing in a corrupted, partially-failed state.
Root Cause
Test suites rely on
afterEachhooks to clean up temporary directories. This pattern fails under three conditions:afterEachhook, artifacts are abandoned.build-cli.js) or left by orphaned test processes occasionally acquire read-only status or OS file locks. Standardfs.rmSync({ force: true })fails to delete these, leading to "permission denied" or "file locked" errors, which subsequently pollute the repository root with residual state.afterEachmay run on a directory tree that is already in a partially-deleted state, causing recursive deletion failures.Solution
cleanup(path)utility that forces deletion:ENOENTsilently.chmod 777) to ensure deleteability.try...finallyblocks within individual test specs. This guarantees that if a spec fails, cleanup logic executes immediately, independent of the test runner's lifecycle health.tmproot, completely forbidding writes to the repository directory.