# 语义逻辑审查模块测试 测试 `core/construction_review/component/reviewers/semantic_logic.py` 中的 `SemanticLogicReviewer` 完整链路。 ## 审查链路 ``` check_semantic_logic() ├── prompt_loader.get_prompt_template("basic", "semantic_logic_check", review_content=..., review_references="") ├── ChatPromptTemplate.format_messages() → [SystemMessage, HumanMessage] ├── generate_model_client.get_model_generate_invoke(trace_id, messages, function_name="grammar_check") └── ReviewResult(success, details={name, response}, error_message, execution_time) ``` ## 文件结构 ``` Semantic_Logic_Test/ ├── conftest.py pytest 配置 ├── pytest.ini pytest 参数 ├── test_data.py 测试用例数据 ├── test_semantic_logic.py pytest 单元测试 + 链路测试 ├── semantic_logic_server.py 前端测试服务器 (HTTP API) ├── index.html 前端测试页面 ├── run_tests.py 交互式测试启动脚本 ├── run_tests.bat Windows 批处理启动脚本 ├── requirements_test.txt 测试依赖 └── README.md 本文档 ``` ## 运行方式 ### 1. pytest 单元测试 ```bash # 设置 PYTHONPATH 后运行 $env:PYTHONPATH = "D:\wx_work\sichuan_luqiao\LQAgentPlatform" pytest utils_test/Semantic_Logic_Test/test_semantic_logic.py -v ``` 或通过交互式脚本: ```bash python utils_test/Semantic_Logic_Test/run_tests.py ``` ### 2. 前端测试页面 (Web UI) ```bash # 启动服务器 python utils_test/Semantic_Logic_Test/semantic_logic_server.py --port 8766 # 浏览器访问 http://localhost:8766 ``` 前端页面功能: - 输入施工方案内容 - 加载示例数据(逻辑错误 / 正常内容) - 一键执行语义逻辑审查 - 查看 AI 模型返回的审查结果 - 查看完整 JSON 响应 - 显示模型耗时、端到端耗时等元数据 ### 3. Windows 快捷方式 双击运行 `run_tests.bat`,按提示选择操作。 ## 测试覆盖 | 测试类 | 说明 | |---|---| | `TestInit` | 初始化:model_client 类型、全局单例 | | `TestCheckSemanticLogicSuccess` | 成功链路:prompt_loader → format_messages → model_client → ReviewResult | | `TestCheckSemanticLogicError` | 错误链路:模型调用失败、prompt_loader 失败、无 state 错误处理 | | `TestChainIntegration` | 集成链路:使用真实 prompt_loader 加载模板,仅 mock AI 调用 | | `TestEdgeCases` | 边界:空内容、超长内容、特殊字符、Unicode、执行时间跟踪 | | `TestLiveAPI` | 真实 API 调用(标记 integration,默认跳过) |