Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions graphify/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,23 @@ def finalize_raw_graph_endpoints(data: dict) -> None:
".cxx": "c", ".hh": "c", ".hxx": "c",
".cu": "c", ".cuh": "c", ".metal": "c", ".m": "c", ".mm": "c",
".rb": "rb", ".rake": "rb", ".php": "php", ".cs": "cs", ".swift": "swift", ".lua": "lua",
# Everything else extract._LANG_FAMILY_BY_EXT knows (#5247): an extension
# missing here resolves to no family, so the guard silently never fires
# (e.g. a Python `from app import db` binding to a Dart `lib/app.dart`).
# tests/test_build.py checks that every extract extension stays covered.
".vue": "js", ".svelte": "js", ".astro": "js", ".ejs": "js",
".kts": "jvm", ".gradle": "jvm",
".vb": "cs", ".razor": "cs", ".cshtml": "cs", ".xaml": "cs",
".phtml": "php", ".php3": "php", ".php4": "php", ".php5": "php",
".php7": "php", ".phps": "php",
".luau": "lua",
".cbl": "cobol", ".cob": "cobol", ".cobol": "cobol", ".cpy": "cobol",
".r": "r", ".sol": "solidity",
".erl": "erlang", ".hrl": "erlang", ".escript": "erlang",
".zig": "zig", ".ex": "elixir", ".exs": "elixir", ".jl": "julia",
".dart": "dart", ".sql": "sql",
".sh": "shell", ".bash": "shell",
".ps1": "powershell", ".psm1": "powershell", ".psd1": "powershell",
}


Expand Down
42 changes: 42 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,48 @@ def test_cross_language_imports_references_are_dropped():
assert G.has_edge("src_time_ts", "src_util_ts"), "same-family (TS->TS) import must survive"


def test_edge_lang_family_covers_every_extract_language():
"""#5247: build's phantom-edge guard table must not drift from
extract._LANG_FAMILY_BY_EXT. An extension missing from _EDGE_LANG_FAMILY has
no family, so a cross-language edge from or to it is never dropped. The two
tables use different family names, so compare the grouping, not the names."""
from graphify.build import _EDGE_LANG_FAMILY
from graphify.extract import _LANG_FAMILY_BY_EXT

missing = sorted(set(_LANG_FAMILY_BY_EXT) - set(_EDGE_LANG_FAMILY))
assert missing == [], f"extensions unguarded in build._EDGE_LANG_FAMILY: {missing}"
# Every build family must sit inside a single extract family, so the guard
# never drops an edge that call resolution treats as same-language. (Build
# is deliberately stricter for Swift vs C/ObjC, which this allows.)
for ext_a, fam_a in _EDGE_LANG_FAMILY.items():
for ext_b, fam_b in _EDGE_LANG_FAMILY.items():
if fam_a == fam_b and ext_a in _LANG_FAMILY_BY_EXT and ext_b in _LANG_FAMILY_BY_EXT:
assert _LANG_FAMILY_BY_EXT[ext_a] == _LANG_FAMILY_BY_EXT[ext_b], (ext_a, ext_b)


def test_cross_language_import_into_dart_is_dropped():
"""#5247: a Python `from app import db` must not bind to `lib/app.dart`."""
ext = {
"nodes": [
{"id": "app_controller", "label": "controller.py", "file_type": "code",
"source_file": "app/controller.py", "source_location": "L1", "_origin": "ast"},
{"id": "lib_app", "label": "app.dart", "file_type": "code",
"source_file": "lib/app.dart", "source_location": "L1", "_origin": "ast"},
{"id": "lib_main", "label": "main.dart", "file_type": "code",
"source_file": "lib/main.dart", "source_location": "L1", "_origin": "ast"},
],
"edges": [
{"source": "app_controller", "target": "lib_app", "relation": "imports_from",
"confidence": "EXTRACTED", "source_file": "app/controller.py", "weight": 1.0},
{"source": "lib_main", "target": "lib_app", "relation": "imports",
"confidence": "EXTRACTED", "source_file": "lib/main.dart", "weight": 1.0},
],
}
G = build_from_json(ext, directed=False)
assert not G.has_edge("app_controller", "lib_app"), "py -> dart import must be dropped"
assert G.has_edge("lib_main", "lib_app"), "dart -> dart import must survive"


def test_cross_family_reference_to_unknown_ext_is_kept():
"""The #1749 guard only drops when BOTH endpoints are known code languages,
so a reference from a config/manifest (unknown ext) to a code file is kept."""
Expand Down
Loading