From 5efbd7cb05519d112bfd045371e600af19f7e12d Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 1 Jul 2026 15:19:58 +0530 Subject: [PATCH] test(anthropic): scope OAuth-UA source check to header lines, not any mention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The salvaged test_token_exchange_ua_prefix did a naive whole-function substring check for 'claude-cli/', which false-positives on an explanatory comment that references the old (blocked) UA. Scope it to actual User-Agent header lines — mirroring the sibling test_no_claude_cli_in_source — so a comment documenting why claude-cli/ is avoided doesn't trip it. Mutation-checked: an actual claude-cli/ UA header still fails the test. --- tests/agent/test_anthropic_oauth_ua_prefix.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/agent/test_anthropic_oauth_ua_prefix.py b/tests/agent/test_anthropic_oauth_ua_prefix.py index 5e6ae887f..aba5cc021 100644 --- a/tests/agent/test_anthropic_oauth_ua_prefix.py +++ b/tests/agent/test_anthropic_oauth_ua_prefix.py @@ -58,9 +58,16 @@ class TestOAuthUserAgentPrefix: except AttributeError: pytest.skip("run_hermes_oauth_login_pure not found") - assert "claude-cli/" not in source, ( - "run_hermes_oauth_login_pure still uses claude-cli/ UA" - ) + # Only fail on claude-cli/ in an actual User-Agent header line — a + # comment that references the old behavior (e.g. "Anthropic blocks + # claude-cli/ on the OAuth endpoint") is allowed. Mirrors the + # header-scoped check in test_no_claude_cli_in_source. + for i, line in enumerate(source.split("\n"), 1): + stripped = line.strip() + if "claude-cli/" in stripped and ("User-Agent" in stripped or "user-agent" in stripped): + pytest.fail( + f"Line {i}: run_hermes_oauth_login_pure still uses claude-cli/ UA header: {stripped}" + ) assert "claude-code/" in source, ( "run_hermes_oauth_login_pure should use claude-code/ UA" )