"""挖题时的脱敏 —— 纯函数,不碰库。 单独一个模块,因为 `test_service.py` 有模块级的 `pytestmark = asyncio`, 而同步用例挂在它下面会让 pytest-asyncio 每次都发一条警告 —— 一条每跑必现 的警告,几周之内就会让人对这个文件的所有输出免疫。 """ from __future__ import annotations def test_redaction_strips_the_things_employees_paste_into_chat(): """🔴 挖出来的是别人的原话。脱敏在**入库时**做,不是在展示时做 —— 一行从来没存过那个值,之后也就泄不出去。""" from app.assistant.evaluation.service import redact assert "zhang.wei@pingcap.com" not in redact("我的邮箱 zhang.wei@pingcap.com 收不到信") assert "13800138000" not in redact("我的手机号 13800138000 变了") assert "sk-abcdefghijklmnop" not in redact("这个 key sk-abcdefghijklmnop 还能用吗") assert "3f2a1b4c-5d6e-4f80-9a1b-2c3d4e5f6071" not in redact( "工单 3f2a1b4c-5d6e-4f80-9a1b-2c3d4e5f6071 怎么样了" ) def test_redaction_leaves_the_question_itself_intact(): """护栏:脱敏不能把问题本身吃掉,否则挖出来的是一堆没法读的残句。""" from app.assistant.evaluation.service import redact assert redact("VPN 连不上怎么办") == "VPN 连不上怎么办"