Repository navigation
Add per-user known package managers for Path Update - #28601
AReindl (areindl1) wants to merge 1 commit into
Conversation
Read the PowerShell-owned per-user list at HKCU\Software\Microsoft\PowerShell\KnownPackageManagers in addition to the machine-wide Command Processor list. This lets commands such as 'uv' refresh the current session PATH after 'uv tool update-shell', without requiring administrator rights or a Windows-side change. The per-user list uses the same one-subkey-per-command shape and 8-entry cap as the machine-wide list, and is still read once per process. Add TestExe -prependuserpath and a non-admin Pester test covering uv's prepend-to-user-PATH behavior.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The tests lack coverage for simultaneously populated HKLM and HKCU lists and their independent eight-entry limits, allowing list-selection or merged-limit regressions to pass.
1 open issue
What changed in this PR
Extends Windows PATH refresh to recognize user-registered package managers, addressing #28458 without requiring administrator rights.
Changes:
- Merges machine-wide and per-user registrations while preserving separate eight-entry limits.
- Adds a test helper option for prepending to the user PATH.
- Adds non-admin tests for append, prepend, and unchanged PATH behavior.
| File | Description |
|---|---|
test/tools/TestExe/TestExe.cs |
Adds user PATH prepend support. |
test/powershell/Language/Scripting/NativeExecution/NativeCommandPathUpdate.Tests.ps1 |
Adds per-user registration and PATH refresh tests. |
src/System.Management.Automation/engine/NativeCommandProcessor.cs |
Merges machine and user package-manager lists. |
Review effort: Balanced
|
|
||
| if (userPackageManagers is not null) | ||
| { | ||
| packageManagers.UnionWith(userPackageManagers); |
@microsoft-github-policy-service agree |

PR Summary
Fixes #28458.
uv tool update-shellprepends its bin directory to the per-userPATH, but the Windows Path Update feature only recognized the machine-wideHKLM:\SOFTWARE\Microsoft\Command Processor\KnownPackageManagerslist. As a result,uv(and similar per-user tools) could not refresh the running session, soruff --versionfailed until the terminal was restarted.This change adds a PowerShell-owned per-user list at
HKCU:\SOFTWARE\Microsoft\PowerShell\KnownPackageManagers, so users can opt in without administrator rights or a Windows-side change:Changes
GetPackageManagerListFromRegistry()now reads the machine-wide and per-user lists and unions them. Either list can be used alone, and names are compared withOrdinalIgnoreCaseas before.static readonlyfield.PATHlogic is reused unchanged. Only prepended or appendedPATHchanges are picked up, and the detected entry is appended to the processPATH.#if !UNIXblock, so behavior on Linux and macOS is unaffected.TestExe -prependuserpathto reproduceuv's prepend-to-user-PATHbehavior, plus a non-admin PesterDescribecovering per-user append, per-user prepend, and the no-change case.PR Context
uv tool update-shellprepends%USERPROFILE%\.local\binto the userPATH, while the existing feature only consulted the machine-wide Command Processor list. Becauseuvwas not in that list, the running session was not refreshed.This implements option 1 from the issue: merge the existing machine-wide list with a per-user list. The key lives under
HKCU\Software\Microsoft\PowerShellso it is owned by PowerShell rather than modifying the Command Processor key, and it requires no elevation. No new cmdlet or experimental feature is introduced.Testing
7.7.0-preview.5) and ran the fulltest/powershell/Language/Scripting/NativeExecutionsuite with the CI tag filters (CI,Feature, excludingSlow,RequireAdminOnWindows).uv, and no-change).Can start an elevated associated process correctly— launchesdiskmgmt.msc, which requires an elevated/interactive session.Does not get truncated or split when redirected— reads[console]::WindowWidth, which throws when the host has no console. This file passes 6/6 when run in a real console.RequireAdminOnWindowsand were not run in the non-elevated local session. That code path is unchanged apart from the refactor into a shared overload, and I manually confirmedchoco(machine list) still refreshes the processPATH.System.Management.Automation.dllcontains the newHKCU\Software\Microsoft\PowerShell\KnownPackageManagersstring, while the installed 7.7.0 does not, and that the tests resolve to the builtpwsh.Not tested: the elevated
diskmgmt.msctest and the admin-tagged machine-list tests, because this session is not elevated.AI Usage
This PR was prepared with help from an AI coding agent (OpenCode with DeepSeek V4.1 Flash Free), which I used to explore the code, implement the change and tests, and run/verify the test suite. I reviewed and validated the final changes myself.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header