fix(setup): auto-configure zsh fpath for shell completions#509
Conversation
`sentry cli setup` installs the zsh completion file to
~/.local/share/zsh/site-functions/_sentry, but that directory isn't in
zsh's default fpath. Previously the setup only printed a hint asking
users to manually edit .zshrc — unlike PATH which is auto-configured.
Now `addToFpath()` mirrors the existing `addToPath()` pattern: it
appends `fpath=("dir" $fpath)` to .zshrc automatically, with
idempotency checks. The fpath check also runs on upgrades so existing
users get their .zshrc fixed on the next setup run.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Telemetry
Other
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1047 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.77% 95.78% +0.01%
==========================================
Files 180 180 —
Lines 24767 24815 +48
Branches 0 0 —
==========================================
+ Hits 23720 23768 +48
- Misses 1047 1047 —
- Partials 0 0 —Generated by Codecov Action |
|
🐑 it |
…ssage drop
Address PR review comments:
1. handleZshFpath used two independent `if` blocks, so when addToFpath
failed to write, result.message ("Could not write to ~/.zshrc") was
silently dropped. Changed to if/else if to always show the error
message alongside the manual instruction — matching handlePathModification.
2. addToFpath was a ~60-line structural copy of addToPath. Extracted a
shared addToShellConfig(configFile, directory, command, label) helper
and reduced both public functions to thin wrappers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Test checked for "Added sentry completions to fpath" which never appears in any code path (actual message: "Added sentry fpath in ..."), making the idempotency assertion vacuously true. Fixed to match the actual message string. - Removed stale addToPath JSDoc left behind after extracting addToShellConfig. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
The error branch hardcoded ".zshrc" but shell.configFile could be .zshenv or ~/.config/zsh/.zshrc. Now interpolates the actual path, matching the success branch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c3cb2fe to
72e30c1
Compare
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
Bug: On upgrade, handleZshFpath silently fails to provide setup instructions if a zsh config file is not found, because it incorrectly checks the isNewInstall flag.
Severity: MEDIUM
Suggested Fix
Modify handleZshFpath to provide manual setup instructions whenever shell.configFile is null, regardless of the isNewInstall flag's value. This will align its behavior with handlePathModification and ensure users always receive guidance.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/commands/cli/setup.ts#L242-L244
Potential issue: The `handleZshFpath` function fails to provide setup instructions
during an upgrade if the user's zsh configuration file was not found on the initial
install. The logic checks for a config file, and if not found, it only provides guidance
if `isNewInstall` is true. On an upgrade, `isNewInstall` is false, causing the function
to silently do nothing. This leaves the user with non-functional shell completions and
no information on how to fix it. This behavior is inconsistent with the
`handlePathModification` function, which always provides guidance when a configuration
file is missing, regardless of whether it's a new install or an upgrade.

Summary
Zsh completions installed by
sentry cli setupdon't work out of the box because~/.local/share/zsh/site-functionsisn't in zsh's defaultfpath. The setup previously only printed a hint asking users to manually edit.zshrc, while PATH was auto-configured — inconsistent and easy to miss.Now setup automatically appends
fpath=("dir" $fpath)to.zshrc, mirroring howaddToPath()already works. Also runs on upgrades so existing users get their fpath fixed on the nextsentry cli setup.Changes
addToFpath()andgetFpathCommand()toshell.ts(mirrorsaddToPath/getPathCommand)handleZshFpath()insetup.tsto keep complexity in check.zshrcmodificationTest Plan
bun test test/lib/shell.test.ts— 23 tests pass (5 new foraddToFpath)bun test test/commands/cli/setup.test.ts— 29 tests pass (updated zsh test + new idempotency test)bun run typecheck— cleanbun run lint— clean (only pre-existing warning in markdown.ts)sentry cli setupon zsh, verify.zshrcgets fpath line, restart shell, confirm tab completion works