Add regression tests for the cross language alias gate
Covers both the clustered build path and the raw no cluster write
path with the reported Dart to Java shape: an unambiguous old stem
alias whose only claimant is in a different, known language family
than the dangling edge naming it must not resolve.
(cherry picked from commit 1776eed2bd)
This commit is contained in:
1 parent
7f7c0ed441
commit
863a024b3b
2 files changed
+76
No files matched your search
@@ -1084,6 +1084,44 @@ def test_build_from_json_unambiguous_old_stem_alias_still_resolves(tmp_path):
|
||||
assert G.has_edge("dev_poker_server", "dev_monitoring_utility")
|
||||
|
||||
|
||||
def test_build_from_json_unambiguous_old_stem_alias_still_needs_language_match(tmp_path):
|
||||
"""#4941: an unambiguous old-stem alias is not enough on its own — the
|
||||
candidate must also be in the SAME language family as the edge naming it.
|
||||
|
||||
A Dart file at the corpus root has no directory prefix, so its old-stem
|
||||
form is identical to its current id and never registers an alias; nest it
|
||||
one directory deep (matching the real report) so it does. A bare `type`
|
||||
reference inside it to a same-named `PunchType` enum, left dangling by the
|
||||
extractor because the enum is declared in a DIFFERENT Dart file not shown
|
||||
to the resolver here, must not ride the bare "punchtype" alias onto an
|
||||
unrelated Java file of the same name just because that Java file is the
|
||||
alias's only claimant — the alias is unambiguous, but the language is
|
||||
wrong, and that must still block it from resolving."""
|
||||
root = tmp_path / "repo"
|
||||
root.mkdir()
|
||||
extraction = {
|
||||
"nodes": [
|
||||
{"id": "mobile_punch", "label": "punch.dart", "file_type": "code",
|
||||
"source_file": "mobile/punch.dart"},
|
||||
{
|
||||
"id": "backend_src_main_java_ec_smartlocalizador_attendance_punchtype",
|
||||
"label": "PunchType.java", "file_type": "code",
|
||||
"source_file": "backend/src/main/java/ec/smartlocalizador/attendance/PunchType.java",
|
||||
},
|
||||
],
|
||||
"edges": [
|
||||
{"source": "mobile_punch", "target": "punchtype", "relation": "references",
|
||||
"confidence": "EXTRACTED", "source_file": "mobile/punch.dart",
|
||||
"context": "variable_type"},
|
||||
],
|
||||
}
|
||||
G = build_from_json(extraction, root=root)
|
||||
assert not G.has_edge(
|
||||
"mobile_punch",
|
||||
"backend_src_main_java_ec_smartlocalizador_attendance_punchtype",
|
||||
)
|
||||
|
||||
|
||||
def test_build_from_json_relative_source_file_unchanged(tmp_path):
|
||||
"""Already-relative source_file paths must not be modified."""
|
||||
extraction = {
|
||||
|
||||
@@ -156,6 +156,44 @@ def test_finalize_raw_graph_endpoints_keeps_an_ambiguous_alias_unresolved():
|
||||
assert "tool" in [n["id"] for n in data["nodes"]]
|
||||
|
||||
|
||||
def test_finalize_raw_graph_endpoints_rejects_a_cross_language_alias():
|
||||
"""#4941: an alias claimed by exactly one file is still the wrong answer
|
||||
when that file is in a different language than the edge naming it.
|
||||
|
||||
A Dart file's bare `PunchType` reference, left dangling because the real
|
||||
enum lives in a Dart file not shown to the resolver here, must not ride
|
||||
the old-stem "punchtype" alias onto an unrelated Java file of the same
|
||||
name just because the Java file is the alias's only claimant.
|
||||
"""
|
||||
from graphify.build import finalize_raw_graph_endpoints
|
||||
|
||||
data = {
|
||||
"nodes": [
|
||||
{
|
||||
"id": "mobile_punch", "label": "punch.dart", "file_type": "code",
|
||||
"source_file": "mobile/punch.dart",
|
||||
},
|
||||
{
|
||||
"id": "backend_attendance_punchtype", "label": "PunchType.java",
|
||||
"file_type": "code",
|
||||
"source_file": "backend/attendance/PunchType.java",
|
||||
},
|
||||
],
|
||||
"edges": [
|
||||
{"source": "mobile_punch", "target": "punchtype", "relation": "references",
|
||||
"source_file": "mobile/punch.dart", "context": "variable_type"},
|
||||
],
|
||||
}
|
||||
finalize_raw_graph_endpoints(data)
|
||||
# The alias is unambiguous but cross-language, so it must not resolve: the
|
||||
# dangling "references" edge is dropped (not import-family, so nothing
|
||||
# stubs it), and it must never have been re-pointed at the Java file.
|
||||
assert data["edges"] == []
|
||||
assert [n["id"] for n in data["nodes"]] == [
|
||||
"mobile_punch", "backend_attendance_punchtype",
|
||||
]
|
||||
|
||||
|
||||
def test_extract_no_cluster_resolves_a_framework_import_like_the_clustered_path(
|
||||
tmp_path: Path,
|
||||
):
|
||||
|
||||
Reference in new issue
Block a user