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:
@@ -5,7 +5,7 @@
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -101,14 +101,16 @@ class TestH2HCurrentHomePerspective:
|
||||
home_name="曼城", away_name="诺维奇"),
|
||||
]
|
||||
import src.llm.context_builder as cb
|
||||
orig = cb._get_h2h
|
||||
cb._get_h2h = lambda db, h, a, before, **kw: matches
|
||||
try:
|
||||
|
||||
async def mock_get_h2h(db, h, a, before, **kw):
|
||||
# 真实契约是 async(见 context_builder.py 的 `h2h = await _get_h2h(...)`),
|
||||
# 同步 lambda 会抛 TypeError: object list can't be used in 'await' expression。
|
||||
return matches
|
||||
|
||||
with patch.object(cb, "_get_h2h", mock_get_h2h):
|
||||
result = await h2h_slice(header, limit=8, before=None)
|
||||
text = str(result)
|
||||
assert "2胜 0平 0负" in text, f"期望「2胜 0平 0负」,实际:\n{text}"
|
||||
finally:
|
||||
cb._get_h2h = orig
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_draw_counted_correctly(self):
|
||||
|
||||
Reference in New Issue
Block a user