Skip to content

Commit 766566f

Browse files
safishamsiclaude
andcommitted
Fill test gaps from PR #890 and fix case-insensitive path in _is_json_key_node
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent aa541a6 commit 766566f

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

graphify/analyze.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ def _is_file_node(G: nx.Graph, node_id: str) -> bool:
7272

7373

7474
def _is_json_key_node(G: nx.Graph, node_id: str) -> bool:
75-
src = G.nodes[node_id].get("source_file", "")
75+
attrs = G.nodes[node_id]
76+
src = (attrs.get("source_file") or "").lower()
7677
if not src.endswith(".json"):
7778
return False
78-
label = G.nodes[node_id].get("label", "").lower().strip()
79+
label = (attrs.get("label") or "").strip().lower()
7980
return label in _JSON_NOISE_LABELS
8081

8182

tests/test_analyze.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,46 @@ def test_code_doc_extracted_calls_not_suppressed():
381381
assert score >= 1
382382

383383

384+
def test_code_doc_inferred_semantically_similar_not_suppressed():
385+
"""`semantically_similar_to` across code↔doc is explicit LLM insight — must not be suppressed."""
386+
G = _make_code_doc_graph()
387+
G.add_edge("py_fn", "md_doc", relation="semantically_similar_to",
388+
confidence="INFERRED", weight=0.85, source_file="src/processor.py")
389+
G.add_edge("py_a", "py_b", relation="calls", confidence="EXTRACTED",
390+
weight=1.0, source_file="src/service.py")
391+
nc = {"py_fn": 0, "md_doc": 1, "py_a": 0, "py_b": 0}
392+
score_sem, _ = _surprise_score(G, "py_fn", "md_doc",
393+
G.edges["py_fn", "md_doc"], nc,
394+
"src/processor.py", "docs/readme.md")
395+
score_same, _ = _surprise_score(G, "py_a", "py_b",
396+
G.edges["py_a", "py_b"], nc,
397+
"src/service.py", "src/utils.py")
398+
assert score_sem > score_same
399+
400+
401+
def test_code_unknown_extension_inferred_calls_suppressed():
402+
"""_file_category falls back to 'doc' for unknown extensions, so INFERRED
403+
calls/uses to unknown-extension files are suppressed the same as code↔doc."""
404+
assert _file_category("vendor/random.xyz") == "doc"
405+
G = nx.Graph()
406+
G.add_node("py_fn", label="Handler", source_file="src/handler.py", file_type="code")
407+
G.add_node("unk", label="Handler", source_file="vendor/unknown.xyz", file_type="document")
408+
G.add_node("py_a", label="A", source_file="src/a.py", file_type="code")
409+
G.add_node("py_b", label="B", source_file="src/b.py", file_type="code")
410+
G.add_edge("py_fn", "unk", relation="calls", confidence="INFERRED",
411+
weight=0.8, source_file="src/handler.py")
412+
G.add_edge("py_a", "py_b", relation="calls", confidence="EXTRACTED",
413+
weight=1.0, source_file="src/a.py")
414+
nc = {"py_fn": 0, "unk": 1, "py_a": 0, "py_b": 0}
415+
score_unk, _ = _surprise_score(G, "py_fn", "unk",
416+
G.edges["py_fn", "unk"], nc,
417+
"src/handler.py", "vendor/unknown.xyz")
418+
score_same, _ = _surprise_score(G, "py_a", "py_b",
419+
G.edges["py_a", "py_b"], nc,
420+
"src/a.py", "src/b.py")
421+
assert score_unk <= score_same
422+
423+
384424
def test_code_paper_inferred_calls_not_suppressed():
385425
"""Code↔paper INFERRED calls should still surface — it is a meaningful link."""
386426
G = nx.Graph()
@@ -439,3 +479,23 @@ def test_god_nodes_excludes_json_noise():
439479
labels = [r["label"] for r in result]
440480
assert "name" not in labels
441481
assert "AuthService" in labels
482+
483+
484+
def test_god_nodes_filter_is_case_insensitive():
485+
"""JSON-key filter must match regardless of label casing."""
486+
G = nx.Graph()
487+
G.add_node("real", label="RealAbstraction", source_file="libs/real.py")
488+
for i in range(3):
489+
G.add_node(f"peer{i}", label=f"P{i}", source_file=f"src/p{i}.py")
490+
G.add_edge("real", f"peer{i}")
491+
for variant in ("Start", "START", "Name", "ID"):
492+
nid = f"json_{variant.lower()}"
493+
G.add_node(nid, label=variant, source_file="testhelpers/data.json")
494+
for i in range(15):
495+
t = f"{nid}_t{i}"
496+
G.add_node(t, label=f"X{i}", source_file="testhelpers/data.json")
497+
G.add_edge(t, nid)
498+
result = god_nodes(G, top_n=10)
499+
labels = [r["label"] for r in result]
500+
for variant in ("Start", "START", "Name", "ID"):
501+
assert variant not in labels, f"`{variant}` should be filtered as JSON-key noise"

0 commit comments

Comments
 (0)