mirror of
https://github.com/safishamsi/graphify.git
synced 2026-07-12 10:27:11 +00:00
1b994965bb
A path query like `explain "app/api/route.ts"` tokenized to terms that matched no node, so explain/affected returned "No node matching". Source-file paths are now part of the search index and matched exactly (serve._find_node gains a leading source-exact tier; affected.resolve_seed gains a source-file match). When several nodes share a source_file (e.g. a file-level node plus a function node), the lookup prefers the file-level node — the L1 node whose label basename matches the queried filename, falling back to the unique L1 or unique basename match, else None. Ported from PR #1503 by @behavio1. Maintainer fixes on top: aligned trailing- separator handling between resolve_seed and _find_node (affected previously returned None for a trailing-slash path that explain resolved), corrected the stale "three-tier" _find_node docstring, and added regression tests for the trailing-slash parity and the ambiguous-no-file-node -> None case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
"""Regression tests for `graphify explain` arrow direction (#853)."""
|
|
from __future__ import annotations
|
|
import json
|
|
import graphify.__main__ as mainmod
|
|
|
|
|
|
def _write_graph(tmp_path):
|
|
graph_data = {
|
|
"directed": False, "multigraph": False, "graph": {},
|
|
"nodes": [
|
|
{"id": "validate", "label": "validateSanitySession()",
|
|
"source_file": "server/sanity-validate-session.ts", "community": 0},
|
|
{"id": "create_patch", "label": "createPatchHandler()",
|
|
"source_file": "server/create-patch-handler.ts", "community": 0},
|
|
{"id": "create_edit", "label": "createEditHandler()",
|
|
"source_file": "server/create-edit-handler.ts", "community": 0},
|
|
{"id": "stable_stringify", "label": "stableStringify()",
|
|
"source_file": "shared/stringify.ts", "community": 0},
|
|
],
|
|
"links": [
|
|
{"source": "create_patch", "target": "validate",
|
|
"relation": "calls", "confidence": "EXTRACTED"},
|
|
{"source": "create_edit", "target": "validate",
|
|
"relation": "calls", "confidence": "EXTRACTED"},
|
|
{"source": "validate", "target": "stable_stringify",
|
|
"relation": "calls", "confidence": "EXTRACTED"},
|
|
],
|
|
}
|
|
p = tmp_path / "graph.json"
|
|
p.write_text(json.dumps(graph_data))
|
|
return p
|
|
|
|
|
|
def _run(monkeypatch, graph_path, label, capsys):
|
|
monkeypatch.setattr(mainmod, "_check_skill_version", lambda _: None)
|
|
monkeypatch.setattr(mainmod.sys, "argv",
|
|
["graphify", "explain", label, "--graph", str(graph_path)])
|
|
mainmod.main()
|
|
return capsys.readouterr().out
|
|
|
|
|
|
def test_callee_shows_callers_as_inbound(monkeypatch, tmp_path, capsys):
|
|
p = _write_graph(tmp_path)
|
|
out = _run(monkeypatch, p, "validateSanitySession", capsys)
|
|
assert "<-- createPatchHandler() [calls]" in out
|
|
assert "<-- createEditHandler() [calls]" in out
|
|
assert "--> stableStringify() [calls]" in out
|
|
assert "--> createPatchHandler() [calls]" not in out
|
|
assert "--> createEditHandler() [calls]" not in out
|
|
|
|
|
|
def test_caller_shows_callee_as_outbound(monkeypatch, tmp_path, capsys):
|
|
p = _write_graph(tmp_path)
|
|
out = _run(monkeypatch, p, "createPatchHandler", capsys)
|
|
assert "--> validateSanitySession() [calls]" in out
|
|
assert "<-- " not in out
|
|
|
|
|
|
def test_explain_source_file_path_prefers_file_level_node(monkeypatch, tmp_path, capsys):
|
|
source_file = "app/api/example/route.ts"
|
|
graph_data = {
|
|
"directed": False, "multigraph": False, "graph": {},
|
|
"nodes": [
|
|
{"id": "example_route_get", "label": "GET()",
|
|
"source_file": source_file, "source_location": "L42", "community": 0},
|
|
{"id": "example_route", "label": "route.ts",
|
|
"source_file": source_file, "source_location": "L1", "community": 0},
|
|
],
|
|
"links": [
|
|
{"source": "example_route", "target": "example_route_get",
|
|
"relation": "contains", "confidence": "EXTRACTED"},
|
|
],
|
|
}
|
|
p = tmp_path / "graph.json"
|
|
p.write_text(json.dumps(graph_data))
|
|
|
|
out = _run(monkeypatch, p, source_file, capsys)
|
|
|
|
assert "Node: route.ts" in out
|
|
assert "ID: example_route" in out
|
|
assert f"Source: {source_file} L1" in out
|
|
assert "Node: GET()" not in out
|