from bidmaster.utils.prompt_planner import PromptPlanner def test_prompt_planner_uses_metadata_and_parent_context() -> None: parent = {"id": "chapter_1", "title": "1. 总体技术方案", "level": 1} child = { "id": "chapter_1_1", "title": "1.1 技术方案-基本要求 (3.0分)", "level": 2, "parent_id": "chapter_1", } state = { "chapter_queue": [parent, child], "chapter_metadata": { "chapter_1_1": { "title": child["title"], "score": 3.0, "category": "technical_solution", "requirements": "方案需覆盖总体架构;提供性能指标;描述安全策略。", "rubric_points": ["总体架构完整", "性能指标量化"], } }, "chapter_children_map": {"chapter_1": ["chapter_1_1"]}, "generated_contents": {"chapter_1": "本章节描述总体设计与安全架构要点。"}, "chapter_configs": {"chapter_1": {"emphasis": "突出安全策略"}}, "expanded_configs": {"chapter_1": "chapter_1", "chapter_1_1": "chapter_1"}, } planner = PromptPlanner(state) spec = planner.build_prompt_spec(child) assert "总体架构完整" in spec["rubric_points"] assert "父章节摘要" in spec["context_summary"] assert "突出安全策略" in spec["objectives"] def test_prompt_planner_fallback_without_metadata() -> None: root = {"id": "chapter_root", "title": "1. 服务方案", "level": 1} child = { "id": "chapter_child", "title": "1.1 现场服务体系", "level": 2, "parent_id": "chapter_root", } state = { "chapter_queue": [root, child], "chapter_children_map": {"chapter_root": ["chapter_child"]}, } planner = PromptPlanner(state) spec = planner.build_prompt_spec(root) assert "1.1 现场服务体系" in spec["requirements_summary"] assert "围绕章节主题" in spec["objectives"]