99 lines
3.3 KiB
Python
99 lines
3.3 KiB
Python
"""tests/test_intent.py —— 意图分流词典(cases_bioflow_intent.md 冻结表)后端同表双跑。
|
|
|
|
覆盖词典 §2 判定顺序 + 用例表关键行 + 复用句式(TC-BIO-INTENT 对应后端行)。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.services.bioflow.intent import extract_reuse_name, route
|
|
|
|
pytestmark = pytest.mark.bioflow_unit
|
|
|
|
|
|
@pytest.mark.parametrize("text", [
|
|
"帮我跑水稻 SPL 家族鉴定",
|
|
"跑一下拟南芥 MADS-box 家族分析",
|
|
"请帮我鉴定水稻 SPL 家族",
|
|
"识别玉米 bZIP 家族成员",
|
|
"帮我研究一下水稻 SPL 基因家族",
|
|
"分析小麦 WRKY 转录因子家族",
|
|
"做个大豆 NAC 家族分析",
|
|
"跑 SPL 家族",
|
|
"水稻 SPL 家族,帮我跑",
|
|
"基因家族鉴定:水稻 SPL",
|
|
"帮我跑水稻叶片 RNA-seq 差异表达分析",
|
|
"帮我做水稻全基因组变异检测",
|
|
"帮我跑水稻产量性状 GWAS 关联分析",
|
|
"Please run rice SPL family identification",
|
|
"跑水稻 spl 家族鉴定",
|
|
])
|
|
def test_bioflow_hits(text):
|
|
assert route(text) == "bioflow"
|
|
|
|
|
|
@pytest.mark.parametrize("text", [
|
|
"什么是基因家族?",
|
|
"帮我跑一下",
|
|
"SPL 家族",
|
|
"今天天气不错",
|
|
"跑 SPL 家族鉴定需要准备什么输入?",
|
|
"帮我跑一个数据分析",
|
|
"你好呀",
|
|
"",
|
|
" ",
|
|
"帮我跑香蕉 XYK 家族鉴定",
|
|
"这个 SPL 会议帮我跑一下流程",
|
|
"用 XXX 存档任务的方法",
|
|
"用 XXX 存档任务的方法帮我跑 yyy",
|
|
])
|
|
def test_qa_fallback(text):
|
|
assert route(text) == "qa"
|
|
|
|
|
|
def test_docgen_first():
|
|
assert route("帮我生成一份水稻 SPL 家族分析报告") == "docgen"
|
|
assert route("帮我写一篇水稻基因家族研究论文") == "docgen"
|
|
|
|
|
|
def test_docgen_attachment():
|
|
assert route("帮我整理一份材料", has_attachments=True) == "docgen"
|
|
|
|
|
|
def test_export_priority():
|
|
assert route("导出成 PDF", has_active_artifact=True) == "export"
|
|
|
|
|
|
def test_edit_priority():
|
|
assert route("把这句话改成红色", has_active_artifact=True) == "edit"
|
|
|
|
|
|
def test_chart_word_skips_edit_goes_bioflow():
|
|
# 图表调整走生信(FR-BIO-019):edit 规则被 CHART_WORD 排除
|
|
assert route("xxx 图表颜色换成红色", has_active_artifact=True) == "bioflow"
|
|
|
|
|
|
def test_bioflow_qa_in_context():
|
|
assert route("identify 需要什么输入", has_bioflow_context=True) == "bioflow_qa"
|
|
# 无上下文 → qa
|
|
assert route("identify 需要什么输入") == "qa"
|
|
|
|
|
|
def test_reuse_patterns():
|
|
for text in [
|
|
"用 XXX 存档任务的方法帮我跑水稻 SPL 家族鉴定",
|
|
"根据 XXX 存档任务的方法帮我跑一下玉米 bZIP",
|
|
"参考 XXX 存档的方法再跑一个水稻 SPL",
|
|
"用《XXX》存档任务的方法帮我跑小麦 WRKY 家族",
|
|
]:
|
|
assert route(text) == "bioflow"
|
|
|
|
|
|
def test_extract_reuse_name():
|
|
assert extract_reuse_name("用 XXX 存档任务的方法帮我跑水稻 SPL 家族鉴定") == "XXX"
|
|
assert extract_reuse_name("根据水稻SPL存档 存档任务的方法帮我跑玉米 bZIP") is not None
|
|
assert extract_reuse_name("帮我跑水稻 SPL 家族鉴定") is None
|
|
# 方法名长度 3-20 截取
|
|
name = extract_reuse_name("用 水稻SPL家族鉴定流程 存档任务的方法帮我跑玉米 bZIP")
|
|
assert name is not None and 3 <= len(name) <= 20
|