- 入库历史遗漏源码/测试:router_system 9 模块(agent/executors/inference/knowledge/ memory/planner/skills/trace)、tests 11 个测试文件、config/knowledge 领域知识 - 入库根目录方案文档(v2/v3/可行性×2)、references 文献(arxiv 14-18/cnki_open/ 参考文献清单)、research 论文素材(routerarena/paper/中文文献 PDF) - 前端构建产物刷新(新 hash);webapp 误写文档删除 - gitignore 增补:deepseek-harness、research/_refs、.mimosa/.zcode、网关日志/pid、 临时调试脚本、tests/e2e/node_modules、AI代理功能开发/prefix - 基线确认:318 passed
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
"""Planner(任务拆解)单元测试。"""
|
|
from router_system.classifier import RuleClassifier
|
|
from router_system.knowledge import KnowledgeBase
|
|
from router_system.planner import Planner
|
|
|
|
|
|
def _plan(query: str):
|
|
clf = RuleClassifier()
|
|
c = clf.classify(query)
|
|
return Planner(KnowledgeBase()).plan(query, c), c
|
|
|
|
|
|
def test_simple_task_no_split():
|
|
graph, c = _plan("2 + 2 等于多少")
|
|
# easy 难度 → 单节点不拆
|
|
assert c.domain == "math"
|
|
assert c.difficulty == "easy"
|
|
assert len(graph) == 1
|
|
n = graph.nodes()[0]
|
|
assert n.id == "solve"
|
|
assert n.kind == "solve"
|
|
|
|
|
|
def test_code_task_split_four():
|
|
graph, c = _plan("用 Python 写一个快速排序函数,并解释时间复杂度")
|
|
assert c.domain == "code"
|
|
assert len(graph) == 4
|
|
ids = [n.id for n in graph.nodes()]
|
|
assert ids == ["analyze", "design", "implement", "verify"]
|
|
|
|
|
|
def test_math_task_split_three():
|
|
graph, c = _plan("求解方程 x^2 - 5x + 6 = 0")
|
|
assert c.domain == "math"
|
|
assert len(graph) == 3
|
|
ids = [n.id for n in graph.nodes()]
|
|
assert ids == ["conditions", "solve", "verify"]
|
|
|
|
|
|
def test_deps_wired():
|
|
graph, _ = _plan("用 Python 写一个快速排序函数,并解释时间复杂度")
|
|
nodes = {n.id: n for n in graph.nodes()}
|
|
assert nodes["design"].deps == ["analyze"]
|
|
assert nodes["implement"].deps == ["design"]
|
|
assert nodes["verify"].deps == ["implement"]
|
|
|
|
|
|
def test_no_template_falls_back_to_single():
|
|
graph, c = _plan("你好呀")
|
|
# general 无模板命中("你好"不在任何 pattern)→ 单节点
|
|
assert c.domain == "general"
|
|
assert len(graph) == 1
|
|
n = graph.nodes()[0]
|
|
assert n.kind == "explain"
|
|
|
|
|
|
def test_explain_plan_trace():
|
|
graph, _ = _plan("求解方程 x^2 - 5x + 6 = 0")
|
|
trace = Planner(KnowledgeBase()).explain_plan(graph)
|
|
assert trace and "plan:multi[3]" in trace[0]
|
|
single_graph, _ = _plan("1 + 1 = ?")
|
|
st = Planner(KnowledgeBase()).explain_plan(single_graph)
|
|
assert "plan:single" in st[0]
|