fix: self-contained tree-inject test + fail-loud on missing question (review)
This commit is contained in:
@@ -610,7 +610,15 @@ def _execute_real(config: VideoSplitConfig, fingerprint: str, args: argparse.Nam
|
||||
canonical_preds = load_canonical_predictions(harness_db, config.baseline_run_id)
|
||||
wrong_ids = select_diagnosable_wrong_ids(canonical_preds)
|
||||
questions = load_questions_by_id(questions_dir)
|
||||
video_ids = [questions[qid].video_id for qid in wrong_ids]
|
||||
video_ids: list[str] = []
|
||||
for qid in wrong_ids:
|
||||
q = questions.get(qid)
|
||||
if q is None:
|
||||
raise SystemExit(
|
||||
f"wrong_id {qid!r} 不在 questions_dir 题库中"
|
||||
"(baseline predictions 与题库不匹配,P5 fail loud)"
|
||||
)
|
||||
video_ids.append(q.video_id)
|
||||
deps = build_diagnosis_deps(
|
||||
harness_db=harness_db,
|
||||
store_dir=store_dir,
|
||||
|
||||
@@ -1,16 +1,35 @@
|
||||
"""离线诊断注入:build_diagnosis_deps 按 video_ids 填充非空 tree_data。"""
|
||||
"""离线诊断注入:build_diagnosis_deps 按 video_ids 填充非空 tree_data。
|
||||
|
||||
from pathlib import Path
|
||||
自包含:在 tmp_path 造最小 tree.json,不依赖真实 store/videos/*(CI/checkout 稳健)。
|
||||
下面 patch 的三项是 build_diagnosis_deps 的**外部依赖边界**(假 LLM 凭证、LLM HTTP
|
||||
客户端、redis 缓存),非实现细节——避免测试触真 .env / 打开 httpx.AsyncClient /
|
||||
连 redis,聚焦"给定 store_dir/video_ids → tree_data 被真实树填充"。
|
||||
"""
|
||||
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.harness.video_split_cli import build_diagnosis_deps
|
||||
|
||||
|
||||
def test_build_diagnosis_deps_loads_tree_for_videos():
|
||||
def test_build_diagnosis_deps_loads_tree_for_videos(tmp_path):
|
||||
vdir = tmp_path / "videos" / "vX"
|
||||
vdir.mkdir(parents=True)
|
||||
(vdir / "tree.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"metadata": {},
|
||||
"roots": [
|
||||
{"id": "vX_L1_000", "card": {"scene_summary": "s"}, "time_range": [0, 1]}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with (
|
||||
patch("app.harness.video_split_cli._DiagLLMSettings") as settings_cls,
|
||||
patch("adapters.llm.GovernedLLMClient"),
|
||||
patch("adapters.telemetry.SQLiteTelemetryRecorder"),
|
||||
patch("app.harness.video_split_cli._build_redis_cache", return_value=None),
|
||||
):
|
||||
s = settings_cls.return_value
|
||||
@@ -23,11 +42,12 @@ def test_build_diagnosis_deps_loads_tree_for_videos():
|
||||
s.llm_max_retries = 1
|
||||
s.llm_retry_base_delay = s.llm_retry_max_delay = 1
|
||||
deps = build_diagnosis_deps(
|
||||
harness_db=Path("workspaces/default/harness.db"),
|
||||
store_dir=Path("store"),
|
||||
video_ids=["0RxMZBLeqRI"],
|
||||
harness_db=tmp_path / "h.db",
|
||||
store_dir=tmp_path,
|
||||
video_ids=["vX"],
|
||||
concurrency=1,
|
||||
expected_model="deepseek-v4-pro",
|
||||
)
|
||||
assert "0RxMZBLeqRI" in deps.tree_data
|
||||
assert deps.tree_data["0RxMZBLeqRI"]["nodes"]
|
||||
|
||||
assert "vX" in deps.tree_data
|
||||
assert deps.tree_data["vX"]["nodes"]
|
||||
|
||||
Reference in New Issue
Block a user