| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- from app.business_detail_text import (
- assessment_text,
- branch_task_sections,
- branch_task_text,
- business_text,
- clean_report,
- event_business_sections,
- )
- def test_business_items_translate_branch_and_base_decision_language():
- assert business_text("选 Branch 1 合入 Base,弃 Branch 2。") == (
- "采用方案 1 并合入主脚本,方案 2 未采用。"
- )
- assert business_text("组 Branch 3 与 Branch 4 合入。") == (
- "组合方案 3 与方案 4,并合入主脚本。"
- )
- def test_evaluator_preview_becomes_business_markdown_not_json():
- event = {
- "event_type": "subagent_dispatch",
- "event_name": "script_multipath_evaluator",
- "title": "派发 script_multipath_evaluator (ok)",
- "status": "ok",
- "input_preview": '{"agent_type":"script_multipath_evaluator","task":"本轮为赛马:branch 1 与 branch 2。\\n\\n当前目标:选出更清晰的骨架。"}',
- "output_preview": '{"status":"completed","summary":"## 委托任务完成\\n\\n## 评估报告 script_build_id=99\\n\\n#### 1. 分支评估 branch_id=1\\n* **分支元信息**:round_index=1,action=增\\n* **该支结论**:**通过**\\n* **目标推进**:结构清晰。"}',
- }
- sections = event_business_sections(event)
- serialized = str(sections)
- assert sections[0]["title"] == "评审了哪些方案"
- assert sections[0]["content"] == "方案 1"
- assert sections[1]["title"] == "各方案结论"
- assert sections[1]["content"] == "方案 1:通过"
- assert "script_multipath_evaluator" not in serialized
- assert "script_build_id" not in serialized
- assert "分支元信息" not in serialized
- assert all("\\n" not in section["content"] for section in sections)
- assert not any(section["content"].lstrip().startswith("{") for section in sections)
- def test_branch_task_and_assessment_remove_technical_headers_and_telemetry():
- task = """路序号:1
- action:增
- target:整篇骨架
- path_type:内容
- 目标:完成五段结构
- 取证方向与约束:
- - scope=创业邦
- 禁止事项:不得写成已上市
- """
- assessment = """## 委托任务完成
- 思维过程:这是内部执行过程。
- ### 完成度申报
- - **完成**:形成五段骨架。
- - **未尽**:无。
- **执行统计**:
- - Tokens: 739446
- - 成本: $0.24
- """
- readable_task = branch_task_text(task)
- readable_assessment = assessment_text(assessment)
- assert "路序号" not in readable_task
- assert "action" not in readable_task
- assert "path_type" not in readable_task
- assert "实现范围" in readable_task
- assert "账号:创业邦" in readable_task
- assert "思维过程" not in readable_assessment
- assert "Tokens" not in readable_assessment
- assert "成本" not in readable_assessment
- assert "形成五段骨架" in readable_assessment
- def test_branch_task_sections_are_optional_and_preserve_recognized_content():
- task = """路序号:1
- action:改
- target:五段骨架
- path_type:内容
- method:产生脉络
- 目标:补齐每段的完整文字。
- 必用素材(已核实):
- - 领域事实 A
- 取证方向与约束:
- - 保持概念准确
- 禁止事项:不得改动原文"""
- sections = branch_task_sections(task)
- assert [item["kind"] for item in sections] == [
- "scope", "method", "goal", "materials", "constraints", "avoid"
- ]
- assert sections[0]["content"] == "五段骨架"
- assert sections[3]["title"] == "必用素材(已核实)"
- assert sections[3]["content"] == "- 领域事实 A"
- assert sections[-1]["content"] == "不得改动原文"
- def test_branch_task_sections_keep_free_form_task_as_one_complete_note():
- task = "这是一个单一数据修复任务。\n\n任务:删除一条悬空边。\n\n执行方式:精确删除。"
- assert branch_task_sections(task) == [
- {"kind": "notes", "title": "任务说明", "content": task}
- ]
- def test_tool_event_business_view_never_prints_raw_json_fields():
- event = {
- "event_type": "tool_call",
- "event_name": "get_script_snapshot",
- "title": "🔧 get_script_snapshot",
- "status": "ok",
- "input_preview": '{"script_build_id":431}',
- "output_preview": '{"script_build":{"id":431},"paragraphs":[{"id":1}],"elements":[{"id":2}]}',
- }
- sections = event_business_sections(event)
- serialized = str(sections)
- assert sections[0]["content"] == "读取当前主脚本"
- assert sections[1]["content"] == "已读取当前主脚本,共 1 个段落、1 个元素。"
- assert "script_build_id" not in serialized
- assert "get_script_snapshot" not in serialized
- assert not any(section["content"].lstrip().startswith("{") for section in sections)
- def test_retrieval_screening_removes_record_ids_and_runtime_telemetry():
- report = """### 初筛结果
- - 找到可用的构图案例,post_id=abc123
- - 保留粉白配色的业务结论。
- **执行统计**:
- - 消息数: 16
- - Tokens: 739446
- - 成本: $0.24
- """
- readable = clean_report(report)
- assert "可用的构图案例" in readable
- assert "粉白配色" in readable
- assert "post_id" not in readable
- assert "abc123" not in readable
- assert "Tokens" not in readable
- assert "成本" not in readable
- def test_retrieval_screening_keeps_business_summary_but_removes_json_fence():
- readable = clean_report(
- """
- 已找到 3 条与烹饪步骤相关的候选证据。
- ```json
- [{"post_id": "abc", "raw": "large payload"}]
- ```
- 初筛后保留防碎处理和火候控制两类信息。
- """
- )
- assert "已找到 3 条" in readable
- assert "保留防碎处理" in readable
- assert "```" not in readable
- assert "post_id" not in readable
- assert "large payload" not in readable
|