test(review): 新增 pytest 离线回归网,锁定 dwg_review 既有行为
在改动审查流水线(确定性检查前置 / 结论结构化 / 证据交叉校验)之前, 先立一张离线、确定性、秒级的回归网。 - tests/fakes.py:假 LLM + 假 MCP 基座 + 响应构造器(ok_text/ok_image/err) + make_ctx/make_evidence,绝不触网、不读密钥 - 10 个模块共 134 用例: mcp_client / llm_client / cad_tools / checklist / config / planning / evidence / review / report / annotator - pytest.ini(testpaths=tests)+ requirements-dev.txt + 根 conftest.py (sys.path + RENDER_WAIT=0 / REPORT_DIR=tmp fixture)
This commit is contained in:
1 parent
8c07c7cad6
commit
0656397a68
15 files changed
+1710
No files matched your search
@@ -0,0 +1,72 @@
|
||||
"""`dwg_review.checklist` 单元测试。"""
|
||||
|
||||
import json
|
||||
|
||||
from dwg_review.checklist import (
|
||||
DEFAULT_CHECKLIST,
|
||||
build_system_prompt,
|
||||
checklist_summary,
|
||||
load_checklist,
|
||||
)
|
||||
|
||||
|
||||
def test_load_valid_checklist(tmp_path):
|
||||
data = {
|
||||
"name": "自定义清单",
|
||||
"categories": [{"title": "类别A", "severity": "high", "checks": ["检查1"]}],
|
||||
}
|
||||
path = tmp_path / "cl.json"
|
||||
path.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
|
||||
loaded = load_checklist(path)
|
||||
assert loaded["name"] == "自定义清单"
|
||||
assert loaded["categories"][0]["title"] == "类别A"
|
||||
|
||||
|
||||
def test_load_missing_file_falls_back(tmp_path, capsys):
|
||||
loaded = load_checklist(tmp_path / "nope.json")
|
||||
assert loaded is DEFAULT_CHECKLIST
|
||||
assert "无法加载审查清单" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_load_malformed_structure_falls_back(tmp_path, capsys):
|
||||
path = tmp_path / "cl.json"
|
||||
path.write_text(json.dumps({"name": "缺 categories"}), encoding="utf-8")
|
||||
assert load_checklist(path) is DEFAULT_CHECKLIST
|
||||
assert "结构异常" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_load_invalid_json_falls_back(tmp_path, capsys):
|
||||
path = tmp_path / "cl.json"
|
||||
path.write_text("{ not json", encoding="utf-8")
|
||||
assert load_checklist(path) is DEFAULT_CHECKLIST
|
||||
assert "无法加载审查清单" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_load_empty_categories_falls_back(tmp_path):
|
||||
path = tmp_path / "cl.json"
|
||||
path.write_text(json.dumps({"categories": []}), encoding="utf-8")
|
||||
assert load_checklist(path) is DEFAULT_CHECKLIST
|
||||
|
||||
|
||||
def test_build_system_prompt_includes_categories_and_checks():
|
||||
prompt = build_system_prompt(DEFAULT_CHECKLIST)
|
||||
assert DEFAULT_CHECKLIST["name"] in prompt
|
||||
for cat in DEFAULT_CHECKLIST["categories"]:
|
||||
assert cat["title"] in prompt
|
||||
assert f"严重度:{cat['severity']}" in prompt
|
||||
for chk in cat["checks"]:
|
||||
assert chk in prompt
|
||||
|
||||
|
||||
def test_build_system_prompt_tool_hint_toggle():
|
||||
with_tools = build_system_prompt(DEFAULT_CHECKLIST, allow_tools=True)
|
||||
without = build_system_prompt(DEFAULT_CHECKLIST, allow_tools=False)
|
||||
assert "只读" in with_tools and "取证工具" in with_tools
|
||||
assert "只读" not in without
|
||||
|
||||
|
||||
def test_checklist_summary_mentions_name_and_count():
|
||||
summary = checklist_summary(DEFAULT_CHECKLIST)
|
||||
assert DEFAULT_CHECKLIST["name"] in summary
|
||||
assert str(len(DEFAULT_CHECKLIST["categories"])) in summary
|
||||
assert DEFAULT_CHECKLIST["categories"][0]["title"] in summary
|
||||
Reference in new issue
Block a user