fix(test): mock keychain lookup in anthropic oauth setup tests - #35093
zons-zhaozhy wants to merge 1 commit into
Conversation
The upstream tests for _run_oauth_setup_token mock subprocess.run at the
outer level, but _read_claude_code_credentials_from_keychain() calls
subprocess.run internally. The MagicMock return value from the outer patch
leaks through to json.loads() inside the keychain helper, causing:
TypeError: the JSON object must be str, bytes or bytearray, not MagicMock
This only manifests on macOS where keychain lookups are attempted.
Linux CI (the upstream default) skips the keychain path entirely.
Fix: monkeypatch _read_claude_code_credentials_from_keychain to return
None in the three affected tests, preventing the MagicMock from reaching
json.loads().
Before: 3 FAILED, 150 passed
After: 153 passed
|
Thanks for isolating this macOS-specific test path. The premise remains valid on current Automated hermes-sweeper review. |
|
Thanks @zons-zhaozhy — closing as resolved on main: the suite-wide autouse Keychain guard from PR #74517 (via #35464) supersedes the per-test mock, covering every test module. You were the earliest on this class (May 30) — credited. Verified post-merge. |
Problem
3 tests in
tests/agent/test_anthropic_adapter.pyfail on macOS:All fail with:
Root Cause
_read_claude_code_credentials_from_keychain()callssubprocess.runinternally. The tests mocksubprocess.runat the outer level viapatch("subprocess.run"), but the MagicMock return value leaks intojson.loads()inside the keychain helper.This only manifests on macOS where keychain lookups are attempted. The upstream CI runs on Linux and skips the keychain path entirely, so it never hits this.
Fix
monkeypatch.setattrthe keychain helper to returnNonein the three affected tests, preventing the MagicMock from reachingjson.loads().Testing