#47a: 红头/标题字号颜色从 render_html 产物解析(新增 docgen/html_css.py: 内嵌 style 块 + 调用方传入的模板 css,组合选择器展开、px->pt),解析失败 回退历史常量(FF0000/22pt、h1/h2/h3 22/16/14pt,行为不变)。converter 与 导出路由把 css 传入 DOCX 转换,与 PDF/预览同源;非红头模板(如 report 灰 #333)不误渲染红头。r3 的 doc-body 包裹/表格/图片结构不回归。 #52: intent.py WRITE_VERB 补总结/概括/归纳,新增动词自指保护(唯一命中的 DOC_TYPE 等于命中动词本身时不算写文档意图,如「总结一下植物光合作用的过程」 仍 qa);cases_intent.md 同步规则与用例 31-34(共 34 条)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
81 lines
3.7 KiB
Python
81 lines
3.7 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"),
|
||
# r4 #52(2026-09-11)新增:总结/概括/归纳 三动词 + 动词自指保护
|
||
("帮我总结论文", True, False, "docgen"),
|
||
("总结一下植物光合作用的过程", False, False, "qa"),
|
||
("概括一下这个通知", True, True, "docgen"),
|
||
("归纳这篇文章", True, False, "docgen"),
|
||
]
|
||
|
||
|
||
@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)
|