Skip to content

feat(cli): add Android and Flutter to sentry wizard - #2528

Open
sentry-junior[bot] wants to merge 20 commits into
mainfrom
feat/cli-wizard-android-flutter
Open

sentry-junior[bot] wants to merge 20 commits into
mainfrom
feat/cli-wizard-android-flutter

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2511. Stacked on #2520 (which is stacked on #2519).

Ports the Android and Flutter flows of sentry-wizard 9.1.0 (src/android/, src/flutter/ and their tests) to packages/cli/src/lib/wizard/{android,flutter}. Both are registered in WIZARD_RUNNERS through the entry points upstream src/run.ts called, so sentry wizard -i android / -i flutter work and the picker lists them.

What changed vs. sentry-wizard

No xml-js / js-yaml.

  • Android used xml-js only to read AndroidManifest.xml: it finds the MAIN activity and the manifest package. That's now android/xml.ts, a small element/attribute reader.
    • It skips text, comments, CDATA, processing instructions and the doctype, and decodes character references in attribute values.
    • It throws on malformed markup. getMainActivity then falls back to "verify the setup by hand".
  • Every write is still a string edit, as upstream did it, so the user's formatting is kept. That covers the manifest, Gradle scripts, main activity, pubspec.yaml and main.dart.
  • Flutter never used js-yaml: pubspec.yaml was already patched with string edits, and none of the helpers it imports touch YAML.

No sentry-cli binary.

  • Nothing installs or checks for sentry-cli. ./gradlew runs through utils/bash.ts, which ports only execute.
  • The Android Gradle Plugin and sentry_dart_plugin bundle their own CLI, so they still read sentry.properties as upstream wrote it.
  • The Flutter auth-token hints used to say "auth token for Sentry CLI" and link the v3 docs.sentry.io/cli/configuration page. They now name the Dart plugin and link its auth-token docs.

Other port changes

  • Sentry.captureException("…") becomes reportCliError(new Error("…")), like utils/clack/index.ts.
  • promoCode is gone from printWelcome.
  • abort() throws WizardExitError.
  • getMainActivity no longer crashes on a lone <activity> without an <intent-filter>. Upstream dereferenced undefined there.
  • The sentry-properties-added tag now reports the sentry.properties result. Upstream reported the pubspec result.
  • release-registry.ts uses fetch instead of axios.

sentry commands

These flows don't generate or print any sentry CLI commands. The only CLI configuration they write is what the Gradle and Dart plugins read (sentry.properties, the pubspec.yaml sentry: block), and that stays as upstream wrote it.

