Skip to content

[AUTOMATION] fix: optimize auth login scope dedup#248

Open
michiosw wants to merge 1 commit into
mainfrom
fix/optimize-login-scope-dedup
Open

[AUTOMATION] fix: optimize auth login scope dedup#248
michiosw wants to merge 1 commit into
mainfrom
fix/optimize-login-scope-dedup

Conversation

@michiosw

@michiosw michiosw commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary
This optimizes auth login scope resolution by deduplicating requested scopes in one pass.

Before this, every extra scope scanned the already-built slice in internal/auth/oidc.go, which turned duplicate filtering into repeated linear work.

Now a small seen-set is the canonical path:

seen := make(map[string]struct{}, len(resolved)+len(scopes))
for _, scope := range resolved {
    seen[scope] = struct{}{}
}

Why
This gives kontext-cli a cheaper runtime path for OAuth login scope assembly:

login request
-> resolveLoginScopes
-> ordered deduplicated scope list

This PR does not broaden behavior beyond the optimization scope.

What changed
Optimized OAuth login scope dedup in resolveLoginScopes
Removed repeated linear membership scans for every requested scope
Preserved scope order and default-vs-identity scope behavior
Updated tests for repeated custom scope deduplication

Verification
go test ./internal/auth
go test ./internal/guard/judge
go test ./...
go vet ./...
git diff --check

michiosw commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown

Greptile Summary

This PR optimizes OAuth login scope assembly. The main changes are:

  • Replaces repeated linear scope membership checks with a seen map.
  • Preserves base scope ordering before appending requested scopes.
  • Removes the now-unused hasScope helper.
  • Adds regression coverage for repeated custom scope deduplication.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
internal/auth/oidc.go Scope deduplication now uses a membership map while keeping the same output order and default-scope behavior.
internal/auth/oidc_test.go Adds coverage for repeated custom scopes being collapsed to their first occurrence.

Reviews (1): Last reviewed commit: "fix(auth): optimize login scope dedup" | Re-trigger Greptile

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