fix: 墙层审查修复——10位号穿透/CC轮回显closing用CC句/breach号码观测/拼接分隔
审查(With fixes)四项:
- Important-1: LONG_NUMBER_RE {9,17}→{8,17}——旧量词最小匹配 11 字符,
纯 10 位号(沙特裸号 0501234567,CC 模板范例市场本体)穿透。实测钉死
行为边界: 逗号不在字符类,"50,000,000" 千分位形态仍放行(与
"45,000 km" 同机制,审查预估会命中系漏算逗号);空格分隔 ≥10 位命中;
DN110/5000m/VIN 规格形态全放行
- Important-2: CC 触发轮回显被零号码墙拦下时(violation==no_contact),
closing 改用 CC 模板句而非 NO_CONTACT_ALREADY——GLM 有 3/3 回显倾向,
客户该收到追问而非"稍后联系"虚假承诺;价格墙路径不变。设计文档 §2
补记该裁决
- Minor-4: breach_rate.py 补号码回显(≥10位,与墙同形)与邮箱回显两条
观测模式,补上漏放观测盲区
- Minor-5: violated 收尾与已流出前缀之间补空格分隔("...xxxx? Got it —"),
空格随 closing 一起流出,客户所见与落库一致;CC/触发轮缓冲未流出,
emitted 恒空天然不受影响
测试 256 passed(253+3)。
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -407,3 +407,19 @@ def test_no_contact_wall_spec_forms_still_pass():
|
||||
assert not no_contact_value("DN110 PE100 pipes, 5000m total, 20ft container")
|
||||
assert not no_contact_value("PN16 SDR11 to ISO4427, batches of 5000")
|
||||
assert not no_contact_value("DN800双壁波纹管,5000米一批")
|
||||
|
||||
|
||||
def test_no_contact_wall_ten_digit_number_blocked():
|
||||
# Important-1(审查修复): 旧 {9,17} 最小匹配 11 字符,纯 10 位号穿透——
|
||||
# 沙特裸号 0501234567 恰是 CC 模板范例市场本体。收窄 {8,17} 后命中。
|
||||
assert no_contact_value("Got it — 0501234567!")
|
||||
assert no_contact_value("my whatsapp is 0501234567")
|
||||
# 千分位行为钉死(审查预估与实际正则的差异): ',' 不在 LONG_NUMBER_RE
|
||||
# 字符类 [\d\s\-().] 内,"50,000,000" 逗号形态天然放行——与 "45,000 km"
|
||||
# 放行同机制(既有误杀防线,不动);空格/横线分隔的 ≥10 位数字串命中。
|
||||
# 若需求方要拦千分位大数量(MOQ 复述),显式把 ',' 加进 class 再扩测试。
|
||||
assert not no_contact_value("MOQ is 50,000,000 for this grade")
|
||||
assert no_contact_value("MOQ is 50 000 000 for this grade")
|
||||
# 规格形态复测(修复后回归锚): 逗号千分位+短数字段仍全放行
|
||||
assert not no_contact_value("DN110 PE100, 5000m per batch, 20ft container")
|
||||
assert not no_contact_value("45,000 km, VIN LFV3A23C8K3123456")
|
||||
|
||||
@@ -1223,3 +1223,60 @@ def test_no_contact_wall_blocks_customer_email_echo(async_db, monkeypatch):
|
||||
assert "a@b.com" not in tail
|
||||
assert tail == NO_CONTACT_ALREADY
|
||||
asyncio.run(manager.db.close())
|
||||
|
||||
|
||||
# ---- 墙层审查修复(2026-10-08): CC轮回显closing/10位穿透/拼接分隔 ----
|
||||
def test_cc_wall_no_contact_violation_uses_cc_template(async_db, monkeypatch):
|
||||
"""Important-2: CC 触发轮回显被零号码墙拦下时,closing 改用 CC 模板句
|
||||
而非 NO_CONTACT_ALREADY——GLM 有 3/3 回显倾向,该路径概率高,客户该
|
||||
收到追问而非"稍后联系"虚假承诺。同时钉死 Important-1: 10 位裸号
|
||||
回显(旧 {9,17} 穿透形态)确实被拦。"""
|
||||
from app.services.conversation import _CC_WALL_EN
|
||||
|
||||
class EchoConfirmAI(FakeAI):
|
||||
async def stream_chat(self, messages, context=""):
|
||||
for token in ("Got it — 0501234567! ",
|
||||
"Manager will contact you soon."):
|
||||
yield token
|
||||
|
||||
(manager, conv), _ = _setup(async_db, monkeypatch,
|
||||
ai=EchoConfirmAI(extract={}),
|
||||
source=ConversationSource.standalone)
|
||||
asyncio.run(_send(manager, conv.session_id, "my whatsapp is 0501234567"))
|
||||
msgs = asyncio.run(manager._load_history(conv.id))
|
||||
tail = [m["content"] for m in msgs if m["role"] == "assistant"][-1]
|
||||
assert "0501234567" not in tail # 回显零残留(10 位穿透已修)
|
||||
assert tail == _CC_WALL_EN # closing=CC 追问句,非"稍后联系"
|
||||
profile = asyncio.run(manager._get_profile(conv.id))
|
||||
assert (profile.raw_info or {}).get("_cc_asked") is True # 计数不受影响
|
||||
asyncio.run(manager.db.close())
|
||||
|
||||
|
||||
def test_violated_closing_separated_by_space(async_db, monkeypatch):
|
||||
"""Minor-5: 中途句违规掐断时,已流出前缀与替换句之间以空格分隔
|
||||
("...xxxx? Got it —"),客户所见与落库一致。"""
|
||||
from app.services.boundary_filter import NO_CONTACT_WEB
|
||||
|
||||
class MidNumberAI(FakeAI):
|
||||
async def stream_chat(self, messages, context=""):
|
||||
for token in ("Great question! ", "Call us at +86 138 0013 8000 ",
|
||||
"anytime."):
|
||||
yield token
|
||||
|
||||
(manager, conv), _ = _setup(async_db, monkeypatch,
|
||||
ai=MidNumberAI(extract={}),
|
||||
source=ConversationSource.standalone)
|
||||
events = []
|
||||
|
||||
async def run():
|
||||
async for e in manager.stream_process_message(
|
||||
conv.session_id, "how can I contact you?"):
|
||||
events.append(e)
|
||||
asyncio.run(run())
|
||||
streamed = "".join(e.get("content", "") for e in events
|
||||
if e["type"] == "stream_chunk")
|
||||
assert streamed == "Great question! " + NO_CONTACT_WEB # 空格分隔钉死
|
||||
msgs = asyncio.run(manager._load_history(conv.id))
|
||||
tail = [m["content"] for m in msgs if m["role"] == "assistant"][-1]
|
||||
assert tail == streamed # 落库=流出
|
||||
asyncio.run(manager.db.close())
|
||||
|
||||
Reference in New Issue
Block a user