配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
"""聊天输入归一:与 memoir 规则共用,配置独立。"""
|
|
|
|
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,
|
|
)
|
|
|
|
|
|
def test_apply_conversation_rules_matches_memoir_mei_kanshang() -> None:
|
|
raw = "我去试镜了 美看上我 张伟"
|
|
assert "没看上我" in apply_conversation_input_rules(raw)
|
|
|
|
|
|
def test_normalize_chat_rules_mode() -> None:
|
|
raw = "美看上我"
|
|
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.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.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.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:
|
|
llm_norm.return_value = None
|
|
out = normalize_chat_input_for_agent(raw, llm=fake, is_from_voice=False)
|
|
llm_norm.assert_called_once()
|
|
assert llm_norm.call_args[0][1] is None
|
|
assert out == "没看上我"
|