feat: add explicit provider profile registry
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""providers.py 注册表测试(M1 设计 §7;register_provider 为纯函数,无可变全局)。"""
|
||||
|
||||
import pytest
|
||||
|
||||
from polygateway.providers import (
|
||||
DEFAULT_PROFILES,
|
||||
ProviderProfile,
|
||||
get_provider,
|
||||
register_provider,
|
||||
)
|
||||
|
||||
|
||||
class TestDefaultProfiles:
|
||||
def test_qwen_profile(self):
|
||||
p = get_provider("qwen")
|
||||
assert p.thinking_on == {"enable_thinking": True}
|
||||
assert p.thinking_off == {"enable_thinking": False}
|
||||
assert p.strip_think_tags is True
|
||||
assert p.supports_native_schema is False
|
||||
|
||||
def test_deepseek_profile(self):
|
||||
p = get_provider("deepseek")
|
||||
assert p.thinking_on == {"thinking": {"type": "enabled"}}
|
||||
assert p.thinking_off == {"thinking": {"type": "disabled"}}
|
||||
assert p.strip_think_tags is False
|
||||
|
||||
def test_openai_baseline_profile(self):
|
||||
p = get_provider("openai")
|
||||
assert p.thinking_on == {} and p.thinking_off == {}
|
||||
assert p.strip_think_tags is False
|
||||
|
||||
def test_unknown_provider_fails_loudly(self):
|
||||
"""消灭子串猜测: 未注册 provider 装配期即报错,不做模糊匹配。"""
|
||||
with pytest.raises(ValueError, match="glm"):
|
||||
get_provider("glm")
|
||||
with pytest.raises(ValueError):
|
||||
get_provider("qwen2") # 子串相似也不放行
|
||||
|
||||
|
||||
class TestPureFunctionRegistration:
|
||||
def test_register_returns_new_mapping(self):
|
||||
glm = ProviderProfile(name="glm", thinking_on={}, thinking_off={}, strip_think_tags=False)
|
||||
table = register_provider(glm)
|
||||
assert get_provider("glm", registry=table) is glm
|
||||
# 默认表未被污染(无可变全局状态铁律)
|
||||
with pytest.raises(ValueError):
|
||||
get_provider("glm")
|
||||
|
||||
def test_register_on_custom_base_and_override(self):
|
||||
custom_qwen = ProviderProfile(
|
||||
name="qwen", thinking_on={"x": 1}, thinking_off={}, strip_think_tags=False
|
||||
)
|
||||
table = register_provider(custom_qwen, base=DEFAULT_PROFILES)
|
||||
assert get_provider("qwen", registry=table).thinking_on == {"x": 1}
|
||||
assert get_provider("qwen").thinking_on == {"enable_thinking": True}
|
||||
|
||||
def test_default_profiles_mapping_is_read_only(self):
|
||||
with pytest.raises(TypeError):
|
||||
DEFAULT_PROFILES["hack"] = None # type: ignore[index]
|
||||
Reference in New Issue
Block a user