fix(gh-project): diagnose env-shadowed gh tokens in auth errors (#1478)
* fix(gh-project): diagnose env-shadowed gh tokens in auth errors `gh auth refresh -s project` silently no-ops when GITHUB_TOKEN/GH_TOKEN is exported in the user's shell — gh prefers env tokens and refuses to modify them, exiting 0. Users follow the canned remediation, see no error, retry, and stay stuck. Add a one-shot `gh auth status` probe (gh:diagnoseAuth IPC) that: - Detects env-shadowed credentials and rewrites the fix to `unset GITHUB_TOKEN` plus a grep to find where it's exported. - Detects missing gh install, plain missing-scope on a keyring login, and SAML SSO authorization. - Surfaces a tailored multi-button error UI in ProjectViewWrapper and ProjectPicker instead of one canned 'Copy command'. Co-authored-by: Orca <help@stably.ai> * fix(gh-project): address review feedback - Cross-platform shell guidance: PowerShell commands on Windows (Get-ChildItem Env:, Remove-Item Env:, [Environment]::SetEnvironmentVariable) via navigator.userAgent platform check. - Use `window.api.shell.openUrl` for the docs button instead of `window.open`, matching SidebarToolbar's external-URL pattern. - Tighten gh auth status parser: accept single-label hostnames and optional trailing colon; recover host from the inline 'Logged in to <host>' line so a missed section header never silently drops accounts. - Add tests for multi-host output and host-recovery fallback. - Drop dead command/copy locals in ProjectViewWrapper.ErrorState by short-circuiting the auth-error case before they're computed. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Shared types for `gh auth status` diagnostics surfaced to the renderer.
|
||||
*/
|
||||
|
||||
export type GhAuthAccount = {
|
||||
host: string
|
||||
user: string
|
||||
/** True when this is the account gh would use for the next call. */
|
||||
active: boolean
|
||||
/**
|
||||
* If gh reports the credential came from an environment variable, the
|
||||
* variable's name. Null when the credential came from the keyring/file
|
||||
* config. Env-token accounts can't be refreshed by `gh auth refresh`.
|
||||
*/
|
||||
envToken: 'GITHUB_TOKEN' | 'GH_TOKEN' | null
|
||||
source: 'env' | 'keyring'
|
||||
scopes: string[]
|
||||
}
|
||||
|
||||
export type GhAuthDiagnostic = {
|
||||
/** False when gh CLI is not installed / not on PATH. */
|
||||
ghAvailable: boolean
|
||||
activeAccount: GhAuthAccount | null
|
||||
accounts: GhAuthAccount[]
|
||||
/**
|
||||
* Whether the Electron main process itself sees GITHUB_TOKEN/GH_TOKEN in
|
||||
* its environment. Distinct from `activeAccount.envToken` because gh may
|
||||
* report an env source even when the variable was set in a parent shell
|
||||
* that didn't propagate to Electron, and vice versa.
|
||||
*/
|
||||
envTokenInProcess: 'GITHUB_TOKEN' | 'GH_TOKEN' | null
|
||||
missingScopes: string[]
|
||||
requiredScopes: string[]
|
||||
/**
|
||||
* True when there's a non-env keyring account on the same/another host
|
||||
* that the user could fall back to by unsetting the env var.
|
||||
*/
|
||||
hasKeyringFallback: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user