Skip to content

fix: add org-slug pre-check to dispatchOrgScopedList (CLI-9A)#485

Merged
BYK merged 1 commit intomainfrom
fix/cli-9a-org-slug-precheck
Mar 19, 2026
Merged

fix: add org-slug pre-check to dispatchOrgScopedList (CLI-9A)#485
BYK merged 1 commit intomainfrom
fix/cli-9a-org-slug-precheck

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 19, 2026

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 to getProject() across all orgs. When no project matches, it throws a confusing ContextError: Project is required — 190 occurrences affecting 98 users (CLI-9A).

Fix

Adds a centralized org-cache pre-check in dispatchOrgScopedList via a new orgSlugMatchBehavior option on DispatchOptions:

  • "redirect": Convert to org-all mode with a warning (used by project list, team list, repo list)
  • "error": Throw a ResolutionError with actionable hints (for commands like issue list that can't auto-redirect)
  • undefined (default): No pre-check — fully backward compatible

The 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.ts had a custom handleProjectSearch that was missing the org-match check present in the shared handler (org-list.ts). By moving the check into dispatchOrgScopedList itself, no handler can forget it.

Changes

  • src/lib/org-list.tsorgSlugMatchBehavior option + resolveOrgSlugMatch() helper
  • src/commands/project/list.ts — Opt in with orgSlugMatchBehavior: "redirect"
  • src/lib/list-command.ts — Opt in for buildOrgListCommand commands (team/repo list)
  • AGENTS.md — Document the pattern for future list commands
  • test/lib/org-list.test.ts — 6 new tests covering redirect, error, fallthrough, and cache-miss scenarios

Fixes CLI-9A

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

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) Track TTY vs non-TTY invocations via metric by betegon in #482
  • Dynamic cache-backed shell completions with fuzzy matching by BYK in #465

Bug Fixes 🐛

  • (project) Fallback to org listing when bare slug matches an organization by betegon in #475
  • 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
  • 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.

@BYK BYK marked this pull request as ready for review March 19, 2026 22:38
@github-actions
Copy link
Contributor

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 96.00%. Project has 1044 uncovered lines.
❌ Project coverage is 95.74%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
org-list.ts 96.12% ⚠️ 18 Missing
list-command.ts 98.62% ⚠️ 3 Missing
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

@BYK BYK merged commit 70b2ac1 into main Mar 19, 2026
22 checks passed
@BYK BYK deleted the fix/cli-9a-org-slug-precheck branch March 19, 2026 22:45
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.

1 participant