mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-15 08:29:26 +00:00
Add regression tests for the god node guard on self calls
Two different structs sharing a bare type name with a colliding
method name must yield no edge rather than a guess, and a self call
to a method that genuinely does not exist anywhere in the corpus
must not fabricate a target.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
(cherry picked from commit afeeefa109)
This commit is contained in:
1 parent
d77dcb9a67
commit
5483e5222c
1 file changed
+45
@@ -84,3 +84,48 @@ def test_self_call_same_file_control_is_unaffected(tmp_path: Path):
|
||||
caller = _find(result, ".show()", "widget")
|
||||
callee = _find(result, ".get()", "widget")
|
||||
assert (caller, callee) in calls
|
||||
|
||||
|
||||
def test_self_call_to_ambiguous_type_name_yields_no_edge(tmp_path: Path):
|
||||
"""Two DIFFERENT structs across the corpus happen to share the bare name
|
||||
`Config`, and both define a same-named method -- the exactly-one-candidate
|
||||
guard must refuse to pick either."""
|
||||
calls, result = _calls(tmp_path, {
|
||||
"a.rs": (
|
||||
"struct Config { x: i32 }\n"
|
||||
"impl Config {\n"
|
||||
" fn load(&self) -> i32 { self.x }\n"
|
||||
"}\n"
|
||||
),
|
||||
"b.rs": (
|
||||
"struct Config { y: i32 }\n"
|
||||
"impl Config {\n"
|
||||
" fn load(&self) -> i32 { self.y }\n"
|
||||
"}\n"
|
||||
),
|
||||
"c.rs": (
|
||||
"struct Config { z: i32 }\n"
|
||||
"impl Config {\n"
|
||||
" fn start(&self) -> i32 { self.load() }\n"
|
||||
"}\n"
|
||||
),
|
||||
})
|
||||
caller = _find(result, ".start()", "c_config")
|
||||
targets = {tgt for (src, tgt) in calls if src == caller}
|
||||
assert not targets, "`Config::load` is ambiguous across a.rs/b.rs -- must not guess"
|
||||
|
||||
|
||||
def test_self_call_to_undefined_method_yields_no_edge(tmp_path: Path):
|
||||
"""A `self.` call whose method genuinely doesn't exist anywhere in the
|
||||
corpus must not fabricate a target."""
|
||||
calls, result = _calls(tmp_path, {
|
||||
"lib.rs": (
|
||||
"struct Widget { n: u32 }\n"
|
||||
"impl Widget {\n"
|
||||
" fn show(&self) -> u32 { self.missing() }\n"
|
||||
"}\n"
|
||||
),
|
||||
})
|
||||
caller = _find(result, ".show()", "widget")
|
||||
targets = {tgt for (src, tgt) in calls if src == caller}
|
||||
assert not targets
|
||||
Reference in new issue
Block a user