Skip to content

fix(auth): harden login self-healing across probe, refresh, and cleanup#9

Merged
phil-accelbyte merged 2 commits into
mainfrom
fix/auth-login-self-healing
May 12, 2026
Merged

fix(auth): harden login self-healing across probe, refresh, and cleanup#9
phil-accelbyte merged 2 commits into
mainfrom
fix/auth-login-self-healing

Conversation

@phil-accelbyte

Copy link
Copy Markdown
Collaborator

Summary

Hardens the ags auth login self-healing flow (probe → refresh → grant) and surrounding state. Source: PR #33 on the internal Bitbucket mirror.

  • Refuse the session-probe short-circuit when the profile config is unreadable — previously could report a stale already_authenticated or silently fall through. JSON output now correctly asks for --base-url.
  • Classify session-refresh failures from helper-observed state so transient (network, 5xx) and permanent (invalid grant) failures are reported distinctly. The login JSON status field now matches reality.
  • Surface stale-token cleanup failures instead of swallowing them, and replace the 0-sentinel expires_in_secs with the real value so JSON consumers never see a phantom "0s" on a valid token.
  • Document the three real JSON status values (`logged_in`, `already_authenticated`, `refreshed`) in `auth login --help`.
  • Consolidate env-guard test helpers under `tests/common/env_guard.rs` and `src/support/test_helpers.rs`. Add coverage for the authorization-code refreshed JSON output path.

Test plan

  • `cargo check --all-targets`
  • `cargo test --lib` — 492 passed
  • Manual: `ags auth login` with valid session → `already_authenticated`
  • Manual: `ags auth login --format json` with unreadable profile config → clean error
  • Manual: `ags auth status --format json` shows real `token_expires_in` (no `0`-sentinel)

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.
@phil-accelbyte
phil-accelbyte merged commit fc7afd0 into main May 12, 2026
5 checks passed
@phil-accelbyte
phil-accelbyte deleted the fix/auth-login-self-healing branch May 12, 2026 13:29
@phil-accelbyte phil-accelbyte mentioned this pull request May 12, 2026
3 tasks
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