Skip to content

feat(auth): launch browser login regardless of TTY#1100

Open
betegon wants to merge 4 commits into
mainfrom
feat/auth-non-tty-browser
Open

feat(auth): launch browser login regardless of TTY#1100
betegon wants to merge 4 commits into
mainfrom
feat/auth-non-tty-browser

Conversation

@betegon

@betegon betegon commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

When you run a command without being logged in, the CLI already starts the OAuth device flow and opens your browser to sign in — but only in an interactive terminal. This drops that restriction so the same login flow runs regardless of TTY (piped output, redirected stdin, CI).

Changes

One change: remove the isatty(0) gate from autoAuthMiddleware in src/cli.ts.

  • On success, the command retries through the middleware chain as before. The device flow's existing ~10-min poll applies while you complete sign-in.
  • If login doesn't complete, behavior is unchanged from today: a non-TTY re-throws the original auth error (exit 10, "Not authenticated"); an interactive terminal exits 1.

No new timeout logic, no new helpers — just the gate removal plus preserving today's failure behavior.

Test Plan

  • New e2e case in test/e2e/auth.test.ts: an unauthenticated non-TTY run now prints "Starting login flow…" and still exits 10 (the device-code request 404s against the mock, so it fails fast).
  • Existing "requires authentication" e2e assertions (exit 10) across trace/issue/project/api/log/event/bundle/auth stay green.
  • biome check and tsc --noEmit clean.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1100/

Built to branch gh-pages at 2026-06-17 13:48 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 0.00%. Project has 5040 uncovered lines.
❌ Project coverage is 81.22%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/cli.ts 0.00% ⚠️ 8 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.23%    81.22%    -0.01%
==========================================
  Files          386       386         —
  Lines        26831     26831         —
  Branches     17427     17428        +1
==========================================
+ Hits         21795     21791        -4
- Misses        5036      5040        +4
- Partials      1810      1811        +1

Generated by Codecov Action

@betegon betegon force-pushed the feat/auth-non-tty-browser branch from 9bee57b to cb2c8cc Compare June 12, 2026 19:31
@betegon betegon marked this pull request as ready for review June 16, 2026 09:33
@betegon betegon force-pushed the feat/auth-non-tty-browser branch from cb2c8cc to dd6678d Compare June 16, 2026 16:41
@betegon betegon changed the title feat(auth): attempt browser login flow in non-TTY feat(auth): attempt browser login in non-TTY, bound the wait Jun 16, 2026
Comment thread src/lib/interactive-login.ts Outdated
@betegon betegon force-pushed the feat/auth-non-tty-browser branch from dd6678d to 334d11f Compare June 16, 2026 16:49
Comment thread src/lib/interactive-login.ts Outdated
Comment thread src/lib/interactive-login.ts Outdated
@betegon betegon force-pushed the feat/auth-non-tty-browser branch 2 times, most recently from 905fff2 to 98e02db Compare June 16, 2026 17:47
Comment thread src/cli.ts Outdated
Comment thread src/commands/init.ts Outdated
@betegon betegon force-pushed the feat/auth-non-tty-browser branch 2 times, most recently from 5e75d4a to aef2027 Compare June 16, 2026 19:19
Comment thread src/lib/interactive-login.ts Outdated
Comment thread src/commands/init.ts Outdated
Comment thread src/commands/init.ts Outdated
autoAuthMiddleware only ran the OAuth device flow (which opens the browser)
in an interactive terminal, so an unauthenticated command in a non-TTY
(piped output, redirected stdin, CI) failed immediately. Remove the
isatty(0) gate so the device flow runs regardless of TTY; on success the
command retries as before.

If login doesn't complete, behavior is unchanged from today: a non-TTY
re-throws the original auth error (exit 10, "Not authenticated"), an
interactive terminal exits 1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@betegon betegon force-pushed the feat/auth-non-tty-browser branch from 40e3b82 to a78f767 Compare June 17, 2026 08:40
@betegon betegon changed the title feat(auth): attempt browser login in non-TTY, bound the wait feat(auth): launch browser login regardless of TTY Jun 17, 2026
Comment thread src/cli.ts Outdated
Comment thread src/cli.ts Outdated
Comment thread test/e2e/auth.test.ts Outdated
betegon and others added 2 commits June 17, 2026 15:02
The auto-auth failure branch re-threw the original auth error (exit 10)
whenever `isatty(0)` was false. But the device-flow prompt (URL/QR) prints to
stderr, so with piped stdin and an interactive stderr (`cat x | sentry cmd`)
a human sees the prompt; cancelling it should exit 1, not 10. Gate the
re-throw on both fds so exit 10 is reserved for the fully-headless case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The non-TTY auto-auth test matched /not authenticated|login/i, but the
`|login` alternative is trivially satisfied by the "Starting login flow…"
line already asserted above, so it couldn't catch a regression in the
not-authenticated message. Drop the alternative.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@betegon betegon force-pushed the feat/auth-non-tty-browser branch from f723eb3 to 494a5a8 Compare June 17, 2026 13:02

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

Reviewed by Cursor Bugbot for commit 494a5a8. Configure here.

Comment thread src/cli.ts Outdated
Dropping the `isatty(0)` gate made `autoAuthMiddleware` run the device flow
for every recoverable auth error, so a fully headless run (no TTY on stdin or
stderr) — where nobody can complete OAuth — sat through the multi-minute poll
before failing, instead of failing immediately as it did before this branch.

Gate auto-login on `hasInteractiveTerminal()` (stdin or stderr a TTY): a human
at a terminal (incl. piped stdin with interactive stderr) still gets the login
flow, while fully headless runs fail fast with the original auth error. This
also makes the post-login re-throw guard unreachable, so it's removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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