feat: implement cli uninstall command#1084
Conversation
|
| const results: string[] = []; | ||
|
|
||
| for (const shellType of shellTypes) { | ||
| const candidates = getConfigCandidates(shellType, home); |
There was a problem hiding this comment.
Missing XDG config home lookup
Medium Severity
findSentryConfigFiles calls getConfigCandidates without XDG_CONFIG_HOME, while sentry cli setup passes that env var into detectShell. Shell configs under a custom XDG location can keep # sentry PATH/fpath blocks after uninstall.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7082ba7. Configure here.
| try { | ||
| const remaining = readdirSync(parentDir); | ||
| if (remaining.length === 0) { | ||
| await rm(parentDir, { recursive: true, force: true }); |
There was a problem hiding this comment.
Broad sentry bin path match
Medium Severity
After deleting the binary, parent cleanup treats any path ending in sentry/bin as safe to remove when empty. That suffix also matches unrelated directories (e.g. my-sentry/bin), so an empty non-Sentry folder could be deleted.
Reviewed by Cursor Bugbot for commit 7082ba7. Configure here.
Codecov Results 📊❌ Patch coverage is 73.17%. Project has 4925 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 81.47% 81.40% -0.07%
==========================================
Files 376 377 +1
Lines 26315 26480 +165
Branches 17158 17251 +93
==========================================
+ Hits 21438 21555 +117
- Misses 4877 4925 +48
- Partials 1776 1791 +15Generated by Codecov Action |
Reverse of `sentry cli setup`: removes all CLI artifacts including shell completions, agent skill files, PATH/fpath entries from shell configs, the config directory, and the binary itself. Key behaviors: - Package manager installs (npm/brew/pnpm/bun/yarn) are detected and the user is advised to use their PM's own uninstall command - `--dry-run` shows what would be removed without making changes - `--yes`/`--force` skips the confirmation prompt - `--keep-config` preserves ~/.sentry/ (auth tokens, caches) - Shell config cleanup identifies blocks by the `# sentry` marker added by `addToShellConfig()` during setup - Binary self-deletion only for curl/direct installs (SEA binaries) - Each removal step is best-effort (logs failures, continues) Uses `buildDeleteCommand` for automatic `--yes`/`--force`/`--dry-run` injection and non-interactive safety guard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 39377f2. Configure here.
| yield new CommandOutput(result); | ||
| return { | ||
| hint: `This CLI was installed via ${pmMethod}. Run \`${hint}\` to uninstall.`, | ||
| }; |
There was a problem hiding this comment.
PM block omits failure exit
Low Severity
When a package manager install is detected, the command yields an UninstallResult with a non-empty failed array and human output under “Failed”, but it returns without setting process.exitCode = 1. That diverges from the partial-removal path, which sets exit code 1 whenever failed is non-empty.
Reviewed by Cursor Bugbot for commit 39377f2. Configure here.
| const home = homedir(); | ||
|
|
||
| // Check if installed via a package manager | ||
| const installInfo = getInstallInfo(); |
There was a problem hiding this comment.
Bug: The uninstall command creates the config directory via getInstallInfo() before checking for artifacts, causing it to always find and offer to remove a directory it may have just created.
Severity: LOW
Suggested Fix
Delay the initialization logic that creates the config directory. The call to getInstallInfo() should be moved to after the gatherArtifacts function and the subsequent check for existing artifacts. This prevents the side effect of directory creation before the uninstallable items are inventoried.
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/uninstall.ts#L457
Potential issue: The `uninstall` command, when executed, calls `getInstallInfo()` which
in turn calls `getDatabase()` and `ensureConfigDir()`. This unconditionally creates the
`~/.sentry/` configuration directory if it doesn't already exist. Subsequently, the
`gatherArtifacts` function identifies this newly created directory as an existing
artifact to be uninstalled. This behavior bypasses the guard condition intended to
report 'nothing to uninstall' when no artifacts are present, leading to a confusing user
experience where the command offers to remove a directory it just created.


Summary
Part of #1055 — implements
sentry cli uninstall, the reverse ofsentry cli setup.What it does
Removes all Sentry CLI artifacts that
sentry cli setupcreates:installCompletions()~/.claude,~/.agents)installAgentSkills()sentry-cli/skill directoriesaddToPath()/addToFpath()# sentryblocks from.bashrc/.zshrc/etc.installBinary()~/.sentry/)ensureConfigDir()Safety features
process.argv[1]sniffing (npm/pnpm/bun/yarn). Advises the user to use their PM's uninstall command.sentrybefore self-deletion, preventing accidental deletion ofnode,tsx, or other interpreters when install info is missing.win32(OS holds mandatory file lock) and reports a manual removal message.--dry-run: Shows what would be removed without making changes.--yes/--force: Skips confirmation prompt (required in non-interactive environments).--keep-config: Preserves~/.sentry/directory (auth tokens, caches).uninstallto confirm (unless--yes/--force).process.exitCode = 1when some removals fail.--yes/--force(viabuildDeleteCommand).Shell config cleanup
Identifies sentry-managed lines by the
# sentrymarker comment thataddToShellConfig()appends during setup. Removes exactly the marker and ONE command line that follows (matching what setup writes), plus any trailing blank line. Uses exact line matching (trim() === "# sentry") to avoid false positives on# sentry-wizardor similar.Artifact ordering
Binary is deleted before config directory to prevent ENOENT failures when the binary lives inside
~/.sentry/bin/.Files
src/commands/cli/uninstall.tsremoveSentryLinesFromConfigfor testing)src/commands/cli/index.tstest/commands/cli/uninstall.test.tsTesting
13 tests covering:
--dry-runmode--yesremoves config directory without prompting--keep-configpreserves config directory--forceas alternative to--yes--jsonstructured output# sentry-wizardfalse-positive, no-entries case