fix: add org-slug pre-check to dispatchOrgScopedList (CLI-9A)#485
Merged
Conversation
When a user runs 'sentry project list ftmo', the bare slug is classified as project-search mode. The CLI then makes N API calls to getProject() across all orgs, and when no project matches, throws a confusing error. Root cause: project/list.ts had a custom handleProjectSearch that didn't check if the slug matches an organization name. Fix: Add a centralized org-cache pre-check in dispatchOrgScopedList that runs before any handler (default or override). This: 1. Prevents recurrence — no handler can forget the check 2. Optimizes — checks SQLite-cached orgs first, avoiding N API calls 3. Respects per-command semantics via orgSlugMatchBehavior option: - 'redirect': convert to org-all mode with warning (project/team/repo list) - 'error': throw ResolutionError with hints (for commands like issue list) - undefined: no pre-check (backward compatible default) The cache check is best-effort: if the cache is cold/stale, falls through to the handler's own org-slug check as a safety net. Fixes CLI-9A
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
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 96.00%. Project has 1044 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.76% 95.74% -0.02%
==========================================
Files 180 180 —
Lines 24465 24506 +41
Branches 0 0 —
==========================================
+ Hits 23428 23462 +34
- Misses 1037 1044 +7
- Partials 0 0 —Generated by Codecov Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user runs
sentry project list ftmo(intending to list projects in org "ftmo"), the CLI classifies the bare slug as a project-search and makes N API calls togetProject()across all orgs. When no project matches, it throws a confusingContextError: Project is required— 190 occurrences affecting 98 users (CLI-9A).Fix
Adds a centralized org-cache pre-check in
dispatchOrgScopedListvia a neworgSlugMatchBehavioroption onDispatchOptions:"redirect": Convert to org-all mode with a warning (used byproject list,team list,repo list)"error": Throw aResolutionErrorwith actionable hints (for commands likeissue listthat can't auto-redirect)undefined(default): No pre-check — fully backward compatibleThe check uses SQLite-cached orgs (
getCachedOrganizations()) so it's O(1) and avoids the expensive N API calls entirely. If the cache is cold/stale, falls through to the handler's own org-slug check as a safety net.Why centralize instead of patching individual handlers?
The bug existed because
project/list.tshad a customhandleProjectSearchthat was missing the org-match check present in the shared handler (org-list.ts). By moving the check intodispatchOrgScopedListitself, no handler can forget it.Changes
src/lib/org-list.ts—orgSlugMatchBehavioroption +resolveOrgSlugMatch()helpersrc/commands/project/list.ts— Opt in withorgSlugMatchBehavior: "redirect"src/lib/list-command.ts— Opt in forbuildOrgListCommandcommands (team/repo list)AGENTS.md— Document the pattern for future list commandstest/lib/org-list.test.ts— 6 new tests covering redirect, error, fallthrough, and cache-miss scenariosFixes CLI-9A