fix(auth): harden login self-healing across probe, refresh, and cleanup#9
Merged
Conversation
The auth login flow short-circuits when a session is already valid, refreshes when only the refresh token survives, and falls through to a full grant otherwise. Several edge cases produced confusing output or silent regressions: - Refused the session-probe short-circuit when the profile config is unreadable (e.g. `chmod 000`). Previously it reported a stale "already_authenticated" or silently fell through; now the unreadable profile is treated as no session and `auth login --format json` cleanly asks for `--base-url`. - Classified session-refresh failures from helper-observed state so a refresh that fails for transient reasons (network, server 5xx) is distinguished from permanent ones (invalid grant). The login JSON status field now matches what actually happened. - Surfaced stale-token cleanup failures instead of swallowing them, and replaced the 0-sentinel `expires_in_secs` with the real value so JSON consumers never see a phantom "0s" remaining on a valid token. - Documented the three real JSON status values in `auth login --help` (`logged_in`, `already_authenticated`, `refreshed`). - Consolidated env-guard helpers under `tests/common/env_guard.rs` and `src/support/test_helpers.rs`, and added coverage for the authorization-code refreshed JSON output path.
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
Hardens the
ags auth loginself-healing flow (probe → refresh → grant) and surrounding state. Source: PR #33 on the internal Bitbucket mirror.already_authenticatedor silently fall through. JSON output now correctly asks for--base-url.statusfield now matches reality.0-sentinelexpires_in_secswith the real value so JSON consumers never see a phantom "0s" on a valid token.Test plan