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:
@@ -2,6 +2,7 @@
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from app.features.conversation.constants import chat
|
||||
from app.features.conversation.input_normalize import (
|
||||
apply_conversation_input_rules,
|
||||
normalize_chat_input_for_agent,
|
||||
@@ -15,39 +16,39 @@ def test_apply_conversation_rules_matches_memoir_mei_kanshang() -> None:
|
||||
|
||||
def test_normalize_chat_rules_mode() -> None:
|
||||
raw = "美看上我"
|
||||
with patch("app.features.conversation.input_normalize.settings") as m:
|
||||
m.chat_input_normalize_enabled = True
|
||||
m.chat_input_normalize_mode = "rules"
|
||||
m.chat_input_normalize_llm_max_tokens = 512
|
||||
m.chat_input_normalize_llm_max_input_chars = 8000
|
||||
with patch("app.features.conversation.input_normalize.chat") as m:
|
||||
m.input_normalize_enabled = True
|
||||
m.input_normalize_mode = "rules"
|
||||
m.input_normalize_llm_max_tokens = 512
|
||||
m.input_normalize_llm_max_input_chars = 8000
|
||||
assert normalize_chat_input_for_agent(raw, llm=None) == "没看上我"
|
||||
|
||||
|
||||
def test_normalize_chat_disabled_returns_raw() -> None:
|
||||
raw = "美看上我"
|
||||
with patch("app.features.conversation.input_normalize.settings") as m:
|
||||
m.chat_input_normalize_enabled = False
|
||||
m.chat_input_normalize_mode = "rules"
|
||||
with patch("app.features.conversation.input_normalize.chat") as m:
|
||||
m.input_normalize_enabled = False
|
||||
m.input_normalize_mode = "rules"
|
||||
assert normalize_chat_input_for_agent(raw, llm=None) == raw
|
||||
|
||||
|
||||
def test_normalize_chat_off_mode() -> None:
|
||||
raw = "美看上我"
|
||||
with patch("app.features.conversation.input_normalize.settings") as m:
|
||||
m.chat_input_normalize_enabled = True
|
||||
m.chat_input_normalize_mode = "off"
|
||||
with patch("app.features.conversation.input_normalize.chat") as m:
|
||||
m.input_normalize_enabled = True
|
||||
m.input_normalize_mode = "off"
|
||||
assert normalize_chat_input_for_agent(raw, llm=None) == raw
|
||||
|
||||
|
||||
def test_normalize_llm_mode_voice_only_passes_no_llm_for_typing() -> None:
|
||||
raw = "美看上我"
|
||||
fake = MagicMock()
|
||||
with patch("app.features.conversation.input_normalize.settings") as m:
|
||||
m.chat_input_normalize_enabled = True
|
||||
m.chat_input_normalize_mode = "llm"
|
||||
m.chat_input_normalize_llm_voice_only = True
|
||||
m.chat_input_normalize_llm_max_tokens = 512
|
||||
m.chat_input_normalize_llm_max_input_chars = 8000
|
||||
with patch("app.features.conversation.input_normalize.chat") as m:
|
||||
m.input_normalize_enabled = True
|
||||
m.input_normalize_mode = "llm"
|
||||
m.input_normalize_llm_voice_only = True
|
||||
m.input_normalize_llm_max_tokens = 512
|
||||
m.input_normalize_llm_max_input_chars = 8000
|
||||
with patch(
|
||||
"app.features.conversation.input_normalize._llm_normalize_chat_input"
|
||||
) as llm_norm:
|
||||
|
||||
Reference in New Issue
Block a user