Files
ai-kefu-jc/tests/test_system_prompt_dual_contact.py
T

64 lines
3.1 KiB
Python

"""Task 4(spec §4.1, 2026-10-08): system.md 双要+国家代码话术静态断言。
- test_system_md_dual_contact_wording: 七处话术落盘(§4.1-1~7 关键锚点)
- test_system_md_contains_verbatim_note_bodies: 同源断言(Task 3 质量审查
Issue 5)——conversation.py 四个逐字注入常量的正文必须逐字出现在
system.md: 两处"逐字指令"若各自漂移,GLM 会混合输出两种措辞。
"""
def _read_system_md() -> str:
with open("app/prompts/system.md", encoding="utf-8") as f:
return f.read()
def _note_body(note: str) -> str:
"""从注入常量提取 AI 逐字复述的正文(剥"⚠️ 轻补指引"系统指令外壳)。
常量形态: 外壳说明 + 请逐字使用这句:"正文" + 尾注。外壳含"留邮箱"等
渠道词,会误触再索要墙的中文模式——正文才是 AI 真正说出口的部分,
同源断言与过墙断言都以正文为准。"""
marker = "请逐字使用这句:\""
assert marker in note, note[:40]
body = note.split(marker, 1)[1].split("\"", 1)[0]
assert body, note[:40]
return body
def test_system_md_dual_contact_wording():
src = _read_system_md()
assert "with the country code" in src # §4.1-1
assert "formal quotation PDF" in src and "轻补" in src # §4.1-2/3
assert "send the full number with the country code" in src # §4.1-4
assert src.count("国家代码") >= 2 # 好差示例
assert "已在手的渠道" in src and "缺失渠道" in src # §4.1-6
assert "国家代码追问句" in src and "邮箱轻补句" in src # §4.1-7 模板句枚举
def test_system_md_contains_verbatim_note_bodies():
"""Step 5b 同源断言: 四常量正文逐字在 system.md(防两处逐字指令漂移)。"""
from app.services.conversation import (
_CC_NOTE_EN, _CC_NOTE_ZH, _EMAIL_NOTE_EN, _EMAIL_NOTE_ZH)
src = _read_system_md()
for note in (_CC_NOTE_EN, _CC_NOTE_ZH, _EMAIL_NOTE_EN, _EMAIL_NOTE_ZH):
body = _note_body(note)
assert body in src, body[:40]
def test_system_md_cc_reask_exception_in_all_five_prohibitions():
"""生产验收场景①修复: 五处禁令例外全部扩围——号码缺国家代码时可请客户
重发完整号一次。CC 追问是对已在手渠道的重发请求,原先只豁免缺失渠道,
GLM 会视其为禁令压制对象(裸号追问两轮一致被压制即此根因)。"""
src = _read_system_md()
# 五节(语言规则/红线/对话流程/提醒配合/注意)逐一扩围,措辞锚点各落一次
assert src.count("重发完整号一次") >= 5
def test_system_md_pseudo_echo_bad_example():
"""生产验收 r2 实测伪回显: AI 把 +966 5x xxx xxxx 掩码样例当客户号码回显
("Got your number +966 5x xxx xxxx")——好差示例补组钉死禁止。"""
src = _read_system_md()
assert "Got your number +966 5x xxx xxxx" in src # 差例逐字在场
assert "那不是客户的号码" in src # 差例定性
assert "掩码样例当号码回显" in src # 好例禁令