@@ -51,5 +51,36 @@ def test_user_agent_with_integration(
5151 assert mock_system .called
5252
5353
54+ @patch ("runpod.user_agent.platform.system" , return_value = "Linux" )
55+ @patch ("runpod.user_agent.platform.release" , return_value = "5.4" )
56+ @patch ("runpod.user_agent.platform.machine" , return_value = "x86_64" )
57+ @patch ("runpod.user_agent.platform.python_version" , return_value = "3.9.5" )
58+ @patch .dict (os .environ , {"CLAUDECODE" : "1" }, clear = False )
59+ def test_user_agent_with_claude_code (
60+ self , mock_python_version , mock_machine , mock_release , mock_system
61+ ):
62+ """Test the User-Agent string includes claude-code agent tag."""
63+ if "RUNPOD_UA_INTEGRATION" in os .environ :
64+ del os .environ ["RUNPOD_UA_INTEGRATION" ]
65+
66+ expected_ua = f"RunPod-Python-SDK/{ runpod_version } (Linux 5.4; x86_64) Language/Python 3.9.5 (via claude-code)"
67+ self .assertEqual (construct_user_agent (), expected_ua )
68+
69+ @patch ("runpod.user_agent.platform.system" , return_value = "Linux" )
70+ @patch ("runpod.user_agent.platform.release" , return_value = "5.4" )
71+ @patch ("runpod.user_agent.platform.machine" , return_value = "x86_64" )
72+ @patch ("runpod.user_agent.platform.python_version" , return_value = "3.9.5" )
73+ def test_user_agent_without_claude_code (
74+ self , mock_python_version , mock_machine , mock_release , mock_system
75+ ):
76+ """Test the User-Agent string excludes agent tag when env var is not set."""
77+ for key in ("RUNPOD_UA_INTEGRATION" , "CLAUDECODE" ):
78+ if key in os .environ :
79+ del os .environ [key ]
80+
81+ ua = construct_user_agent ()
82+ self .assertNotIn ("via claude-code" , ua )
83+
84+
5485if __name__ == "__main__" :
5586 unittest .main ()
0 commit comments