test: harden baseline_cache guard to per-call unit_id check

This commit is contained in:
2026-07-15 10:13:33 -04:00
parent a536a81b0d
commit f8ad8f0143
+15 -3
View File
@@ -10,6 +10,7 @@ app.harness.validategate 块核心残留点)。
""" """
import inspect import inspect
import re
from app.harness import batching, inference, pools from app.harness import batching, inference, pools
@@ -26,9 +27,20 @@ def test_no_parallel_perquestion_split_helpers():
) )
# 旧逐题分桶残留:正确率不应按 qid 直接取 # 旧逐题分桶残留:正确率不应按 qid 直接取
assert "correctness.get(qid)" not in src, "batching 仍有逐题分桶残留" 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" # gate 块残留探测:validate.py 是逐题 gate 核心残留点。
# 逐个 baseline_cache.get(...) 调用点都必须按 unit_id 键控、不得回退到裸 qid/question_id
# 否则视为逐题残留复活。跨行实参用容纳换行的懒惰匹配抓全整个调用文本。
baseline_get_calls = re.findall(r"baseline_cache\.get\((?:[^()]|\n)*?\)", src)
# 兜底:正则必须真抓到 validate.py 的调用,否则 for 空转又成 tautology
assert baseline_get_calls, "守卫失效:未抓到任何 baseline_cache.get 调用"
for call in baseline_get_calls:
assert "unit_id" in call, f"baseline_cache.get 未按 unit_id 键控(逐题残留): {call}"
assert "qid" not in call and "question_id" not in call, (
f"baseline_cache.get 回退逐题 qid: {call}"
)
# 逐题累加残留:n_used 不应按逐题 chunk 长度累加(应按 unit) # 逐题累加残留:n_used 不应按逐题 chunk 长度累加(应按 unit)
assert "n_used += len(chunk)" not in src, "validate n_used 仍逐题累加(应按 unit" assert "n_used += len(chunk)" not in src, "validate n_used 仍逐题累加(应按 unit"
# 正向 unit 化探测:pools/batching/validate/inference 已走 unit 契约 # 正向 unit 化探测:pools/batching/validate/inference 已走 unit 契约
assert src.count("build_units") >= 1 or "unit_id" in src, "pools/batching/validate 未走 unit 化" assert src.count("build_units") >= 1, "pools/batching/validate/inference 未走 unit 化聚合"