Fixes #3806.
Problem#
GitHub auth discovery probes with gh auth status --json hosts. The --json flag landed in gh 2.81; older CLIs exit non-zero with unknown flag: --json, so parseGitHubAuthStatus sees no JSON, and the probe reports Not authenticated — with a detail line telling the user to sign in. Users then run gh auth login repeatedly, which never helps, because the login is fine and the CLI version is the problem.
Reproduced on Linux with gh 2.45.0 (Ubuntu's package), fully logged in:
$ gh auth status --json hosts
unknown flag: --json # exit 1
$ gh auth status
github.com
✓ Logged in to github.com account octocat (~/.config/gh/hosts.yml)
T3 reported: auth: { status: "unauthenticated", detail: "unknown flag: --json" }.
Fix#
- Add an optional
authFallbackArgs to SourceControlCliDiscoverySpec. It is retried only when the primary auth probe exits non-zero and did not resolve an account, so there is no extra process spawn on the happy path, and no behavior change for providers that do not set it.
- Give the GitHub spec
authFallbackArgs: ["auth", "status"].
- Parse the human-readable output when the JSON parse yields nothing (
parseGitHubAuthStatusText), handling both the current Logged in to <host> account <login> and the older Logged in to <host> as <login> phrasings, plus Active account: and failed-login lines. This mirrors the existing text parsing in gitLabAuthStatus.ts.
Verification#
Built the server from this branch and ran it against a gh stub that rejects --json and prints the 2.45.0 text output:
| before | after |
|---|
auth.status | unauthenticated | authenticated |
auth.account | — | octocat |
auth.detail | unknown flag: --json | — |
vp test run apps/server/src/sourceControl/ — 93 passed (12 files), including 4 new tests: three parser cases (current phrasing, legacy as <login> phrasing, failed login stays unauthenticated) and one discovery-level test asserting the fallback runs and recovers the account when --json is rejected.
vp run --filter t3 typecheck — clean.
vp check — 0 errors.
Notes#
Scoped to GitHub deliberately. GitLab/Azure/Bitbucket specs are untouched; the new spec field is opt-in, so the same mechanism is available if another CLI ever needs it.
Note
Low Risk
Scoped to opt-in GitHub auth discovery and parsing; happy path unchanged and genuine sign-out messages are preserved without extra CLI calls.
Overview
Fixes false unauthenticated GitHub discovery when gh is older than 2.81 and rejects auth status --json hosts with errors like unknown flag: --json.
Discovery gains optional authFallbackArgs on CLI specs and looksLikeUnsupportedInvocation so a second probe runs only when the primary command fails with an unsupported-flag/command pattern—not when the user is genuinely signed out. GitHub sets authFallbackArgs: ["auth", "status"].
Auth parsing adds parseGitHubAuthStatusText for human-readable gh auth status output (current account phrasing, legacy as <login>, active/failed lines). parseGitHubAuth uses JSON when it parses, otherwise plain text from combined stdout/stderr.
Tests cover the text parser, end-to-end fallback recovery, and the case where a modern CLI reports sign-out without triggering fallback.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2a2e502e8e23866952ea4b952028ef9553d26630. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
Note
Fall back to plain gh auth status when GitHub CLI does not support --json#
- Adds
authFallbackArgs to the CLI discovery spec and parseGitHubAuthStatusText to parse human-readable gh auth status output from older GitHub CLI versions.
- When the primary JSON-based auth probe (
gh auth status --json hosts) exits non-zero with an "unknown flag" error, SourceControlProviderDiscovery retries using the plain gh auth status command.
- Fallback is skipped when the primary probe returns a genuine sign-out on a modern CLI, preserving the specific sign-out detail.
gitHubAuthStatus.ts handles both current (account) and legacy (as) phrasing in plain-text output.
Macroscope summarized 2a2e502.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
49bb1282-a5c7-40a4-a0cf-fab42bc64c26You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share