fix: set USERPROFILE on Windows in config_fresh tests#992
Merged
Conversation
…esolves to temp dir On Windows, home_dir() (src/mdm/utils.rs) reads USERPROFILE before HOME, so tests that only set HOME were writing config to the real user profile directory while asserting the file existed under the temp dir — causing all config_fresh_test cases to fail on every Windows CI job. Introduce a HomeEnvGuard RAII helper that saves/restores HOME (all platforms) plus USERPROFILE, HOMEDRIVE, and HOMEPATH (Windows-only), and clears HOMEDRIVE/HOMEPATH so the USERPROFILE branch is taken exclusively. Replace the open-coded save/restore blocks in every test with _home_guard = HomeEnvGuard::set(temp_dir.path()). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Root cause
PR #930 added
tests/config_fresh_test.rs, which redirects the home directory during each test by setting theHOMEenv var to aTempDir. This works on Linux/macOS, but on Windowshome_dir()(src/mdm/utils.rs) readsUSERPROFILEbeforeHOME:So on Windows CI
USERPROFILEis always set (e.g.C:\Users\runneradmin), meaning:save_file_config()wrote the config to the real user profile directorytemp_dir/.git-ai/config.json— which never got createdConfig file should existFix
Introduce a
HomeEnvGuardRAII helper that saves and restoresHOMEon all platforms, plusUSERPROFILE/HOMEDRIVE/HOMEPATHon Windows. It clearsHOMEDRIVE/HOMEPATHso theUSERPROFILEbranch inhome_dir()is taken exclusively and points at the temp dir. Every test is updated to use_home_guard = HomeEnvGuard::set(temp_dir.path())instead of the open-coded save/restore blocks.All 7 tests pass locally (Linux). The Windows-specific guard code compiles only under
#[cfg(windows)].Test plan
wrapper,wrapper-daemon,daemon) passconfig_fresh_testcargo test --test config_fresh_testpasses: 7/7 ✓)🤖 Generated with Claude Code