test: 修复 13 个腐化用例,套件恢复全绿且顺序无关

按「测试腐化(a)/ 源码缺陷(b)/ 测试污染(c)」逐项定性,仅改 tests/:

- 外机绝对路径(4): 迁移文件路径改为相对仓库根解析(沿用
  test_regressions._read 约定),断言内容保持不变。
- cutoff 用例(4+1): mock 未生效的真因是 _agent_provider 被换成同步
  lambda,await 抛 TypeError 被生产代码吞掉后 IndexError;改为 async
  mock 并按 run_specialists/load_match_header/_agent_provider 的真实契约
  打补丁。degraded 用例再加 _upsert_prediction 顶层 kwargs(model)采集。
- 陈旧断言(3): agent 键按现契约断言中文映射;h2h mock 改 async;
  Match.stats 按设计为 lazy="select",从 MATCH_RELATIONS 移出并单独
  固化该设计决定。
- P0-3 守卫(1): seg 越界扫到下游 stats 管线导致误报,改为按缩进收口;
  合法形状含经 raw 派生变量中转的写法,并补元测试确保守卫仍能抓到回归。
- 交叉污染(6): test_multi_agent_cutoff 用 patch.object 精确还原,消除
  裸赋值泄漏的同步 mock;现已验证顺序无关。
This commit is contained in:
shangfangjian
2026-09-21 17:31:36 +08:00
parent 11da4d3631
commit 951faf31df
7 changed files with 241 additions and 99 deletions
+6 -2
View File
@@ -196,7 +196,7 @@ class TestOrchestratorAggregation:
"""终裁输入拼装逻辑。"""
def test_reports_to_json(self):
from src.llm.agents.orchestrator import _reports_to_json
from src.llm.agents.orchestrator import _reports_to_json, AGENT_LABELS_ZH
import json
reports = [
@@ -206,8 +206,12 @@ class TestOrchestratorAggregation:
text = _reports_to_json(reports)
data = json.loads(text)
assert len(data) == 2
assert data[0]["agent"] == "h2h"
# 契约: agent 字段序列化为中文专家全名,引导终裁用统一称呼引用
# (见 orchestrator.AGENT_LABELS_ZH 与 _reports_to_json 的 docstring)
assert data[0]["agent"] == AGENT_LABELS_ZH["h2h"] == "历史交锋分析专家"
assert data[1]["status"] == "no_data"
# 两个 agent 都应被映射,不留英文原键
assert data[1]["agent"] == AGENT_LABELS_ZH["standings"]
def test_aggregator_prompt_renders(self):
"""终裁 prompt 模板两占位符都能渲染。"""