Files
Video-Tree-TRM5/tests/unit/test_no_dead_perquestion_paths.py
T

39 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""守卫测试:防止旧逐题(per-question)路径在 unit 化迁移后复活或残留。
Task 3-10 已将三池切分、分批整锁、pair-level 聚合、gate 块基线缓存等契约
从"逐题 qid"迁移到"QuestionUnit 整锁"。本测试对迁移后的源码做静态锚点扫描,
锁住四个不可回退的语义标志:一旦有人误引入旧逐题分桶 / 逐题 gate 缓存 / 逐题
累加 / 未走 unit 化的代码,断言即刻失败。
覆盖模块:batching(分批)、pools(三池切分)、inferencepair 聚合)、
app.harness.validategate 块核心残留点)。
"""
import inspect
from app.harness import batching, inference, pools
def test_no_parallel_perquestion_split_helpers():
"""契约迁 unit 后,不得残留会拆 pair 的旧逐题分批 / 切分 / gate 块路径。"""
from app.harness import validate as hvalidate # gate 块真实路径
src = (
inspect.getsource(batching)
+ inspect.getsource(pools)
+ inspect.getsource(hvalidate)
+ inspect.getsource(inference) # 覆盖 T6 pair-level 聚合路径
)
# 旧逐题分桶残留:正确率不应按 qid 直接取
assert "correctness.get(qid)" not in src, "batching 仍有逐题分桶残留"
# gate 块残留探测:validate.py 是逐题 gate 核心残留点,基线缓存键须含 unit_id
assert "baseline_cache.get(" not in src or "unit_id" in src, (
"validate baseline_cache 仍按 qid"
)
# 逐题累加残留:n_used 不应按逐题 chunk 长度累加(应按 unit)
assert "n_used += len(chunk)" not in src, "validate n_used 仍逐题累加(应按 unit"
# 正向 unit 化探测:pools/batching/validate/inference 已走 unit 契约
assert src.count("build_units") >= 1 or "unit_id" in src, (
"pools/batching/validate 未走 unit 化"
)