fix: restore CWD before TemporaryDirectory cleanup on Windows#281
Merged
danielmeppiel merged 1 commit intomicrosoft:mainfrom Mar 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Windows-only unit test failure where TemporaryDirectory cleanup fails if the process CWD is still inside the temp folder, by restoring the original working directory before the context manager exits.
Changes:
- Wrap each
TemporaryDirectory()test body intry/finallyto restore CWD before temp cleanup runs (Windows-safe). - Ensure all tests in
TestInstallCommandAutoBootstrapfollow the same CWD restoration pattern.
You can also share your feedback on Copilot code review. Take the survey.
…ix emoji assertions - Extract duplicated try/finally CWD-restore into _chdir_tmp() context manager (addresses Copilot review feedback) - Fix integration test emoji assertions: replace emoji-dependent '✨ Package installed and ready to run' checks with the stable 'Package installed and ready to run' substring after PR microsoft#227 replaced emoji with ASCII in CLI output Fixes Windows PermissionError [WinError 32] when TemporaryDirectory cleanup runs while the process CWD is inside the temp dir.
a3bd59e to
13c9c8c
Compare
danielmeppiel
approved these changes
Mar 13, 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.
Description
Fix Windows CI failure introduced by PR #227. All 7 tests in
TestInstallCommandAutoBootstrapfail onwindows-latestwithPermissionError: [WinError 32]becauseTemporaryDirectorycleanup cannot delete a directory that is the process's current working directory.Root cause: Each test calls
os.chdir(tmp_dir)inside awith tempfile.TemporaryDirectory()block. When the context manager exits, it tries tormtreethe temp directory — but on Windows, this fails because the CWD still points there. On Unix this silently succeeds, so it was never caught before.Fix: Wrap each test body in
try/finallyto restore CWD beforeTemporaryDirectory.__exit__runs.CI run: https://github.com/microsoft/apm/actions/runs/23044256406/job/66929873022
Type of change
Testing