feat: system.md双要话术+国家代码引导+四处禁令改写(防自锁)+同源断言
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -219,6 +219,33 @@ def test_reask_wall_channel_precision():
|
||||
assert asks_contact("hello there") is False
|
||||
|
||||
|
||||
def test_new_templates_pass_reask_wall():
|
||||
"""新模板句(与 conversation.py 四常量同源导入)在所有渠道状态下均不命中
|
||||
asks_contact(spec §6-4): 墙只拦意译索要,不得拦系统注入话术——若扩REASK
|
||||
模式(如往动词表加send)或改模板措辞致命中,此断言报警,防功能自锁。
|
||||
|
||||
⚠️ 断言对象是常量正文而非全文: 外壳是给AI的系统指令(含"留邮箱""留下的
|
||||
号码"等渠道词,本就命中中文REASK——那不是AI说出口的话); AI逐字复述的
|
||||
正文才过墙。正文提取方式与 test_system_prompt_dual_contact._note_body
|
||||
同款(请逐字使用这句:"正文")。"""
|
||||
from app.services.conversation import (
|
||||
_CC_NOTE_EN, _CC_NOTE_ZH, _EMAIL_NOTE_EN, _EMAIL_NOTE_ZH)
|
||||
|
||||
def _body(note):
|
||||
marker = "请逐字使用这句:\""
|
||||
assert marker in note, note[:40]
|
||||
return note.split(marker, 1)[1].split("\"", 1)[0]
|
||||
|
||||
for note in (_CC_NOTE_EN, _CC_NOTE_ZH, _EMAIL_NOTE_EN, _EMAIL_NOTE_ZH):
|
||||
body = _body(note)
|
||||
assert body
|
||||
# CC追问注入时号码渠道恰已确认(whatsapp/phone),邮箱轻补注入时
|
||||
# 号码在手缺邮箱——全渠道状态含 None/空集一起钉死
|
||||
for chans in (None, set(), {"whatsapp"}, {"phone"},
|
||||
{"whatsapp", "email"}, {"whatsapp", "phone"}):
|
||||
assert not asks_contact(body, chans), (body[:40], chans)
|
||||
|
||||
|
||||
def test_warranty_commitment_violates():
|
||||
# 政策变更(2026-09-10 用户定调: 不清楚的留资转经理): AI 输出的保修期限
|
||||
# 是编造的公司政策承诺——从"白名单放行"改为墙级违规
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""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]
|
||||
Reference in New Issue
Block a user