fix(scripts): resolve repo root two levels up in Install-PSModules fallback - #2698
Open
Max Zeier (zeier) wants to merge 5 commits into
Open
fix(scripts): resolve repo root two levels up in Install-PSModules fallback#2698Max Zeier (zeier) wants to merge 5 commits into
Max Zeier (zeier) wants to merge 5 commits into
Conversation
…llback - Strip two path segments from PSScriptRoot, matching Test-PSModulePins.ps1 - Prevents duplicated scripts/scripts segment when git rev-parse is unavailable - Add regression tests that force the fallback and assert the resolved path Closes microsoft#2697
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2698 +/- ##
==========================================
- Coverage 83.17% 81.36% -1.81%
==========================================
Files 180 150 -30
Lines 32201 21745 -10456
Branches 25 0 -25
==========================================
- Hits 26782 17693 -9089
+ Misses 5416 4052 -1364
+ Partials 3 0 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Katrien De Graeve (katriendg)
approved these changes
Aug 18, 2026
Katrien De Graeve (katriendg)
left a comment
Contributor
There was a problem hiding this comment.
Thank you for this one!
Member
|
Max Schoening (@max) Zeier (zeier) - you may want to enable the permissions for us to edit your forks so that we can keep the branch up to date and ensure it stays in a state that can be merged. |
Bill Berry (WilliamBerryiii)
approved these changes
Aug 19, 2026
Contributor
Author
|
Katrien De Graeve (@katriendg), thank you again for the review and approval. I don't have merge permissions, could you please merge the PR for me? |
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.
Pull Request
Description
Resolve-ConfigPathinscripts/security/Install-PSModules.ps1strips only one path segment from$PSScriptRootwhengit rev-parse --show-toplevelreturns nothing. Because the script sits two levels below the repository root (<repo>/scripts/security), the fallback resolves to<repo>/scriptsand the subsequentJoin-Pathproduces a duplicated segment:The script then aborts with
Config file not found.This PR strips two segments instead, matching the sibling script
scripts/security/Test-PSModulePins.ps1, which already resolves the same manifest correctly:The two scripts previously disagreed on how to locate the same file. They now agree.
The fallback is only reached when
git rev-parse --show-toplevelyields no output — for example a linkedgit worktreewhose main.gitdirectory is not reachable from the current mount,gitmissing fromPATH, a non-clone checkout, orgitrefusing to operate due todetected dubious ownership. In environments wheregitworks normally the fallback is dead code, which is why this went unnoticed.Related Issue(s)
Closes #2697
Type of Change
Select all that apply:
Code & Documentation:
Other:
.ps1,.sh,.py)Testing
Added two regression tests in
scripts/tests/security/Install-PSModules.Tests.ps1under a new context that mocksgitto return nothing, forcing the fallback branch:Does not duplicate the scripts path segment— asserts the result does not matchscripts[\\/]scriptsResolves to the existing manifest at the repository root— asserts the resolved path actually existsBoth tests were verified to fail before the fix and pass after it.
The pre-existing coverage could not catch this defect for two reasons, both addressed by the new context:
Should -BeLike '*ps-module-versions.json', which the broken path<repo>/scripts/scripts/security/ps-module-versions.jsonalso satisfies.git rev-parsesucceeds, so the fallback branch was never executed.Results:
npm run test:ps -- -TestPath "scripts/tests/security/Install-PSModules.Tests.ps1"— 26/26 passed (24 pre-existing plus 2 new)npm run test:ps -- -TestPath "scripts/tests/security/"— 604/604 passed, 16 not runInvoke-ScriptAnalyzerwithscripts/linting/PSScriptAnalyzer.psd1on both changed files — no findingsnpm run validate:local— PSScriptAnalyzer reported 0 errors and 0 warnings across 276 filesChecklist
Required Checks
Required Local Checks
npm run validate:local— see note belownpm run validate:docs— not applicable, no docs changednpm run spell-check— run as part ofvalidate:localnpm run lint:md-links— see note belowNote on
validate:local: the aggregate exits non-zero in my environment solely becausemarkdown-link-checkreports 3 broken links out of 4134 checked, all of which are the same external URLhttps://eur-lex.europa.eu/eli/reg/2024/1689returning HTTP 202, in.github/instructions/rai-planning/rai-license-posture.instructions.md,.github/skills/rai/rai-standards/references/eu-ai-act.md, and.github/skills/rai/rai-standards/SKILL.md. This PR changes no markdown, so these are pre-existing and unrelated. All other validators in the aggregate passed.Security Considerations
Additional Notes
The change is one line in
Resolve-ConfigPathplus a test context. No public interface, parameter, or documented behavior changes; the-ConfigPathparameter andPS_MODULE_CONFIG_PATHenvironment variable continue to take precedence over the fallback exactly as before.Install-PSModules.ps1is invoked by.devcontainer/scripts/on-create.sh,.github/actions/setup-ps-modules/action.yml, and.github/workflows/copilot-setup-steps.yml. CI is unaffected in practice becausegit rev-parsesucceeds there; the user-visible impact is in dev container creation, where the failure is fatal toonCreateCommandand causes container creation to abort.