feat(auth): launch browser login regardless of TTY#1120
Draft
betegon wants to merge 1 commit into
Draft
Conversation
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>
Contributor
|
Contributor
Codecov Results 📊❌ Patch coverage is 0.00%. Project has 5052 uncovered lines. Files with missing lines (1)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
autoAuthMiddlewarealready 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 theisatty(0)term from theautoAuthMiddlewareguard. Reuses the existingrunInteractiveLogindevice flow — no new login code. (The guard is also reshaped into an early-throw to stay under the cognitive-complexity limit; same conditions otherwise.)Test Plan
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).biome check+tsc --noEmitclean; e2e auth/trace/api (40 tests) pass.