test_business_detail_text.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. from app.business_detail_text import (
  2. assessment_text,
  3. branch_task_sections,
  4. branch_task_text,
  5. business_text,
  6. clean_report,
  7. event_business_sections,
  8. )
  9. def test_business_items_translate_branch_and_base_decision_language():
  10. assert business_text("选 Branch 1 合入 Base,弃 Branch 2。") == (
  11. "采用方案 1 并合入主脚本,方案 2 未采用。"
  12. )
  13. assert business_text("组 Branch 3 与 Branch 4 合入。") == (
  14. "组合方案 3 与方案 4,并合入主脚本。"
  15. )
  16. def test_evaluator_preview_becomes_business_markdown_not_json():
  17. event = {
  18. "event_type": "subagent_dispatch",
  19. "event_name": "script_multipath_evaluator",
  20. "title": "派发 script_multipath_evaluator (ok)",
  21. "status": "ok",
  22. "input_preview": '{"agent_type":"script_multipath_evaluator","task":"本轮为赛马:branch 1 与 branch 2。\\n\\n当前目标:选出更清晰的骨架。"}',
  23. "output_preview": '{"status":"completed","summary":"## 委托任务完成\\n\\n## 评估报告 script_build_id=99\\n\\n#### 1. 分支评估 branch_id=1\\n* **分支元信息**:round_index=1,action=增\\n* **该支结论**:**通过**\\n* **目标推进**:结构清晰。"}',
  24. }
  25. sections = event_business_sections(event)
  26. serialized = str(sections)
  27. assert sections[0]["title"] == "评审了哪些方案"
  28. assert sections[0]["content"] == "方案 1"
  29. assert sections[1]["title"] == "各方案结论"
  30. assert sections[1]["content"] == "方案 1:通过"
  31. assert "script_multipath_evaluator" not in serialized
  32. assert "script_build_id" not in serialized
  33. assert "分支元信息" not in serialized
  34. assert all("\\n" not in section["content"] for section in sections)
  35. assert not any(section["content"].lstrip().startswith("{") for section in sections)
  36. def test_branch_task_and_assessment_remove_technical_headers_and_telemetry():
  37. task = """路序号:1
  38. action:增
  39. target:整篇骨架
  40. path_type:内容
  41. 目标:完成五段结构
  42. 取证方向与约束:
  43. - scope=创业邦
  44. 禁止事项:不得写成已上市
  45. """
  46. assessment = """## 委托任务完成
  47. 思维过程:这是内部执行过程。
  48. ### 完成度申报
  49. - **完成**:形成五段骨架。
  50. - **未尽**:无。
  51. **执行统计**:
  52. - Tokens: 739446
  53. - 成本: $0.24
  54. """
  55. readable_task = branch_task_text(task)
  56. readable_assessment = assessment_text(assessment)
  57. assert "路序号" not in readable_task
  58. assert "action" not in readable_task
  59. assert "path_type" not in readable_task
  60. assert "实现范围" in readable_task
  61. assert "账号:创业邦" in readable_task
  62. assert "思维过程" not in readable_assessment
  63. assert "Tokens" not in readable_assessment
  64. assert "成本" not in readable_assessment
  65. assert "形成五段骨架" in readable_assessment
  66. def test_branch_task_sections_are_optional_and_preserve_recognized_content():
  67. task = """路序号:1
  68. action:改
  69. target:五段骨架
  70. path_type:内容
  71. method:产生脉络
  72. 目标:补齐每段的完整文字。
  73. 必用素材(已核实):
  74. - 领域事实 A
  75. 取证方向与约束:
  76. - 保持概念准确
  77. 禁止事项:不得改动原文"""
  78. sections = branch_task_sections(task)
  79. assert [item["kind"] for item in sections] == [
  80. "scope", "method", "goal", "materials", "constraints", "avoid"
  81. ]
  82. assert sections[0]["content"] == "五段骨架"
  83. assert sections[3]["title"] == "必用素材(已核实)"
  84. assert sections[3]["content"] == "- 领域事实 A"
  85. assert sections[-1]["content"] == "不得改动原文"
  86. def test_branch_task_sections_keep_free_form_task_as_one_complete_note():
  87. task = "这是一个单一数据修复任务。\n\n任务:删除一条悬空边。\n\n执行方式:精确删除。"
  88. assert branch_task_sections(task) == [
  89. {"kind": "notes", "title": "任务说明", "content": task}
  90. ]
  91. def test_tool_event_business_view_never_prints_raw_json_fields():
  92. event = {
  93. "event_type": "tool_call",
  94. "event_name": "get_script_snapshot",
  95. "title": "🔧 get_script_snapshot",
  96. "status": "ok",
  97. "input_preview": '{"script_build_id":431}',
  98. "output_preview": '{"script_build":{"id":431},"paragraphs":[{"id":1}],"elements":[{"id":2}]}',
  99. }
  100. sections = event_business_sections(event)
  101. serialized = str(sections)
  102. assert sections[0]["content"] == "读取当前主脚本"
  103. assert sections[1]["content"] == "已读取当前主脚本,共 1 个段落、1 个元素。"
  104. assert "script_build_id" not in serialized
  105. assert "get_script_snapshot" not in serialized
  106. assert not any(section["content"].lstrip().startswith("{") for section in sections)
  107. def test_retrieval_screening_removes_record_ids_and_runtime_telemetry():
  108. report = """### 初筛结果
  109. - 找到可用的构图案例,post_id=abc123
  110. - 保留粉白配色的业务结论。
  111. **执行统计**:
  112. - 消息数: 16
  113. - Tokens: 739446
  114. - 成本: $0.24
  115. """
  116. readable = clean_report(report)
  117. assert "可用的构图案例" in readable
  118. assert "粉白配色" in readable
  119. assert "post_id" not in readable
  120. assert "abc123" not in readable
  121. assert "Tokens" not in readable
  122. assert "成本" not in readable
  123. def test_retrieval_screening_keeps_business_summary_but_removes_json_fence():
  124. readable = clean_report(
  125. """
  126. 已找到 3 条与烹饪步骤相关的候选证据。
  127. ```json
  128. [{"post_id": "abc", "raw": "large payload"}]
  129. ```
  130. 初筛后保留防碎处理和火候控制两类信息。
  131. """
  132. )
  133. assert "已找到 3 条" in readable
  134. assert "保留防碎处理" in readable
  135. assert "```" not in readable
  136. assert "post_id" not in readable
  137. assert "large payload" not in readable