fix(honcho): honor host-specific baseUrl

This commit is contained in:
LeonSGP43 2026-04-23 17:27:56 +08:00
parent 5e76c650bb
commit 26056fa965
2 changed files with 8 additions and 5 deletions

View file

@ -362,7 +362,9 @@ class HonchoClientConfig:
)
base_url = (
raw.get("baseUrl")
host_block.get("baseUrl")
or host_block.get("base_url")
or raw.get("baseUrl")
or raw.get("base_url")
or os.environ.get("HONCHO_BASE_URL", "").strip()
or None

View file

@ -251,16 +251,17 @@ class TestFromGlobalConfig:
config = HonchoClientConfig.from_global_config(config_path=config_file)
assert config.base_url == "http://config-host:9000"
def test_base_url_not_read_from_host_block(self, tmp_path):
"""baseUrl is a root-level connection setting, not overridable per-host (consistent with apiKey)."""
def test_base_url_host_block_overrides_root_and_env(self, tmp_path):
"""Host-specific baseUrl should win for self-hosted Honcho deployments."""
config_file = tmp_path / "config.json"
config_file.write_text(json.dumps({
"baseUrl": "http://root:9000",
"hosts": {"hermes": {"baseUrl": "http://host-block:9001"}},
}))
config = HonchoClientConfig.from_global_config(config_path=config_file)
assert config.base_url == "http://root:9000"
with patch.dict(os.environ, {"HONCHO_BASE_URL": "http://env:8000"}, clear=False):
config = HonchoClientConfig.from_global_config(config_path=config_file)
assert config.base_url == "http://host-block:9001"
def test_timeout_from_config_root(self, tmp_path):
config_file = tmp_path / "config.json"