From 996e82b3d93fc4a9ea946114889f97447c22079a Mon Sep 17 00:00:00 2001 From: Safi Date: Sat, 2 May 2026 16:39:53 +0100 Subject: [PATCH] test: add regression test for ambiguous cross-file call resolution (#632) --- tests/test_extract.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_extract.py b/tests/test_extract.py index 3d5b9f530..3a26693d9 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -168,3 +168,25 @@ def test_calls_deduplication(): result = extract_python(FIXTURES / "sample_calls.py") call_pairs = [(e["source"], e["target"]) for e in result["edges"] if e["relation"] == "calls"] assert len(call_pairs) == len(set(call_pairs)), "Duplicate calls edges found" + + +def test_cross_file_calls_skip_ambiguous_duplicate_labels(tmp_path): + """Unqualified cross-file calls must not guess between duplicate helper names.""" + caller = tmp_path / "caller.py" + helper_a = tmp_path / "a.py" + helper_b = tmp_path / "b.py" + caller.write_text("def run():\n log()\n") + helper_a.write_text("def log():\n return 'a'\n") + helper_b.write_text("def log():\n return 'b'\n") + + result = extract([caller, helper_a, helper_b], cache_root=tmp_path) + nodes = {n["id"]: n for n in result["nodes"]} + calls = [ + e for e in result["edges"] + if e["relation"] == "calls" and e["confidence"] == "INFERRED" + ] + + assert not any( + nodes[e["source"]]["label"] == "run()" and nodes[e["target"]]["label"] == "log()" + for e in calls + )