From 920b350e57544285002c813b35747ebcc6659f9a Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 25 May 2026 01:06:11 -0700 Subject: [PATCH] test(auth): align copilot-remove test with borrowed-credential policy (#31416) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #31416 (avoid persisting borrowed credential secrets) added sanitize_borrowed_credential_payload, which strips access_token from any auth.json pool entry whose (provider, source) isn't in the _PERSISTABLE_PROVIDER_SOURCES allowlist. (copilot, gh_cli) is borrowed (not in the allowlist), so the test fixture's pre-seeded access_token now gets stripped at load_pool() time, leaving the pool empty. resolve_target('1') then fails with 'No credential #1. Provider: copilot.' Fix: align the test with the new contract. At runtime, copilot tokens are hydrated by resolve_copilot_token() — mock that path so the pool gets an entry the test can remove. The behavior under test (suppression of gh_cli + env variants on remove) is unchanged. CI repro on origin/main HEAD; reproduced locally with stock checkout. --- tests/hermes_cli/test_auth_commands.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/hermes_cli/test_auth_commands.py b/tests/hermes_cli/test_auth_commands.py index 22182ba43a8..801b190cd79 100644 --- a/tests/hermes_cli/test_auth_commands.py +++ b/tests/hermes_cli/test_auth_commands.py @@ -1590,20 +1590,16 @@ def test_auth_remove_copilot_suppresses_all_variants(tmp_path, monkeypatch): hermes_home.mkdir(parents=True, exist_ok=True) monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + # The copilot pool entry is no longer persisted directly in auth.json — + # `(copilot, gh_cli)` is borrowed and stripped by + # sanitize_borrowed_credential_payload (PR #31416, May 2026). Tokens are + # hydrated at runtime via resolve_copilot_token(). Mock that path so the + # pool has an entry to remove. _write_auth_store( tmp_path, { "version": 1, - "credential_pool": { - "copilot": [{ - "id": "c1", - "label": "gh auth token", - "auth_type": "api_key", - "priority": 0, - "source": "gh_cli", - "access_token": "ghp_fake", - }] - }, + "credential_pool": {"copilot": []}, }, ) @@ -1611,7 +1607,14 @@ def test_auth_remove_copilot_suppresses_all_variants(tmp_path, monkeypatch): from hermes_cli.auth import is_source_suppressed from hermes_cli.auth_commands import auth_remove_command - auth_remove_command(SimpleNamespace(provider="copilot", target="1")) + with patch( + "hermes_cli.copilot_auth.resolve_copilot_token", + return_value=("ghp_fake", "gh"), + ), patch( + "hermes_cli.copilot_auth.get_copilot_api_token", + return_value="ghu_fake_api", + ): + auth_remove_command(SimpleNamespace(provider="copilot", target="1")) assert is_source_suppressed("copilot", "gh_cli") assert is_source_suppressed("copilot", "env:COPILOT_GITHUB_TOKEN")