Skip to content

fix(init): prompt for team selection when user belongs to multiple teams#621

Merged
betegon merged 10 commits intomainfrom
fix/init-team-selection
Apr 1, 2026
Merged

fix(init): prompt for team selection when user belongs to multiple teams#621
betegon merged 10 commits intomainfrom
fix/init-team-selection

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented Apr 1, 2026

Summary

sentry init failed for most new users — people who just signed up on sentry.io and ran the wizard. The root causes:

  1. The CLI's OAuth token lacked team:write scope, so even org Owners couldn't create teams
  2. Team resolution only happened deep in the workflow (after minutes of AI analysis), not upfront
  3. The 0-teams case failed with a cryptic 403 error

Now all team scenarios are resolved early in resolvePreSpinnerOptions(), right after org selection and before the spinner starts. Also added team:write to the OAuth scopes.

All team scenarios handled

Scenario Behavior
0 teams Auto-creates a team called "default". On failure (e.g. missing permissions), shows friendly error with link to create a team in the UI
1 team Auto-selects it silently
Multiple teams, user is member of 1 Auto-selects the member team
Multiple teams, user is member of several Shows interactive prompt to pick one
Multiple teams, user is member of several + --yes Auto-selects the first member team
Multiple teams, user is member of none (new user) Shows interactive prompt with all org teams
Multiple teams, user is member of none + --yes Auto-selects the first org team
--team flag provided Uses it directly, skips all resolution
API error fetching teams Silently falls through to existing resolveOrCreateTeam as fallback

Test plan

  • sentry login then sentry init on org with 0 teams → auto-creates "default" team, proceeds
  • sentry init on org with 1 team → no prompt, auto-selects
  • sentry init on org with multiple teams → shows team selection prompt
  • sentry init --team <slug> → skips prompt
  • sentry init --yes on org with multiple teams → auto-selects first member team
  • Cancel team prompt (Ctrl+C) → clean exit
  • Existing users need sentry login again to get the new team:write scope

🤖 Generated with Claude Code

When users belong to more than one team, `sentry init` would fail during
project creation with "Team is required" after minutes of setup. Now
resolves the team interactively in `resolvePreSpinnerOptions()` before
the spinner starts, so the prompt appears early alongside org selection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 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 ✨

  • (auth) Show token expiry in days/weeks instead of raw hours by BYK in #620
  • (ci) Add delta patch generation for stable releases by BYK in #618
  • (dashboard) Render text widget markdown content in dashboard view by BYK in #624
  • (telemetry) Upgrade Sentry SDK to 10.47.0 and enable runtime metrics by BYK in #622
  • (traces) Expose custom span attributes and improve agent guidance by BYK in #623

Bug Fixes 🐛

  • (build) Use esbuild for binary bundling to fix minifier collision bug by BYK in #619
  • (init) Prompt for team selection when user belongs to multiple teams by betegon in #621

Internal Changes 🔧

  • Regenerate skill files and command docs by github-actions[bot] in e01b2520

🤖 This preview updates automatically when you update the PR.

betegon and others added 2 commits April 1, 2026 13:11
Sort imports and use type assertion instead of non-null assertion
to match existing codebase patterns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
File is in src/lib/init/, so types need ../../types/ not ../types/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@betegon betegon marked this pull request as ready for review April 1, 2026 11:20
The team selection code calls listTeams() which triggers real API calls
through the authenticated fetch chain, causing tests to hang. Mock it
following the same pattern as local-ops.create-sentry-project.test.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Codecov Results 📊

129 passed | Total: 129 | 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 1291 uncovered lines.
✅ Project coverage is 95.67%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.65%    95.67%    +0.02%
==========================================
  Files          204       204         —
  Lines        29769     29785       +16
  Branches         0         0         —
==========================================
+ Hits         28472     28494       +22
- Misses        1297      1291        -6
- Partials         0         0         —

Generated by Codecov Action

betegon and others added 3 commits April 1, 2026 14:27
Previously, when a user had no team memberships, --yes mode would
arbitrarily pick the first org team, which could cause 403 errors
during project creation. Now only member teams are considered for
auto-selection; if there are none, we defer to resolveOrCreateTeam
which surfaces a proper error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…scope

The primary use case for sentry init is new users who just signed up —
they have an org but no teams and no projects. Previously this failed
with a cryptic 403 deep in the workflow because:

1. The OAuth token lacked team:write scope (even Owners couldn't create
   teams via CLI)
2. The 0-teams case was only handled after minutes of AI analysis

Now:
- Added team:write to OAuth scopes so team creation works
- All team scenarios are resolved in resolvePreSpinnerOptions (before
  the spinner), not just the multi-team case:
  - 0 teams: auto-create one (named after user or org)
  - 1 team: auto-select it
  - Multiple teams: prompt to pick (or auto-select with --yes)
- If team creation fails (e.g. permissions), shows a friendly error
  with a link to create a team in the UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
betegon and others added 2 commits April 1, 2026 22:44
Both the team auto-creation failure (403) and the listTeams API error
are now reported via captureException with org/context metadata, even
when the error is the user's fault — helps track onboarding friction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The helper was inserted between the JSDoc block and its function,
orphaning the documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@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.

@betegon betegon merged commit 8e8973d into main Apr 1, 2026
26 checks passed
@betegon betegon deleted the fix/init-team-selection branch April 1, 2026 20:58
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