@@ -60,6 +60,21 @@ def test_custom_workspace(self):
6060 config = HonchoClientConfig .from_env (workspace_id = "custom" )
6161 assert config .workspace_id == "custom"
6262
63+ def test_reads_base_url_from_env (self ):
64+ with patch .dict (os .environ , {"HONCHO_BASE_URL" : "http://localhost:8000" }, clear = False ):
65+ config = HonchoClientConfig .from_env ()
66+ assert config .base_url == "http://localhost:8000"
67+ assert config .enabled is True
68+
69+ def test_enabled_without_api_key_when_base_url_set (self ):
70+ """base_url alone (no API key) is sufficient to enable a local instance."""
71+ with patch .dict (os .environ , {"HONCHO_BASE_URL" : "http://localhost:8000" }, clear = False ):
72+ os .environ .pop ("HONCHO_API_KEY" , None )
73+ config = HonchoClientConfig .from_env ()
74+ assert config .api_key is None
75+ assert config .base_url == "http://localhost:8000"
76+ assert config .enabled is True
77+
6378
6479class TestFromGlobalConfig :
6580 def test_missing_config_falls_back_to_env (self , tmp_path ):
@@ -188,6 +203,36 @@ def test_api_key_env_fallback(self, tmp_path):
188203 config = HonchoClientConfig .from_global_config (config_path = config_file )
189204 assert config .api_key == "env-key"
190205
206+ def test_base_url_env_fallback (self , tmp_path ):
207+ """HONCHO_BASE_URL env var is used when no baseUrl in config JSON."""
208+ config_file = tmp_path / "config.json"
209+ config_file .write_text (json .dumps ({"workspace" : "local" }))
210+
211+ with patch .dict (os .environ , {"HONCHO_BASE_URL" : "http://localhost:8000" }, clear = False ):
212+ config = HonchoClientConfig .from_global_config (config_path = config_file )
213+ assert config .base_url == "http://localhost:8000"
214+ assert config .enabled is True
215+
216+ def test_base_url_from_config_root (self , tmp_path ):
217+ """baseUrl in config root is read and takes precedence over env var."""
218+ config_file = tmp_path / "config.json"
219+ config_file .write_text (json .dumps ({"baseUrl" : "http://config-host:9000" }))
220+
221+ with patch .dict (os .environ , {"HONCHO_BASE_URL" : "http://localhost:8000" }, clear = False ):
222+ config = HonchoClientConfig .from_global_config (config_path = config_file )
223+ assert config .base_url == "http://config-host:9000"
224+
225+ def test_base_url_not_read_from_host_block (self , tmp_path ):
226+ """baseUrl is a root-level connection setting, not overridable per-host (consistent with apiKey)."""
227+ config_file = tmp_path / "config.json"
228+ config_file .write_text (json .dumps ({
229+ "baseUrl" : "http://root:9000" ,
230+ "hosts" : {"hermes" : {"baseUrl" : "http://host-block:9001" }},
231+ }))
232+
233+ config = HonchoClientConfig .from_global_config (config_path = config_file )
234+ assert config .base_url == "http://root:9000"
235+
191236
192237class TestResolveSessionName :
193238 def test_manual_override (self ):
0 commit comments