Skip to content

fix(setup): auto-configure zsh fpath for shell completions#509

Merged
betegon merged 4 commits intomainfrom
fix/zsh-completion-fpath
Mar 20, 2026
Merged

fix(setup): auto-configure zsh fpath for shell completions#509
betegon merged 4 commits intomainfrom
fix/zsh-completion-fpath

Conversation

@betegon
Copy link
Member

@betegon betegon commented Mar 20, 2026

Summary

Zsh completions installed by sentry cli setup don't work out of the box because ~/.local/share/zsh/site-functions isn't in zsh's default fpath. 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 how addToPath() already works. Also runs on upgrades so existing users get their fpath fixed on the next sentry cli setup.

Changes

  • Add addToFpath() and getFpathCommand() to shell.ts (mirrors addToPath/getPathCommand)
  • Extract handleZshFpath() in setup.ts to keep complexity in check
  • Replace passive fpath hint with active .zshrc modification
  • Run fpath check even on completion file updates (one-time migration for existing installs)

Test Plan

  • bun test test/lib/shell.test.ts — 23 tests pass (5 new for addToFpath)
  • bun test test/commands/cli/setup.test.ts — 29 tests pass (updated zsh test + new idempotency test)
  • bun run typecheck — clean
  • bun run lint — clean (only pre-existing warning in markdown.ts)
  • Manual: run sentry cli setup on zsh, verify .zshrc gets fpath line, restart shell, confirm tab completion works

`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>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Telemetry

  • Include user email in Sentry telemetry context by BYK in #513
  • Track TTY vs non-TTY invocations via metric by betegon in #482

Other

  • (upgrade) Add progress spinners for version check and download phases by BYK in #515
  • Dynamic cache-backed shell completions with fuzzy matching by BYK in #465

Bug Fixes 🐛

  • (help) Hide ASCII banner when stdout is not a TTY by betegon in #501
  • (json) Flatten view command JSON output for --fields filtering by BYK in #495
  • (polling) Throw TimeoutError instead of bare Error on timeout by BYK in #503
  • (project) Fallback to org listing when bare slug matches an organization by betegon in #475
  • (setup) Auto-configure zsh fpath for shell completions by betegon in #509
  • Isolate multiregion 403 tests from env-var auth tokens by BYK in #514
  • Only mention token scopes in 403 errors for env-var tokens by BYK in #512
  • Suggest similar projects on project-search miss (CLI-A4) by BYK in #511
  • Preserve ApiError type in Seer handler + suggest trial start command (CLI-N, CLI-1D/BW/98) by BYK in #510
  • Add 403 scope guidance to issue list error handling (CLI-97) by BYK in #508
  • Propagate 403 from multi-region fan-out instead of returning empty list (CLI-89) by BYK in #507
  • Lowercase project slug in URL-parsed issue short IDs (CLI-C8 follow-up) by BYK in #506
  • Handle EIO stream errors gracefully in bin.ts by BYK in #505
  • Use fuzzyMatch for similar project suggestions and add tests (CLI-C0) by BYK in #504
  • Use resolved org in numeric issue ID 404 hint (CLI-BT) by BYK in #502
  • Include API endpoint in error messages for better diagnostics (CLI-BS) by BYK in #500
  • Enrich 403 on org listing with token scope guidance (CLI-89) by BYK in #498
  • Add 400 suggestions to org-all issue list path (CLI-BY) by BYK in #497
  • Lowercase project slug in issue arg parsing (CLI-C8) by BYK in #496
  • Enrich short ID 404 with org context and suggestions (CLI-A1) by BYK in #494
  • Suggest similar projects when project not found in org (CLI-C0) by BYK in #493
  • Event 404 hint should suggest different project, not repeat failing command by BYK in #492
  • Enrich event 404 errors with retention and format suggestions (CLI-6F) by BYK in #491
  • Add actionable suggestions for 400 Bad Request on issue list (CLI-BM, CLI-7B) by BYK in #489
  • Detect issue short IDs passed to issue list (CLI-C3) by BYK in #488
  • Add Glob.match() polyfill + improve auto-detect diagnostics (CLI-7T) by BYK in #487
  • Add org-slug pre-check to dispatchOrgScopedList (CLI-9A) by BYK in #485

Internal Changes 🔧

  • (issue) Skip getProject round-trip in project-search resolution by betegon in #473
  • (resolve) Carry project data through resolution to eliminate redundant getProject calls by BYK in #486
  • (telemetry) Convert is_tty metric to span tag by betegon in #499
  • HTTP latency optimizations — diagnostics, cache warming, concurrency limits by BYK in #490
  • Switch from @sentry/bun to @sentry/node-core/light (~170ms startup savings) by BYK in #474
  • Regenerate skill files by github-actions[bot] in b7b240ec

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1047 uncovered lines.
✅ Project coverage is 95.78%. Comparing base (base) to head (head).

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

@BYK
Copy link
Member

BYK commented Mar 20, 2026

🐑 it

@betegon betegon marked this pull request as ready for review March 20, 2026 12:30
…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>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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>
@betegon betegon force-pushed the fix/zsh-completion-fpath branch from c3cb2fe to 72e30c1 Compare March 20, 2026 13:08
@betegon betegon merged commit 2605e73 into main Mar 20, 2026
22 checks passed
@betegon betegon deleted the fix/zsh-completion-fpath branch March 20, 2026 13:12
Comment on lines 242 to +244
);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants