fix(install): persist install dir to user PATH on Windows#407
Conversation
The PowerShell installer only printed a suggestion to add the install directory to PATH but never actually did it, so `zero` was unusable from a fresh terminal after install. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe install script now persists the install directory to the user PATH and also appends it to the current session PATH when missing. ChangesPATH Persistence Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/install.ps1 (1)
152-166: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor duplication between user-PATH and session-PATH checks.
The split/
-notcontainspattern is repeated almost verbatim for the user scope and the session scope. Could be factored into a small helper (e.g.Test-PathContainsDir) for readability, though given the script's size this is optional.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/install.ps1` around lines 152 - 166, The PATH update logic in the install script repeats the same split and -notcontains check for both the user PATH and the session PATH. Factor that repeated pattern into a small helper such as Test-PathContainsDir, then use it from the user-scope and session-scope checks in the install flow to keep the behavior unchanged but improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/install.ps1`:
- Around line 152-161: The PATH persistence step in the install flow can throw
and abort an otherwise successful install because $ErrorActionPreference is
Stop. Update the install logic around the user PATH update in install.ps1, using
the SetEnvironmentVariable call and the existing $InstallDir/$userPathEntries
check, to catch failures from [Environment]::SetEnvironmentVariable and continue
so the binary install and the later $env:PATH fallback still complete. Keep the
user-facing success message for the copy/install step separate from any PATH
persistence warning.
---
Nitpick comments:
In `@scripts/install.ps1`:
- Around line 152-166: The PATH update logic in the install script repeats the
same split and -notcontains check for both the user PATH and the session PATH.
Factor that repeated pattern into a small helper such as Test-PathContainsDir,
then use it from the user-scope and session-scope checks in the install flow to
keep the behavior unchanged but improve readability.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 01c65a1b-7f2f-43f3-b6e1-c64fc0efd734
📒 Files selected for processing (1)
scripts/install.ps1
Address CodeRabbit review on PR Gitlawb#407: - Wrap the [Environment]::SetEnvironmentVariable call in try/catch so a PATH-persistence failure (e.g. restricted user profile) warns instead of aborting the whole install under $ErrorActionPreference = Stop. - Factor the repeated PATH-contains check for user/session scopes into a Test-ZeroPathContainsDir helper. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gnanam1990
left a comment
There was a problem hiding this comment.
Approving.
The high-consequence axes are all handled correctly: it appends to the User PATH (doesn't clobber), is idempotent (guarded by Test-ZeroPathContainsDir), writes User scope so it needs no elevation, and won't abort the install if the PATH write fails (try/catch + the current-session fallback still runs). The non-Windows installer is untouched, and CodeRabbit's earlier change-request (guard SetEnvironmentVariable) is addressed.
One non-blocking note: [Environment]::GetEnvironmentVariable(..., 'User') returns %VAR% entries already expanded, so writing back via SetEnvironmentVariable freezes any dynamic %VAR% PATH entries to literals (REG_EXPAND_SZ → REG_SZ). It's inherent to the .NET API and standard across install scripts, so fine to ship — a registry-level write with ExpandString would preserve them if you want to harden it later.
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Approve — fixes a genuinely broken Windows install path, done carefully
Worth it: yes, high value. The Windows installer copies zero.exe into %LOCALAPPDATA%\zero\bin but never puts that directory on PATH, so after the advertised irm … | iex install, zero isn't found from a fresh terminal (#406). That makes the primary Windows install path effectively broken for new users. Thanks @PierrunoYT.
The PATH manipulation is done safely:
- Idempotent —
Test-ZeroPathContainsDirsplits the User PATH and uses-contains, which is case-insensitive in PowerShell (C:\ZERO\BINmatchesC:\zero\bin), so re-running the installer won't duplicate the entry. - No clobber — reads the existing User PATH and appends
;$InstallDir, handling the empty case. - Correct scope — reads and writes the
"User"hive (HKCU), and reads the User PATH (not the process PATH), so it won't fold system entries into the user PATH — a common mistake this avoids. - Resilient — try/catch with actionable warnings, updates the current session's
$env:PATHsozeroworks immediately, and prints a restart hint.
I parse-checked the PR's script on Windows (PowerShell 5.1) — clean — and validated the helper's idempotency/case behavior locally.
Non-blocking notes for a future pass (don't hold merge): [Environment]::GetEnvironmentVariable("PATH","User") expands %VAR% tokens and writes back REG_SZ, so a User PATH containing e.g. %USERPROFILE%\bin gets flattened to a literal path (the standard .NET-installer pitfall; the path still works). And no WM_SETTINGCHANGE broadcast, so already-open shells need a restart — which the message already says.
CI note: the Go CI checks haven't run here because this is a cross-repo fork PR whose workflows are gated on maintainer approval — not because the change is script-only. A maintainer should trigger the workflows before merge. That said, the change touches only scripts/install.ps1 (no Go, and install.ps1 isn't exercised by the smoke job), so the risk of CI catching anything is low. Approving on the script review.
Summary
The PowerShell installer only printed a suggestion to add the install directory to PATH but never actually did it, so
zerowas unusable from a fresh terminal after install. This change persists the install directory to the user's PATH via[Environment]::SetEnvironmentVariableand also updates the current session's$env:PATHsozeroworks immediately after install without a terminal restart.Linked issue
Fixes #406
Checklist
issue-approvedlabel.go build ./...,go vet ./..., andgo test ./...pass locally.gofmtclean.-racewhere relevant).Verification notes
go build ./...andgo vet ./...pass clean.go test ./...has 4 pre-existing failures unrelated to this change (env has no provider/API key configured, a Windows file-lock permission error ininternal/oauth, and a TUI string-match assertion ininternal/tui) — none touch install/PATH logic, and this PR does not modify any.gofiles.gofmt -lflags nearly the whole repo pre-existing due tocore.autocrlf=trueon Windows (CRLF vs LF); not introduced by this change and no.gofiles are touched here.scripts/install.ps1; verified manually by reproducing the bug (fresh install, PATH unchanged,zeronot found) and confirming the fix persists the entry via[Environment]::SetEnvironmentVariable("PATH", ..., "User")and thatzeroresolves afterward.Summary by CodeRabbit
PATHonly when it’s missing.PATHupdates fail, clearer warnings guide you to update it manually.PATHupdate.