From c28114a5f8b13e8b294a7ff789e45f3503b6cb0e Mon Sep 17 00:00:00 2001 From: Daniel Magro <87080165+DanDo385@users.noreply.github.com> Date: Mon, 10 Aug 2026 09:38:50 -0400 Subject: [PATCH] fix(tests): isolate suite fixtures from host auth --- .../agent/test_anthropic_output_field_leak.py | 3 --- tests/agent/test_credential_pool_routing.py | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/agent/test_anthropic_output_field_leak.py b/tests/agent/test_anthropic_output_field_leak.py index 93c05c3e62299..138aba2c0ef38 100644 --- a/tests/agent/test_anthropic_output_field_leak.py +++ b/tests/agent/test_anthropic_output_field_leak.py @@ -10,9 +10,6 @@ Fix: whitelist input-permitted fields per block type at three points — normalize_response capture, _sanitize_replay_block (ordered-blocks replay), and _convert_content_part_to_anthropic (content-list replay). """ -import sys, os -sys.path.insert(0, os.path.expanduser("~/.hermes/hermes-agent")) - import pytest from agent.anthropic_adapter import ( _sanitize_replay_block, diff --git a/tests/agent/test_credential_pool_routing.py b/tests/agent/test_credential_pool_routing.py index d7e68e840cae6..61f9e4274c101 100644 --- a/tests/agent/test_credential_pool_routing.py +++ b/tests/agent/test_credential_pool_routing.py @@ -371,15 +371,35 @@ class TestFailureAttribution: """ def _make_pool(self, tmp_path, monkeypatch, entries): - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes")) hermes_home = tmp_path / "hermes" hermes_home.mkdir(parents=True, exist_ok=True) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + # Keep host Anthropic/Claude credentials out of this fixture. load_pool() + # auto-seeds ~/.claude/.credentials.json and env keys when anthropic is + # explicitly configured on the machine, which turns a deliberate + # single-entry pool into a multi-entry pool and invalidates isolation + # assertions (see test_unmatched_key_does_not_retry_only_pool_entry). + for env_var in ( + "ANTHROPIC_API_KEY", + "ANTHROPIC_TOKEN", + "CLAUDE_CODE_OAUTH_TOKEN", + ): + monkeypatch.delenv(env_var, raising=False) + monkeypatch.setattr( + "hermes_cli.auth.is_provider_explicitly_configured", + lambda provider: False, + ) (hermes_home / "auth.json").write_text( - json.dumps({"version": 1, "credential_pool": {"anthropic": entries}}) + json.dumps({"version": 1, "credential_pool": {"anthropic": entries}}), + encoding="utf-8", ) from agent.credential_pool import load_pool - return load_pool("anthropic") + pool = load_pool("anthropic") + assert [entry.id for entry in pool.entries()] == [ + entry["id"] for entry in entries + ], "pool fixture leaked host credentials into the test pool" + return pool def _entry(self, idx, key, **overrides): entry = {