From 26cac4192d843f312404c0d1043b514471689391 Mon Sep 17 00:00:00 2001 From: Rishet Mehra Date: Fri, 24 Jul 2026 01:21:22 +0530 Subject: [PATCH] test(extract): cover cross-file class-ref indirect_call suppression (#2137) Copilot flagged that the #2137 regression test only exercised the intra-file suppression path; a regression in the cross-file resolver guard in extract.py would still pass. Add a cross-file test: class and function imported from another module, asserting the imported class is never an indirect_call target while a genuine imported callback still emits its edge. --- tests/test_indirect_dispatch.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_indirect_dispatch.py b/tests/test_indirect_dispatch.py index b96eefd..a1ceaed 100644 --- a/tests/test_indirect_dispatch.py +++ b/tests/test_indirect_dispatch.py @@ -248,6 +248,31 @@ def test_cross_file_imported_callback_emits_indirect_call(tmp_path): assert e["confidence"] == "INFERRED" +def test_cross_file_class_ref_is_not_indirect_call(tmp_path): + """The cross-file resolver guard in extract.py must suppress indirect_call edges + whose target is a class imported from another module (a descriptor, not an + invocation), while a genuine imported function callback still emits its edge. + This exercises the _callable_class exclusion on the CROSS-FILE path, which the + intra-file test (test_class_ref_is_not_indirect_call) does not reach.""" + r, nid = _extract_dir(tmp_path, { + "models.py": ( + "class Widget:\n pass\n\n\n" + "def on_event(x):\n return x\n" + ), + "scheduler.py": ( + "from models import Widget, on_event\n\n\n" + "def schedule(pool, db, i):\n" + " db.get(Widget, i) # imported class as descriptor -> no edge\n" + " pool.submit(on_event) # imported fn callback -> indirect_call\n" + ), + }) + indirect = _rels(r, "indirect_call") + # imported class is never an indirect_call target across files + assert all(t != nid["Widget"] for _s, t in indirect) + # genuine imported function callback still emits its edge + assert (nid["schedule"], nid["on_event"]) in indirect + + def test_cross_file_affected_includes_importing_dispatcher(tmp_path): r, nid = _extract_dir(tmp_path, { "handlers.py": "def on_event(x):\n return x\n",