The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tests): carry hermetic guards across the anthropic adapter module split
Tekniumb095c3d958c8
diff --git a/tests/conftest.py b/tests/conftest.pyindex 56c92149fb7..e4dfb0ed067 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -21,6 +21,7 @@ test runner at ``scripts/run_tests.sh``.import asyncioimport atexit+import importlibimport osimport shutilimport sqlite3@@ -630,17 +631,21 @@ def _neutralize_macos_keychain_creds(request, monkeypatch):if request.node.get_closest_marker(_ALLOW_MACOS_KEYCHAIN_MARK):return None- try:- import agent.anthropic_adapter as _anthropic_adapter- except Exception:- return None-- monkeypatch.setattr(- _anthropic_adapter,- "_read_claude_code_credentials_from_keychain",- lambda *_args, **_kwargs: None,- raising=False,- )+ # Patch the implementation owner (agent.anthropic_credentials) AND the+ # adapter re-export: after the adapter godfile split, the real call+ # executes inside agent.anthropic_credentials, so patching only the+ # adapter alias silently stopped intercepting Keychain reads.+ for _module_name in ("agent.anthropic_credentials", "agent.anthropic_adapter"):+ try:+ _mod = importlib.import_module(_module_name)+ except Exception:+ continue+ monkeypatch.setattr(+ _mod,+ "_read_claude_code_credentials_from_keychain",+ lambda *_args, **_kwargs: None,+ raising=False,+ )return Nonediff --git a/tests/test_hermetic_side_effect_guards.py b/tests/test_hermetic_side_effect_guards.pyindex f6bbada2113..983e6c44ada 100644--- a/tests/test_hermetic_side_effect_guards.py+++ b/tests/test_hermetic_side_effect_guards.py@@ -34,17 +34,20 @@ def test_webbrowser_get_controller_is_neutralized(_neutralize_webbrowser):def _isolate_anthropic_credentials(monkeypatch, tmp_path):from agent import anthropic_adapter as aa+ from agent import anthropic_credentials as acmonkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)monkeypatch.delenv("ANTHROPIC_TOKEN", raising=False)monkeypatch.delenv("CLAUDE_CODE_OAUTH_TOKEN", raising=False)- monkeypatch.setattr(aa.Path, "home", lambda: tmp_path)- monkeypatch.setattr(aa.platform, "system", lambda: "Darwin")+ # Patch the implementation owner (anthropic_credentials); the adapter+ # merely re-exports these functions after the godfile split.+ monkeypatch.setattr(ac.Path, "home", lambda: tmp_path)+ monkeypatch.setattr(ac.platform, "system", lambda: "Darwin")def _real_keychain_reached(*_args, **_kwargs):raise AssertionError("test reached the real macOS Keychain command")- monkeypatch.setattr(aa.subprocess, "run", _real_keychain_reached)+ monkeypatch.setattr(ac.subprocess, "run", _real_keychain_reached)return aadiff --git a/tests/tools/test_subprocess_stdin_guard.py b/tests/tools/test_subprocess_stdin_guard.pyindex 7081e6c0904..d3957fd9b67 100644--- a/tests/tools/test_subprocess_stdin_guard.py+++ b/tests/tools/test_subprocess_stdin_guard.py@@ -42,16 +42,30 @@ def test_oauth_setup_token_keeps_inherited_stdin():break interactive token setup. A blanket DEVNULL sweep over TUI-contextsubprocess calls must leave this one inheriting stdin. Regression guard forthe over-application caught while salvaging the stdin-EOF fix.++ The call's owner moved from agent/anthropic_adapter.py into+ agent/anthropic_credentials.py in the adapter godfile split; the guard+ scans both seams so a future move fails loudly instead of going dark."""- src = (REPO_ROOT / "agent" / "anthropic_adapter.py").read_text()- assert 'subprocess.run([claude_path, "setup-token"])' in src, (- "interactive setup-token call changed shape; re-verify it still "- "inherits stdin (no stdin=subprocess.DEVNULL)"- )- assert 'subprocess.run([claude_path, "setup-token"], stdin' not in src, (- "setup-token must inherit stdin so the user can complete the OAuth "- "login prompt; do not add stdin=subprocess.DEVNULL"+ candidates = [+ REPO_ROOT / "agent" / "anthropic_credentials.py",+ REPO_ROOT / "agent" / "anthropic_adapter.py",+ ]+ sources = [p.read_text() for p in candidates if p.exists()]+ owners = [+ src for src in sources+ if 'subprocess.run([claude_path, "setup-token"])' in src+ ]+ assert owners, (+ "interactive setup-token call changed shape or moved; re-verify it "+ "still inherits stdin (no stdin=subprocess.DEVNULL) and update this "+ "guard's candidate list")+ for src in sources:+ assert 'subprocess.run([claude_path, "setup-token"], stdin' not in src, (+ "setup-token must inherit stdin so the user can complete the OAuth "+ "login prompt; do not add stdin=subprocess.DEVNULL"+ )def test_inline_noqa_marker_exempts_a_call():