diff --git a/tests/test_semantic_cache_basename_recovery.py b/tests/test_semantic_cache_basename_recovery.py index 62fea2236..7ee0c1b8f 100644 --- a/tests/test_semantic_cache_basename_recovery.py +++ b/tests/test_semantic_cache_basename_recovery.py @@ -30,6 +30,31 @@ def test_malformed_but_basename_unique_path_recovers(tmp_path): assert {n["id"] for n in cached["nodes"]} == {"n1"} +def test_recovered_group_edges_are_not_pruned_as_dangling(tmp_path): + # group_skipped (used by the dangling-reference pruning pass) and the + # write loop must agree a recovered group is WRITTEN, not skipped -- + # otherwise an edge between two nodes in that same recovered group would + # be wrongly pruned as referencing a "skipped" id. + real = tmp_path / "sub" / "weird_named_file.py" + real.parent.mkdir(parents=True) + real.write_text("def f(): pass\ndef g(): pass\n") + + nodes = [ + {"id": "n1", "label": "f", "source_file": "lost_dir/weird_named_file.py"}, + {"id": "n2", "label": "g", "source_file": "lost_dir/weird_named_file.py"}, + ] + edges = [ + {"source": "n1", "target": "n2", "relation": "calls", + "source_file": "lost_dir/weird_named_file.py"}, + ] + saved = save_semantic_cache(nodes, edges, root=tmp_path, allowed_source_files=[real]) + assert saved == 1 + + cached = load_cached(real, root=tmp_path, kind="semantic") + assert cached is not None + assert len(cached["edges"]) == 1 + + def test_ambiguous_basename_stays_skipped(tmp_path): a = tmp_path / "pkg_a" / "shared.py" b = tmp_path / "pkg_b" / "shared.py"