@@ -48,6 +48,7 @@ def test_hosts_the_agent_was_deployed_to_reach_directly_stay_direct_on_an_armed_
4848def test_a_model_endpoint_over_plain_http_or_at_a_private_address_is_reached_directly_on_an_armed_clock (
4949 monkeypatch , base_url , direct ):
5050 resolves = {"litellm.internal" : "10.1.2.3" , "litellm.example.com" : "93.184.216.34" }
51+ monkeypatch .setattr (claude_bridge , "_GLOBAL_HOSTS" , {})
5152 monkeypatch .setattr (claude_bridge .socket , "getaddrinfo" ,
5253 lambda host , port : [(None , None , None , "" , (resolves [host ], 0 ))])
5354 env = claude_bridge .cli_env ({claude_bridge .EGRESS_PROXY_ENV : PROXY , "LITELLM_BASE_URL" : base_url ,
@@ -102,3 +103,25 @@ def test_while_the_follower_reconnects_or_restarts_the_page_still_routes_the_cli
102103 page .write_bytes (_page (1 ))
103104 env = claude_bridge .cli_env ({claude_bridge .EGRESS_PROXY_ENV : PROXY }, clock_armed = claude_bridge .clock_armed (str (page )))
104105 assert env ["HTTPS_PROXY" ] == PROXY
106+
107+
108+ def test_a_model_host_that_doesnt_resolve_in_time_is_left_to_the_proxy_and_asked_once (monkeypatch ):
109+ # A slow resolver holds a CLI's start for _RESOLVE_TIMEOUT_S at most, and only the first time.
110+ import threading
111+
112+ asked , release = [], threading .Event ()
113+
114+ def slow (host , port ):
115+ asked .append (host )
116+ release .wait (5 )
117+ return [(None , None , None , "" , ("10.1.2.3" , 0 ))]
118+
119+ monkeypatch .setattr (claude_bridge , "_GLOBAL_HOSTS" , {})
120+ monkeypatch .setattr (claude_bridge , "_RESOLVE_TIMEOUT_S" , 0.05 )
121+ monkeypatch .setattr (claude_bridge .socket , "getaddrinfo" , slow )
122+ try :
123+ assert claude_bridge .model_direct_hosts ("https://slow.internal" ) == []
124+ assert claude_bridge .model_direct_hosts ("https://slow.internal" ) == []
125+ finally :
126+ release .set ()
127+ assert asked == ["slow.internal" ]
0 commit comments