Skip to content

feat(auth): sort scopes alphabetically wherever they're displayed#483

Merged
platinummonkey merged 2 commits into
DataDog:mainfrom
srosenthal-dd:stephen.rosenthal/auth-list-scopes
May 9, 2026
Merged

feat(auth): sort scopes alphabetically wherever they're displayed#483
platinummonkey merged 2 commits into
DataDog:mainfrom
srosenthal-dd:stephen.rosenthal/auth-list-scopes

Conversation

@srosenthal-dd
Copy link
Copy Markdown
Member

Summary

Scopes arrive from the OAuth issuer in non-deterministic order, which makes pup's various scope-display surfaces unstable across invocations and hard to scan or diff. Sort them alphabetically at every display point.

Surfaces touched

  • pup auth login pre-launch print (the 🔑 Requesting N scope(s): ... line when scope count is small enough to be inlined).
  • pup auth list JSON output: each session's scopes array is now sorted.
  • pup auth status JSON output: same.
  • dcr::build_authorization_url: the printed authorize URL's scope= parameter is sorted too. OAuth treats scope as an unordered set so this is a no-op for the issuer; for users it makes the URL stable enough to grep or diff across runs.

A small sorted_scopes(scope_claim: &str) -> Vec<&str> helper deduplicates the parse-and-sort step shared by list and status.

Schema

The JSON output schema is unchanged (scopes stays a Vec<String> array). Only the order changes, so existing snapshot fixtures at tests/snapshots/auth_list__{human,agent}.json continue to pass.

Test plan

  • cargo test --bin pup — 67 auth-related tests pass, 2 new for sorted_scopes.
  • cargo clippy --bin pup --all-targets -- -D warnings clean.
  • cargo fmt --check clean.
  • Local E2E with synthetic sessions.json + tokens via PUP_CONFIG_DIR and DD_TOKEN_STORAGE=file: pup auth list and pup auth status both emit alphabetised arrays.

Scopes arrive from the OAuth issuer in non-deterministic order, which
makes pup's various scope-display surfaces hard to scan and unstable
between invocations. Sort them at every point we render to a user:

- `pup auth login` pre-launch print: alphabetised before the joined
  display line.
- `pup auth list` JSON: scopes array now sorted.
- `pup auth status` JSON: same.
- `dcr::build_authorization_url`: the printed authorize URL's `scope=`
  parameter is sorted too. OAuth treats scope as an unordered set so
  this is a no-op for the issuer; for users it makes the URL stable
  enough to grep/diff across runs.

A small `sorted_scopes(&str) -> Vec<&str>` helper de-duplicates the
parse-and-sort step shared by list and status. The schema of the JSON
output is unchanged (still an array of strings); only the order
changes.
…h-list-scopes

# Conflicts:
#	src/auth/dcr.rs
#	src/commands/auth.rs
@srosenthal-dd srosenthal-dd marked this pull request as ready for review May 8, 2026 19:27
@srosenthal-dd srosenthal-dd requested a review from a team as a code owner May 8, 2026 19:27
@platinummonkey platinummonkey merged commit 23378dc into DataDog:main May 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants