Skip to content

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

Draft
betegon wants to merge 1 commit into
mainfrom
feat/auth-non-tty-relaunch
Draft

feat(auth): launch browser login regardless of TTY#1120
betegon wants to merge 1 commit into
mainfrom
feat/auth-non-tty-relaunch

Conversation

@betegon

@betegon betegon commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

autoAuthMiddleware already auto-launches the OAuth device-flow login for every command when you're not logged in — but only in an interactive terminal (isatty(0) gate). In a non-TTY (piped output, redirected stdin, CI) it does nothing and the command fails immediately with exit 10. This drops the gate so the same existing logic also fires in non-TTY.

Changes

One change in src/cli.ts: remove the isatty(0) term from the autoAuthMiddleware guard. Reuses the existing runInteractiveLogin device flow — no new login code. (The guard is also reshaped into an early-throw to stay under the cognitive-complexity limit; same conditions otherwise.)

  • On success, the command retries through the middleware chain as before.
  • On failure, behavior is unchanged from today: a non-TTY re-throws the original auth error (exit 10, "Not authenticated"); an interactive terminal exits 1.

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 — no hang).
  • Existing "requires authentication" e2e assertions (exit 10) across auth/trace/api/etc. stay green because non-TTY login failure still re-throws → exit 10.
  • biome check + tsc --noEmit clean; e2e auth/trace/api (40 tests) pass.

autoAuthMiddleware ran the OAuth device flow (which opens the browser) only
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 same existing login flow runs for every command
regardless of TTY; on success the command retries as before.

On failure, 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>
@github-actions

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-1120/

Built to branch gh-pages at 2026-06-22 14:33 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 0.00%. Project has 5052 uncovered lines.
✅ Project coverage is 81.25%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/cli.ts 0.00% ⚠️ 9 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.25%    81.25%        —%
==========================================
  Files          388       388         —
  Lines        26936     26937        +1
  Branches     17493     17493         —
==========================================
+ Hits         21884     21885        +1
- Misses        5052      5052         —
- Partials      1825      1825         —

Generated by Codecov Action

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