aboutsummaryrefslogtreecommitdiffstats
path: root/test_llamachat.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_llamachat.py')
-rwxr-xr-xtest_llamachat.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py
index a06d737..6a5c0e6 100755
--- a/test_llamachat.py
+++ b/test_llamachat.py
@@ -905,6 +905,62 @@ def test_config_defaults():
print("ok config defaults")
+def test_provider_parsing():
+ """Providers come from [providers.*]; a bare base_url synthesizes local."""
+ from llamachat import providers
+
+ # A modern config with two providers.
+ parsed = providers.parse(
+ {
+ "providers": {
+ "local": {"base_url": "http://localhost:8181/"},
+ "together": {
+ "base_url": "https://api.example.org",
+ "api_key": "env:TEST_KEY_NAME",
+ "filter": ["qwen", "deepseek"],
+ "ctx_size": 32768,
+ "price_in": 0.6,
+ "price_out": 0.9,
+ },
+ }
+ }
+ )
+ assert set(parsed) == {"local", "together"}
+ # Trailing slashes are stripped so URL joining stays predictable.
+ assert parsed["local"].base_url == "http://localhost:8181"
+ assert parsed["local"].api_key == ""
+ assert parsed["together"].filter == ["qwen", "deepseek"]
+ assert parsed["together"].ctx_size == 32768
+ assert parsed["together"].price_in == 0.6
+ assert parsed["together"].price_out == 0.9
+
+ # An old config: bare base_url, no providers table at all.
+ legacy = providers.parse({"base_url": "http://localhost:8181"})
+ assert set(legacy) == {"local"}
+ assert legacy["local"].base_url == "http://localhost:8181"
+
+ # Both present: the explicit entry wins over the bare key.
+ both = providers.parse(
+ {
+ "base_url": "http://ignored.example.org",
+ "providers": {"local": {"base_url": "http://explicit.example.org"}},
+ }
+ )
+ assert both["local"].base_url == "http://explicit.example.org"
+
+ # A provider with no base_url is skipped rather than half-configured.
+ broken = providers.parse(
+ {"providers": {"local": {"base_url": "http://x.example.org"},
+ "bad": {"api_key": "literal"}}}
+ )
+ assert set(broken) == {"local"}
+
+ # Unset numbers stay None so "unknown" is distinguishable from zero.
+ assert parsed["local"].ctx_size is None
+ assert parsed["local"].price_in is None
+ print("ok provider config parsing")
+
+
class _FakeResponse:
"""Enough of an http.client response for urlopen's context manager."""
@@ -1642,6 +1698,7 @@ if __name__ == "__main__":
test_version_matches_changelog()
test_venv_discovery()
test_config_defaults()
+ test_provider_parsing()
test_search_tool_schema()
test_search_results_sanitising()
test_tool_call_accumulation()