@@ -34,6 +34,62 @@ def test_raises_on_missing_non_nullable_opts
3434 assert_match ( /is required/ , e . message )
3535 end
3636
37+ def test_client_base_url_from_stagehand_api_url
38+ with_env ( "STAGEHAND_API_URL" => "http://localhost:5000/from/api/env" , "STAGEHAND_BASE_URL" => nil ) do
39+ stagehand =
40+ Stagehand ::Client . new (
41+ browserbase_api_key : "My Browserbase API Key" ,
42+ browserbase_project_id : "My Browserbase Project ID" ,
43+ model_api_key : "My Model API Key"
44+ )
45+
46+ assert_equal ( "http://localhost:5000/from/api/env" , stagehand . base_url . to_s )
47+ end
48+ end
49+
50+ def test_client_base_url_from_legacy_stagehand_base_url
51+ with_env ( "STAGEHAND_API_URL" => nil , "STAGEHAND_BASE_URL" => "http://localhost:5000/from/base/env" ) do
52+ stagehand =
53+ Stagehand ::Client . new (
54+ browserbase_api_key : "My Browserbase API Key" ,
55+ browserbase_project_id : "My Browserbase Project ID" ,
56+ model_api_key : "My Model API Key"
57+ )
58+
59+ assert_equal ( "http://localhost:5000/from/base/env" , stagehand . base_url . to_s )
60+ end
61+ end
62+
63+ def test_client_base_url_prefers_stagehand_api_url
64+ with_env (
65+ "STAGEHAND_API_URL" => "http://localhost:5000/from/api/env" ,
66+ "STAGEHAND_BASE_URL" => "http://localhost:5000/from/base/env"
67+ ) do
68+ stagehand =
69+ Stagehand ::Client . new (
70+ browserbase_api_key : "My Browserbase API Key" ,
71+ browserbase_project_id : "My Browserbase Project ID" ,
72+ model_api_key : "My Model API Key"
73+ )
74+
75+ assert_equal ( "http://localhost:5000/from/api/env" , stagehand . base_url . to_s )
76+ end
77+ end
78+
79+ def with_env ( vars )
80+ old_values = vars . keys . to_h { |key | [ key , ENV . fetch ( key , nil ) ] }
81+
82+ vars . each do |key , value |
83+ value . nil? ? ENV . delete ( key ) : ENV [ key ] = value
84+ end
85+
86+ yield
87+ ensure
88+ old_values . each do |key , value |
89+ value . nil? ? ENV . delete ( key ) : ENV [ key ] = value
90+ end
91+ end
92+
3793 def test_client_default_request_default_retry_attempts
3894 stub_request ( :post , "http://localhost/v1/sessions/start" ) . to_return_json ( status : 500 , body : { } )
3995
0 commit comments