feat(v2): 模型设置(用户可调小模型/大模型/管线,/config + UI)
This commit is contained in:
@@ -66,6 +66,24 @@ def test_metrics(client):
|
||||
assert "review" in data
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_config_get_put_reset(client):
|
||||
# GET 默认
|
||||
r = client.get("/config")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["worker"]["backend"] in ("llama_server", "openai", "mock")
|
||||
# PUT 更新 worker
|
||||
r2 = client.put("/config", json={"worker": {"backend": "mock", "temperature": 0.5}})
|
||||
assert r2.status_code == 200
|
||||
assert r2.json()["worker"]["temperature"] == 0.5
|
||||
# 重置
|
||||
r3 = client.post("/config/reset")
|
||||
assert r3.status_code == 200
|
||||
assert r3.json()["worker"]["backend"] == "llama_server"
|
||||
|
||||
|
||||
def test_workspace_not_found(client):
|
||||
resp = client.get("/runs/nonexistent/workspace")
|
||||
assert resp.status_code == 404
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"""SettingsStore 单测(封闭:临时路径)。"""
|
||||
import json
|
||||
|
||||
from gateway.settings import DEFAULTS, SettingsStore, _coerce
|
||||
|
||||
|
||||
def test_defaults(tmp_path):
|
||||
s = SettingsStore(path=tmp_path / "s.json")
|
||||
d = s.to_dict()
|
||||
assert d["worker"]["backend"] == "llama_server"
|
||||
assert "pipeline" in d and "architect" in d
|
||||
|
||||
|
||||
def test_update_and_coerce(tmp_path):
|
||||
s = SettingsStore(path=tmp_path / "s.json")
|
||||
s.update({"worker": {"backend": "openai", "temperature": "0.4", "max_fix_attempts": "3"}})
|
||||
d = s.to_dict()
|
||||
assert d["worker"]["backend"] == "openai"
|
||||
assert d["worker"]["temperature"] == 0.4 # 字符串转 float
|
||||
assert d["worker"]["max_fix_attempts"] == 3 # 字符串转 int
|
||||
|
||||
|
||||
def test_ignores_unknown_keys(tmp_path):
|
||||
s = SettingsStore(path=tmp_path / "s.json")
|
||||
s.update({"worker": {"not_a_key": 1}, "unknown_section": {"x": 1}})
|
||||
d = s.to_dict()
|
||||
assert "not_a_key" not in d["worker"]
|
||||
assert "unknown_section" not in d
|
||||
|
||||
|
||||
def test_persistence_roundtrip(tmp_path):
|
||||
p = tmp_path / "s.json"
|
||||
s = SettingsStore(path=p)
|
||||
s.update({"worker": {"temperature": 0.5}})
|
||||
s2 = SettingsStore(path=p) # 重新加载
|
||||
assert s2.to_dict()["worker"]["temperature"] == 0.5
|
||||
|
||||
|
||||
def test_reset(tmp_path):
|
||||
s = SettingsStore(path=tmp_path / "s.json")
|
||||
s.update({"worker": {"backend": "mock"}})
|
||||
d = s.reset()
|
||||
assert d["worker"]["backend"] == "llama_server"
|
||||
|
||||
|
||||
def test_coerce():
|
||||
assert _coerce("true", True) is True
|
||||
assert _coerce("42", 0) == 42
|
||||
assert _coerce("bad", 0) == 0
|
||||
assert _coerce(1.5, 0.0) == 1.5
|
||||
Reference in New Issue
Block a user