Overlap with parallel ports

  • test/commands/wizard.test.ts no longer hard-codes an integration for the "not available in this version yet" case. It picks any id without a runner through the new hasWizardRunner() in run.ts, which the picker uses too. So sibling ports registering more integrations (feat(cli): add SvelteKit, Remix and React Router to sentry wizard #2526 switched it to flutter) don't break it. When that conflicts, keep this version.
  • Expect small additive conflicts in WIZARD_RUNNERS.

These shared helpers are ported at their upstream paths because these flows import them. Other flows may port the same files:

  • utils/release-registry.ts
  • utils/line-endings.ts
  • utils/abort-if-sportlight-not-supported.ts (keeps upstream's file name)
  • utils/bash.ts (execute only; installSentryCLI / hasSentryCLI are intentionally left out)

Kept as upstream (possible follow-ups)

  • Spotlight aborts for both flows ("only available for Next.js").
  • Flutter returns with exit code 0 when pubspec.yaml is missing.
  • Without a dependencies: or dev_dependencies: section, the package line is inserted at the top of pubspec.yaml, which gives invalid YAML.
  • The search for Gradle files walks the whole tree, including build/ and .gradle/.

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 5 commits November 26, 2026 11:48
Start moving getsentry/sentry-wizard into the CLI as `sentry wizard`.
This adds the command with the `@sentry/wizard` integrations and flags
(`-i`, `--url`, `--org`, `--project`, `--saas`, `--spotlight`, and the
rest), the shared wizard helpers, and the Next.js flow. The other
integrations report that they are not available in this version yet.

The wizard logs in with the CLI's own login: a stored `sentry auth
login` session, an agent handoff, or the device flow, instead of the
`account/settings/wizard/<hash>` browser flow. It then picks or creates
the project, reads its DSN, and creates an org auth token for source map
uploads. Telemetry goes through the CLI's client.

`sentry init` stays the agent setup guide; its help now points to
`sentry wizard` for the interactive setup.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Port `ast-utils` and `url` from getsentry/sentry-wizard into
`src/lib/wizard/utils/`. The SvelteKit, Remix, React Router, Angular,
Nuxt, source maps, Cloudflare, React Native and Android wizards all use
them, so they land once here and the platform PRs that follow build on
them in parallel.

`ast-utils` edits recast ASTs, so recast and ast-types become direct
dev dependencies; both already came in through magicast.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry wizard` logs in with the CLI's login, which has no sign-up or
partner step, so `--signup`, `--promo-code` and `--coming-from` no longer
do anything. Passing one now fails with a message that points to
https://sentry.io/signup/ instead of being accepted silently.

`promoCode` and `comingFrom` leave `WizardOptions`, the welcome banner and
`setupCI`, which loses its Vercel partner branch. The help text and the
docs say which `@sentry/wizard` flags were removed.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…st-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Port the Android and Flutter flows of sentry-wizard 9.1.0 to
`sentry wizard -i android` and `-i flutter`, and register both in the
wizard's runner map so the picker lists them.

Android reads AndroidManifest.xml with a small element/attribute reader
(android/xml.ts) instead of xml-js; every write to the manifest, the
Gradle scripts, and main activity stays a string edit, as upstream did,
so user formatting is kept. Flutter already edited pubspec.yaml with
string edits and needs no YAML library.

Neither flow installs or checks for a sentry-cli binary: `./gradlew` runs
through a bash.ts that ports only `execute`. The Gradle plugin and the
Dart plugin bundle their own CLI and keep reading sentry.properties. The
Flutter auth-token hints now point at the Dart plugin docs instead of the
v3 sentry-cli configuration page.

The shared helpers these flows import (release-registry, line-endings,
abort-if-sportlight-not-supported) are ported at their upstream paths;
release-registry uses fetch instead of axios.

Refs #2511

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 27, 2026 5:23pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 27, 2026 5:23pm UTC

Request Review

…e test

The test hard-coded an integration without a flow, which breaks each time
a sibling port registers that integration. Add `hasWizardRunner()` to
run.ts (the picker now uses it too) and let the test pick any integration
that has no runner yet, skipping once every integration has one.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot and others added 3 commits November 26, 2026 18:10
- Skip the `.sentryclirc` URL check, like `sentry init`: the wizard picks
  its instance (`--url`, `--saas` or a prompt) before it logs in.
- Use the stored login's instance for `sentryUrl` when none was chosen,
  and log in again when the stored login is for another instance.
- Link self-hosted users to `/settings/<org>/auth-tokens/`.
- Leave an unparseable MCP config alone (show the copy-paste fallback),
  and let a cancel inside the MCP setup stop the wizard.
- Resolve `catalog:` and `catalog:default` against both pnpm default
  catalog forms.
- Find an existing `SENTRY_AUTH_TOKEN` after the comment header of
  `.env.sentry-build-plugin`, so re-runs don't add a second one.
- Run Windows formatters with Node in the standalone binary, where
  `process.execPath` is `sentry`.
- Ask before updating an `@sentry/nextjs` listed in devDependencies, and
  treat an unknown SDK version as the `^11` the wizard installs.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…st-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
No Gradle project, no main activity (or package name), and a failed
Gradle sync are problems with the user's project, not CLI bugs. The
Android wizard now shows a message for each and exits non-zero via
abort(), without reporting them to Sentry. Unexpected failures still go
through reportCliError.

The sentry.properties step now says the token is for the Sentry Android
Gradle plugin.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot and others added 6 commits November 26, 2026 19:01
Address review feedback on the shared wizard helpers:

- Enable unicorn/no-array-for-each repo-wide and convert every
  .forEach call site to for...of, including getLastRequireIndex.
- Add buildProjectIssuesUrl to lib/sentry-urls.ts, built on
  getOrgBaseUrl like buildEventSearchUrl, and delete the
  wizard-specific wizard/utils/url.ts.
- Move findFile into lib/dsn/fs-utils.ts and build it on
  isRegularFile, so a directory or FIFO with a matching name is
  skipped. It is async now.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry wizard [<org>/<project>] [<integration>]` replaces the
`@sentry/wizard` flags, with the target first like other commands.

- The integration is a positional, one at a time. A bare integration id
  is never read as a target, and a single bare word is always read as an
  integration, so a project or org spelled like one is written
  `my-org/nextjs`, `nextjs/` or `/nextjs`.
- The target parses with the CLI's org/project grammar and resolves after
  login with `resolveOrgOptionalTarget`, like other commands. Without one
  the org and project pickers run, with no detection.
- `-f/--force` is the only flag. It sets both `forceInstall` and
  `ignoreGitChanges`.
- The instance comes from `SENTRY_URL` or the stored login, so the
  SaaS/self-hosted prompt, `--url`, `--saas` and `skipRcUrlCheck` go.
- Spotlight mode follows `SENTRY_SPOTLIGHT`, telemetry follows
  `isTelemetryEnabled()`, and debug output goes through the CLI logger
  (`--verbose`, `--log-level`).
- Every other `@sentry/wizard` flag and `SENTRY_WIZARD_*` variable is
  gone, hidden ones included, with `disableTelemetryForRun` and
  `rejectRemovedFlags`.

A test pins the wizard's own flags to `force`, and `check:env-coverage`
(part of `ci:policy`) fails when any file under `src/` names
`SENTRY_WIZARD_`.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Re-export buildProjectIssuesUrl from lib/sentry-web-urls.ts through
withSentryBaseUrl(getApiBaseUrl()), like the other user-facing link
builders, so self-hosted and regional logins get links on the host they
are authenticated against.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…eat/cli-wizard-shared-ast-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Merge feat/cli-wizard-shared-ast-helpers (f0a48de), which brings the
positional `[<org>/<project>] [<integration>]` wizard command line and
removes findFile from wizard/utils/ast-utils.ts.

- The Android wizard finds the main activity source with the async
  findFile from lib/dsn/fs-utils.ts, so findActivitySourceFile is async
  and its caller awaits it.
- The wizard command test for an integration without a runner passes the
  integration as a positional argument.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
#2519 and #2520 were squash-merged into main, so this
branch's base is now main. The add/add conflicts came from the squashed
wizard files. main's copies of run.ts and test/commands/wizard.test.ts
equal f0a48de, which this branch already merged, so this branch's
Android and Flutter additions are kept. project-data.ts and its test take
main's copy, which has the #2559 fix for the origin trust check.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 27, 2026 16:45
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 16:45
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 27, 2026
…roid

The Android wizard wrote only auth.token to sentry.properties, so for a
self-hosted project the Sentry Android Gradle plugin still uploaded
mappings to sentry.io. Pass the instance URL when the project is
self-hosted, so the existing properties config adds defaults.url.
sentry.io projects get no defaults.url, as before.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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 using default effort and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5cd3f7a. Configure here.

Review fixes for edits that broke projects or reported false success.
All of these come from upstream sentry-wizard.

Flutter:
- A missing pubspec.yaml stops the wizard with a non-zero exit, like the
  Android wizard's expected project states.
- A missing lib/ directory or main.dart shows the main.dart snippet
  instead of crashing in findFile.
- A dependencies:/dev_dependencies: header with a trailing comment is
  found. When the section is missing, the wizard adds it instead of
  writing the package at the top of pubspec.yaml.
- runApp(...); is matched to its own closing parenthesis, skipping
  strings and comments, so nested statements in its arguments no longer
  cut the call short.
- An expression-bodied main (`void main() => runApp(...);`) becomes an
  async block, and a main with parameters is made async.
- Without a runApp(...); statement to wrap, patchMain returns false, so
  the wizard shows the snippet instead of claiming success.
- The copy-paste init snippet ends the SentryFlutter.init call with `;`.

Android:
- The Gradle check runs gradlew.bat on Windows, where cmd.exe can't run
  ./gradlew.
… wizard

Android reads an android:name with no dot (`MainActivity`) as relative
to the app's package, like `.MainActivity`. The wizard looked for it in
the source root instead, so it skipped the test-error patch. Prefix the
package for both forms.
- Android: with no imports, add the Sentry import after the package
  declaration instead of above it.
- Android: when there is no plugins block, insert it after the whole
  last import line, so static, star and alias imports stay intact.
- Flutter: skip runApp calls inside comments and strings.
- Flutter: look for a top-level `sentry:` key only, so a dependency
  named `sentry` doesn't hide the missing plugin options.
- Flutter: let a cancelled feature prompt exit the wizard instead of
  reporting it as a main.dart write failure.
Comment on lines +99 to +109
if (/import\s+io\.sentry\.Sentry;?/i.test(activityContent)) {
// sentry is already configured
clack.log.success(
chalk.greenBright(
`${chalk.bold(
"Main Activity",
)} is already patched with test error snippet.`,
),
);
return true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Existing-import check matches any io.sentry.Sentry import*

The already-patched guard treats imports like io.sentry.SentryOptions as io.sentry.Sentry, so patchMainActivity skips adding the real import and test error snippet and reports success.

Evidence
  • patchMainActivity returns early on /import\s+io\.sentry\.Sentry;?/i with no word boundary or end anchor after Sentry.
  • That pattern matches any import io.sentry.Sentry… name (SentryOptions, SentryEvent, SentryLevel, etc.), not only import io.sentry.Sentry.
  • On match it logs success and returns true without inserting sentryImport(Kt) or testErrorSnippet(Kt).
  • Callers treat that true as main-activity-patched, so verification setup is skipped after a partial/manual Sentry import.

Identified by Warden · code-review · D24-4SP

Comment on lines +288 to +304
const arrowMain =
/(?:Future<void>|void)\s+main\s*\(([^)]*)\)\s*(?:async\s*)?=>/.exec(source);
if (!arrowMain) {
return source;
}
const bodyStart = arrowMain.index + arrowMain[0].length;
const bodyEnd = scanCode(
source,
bodyStart,
(char, depth) => char === ";" && depth === 0,
);
if (bodyEnd === -1) {
return source;
}
const params = arrowMain[1] ?? "";
const body = source.slice(bodyStart, bodyEnd).trim();
return `${source.slice(0, arrowMain.index)}Future<void> main(${params}) async {\n ${body};\n}${source.slice(bodyEnd + 1)}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A commented arrow main can be rewritten into invalid live Dart code

If main.dart contains // void main() => runApp(...);, the wizard treats the commented declaration as the entrypoint, then moves the runApp call onto a live line. It writes the result as a successful setup, leaving invalid Dart and breaking the app build.

Evidence
  • patchMainContent calls arrowMainToBlock before replaceRunAppCalls; the arrow-main regex has no comment check, so it matches void main() => inside a line comment.
  • scanCode starts after the matched arrow and does not know it is inside a comment, so it finds the commented body’s semicolon. The replacement preserves the // prefix on the generated declaration but inserts a newline before the body.
  • replaceRunAppCalls then sees the body’s runApp on the next line as code and replaces it with the Sentry init snippet, leaving top-level await and an unmatched closing brace.
  • patchMain only checks that the result includes SentryFlutter.init( before writing it. Existing tests cover a live arrow main and a commented runApp, but not a commented arrow main.

Identified by Warden · code-review · 3XK-9UA

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — c158f2f5 Deployed Nov 27, 2026 by vercel[bot]
Preview – sentry-local — c158f2f5 Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant