配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""口述规则归一与 memoir 入口行为。"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from app.core.text_normalize import apply_oral_rules
|
|
from app.features.memoir.oral_normalize import normalize_oral_for_memoir
|
|
|
|
|
|
def test_apply_rules_mei_kanshang_wo() -> None:
|
|
assert "没看上我" in apply_oral_rules("我去试镜了 美看上我 张伟")
|
|
|
|
|
|
def test_apply_rules_mei_kanshang_ni() -> None:
|
|
assert apply_oral_rules("美看上你") == "没看上你"
|
|
|
|
|
|
def test_apply_rules_no_false_positive_rong() -> None:
|
|
"""「美容」等不应被误替换。"""
|
|
s = "我去了解美容项目"
|
|
assert apply_oral_rules(s) == s
|
|
|
|
|
|
def test_normalize_respects_global_off() -> None:
|
|
raw = "美看上我"
|
|
with patch("app.features.memoir.oral_normalize.memoir") as m:
|
|
m.oral_normalize_enabled = False
|
|
m.oral_normalize_mode = "rules"
|
|
assert normalize_oral_for_memoir(raw, llm=None) == raw
|
|
|
|
|
|
def test_normalize_rules_mode_no_llm() -> None:
|
|
raw = "美看上我"
|
|
with patch("app.features.memoir.oral_normalize.memoir") as m:
|
|
m.oral_normalize_enabled = True
|
|
m.oral_normalize_mode = "rules"
|
|
m.oral_normalize_llm_max_tokens = 512
|
|
m.oral_normalize_llm_max_input_chars = 8000
|
|
assert normalize_oral_for_memoir(raw, llm=None) == "没看上我"
|
|
|
|
|
|
def test_normalize_mode_off_string() -> None:
|
|
raw = "美看上我"
|
|
with patch("app.features.memoir.oral_normalize.memoir") as m:
|
|
m.oral_normalize_enabled = True
|
|
m.oral_normalize_mode = "off"
|
|
m.oral_normalize_llm_max_tokens = 512
|
|
m.oral_normalize_llm_max_input_chars = 8000
|
|
assert normalize_oral_for_memoir(raw, llm=None) == raw
|