From 05294412df7432e8e3886d225620e7c67f1d1197 Mon Sep 17 00:00:00 2001 From: iomgaa Date: Wed, 15 Jul 2026 22:11:36 -0400 Subject: [PATCH] test: cover missing-id and non-list roots; drop unreachable empty-nodes guard --- app/harness/tree_nodes.py | 2 -- tests/unit/test_tree_nodes.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/harness/tree_nodes.py b/app/harness/tree_nodes.py index 5746bea..39f6ccb 100644 --- a/app/harness/tree_nodes.py +++ b/app/harness/tree_nodes.py @@ -66,8 +66,6 @@ def load_tree_nodes(store_dir: Path, video_id: str) -> dict[str, Any]: for root in roots: _walk(root, 1) - if not nodes: - raise ValueError(f"展平后 nodes 为空: {tree_path}") return {"nodes": nodes} diff --git a/tests/unit/test_tree_nodes.py b/tests/unit/test_tree_nodes.py index d25ccf3..72cb7e9 100644 --- a/tests/unit/test_tree_nodes.py +++ b/tests/unit/test_tree_nodes.py @@ -50,6 +50,24 @@ def test_empty_roots_raises_value_error(tmp_path): load_tree_nodes(tmp_path, "vX") +def test_node_missing_id_raises_value_error(tmp_path): + vdir = tmp_path / "videos" / "vX" + vdir.mkdir(parents=True) + (vdir / "tree.json").write_text( + json.dumps({"roots": [{"card": {}, "time_range": [0, 1]}]}), encoding="utf-8" + ) + with pytest.raises(ValueError): + load_tree_nodes(tmp_path, "vX") + + +def test_roots_not_list_raises_value_error(tmp_path): + vdir = tmp_path / "videos" / "vX" + vdir.mkdir(parents=True) + (vdir / "tree.json").write_text(json.dumps({"roots": "not-a-list"}), encoding="utf-8") + with pytest.raises(ValueError): + load_tree_nodes(tmp_path, "vX") + + def test_load_for_videos_dedups(): data = load_tree_data_for_videos(_STORE, [_VID, _VID]) assert set(data.keys()) == {_VID}