Skip to content

fix(tests): mock keychain in TestReadClaudeCodeCredentials to prevent credential leakage#26215

Closed
therahul-yo wants to merge 1 commit into
NousResearch:mainfrom
therahul-yo:fix/test-keychain-isolation-anthropic-adapter
Closed

fix(tests): mock keychain in TestReadClaudeCodeCredentials to prevent credential leakage#26215
therahul-yo wants to merge 1 commit into
NousResearch:mainfrom
therahul-yo:fix/test-keychain-isolation-anthropic-adapter

Conversation

@therahul-yo

Copy link
Copy Markdown
Contributor

Summary

  • TestReadClaudeCodeCredentials tests were written before _read_claude_code_credentials_from_keychain was added to read_claude_code_credentials()
  • On macOS machines with real Claude Code credentials in the Keychain, the unmocked keychain call returns live credentials, causing test assertions to fail and leaking real tokens in test output
  • Added an autouse fixture that stubs _read_claude_code_credentials_from_keychain to None so all tests in the class exclusively exercise the file-based credential path

Test plan

  • Run python -m pytest tests/agent/test_anthropic_adapter.py::TestReadClaudeCodeCredentials -v — all 5 tests pass
  • Confirm tests also pass on machines without Claude Code credentials in the Keychain (no regression)

Platforms tested

  • macOS (Darwin) with real Claude Code credentials present in Keychain

🤖 Generated with Claude Code

… credential leakage

Tests in TestReadClaudeCodeCredentials were not mocking
_read_claude_code_credentials_from_keychain, which was added after the
tests were written. On macOS machines with real Claude Code credentials
stored in the Keychain, the function returns live credentials instead of
the test fixtures, causing assertions to fail and leaking real tokens in
test output.

Add an autouse fixture that stubs the keychain reader to None so all
tests in the class exercise only the file-based credential path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alt-glitch alt-glitch added type/test Test coverage or test infrastructure P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder provider/anthropic Anthropic native Messages API labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #22692 (same autouse fixture approach to stub _read_claude_code_credentials_from_keychain). See also closed #16498 and #15958 which had the same fix.

NishantEC

This comment was marked as outdated.

teknium1 added a commit that referenced this pull request May 17, 2026
…tors

Adds release-note attribution mappings for 9 contributors from group 3:
- @darvsum (PR #26766)
- @hueilau (PR #26498)
- @Timur00Kh (PR #27114)
- @Grogger (PR #27061)
- @lemassykoi (PR #27042)
- @draplater (PR #26707)
- @pr7426 (PR #27048)
- @therahul-yo (PR #26215)
- @flamiinngo (PR #27205)

#27154 dropped from this batch — already landed on main as 4e9cedc.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #27302 — your commit was cherry-picked onto current main as part of a batch salvage of low-risk new-contributor PRs. Authorship preserved (fix(tests): mock keychain in TestReadClaudeCodeCredentials to prevent credential leakage). Thanks for the contribution.

@teknium1 teknium1 closed this May 17, 2026
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants