fix(engine): 非中/西语轮注入 other 语言提醒——英文漂中文镜像修复(Task 11 对向)
历史护栏: 中文/西语会话纯拉丁轮不注入(护住 Task 11 场景);wall other 为 可选变体(存量快照/auto/生成器回退 DEFAULT_WALL,引擎部署即全租户生效) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -160,6 +160,46 @@ def test_template_with_literal_braces_rejected():
|
||||
assert "reminders.boundary.normal" in str(ei.value)
|
||||
|
||||
|
||||
# ---- 2026-11-03 英文漂中文修复: language_follow.other 可选变体 ----
|
||||
|
||||
def test_language_follow_other_optional_variant():
|
||||
"""other 为可选变体: 在场则校验,缺省合法(auto 墙/生成器产出/生产 DB
|
||||
快照无此键;运行期 _lang_note_for 回退 DEFAULT_WALL 文案)。设为必填
|
||||
会让新代码编译旧生产快照即炸全部租户运行时——绝不改为必填。"""
|
||||
import copy
|
||||
base = _load("jiancai")
|
||||
assert "other" in base["reminders"]["language_follow"] # 出厂墙已有
|
||||
compile_wall(base) # 在场: 合法
|
||||
without = copy.deepcopy(base)
|
||||
del without["reminders"]["language_follow"]["other"]
|
||||
compile_wall(without) # 缺省: 合法
|
||||
bad = copy.deepcopy(base)
|
||||
bad["reminders"]["language_follow"]["other"] = ""
|
||||
with pytest.raises(WallConfigError):
|
||||
compile_wall(bad) # 空串: 显性拒绝
|
||||
|
||||
|
||||
def test_language_follow_other_text_pinned():
|
||||
"""other 文案钉死关键语义: 纯反漂中文(不提任何语言分类——无重音符的
|
||||
西/葡语客户会落进本桶,分类断言会把他们误导去英语)+模板句跟随+号码
|
||||
照抄(与 zh/es 两条同款条款)。"""
|
||||
note = _load("jiancai")["reminders"]["language_follow"]["other"]
|
||||
assert "不要出现汉字" in note
|
||||
assert "无法确定时用英语" in note
|
||||
assert "跟随客户语言自然表达" in note and "逐字照抄" in note
|
||||
assert "西语" not in note # 措辞禁区: 不做语言分类断言
|
||||
|
||||
|
||||
def test_language_note_other_wall_fallback():
|
||||
"""租户墙无 other 键(auto/存量生产快照)→ _lang_note_for 回退
|
||||
DEFAULT_WALL 文案——引擎部署即全租户生效,无需推配置。"""
|
||||
from app.engine.services import conversation as conv
|
||||
auto = compile_wall(_load("auto"))
|
||||
assert "other" not in auto.reminders["language_follow"] # 前提钉死
|
||||
note = conv._lang_note_for("how much?", history=[], wall=auto)
|
||||
assert "语言提醒" in note and "不要出现汉字" in note
|
||||
|
||||
|
||||
def test_template_with_unknown_placeholder_rejected():
|
||||
"""I-2: 白名单外占位符({name})编译期拒绝——原属运行期 KeyError。"""
|
||||
cfg = _load("jiancai")
|
||||
|
||||
Reference in New Issue
Block a user