fix: self-contained tree-inject test + fail-loud on missing question (review)
This commit is contained in:
@@ -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