d1aed8e722
上游 ai-kefu → phase1 吸收(Task 11 unit 12): - 拷入 7 个测试文件,import/夹具按目标库重锚(app.engine.* / conftest async_db+build_jiancai_runtime / seed_profiles 提示词锚点) - 补实现(同步自上游): chat_rest 服务端可信 IP(_server_ip/ _merge_client_info,直连场景自报假 IP 不再原样落库);widget.js 与 chat.js 的 data-placeholder 读取(叠加 Task 10 管道:data-* > brand > 中性兜底,tests/test_placeholder_static.py 守卫) - 断言重锚以 jc 主线为准: ev.contact_info 存裸号+等待尾注(e164 走 _cc 派生)、source 值 fallback/customer_stated 口径、推送标注键 号码补全说明、prompt 静态锚按租户(seed_profiles)双测 - 全量回归 459 passed(基线 421 + 吸收 38) Co-Authored-By: Claude Code <noreply@anthropic.com>
72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
"""提示词静态断言(同步自上游 ai-kefu tests/test_prompt_static.py)。
|
|
|
|
锚点迁移(Task 6): 上游单副本 app/prompts → seed_profiles/<slug>/prompts
|
|
按租户持有。auto 租户保留上游逐字锚点;jiancai(主线)措辞已演化——例外
|
|
句/回显句式/禁令是其等价形态。两租户同测,任何一侧缺件都红;断言语义
|
|
不变: 例外句在场(教学多点复述)、好例在场、extractor 门控声明在场。
|
|
"""
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
PROMPTS = Path(__file__).resolve().parent.parent / "seed_profiles"
|
|
|
|
# 各租户锚点: exception=(例外句, 最少出现次数), good_example 与小写比较
|
|
ANCHORS = {
|
|
# 主线措辞: "**唯一例外**:系统提供的补全号码原文" + 确认/回显各节的
|
|
# 机制复述("按系统提醒回显补全后的完整号码请客户确认");好例句式与
|
|
# wall.json cc_templates.echo 同源("— is that right?")
|
|
"jiancai": {
|
|
"exception": ("唯一例外", 1),
|
|
"exception_extra": ("回显补全后的完整号码", 4),
|
|
"forbidden": "客户自己的号码也不回显",
|
|
"good_example": "is that right",
|
|
"gate": "仅当客户在回应号码确认时填写",
|
|
},
|
|
# 上游原句(L47/L67/L127/L170 四处),auto 出厂未随主线演化
|
|
"auto": {
|
|
"exception": ("唯一例外:系统提醒提供的补全号", 4),
|
|
"exception_extra": None,
|
|
"forbidden": "禁止回显任何其他号码",
|
|
"good_example": "is this your full number",
|
|
"gate": "仅当客户消息是对号码确认的回应",
|
|
},
|
|
}
|
|
|
|
|
|
def _read(tenant, name):
|
|
return (PROMPTS / tenant / "prompts" / name).read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.parametrize("tenant", ["jiancai", "auto"])
|
|
def test_system_md_exception_clauses_present(tenant):
|
|
src = _read(tenant, "system.md")
|
|
a = ANCHORS[tenant]
|
|
needle, floor = a["exception"]
|
|
assert src.count(needle) >= floor, f"{tenant}: 例外句缺失/少于 {floor} 处"
|
|
if a["exception_extra"]:
|
|
needle2, floor2 = a["exception_extra"]
|
|
assert src.count(needle2) >= floor2, \
|
|
f"{tenant}: 例外机制复述少于 {floor2} 处"
|
|
|
|
|
|
@pytest.mark.parametrize("tenant", ["jiancai", "auto"])
|
|
def test_system_md_echo_examples_present(tenant):
|
|
src = _read(tenant, "system.md").lower()
|
|
assert ANCHORS[tenant]["good_example"] in src, \
|
|
f"{tenant}: 回显好例句式缺失(应与提醒模板同源)"
|
|
|
|
|
|
@pytest.mark.parametrize("tenant", ["jiancai", "auto"])
|
|
def test_system_md_forbidden_clause_present(tenant):
|
|
src = _read(tenant, "system.md")
|
|
assert ANCHORS[tenant]["forbidden"] in src, \
|
|
f"{tenant}: 禁止回显其他号码条款缺失"
|
|
|
|
|
|
@pytest.mark.parametrize("tenant", ["jiancai", "auto"])
|
|
def test_extractor_md_cc_reply_declared_with_gate(tenant):
|
|
src = _read(tenant, "extractor.md")
|
|
assert "cc_reply" in src and "affirm" in src
|
|
assert ANCHORS[tenant]["gate"] in src, f"{tenant}: 双门控第一道门声明缺失"
|