- tests/docgen/:DC-UNIT/API/CONF/E2E/UI/REGRESSION/PERF 分组用例与可复跑脚本,报告逐条留痕(R1-R3 全记录) - 意图 30 条前后端同表双跑(pytest + node) - Playwright headless:docgen-ui/docgen-regression spec + b3 benchpanel 第 5 TAB 断言更新 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
76 lines
3.4 KiB
Python
76 lines
3.4 KiB
Python
"""test_intent.py —— 意图路由 30 条用例(唯一事实源 docs/team/cases_intent.md)。
|
|
|
|
与前端同用例表:每条 (text, has_attachments, has_active_artifact) → 期望路由。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# app 包在 sdk/ 下:测试从仓库根运行时需把 sdk/ 加入 sys.path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
|
|
|
import pytest # noqa: E402
|
|
|
|
from app.services.docgen.intent import route # noqa: E402
|
|
|
|
# cases_intent.md 冻结用例表(30 条)
|
|
CASES = [
|
|
# (text, has_attachments, has_active_artifact, expected)
|
|
("给我写一篇关于小麦育种的论文", False, False, "docgen"),
|
|
("帮我写一个关于疫情防控的通知,参考xxx文档的格式", False, False, "docgen"),
|
|
("你来帮我起草一份项目总结报告", False, False, "docgen"),
|
|
("拟一份关于安全生产的通知", False, False, "docgen"),
|
|
("写一个基金申请文档,参考xxxx和xxxx资料,你来润色", False, False, "docgen"),
|
|
("根据这个文档,帮我写一篇申报材料", True, False, "docgen"),
|
|
("写一段水稻基因的介绍", False, False, "qa"),
|
|
("水稻基因是什么?介绍一下", False, False, "qa"),
|
|
("帮我总结一下这个问题的要点", False, False, "qa"),
|
|
("写一首关于秋天的诗", False, False, "qa"),
|
|
("帮我写代码实现一个排序函数", False, False, "qa"),
|
|
("这个方案你怎么看?", False, False, "qa"),
|
|
("通知今天下午开会", False, False, "qa"),
|
|
("导出成PDF", False, True, "export"),
|
|
("把文档转成word发给我", False, True, "export"),
|
|
("导出成PDF", False, False, "qa"),
|
|
("第2段改正式一点", False, True, "edit"),
|
|
("把标题改成黑体", False, True, "edit"),
|
|
("润色一下第二段", False, True, "edit"),
|
|
("第2段改正式一点", False, False, "qa"),
|
|
("帮我写个方案,参考上次上传的材料", False, False, "docgen"),
|
|
("写一份年度工作计划", False, False, "docgen"),
|
|
("起草会议纪要", False, False, "docgen"),
|
|
("帮我生成一个市场分析报告", False, False, "docgen"),
|
|
("写一篇演讲稿,要有感染力", False, False, "docgen"),
|
|
("帮我写一份劳动合同", False, False, "docgen"),
|
|
("转成PDF", False, True, "export"),
|
|
("帮我写个会议通知模板", False, True, "docgen"),
|
|
("给这个通知加个结尾", False, True, "edit"),
|
|
("增加一段关于风险的描述", False, True, "edit"),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("text,attachments,artifact,expected", CASES)
|
|
def test_route_cases(text, attachments, artifact, expected):
|
|
assert route(text, attachments, artifact) == expected, f"用例失败:{text!r}"
|
|
|
|
|
|
def test_route_empty_text_qa():
|
|
assert route("", False, False) == "qa"
|
|
assert route(" ", False, True) == "qa"
|
|
|
|
|
|
def test_is_docgen_intent_contract():
|
|
"""dev2 护栏只用了 is_docgen_intent;验证其与 route 一致性。"""
|
|
import anyio
|
|
|
|
from app.services.docgen.intent import is_docgen_intent
|
|
|
|
async def _check():
|
|
# is_docgen_intent 只看文本(无附件/无活动文档上下文)
|
|
assert await is_docgen_intent("给我写一篇关于小麦育种的论文") is True
|
|
assert await is_docgen_intent("水稻基因是什么?") is False
|
|
assert await is_docgen_intent("") is False
|
|
|
|
anyio.run(_check)
|