test(windows): fix CLAUDE_CONFIG_DIR scope tests on Windows#1086
Merged
danielmeppiel merged 2 commits intomainfrom Apr 30, 2026
Merged
test(windows): fix CLAUDE_CONFIG_DIR scope tests on Windows#1086danielmeppiel merged 2 commits intomainfrom
danielmeppiel merged 2 commits intomainfrom
Conversation
The CLAUDE_CONFIG_DIR scope tests added in #1055 patched only HOME, but Path.home() on Windows uses USERPROFILE (with HOMEDRIVE+HOMEPATH as fallback) and ignores HOME. As a result, Path.home() returned the real runner profile, relative_to(home) succeeded against the AppData/Local tmp_path, and the assertions on root_dir failed on windows-latest. Add a small _set_home() helper in both scope test modules that also sets USERPROFILE / HOMEDRIVE / HOMEPATH on Windows, and use it in the three failing tests: - test_user_scope_with_claude_config_dir - test_user_scope_outside_home_keeps_absolute - test_user_scope_collapses_dotdot_segments plus test_user_scope_expands_tilde for consistency. Also resolve() the expected outside path in test_user_scope_outside_home_keeps_absolute to match the source's abs_path.expanduser().resolve() output (e.g. /var -> /private/var on macOS, 8.3 short-name expansion on Windows). Fixes failures from CI run 25190857376. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes failing Windows CI unit tests by ensuring Path.home() honors the monkeypatched home directory on Windows, and aligns expected path normalization with the implementation.
Changes:
- Added a
_set_home()helper to patchHOMEplus Windows-specific home variables (USERPROFILE,HOMEDRIVE,HOMEPATH). - Updated affected scope tests to use
_set_home()for consistent behavior across OSes. - Updated one assertion to compare against a resolved absolute path.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/integration/test_scope_integration.py | Adds portable home env patch helper and updates user-scope path tests (including resolved-path expectation). |
| tests/unit/integration/test_scope_install_uninstall.py | Adds the same helper and updates the Windows-failing CLAUDE_CONFIG_DIR scope test to use it. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 3
Comment on lines
+25
to
+40
| def _set_home(monkeypatch, home: Path) -> None: | ||
| """Set the user's home directory portably across POSIX and Windows. | ||
|
|
||
| ``Path.home()`` consults ``HOME`` on POSIX but ``USERPROFILE`` (with | ||
| ``HOMEDRIVE`` + ``HOMEPATH`` fallback) on Windows. Setting only ``HOME`` | ||
| is a no-op on Windows and causes ``relative_to(Path.home())`` checks in | ||
| code under test to compare against the real user's profile. | ||
| """ | ||
| home_str = str(home) | ||
| monkeypatch.setenv("HOME", home_str) | ||
| if os.name == "nt": | ||
| monkeypatch.setenv("USERPROFILE", home_str) | ||
| drive, _, tail = home_str.partition(":") | ||
| if tail: | ||
| monkeypatch.setenv("HOMEDRIVE", f"{drive}:") | ||
| monkeypatch.setenv("HOMEPATH", tail) |
There was a problem hiding this comment.
The _set_home() helper is duplicated across two test modules with the same logic. To avoid drift and keep behavior consistent, consider moving this into a shared test utility (e.g., tests/unit/conftest.py fixture or a tests/unit/utils.py helper) and importing/using it from both files.
- Update comment to reflect that paths outside $HOME are resolved (normalized), not preserved verbatim. - Make the .resolve() call explicit with strict=False to mirror the implementation in for_scope() and document the expected behavior for non-existent paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
Author
|
Thanks for the review. Addressed in 82cebf3:
|
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
Three Windows unit tests added in #1055 fail on
windows-latest(CI run 25190857376):test_user_scope_with_claude_config_dirtest_user_scope_outside_home_keeps_absolutetest_user_scope_collapses_dotdot_segmentsAll three patch
HOMEviamonkeypatchand then exercise code that callsPath.home(). On Windows,Path.home()ignoresHOMEand readsUSERPROFILE(withHOMEDRIVE+HOMEPATHas fallback). SoPath.home()returned the real runner profile (C:\Users\runneradmin),relative_to(home)succeeded againsttmp_path(which lives underAppData\Local\Temp\...), and the assertions onroot_dirfailed:Fix
Add a small
_set_home()helper in both scope test modules that, on Windows, also patchesUSERPROFILE/HOMEDRIVE/HOMEPATHsoPath.home()returns the fake home. Use it in the three failing tests plustest_user_scope_expands_tildefor consistency.Also call
.resolve()on the expectedoutsidepath intest_user_scope_outside_home_keeps_absoluteto match the source'sPath(env).expanduser().resolve(strict=False)output (covers macOS/var->/private/varand Windows 8.3 short-name expansion).Test-only change. No production code touched.
Validation