Skip to content

fix: set USERPROFILE on Windows in config_fresh tests#992

Merged
svarlamov merged 1 commit intomainfrom
fix/config-fresh-test-windows-home-dir
Apr 6, 2026
Merged

fix: set USERPROFILE on Windows in config_fresh tests#992
svarlamov merged 1 commit intomainfrom
fix/config-fresh-test-windows-home-dir

Conversation

@svarlamov
Copy link
Copy Markdown
Member

@svarlamov svarlamov commented Apr 6, 2026

Root cause

PR #930 added tests/config_fresh_test.rs, which redirects the home directory during each test by setting the HOME env var to a TempDir. This works on Linux/macOS, but on Windows home_dir() (src/mdm/utils.rs) reads USERPROFILE before HOME:

// src/mdm/utils.rs
#[cfg(windows)]
if let Ok(userprofile) = std::env::var("USERPROFILE") ... {
    return PathBuf::from(userprofile);  // always wins on Windows CI
}
// HOME is only reached if USERPROFILE is unset

So on Windows CI USERPROFILE is always set (e.g. C:\Users\runneradmin), meaning:

  • save_file_config() wrote the config to the real user profile directory
  • The test then asserted the file existed under temp_dir/.git-ai/config.json — which never got created
  • All 7 tests in the suite (3 Windows jobs × 7 tests) panicked with Config file should exist

Fix

Introduce a HomeEnvGuard RAII helper that saves and restores HOME on all platforms, plus USERPROFILE/HOMEDRIVE/HOMEPATH on Windows. It clears HOMEDRIVE/HOMEPATH so the USERPROFILE branch in home_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

  • All 3 Windows CI jobs (wrapper, wrapper-daemon, daemon) pass config_fresh_test
  • No Linux/macOS regressions (cargo test --test config_fresh_test passes: 7/7 ✓)

🤖 Generated with Claude Code


Open with Devin

…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>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@svarlamov svarlamov merged commit 3b93e05 into main Apr 6, 2026
25 of 26 checks passed
@svarlamov svarlamov deleted the fix/config-fresh-test-windows-home-dir branch April 6, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant