fix(shared): read the Machine and User registry PATH scopes on Windows - #7407
fix(shared): read the Machine and User registry PATH scopes on Windows#7407hey-jj wants to merge 1 commit into
Conversation
The PowerShell probe read PATH with no scope. That returns the PATH the probe inherited from the app process itself, so a directory the user registered after the app's parent process started stayed invisible for the life of the app. With npm invisible, the one-click provider update spawned bare "npm" with shell disabled, which Node cannot start for a .cmd shim, and the update died with NotFound. The capture command now also reads the Machine and User registry scopes for PATH and joins the non-empty values, process value first, so an entry that already resolved keeps winning and registry entries only add what was missing. Other captured names keep the single unscoped read. The new test pins the exact generated statement sequence, which is the only guard the suite can provide for a command that never executes on the machines that run it.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR changes runtime behavior for Windows PATH resolution by reading additional registry scopes (Machine and User). While well-tested and scoped to PATH only, this alters how environment variables are assembled and warrants human verification of the intended behavior. You can add or adjust custom eligibility rules. Learn more. |
|
Note 🤖 GPT-5.6 Sol responding on behalf of Theo We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together. We are keeping OPEN #8465 as the review path for refreshing the Windows PATH before provider checks. The registry-scope tests here remain useful reference. If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. |
TITLE: fix(shared): read the Machine and User registry PATH scopes on Windows
Fixes #7406.
When the app launches with a stale Windows environment, for example after Node was installed later in the same desktop session, the Windows PATH repair never finds the registered Node directory and the one-click provider update dies with
NotFound: ChildProcess.spawn. The repair probes PowerShell with an unscoped[Environment]::GetEnvironmentVariable('PATH'), which returns the PATH the probe inherited from the app itself, while the directory it needs sits in the Machine or User registry scope that the probe never reads.What changed
buildWindowsEnvironmentCaptureCommandnow reads the Machine and User registry scopes for PATH alongside the existing unscoped read and joins the non-empty values, process value first. Every other captured name keeps the single unscoped read. The new test pins the exact generated statement sequence for the PATH capture and pins that FNM_DIR keeps its unscoped read.Why this shape
The registry scopes hold what a fresh sign-in would see, which is what the repair is trying to reconstruct. Ordering is preserved on purpose. The process value stays first in the join, so every directory that resolved before still wins, and the registry values only add what was missing.
mergePathValuesalready drops the duplicates case-insensitively downstream.Testing
npx vitest run --root packages/shared shell.test.tspasses, 30 tests.tsgo --noEmitis clean forpackages/shared.C:\Windows\System32and Node registered only in the User registry PATH, the repaired environment contains the Node directory,resolveSpawnCommand("npm", ["--version"])resolves the fullnpm.CMDpath withshell: true, and the command exits 0.Note
Medium Risk
Touches core Windows spawn/PATH repair used for Node and CLI resolution; behavior change is narrow (PATH capture only) but affects command discovery when the inherited PATH is stale.
Overview
Fixes Windows PATH repair when the app inherits a stale process PATH (e.g. Node added to User/Machine registry after launch).
buildWindowsEnvironmentCaptureCommandnow, forPATHonly, reads the unscoped value plusMachineandUserregistry scopes, joins non-empty segments with;(process value first); other captured names still use a single unscoped read. DownstreammergePathValuescontinues to dedupe.A new unit test locks the generated PowerShell statement order for PATH and confirms vars like
FNM_DIRdo not get scoped reads.Reviewed by Cursor Bugbot for commit 8ff87e5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
readEnvironmentFromWindowsShellto read Machine and User registry PATH scopes on WindowsPreviously,
buildWindowsEnvironmentCaptureCommandin shell.ts readPATHusing a single unscoped[Environment]::GetEnvironmentVariablecall, which only returned the process-level value. Now, when the variable name isPATH, the generated PowerShell reads from the process, Machine, and User registry scopes separately and joins the non-null results with;. Non-PATH variables continue to use the single unscoped read.Macroscope summarized 8ff87e5.