Repository navigation
Read PSModulePath under the key Windows actually exports - #8304
Merged
Merged
Conversation
os.environ upper-cases keys on Windows, so dict(os.environ) carries PSMODULEPATH and a plain dict is case-sensitive. _profile_probe_env read "PSModulePath", always got the empty default, and wrote back a second key differing only by case, so the probe child lost the caller's module entries instead of having them reordered behind Windows PowerShell's own. Resolve the key case-insensitively and update it in place. This is what has failed parity (windows-latest) on every branch since #8161: the five PSModulePath tests read the same missing key out of the returned dict.
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Aug 10, 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.
parity (windows-latest)has been red on every branch since #8161 merged, with five failures intests/test_installer_profile_hardening.py:Cause
os.environupper-cases keys on Windows (docs: "On Windows, the keys are converted to uppercase. This also applies when getting, setting, or deleting an item").os.environitself stays case-insensitive because it uppercases on both ends, butdict(os.environ)is a plain dict holdingPSMODULEPATH, and a plain dict is not.So in
_profile_probe_env:getalways returned the empty default, never the caller's module path;_windows_powershell_module_path("")therefore returned just%SystemRoot%\System32\WindowsPowerShell\v1.0\Modules;PSMODULEPATH.That is the "reordered, not pruned" invariant broken in production, not only in the tests: the probe child was handed two entries differing only by case, and the surviving value had the caller's PowerShell 7 module directories dropped rather than demoted.
parity (ubuntu-latest)stayed green because POSIXos.environpreserves case.test_the_module_path_is_untouched_off_windowspins the mechanism down: it forcesplatform.system()to Linux, so_profile_probe_envreturnsdict(os.environ)unmodified, and the lookup still raisesKeyError. The key isPSMODULEPATH.Fix
Resolve the key case-insensitively and update it in place, so nothing is added:
The five existing assertions read the same key out of a plain dict, so they go through a small
_module_path(env)helper that does the same lookup.Tests
Added
test_the_probe_reads_the_module_path_windows_actually_exports, which sets only the uppercase key so it reproduces the defect on any platform. Against the old code it fails exactly as Windows CI does:tests/test_installer_profile_hardening.py: 75 passed. Ruff clean on both files.