fix(credential_pool): exact-match copilot source name instead of substring - #76349
fix(credential_pool): exact-match copilot source name instead of substring#76349wangyunyou wants to merge 1 commit into
Conversation
…tring The copilot source-name mapping used "gh" in source.lower() to decide between the gh CLI and env-var sources. Every env var name — GH_TOKEN, GITHUB_TOKEN, COPILOT_GITHUB_TOKEN — contains the substring "gh", so env-seeded copilot entries were tagged as gh_cli instead of env:<VAR>. That mislabeling breaks per-source suppression: a user who suppressed only the gh CLI path (hermes auth remove copilot gh_cli) also lost their env-var token, because the env entry was filed under gh_cli and tripped the same suppression check. It also mislabeled entries in hermes auth list. resolve_copilot_token() returns exactly "gh auth token" for the gh CLI path and the raw env var name otherwise, so the mapping can be an exact match. Add regression tests covering env tagging and gh_cli-suppression independence.
Related: #76341 repairs when suppression is checked; this PR repairs how the resolved Copilot source is named. Both change the same credential-pool flow and are complementary rather than duplicates. |
|
Thanks for the focused credential-source fix. The premise is confirmed on current main: The new tests cover both the corrected source label and the resulting per-source suppression behavior. The related #76341 change remains complementary: its current diff moves suppression earlier but retains the substring mapping, so any combined salvage should preserve this exact-match mapping. Automated hermes-sweeper review. |
Problem
The copilot source-name mapping in
_seed_from_singletonsused a substring test to decide between the gh CLI and env-var sources:Every copilot env var name —
GH_TOKEN,GITHUB_TOKEN,COPILOT_GITHUB_TOKEN— contains the substring "gh", so env-seeded copilot credentials were tagged asgh_cliinstead ofenv:<VAR>.That mislabeling breaks per-source suppression:
hermes auth remove copilot gh_clisuppresses all sources, but a manual/partial suppression of justgh_cli) also lost their env-var token — the env entry was filed undergh_cliand tripped the same suppression check.hermes auth listmislabeled env-seeded entries asgh_cli.Verified against the pre-fix code: with
suppressed_sources.copilot = ["gh_cli"]and a liveGH_TOKENenv var, the pool seeds 0 entries (env token wrongly suppressed). After the fix it seeds 1 entry withsource = "env:GH_TOKEN".Fix
resolve_copilot_token()returns exactly"gh auth token"for the gh CLI path and the raw env var name otherwise, so the mapping is now an exact match:The gh CLI path still maps to
gh_cli(unchanged); env sources now map to their trueenv:<VAR>names, so suppression and display are per-source correct.Test
Two new regression tests in
tests/agent/test_credential_pool.py:test_load_pool_tags_env_copilot_source_as_env_var— env source seeds withsource == "env:GH_TOKEN".test_load_pool_env_copilot_ignores_gh_cli_suppression— suppressinggh_clileavesenv:GH_TOKENseedable.Full suite: 77 tests passed (credential_pool 55 + copilot auth/exchange 22).