@@ -32,6 +32,36 @@ def test_client_config_from_env_reads_api_key_and_base_url(monkeypatch):
3232 assert config .base_url == "https://example.local"
3333
3434
35+ def test_client_config_from_env_reads_headers (monkeypatch ):
36+ monkeypatch .setenv ("HYPERBROWSER_API_KEY" , "test-key" )
37+ monkeypatch .setenv ("HYPERBROWSER_HEADERS" , '{"X-Request-Id":"abc123"}' )
38+
39+ config = ClientConfig .from_env ()
40+
41+ assert config .headers == {"X-Request-Id" : "abc123" }
42+
43+
44+ def test_client_config_from_env_rejects_invalid_headers_json (monkeypatch ):
45+ monkeypatch .setenv ("HYPERBROWSER_API_KEY" , "test-key" )
46+ monkeypatch .setenv ("HYPERBROWSER_HEADERS" , "{invalid" )
47+
48+ with pytest .raises (
49+ HyperbrowserError , match = "HYPERBROWSER_HEADERS must be valid JSON object"
50+ ):
51+ ClientConfig .from_env ()
52+
53+
54+ def test_client_config_from_env_rejects_non_object_headers_json (monkeypatch ):
55+ monkeypatch .setenv ("HYPERBROWSER_API_KEY" , "test-key" )
56+ monkeypatch .setenv ("HYPERBROWSER_HEADERS" , '["not-an-object"]' )
57+
58+ with pytest .raises (
59+ HyperbrowserError ,
60+ match = "HYPERBROWSER_HEADERS must be a JSON object of string pairs" ,
61+ ):
62+ ClientConfig .from_env ()
63+
64+
3565def test_client_config_from_env_normalizes_base_url (monkeypatch ):
3666 monkeypatch .setenv ("HYPERBROWSER_API_KEY" , "test-key" )
3767 monkeypatch .setenv ("HYPERBROWSER_BASE_URL" , " https://example.local/ " )
0 commit comments