refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
This commit is contained in:
@@ -4,6 +4,7 @@ import pytest
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.dependencies import build_eval_judge_llm_spec
|
||||
from app.features.evaluation.constants import eval_cfg
|
||||
from app.features.evaluation.judge_service import (
|
||||
eval_judge_compare_transcript_each_max_chars_for_context,
|
||||
eval_judge_conversation_transcript_max_chars_for_context,
|
||||
@@ -13,22 +14,21 @@ from app.features.evaluation.judge_service import (
|
||||
def test_build_eval_judge_zhipu_uses_bigmodel_defaults(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "eval_judge_api_key", "")
|
||||
monkeypatch.setattr(settings, "zhipu_api_key", "z-test")
|
||||
monkeypatch.setattr(settings, "eval_judge_model", "glm-5")
|
||||
monkeypatch.setattr(eval_cfg, "judge_model", "glm-5")
|
||||
spec = build_eval_judge_llm_spec("zhipu", None)
|
||||
assert spec is not None
|
||||
assert spec.provider == "zhipu"
|
||||
assert spec.resolved_model == "glm-5"
|
||||
assert spec.llm is not None
|
||||
assert spec.context_window_tokens == settings.eval_judge_context_window_tokens
|
||||
assert spec.context_window_tokens == eval_cfg.judge_context_window_tokens
|
||||
|
||||
|
||||
def test_build_eval_judge_zhipu_request_model_override(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "eval_judge_api_key", "e-test")
|
||||
monkeypatch.setattr(settings, "eval_judge_model", "glm-5")
|
||||
monkeypatch.setattr(settings, "zhipu_api_key", "e-test")
|
||||
monkeypatch.setattr(eval_cfg, "judge_model", "glm-5")
|
||||
spec = build_eval_judge_llm_spec("zhipu", "glm-4-plus")
|
||||
assert spec is not None
|
||||
assert spec.resolved_model == "glm-4-plus"
|
||||
@@ -38,7 +38,6 @@ def test_build_eval_judge_deepseek_requires_key(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "deepseek_api_key", "")
|
||||
monkeypatch.setattr(settings, "llm_api_key", "")
|
||||
assert build_eval_judge_llm_spec("deepseek", None) is None
|
||||
|
||||
|
||||
@@ -47,8 +46,8 @@ def test_build_eval_judge_deepseek_v4_flash_non_thinking_default_path(
|
||||
) -> None:
|
||||
"""默认 deepseek-v4-flash 且关闭 thinking 时显式传 disabled(避免 API 默认 enabled)。"""
|
||||
monkeypatch.setattr(settings, "deepseek_api_key", "d-test")
|
||||
monkeypatch.setattr(settings, "eval_judge_deepseek_model", "deepseek-v4-flash")
|
||||
monkeypatch.setattr(settings, "eval_judge_deepseek_thinking_enabled", False)
|
||||
monkeypatch.setattr(eval_cfg, "judge_deepseek_model", "deepseek-v4-flash")
|
||||
monkeypatch.setattr(eval_cfg, "judge_deepseek_thinking_enabled", False)
|
||||
spec = build_eval_judge_llm_spec("deepseek", None)
|
||||
assert spec is not None
|
||||
assert spec.resolved_model == "deepseek-v4-flash"
|
||||
@@ -60,8 +59,8 @@ def test_build_eval_judge_deepseek_context_budget(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "deepseek_api_key", "d-test")
|
||||
monkeypatch.setattr(settings, "eval_judge_deepseek_model", "deepseek-reasoner")
|
||||
monkeypatch.setattr(settings, "eval_judge_deepseek_context_window_tokens", 64_000)
|
||||
monkeypatch.setattr(eval_cfg, "judge_deepseek_model", "deepseek-reasoner")
|
||||
monkeypatch.setattr(eval_cfg, "judge_deepseek_context_window_tokens", 64_000)
|
||||
spec = build_eval_judge_llm_spec("deepseek", None)
|
||||
assert spec is not None
|
||||
assert spec.provider == "deepseek"
|
||||
|
||||
Reference in New Issue
Block a user