支持直接审查 PDF 与位图图纸,全链路离线(不连 CAD、不连 8080 端口)。 渲染在内存内完成,复用既有墨迹热力图 + 自适应瓦片规划。 - 新增 dwg_review/sources.py - detect_source / plan_file / collect 统一入口 - PdfReader:pypdfium2 惰性导入,页序即图框序,处理 /Rotate 与 crop 边距 - ImageReader:世界单位 = 源像素,snap_box 整数对齐保证窗口与像素严格一致 - ink_grid:纯 PIL 灰度阈值 → 占用网格(不引入 numpy) - ReviewContext.create(connect_cad=False):离线时 client/tools 均为 None - 全链路 ctx.tools is None 守卫:review 只读子循环 / inspect_region / annotator / checks 的窗口类检查 / 绘图区最大化 - checklist.build_system_prompt(allow_tools=False, offline=True):离线提示词 - __main__:位置参数 source,按扩展名自动判定源类型并决定是否连 CAD - config 新增 8 个常量(PDF_MAX_PAGES / 文本最小字数 / 各源缩放上限 / 墨迹阈值等) - tiling.content_predicate 与 heatmap.cell_box 提升为公开函数 验证: - pytest 457 passed - verify_pdf_source.py:PDF 23/23、图片 9/9(不需 CAD),含实测瓦片字高像素与 旋转映射自检(文本区墨迹 0.311 vs 忽略 /Rotate 反向对照 0.145) - 真实 LLM 端到端:20 页 HVAC 图纸前 3 页跑通,结论具体可核验且未编造 handle 已知局限:页边线在墨迹网格里会把整页连成单簇,瓦片常退化为整页象限(CAD 侧 靠 drop_oversized 丢图框块,离线侧暂无等价手段),留待后续打磨。
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""`dwg_review.context.ReviewContext` 单元测试(重点:离线模式不碰网络)。"""
|
|
|
|
from dwg_review import evidence_model
|
|
from dwg_review.context import ReviewContext
|
|
|
|
|
|
def test_create_offline_has_no_client_or_tools():
|
|
"""connect_cad=False → client / tools 均为 None(不构造 CadTools,不连 8080)。"""
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
|
assert ctx.client is None
|
|
assert ctx.tools is None
|
|
assert ctx.llm is None
|
|
# 离线上下文仍应加载好清单(纯文件读取)
|
|
assert isinstance(ctx.checklist, dict)
|
|
|
|
|
|
def test_create_offline_default_source_is_cad():
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
|
assert ctx.source == evidence_model.SOURCE_CAD
|
|
|
|
|
|
def test_create_offline_explicit_source():
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False, source=evidence_model.SOURCE_PDF)
|
|
assert ctx.source == evidence_model.SOURCE_PDF
|
|
|
|
|
|
def test_create_offline_overrides_apply():
|
|
ctx = ReviewContext.create(
|
|
need_llm=False, connect_cad=False, max_frames=3, frame_limit=9, dry_run=True
|
|
)
|
|
assert ctx.max_frames == 3
|
|
assert ctx.frame_limit == 9
|
|
assert ctx.dry_run is True
|
|
|
|
|
|
def test_create_offline_does_not_connect(monkeypatch):
|
|
"""确保离线路径完全没有实例化 McpClient / CadTools(真连会抛 OSError)。"""
|
|
|
|
def _boom(*a, **k): # pragma: no cover - 被调用即失败
|
|
raise AssertionError("离线模式不应触碰 CAD 客户端")
|
|
|
|
monkeypatch.setattr("dwg_review.context.McpClient", _boom)
|
|
monkeypatch.setattr("dwg_review.context.CadTools", _boom)
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
|
assert ctx.client is None and ctx.tools is None
|