Skip to content
Closed
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
6 changes: 6 additions & 0 deletions graphify/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,13 @@ def _resolve_single_node(G: nx.Graph, label: str) -> tuple[str | None, str | Non
in the middle of an unrelated label (`MailController` -> `EmailController`),
which is a search hit, so it comes back as a near miss with suggestions
instead of a different node presented as the answer (#3917).

A node id names exactly one node, so it resolves before any ranking: the
refusals tell the caller to retry with the id, and an id that tokenizes
like a source path must not lose to that file's node (#5343).
"""
if label in G:
return label, None
source_exact, exact, prefix, substring = _find_node_tiers(G, label)
if not (source_exact or exact or prefix):
if not substring:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,24 @@ def test_resolve_single_node_still_takes_a_prefix_shorthand():
assert _resolve_single_node(G, "email") == ("mail", None)


def test_resolve_single_node_takes_an_exact_node_id_before_ranking():
"""An id that tokenizes like its source path lost to that file's L1 node, so
the "Retry with the full node id" advice itself failed (#5343)."""
from graphify.serve import _resolve_single_node

G = nx.MultiDiGraph()
G.add_node("docs_example_skill_skill", label="example-skill/SKILL.md",
source_file="docs/example-skill/SKILL.md", source_location="L1")
G.add_node("docs_example-skill_SKILL.md", label="example-skill/SKILL.md",
source_file="docs/example-skill/SKILL.md")

for nid in G:
assert _resolve_single_node(G, nid) == (nid, None)
nid, err = _resolve_single_node(G, "example-skill/SKILL.md")
assert nid is None
assert err is not None and err.startswith("Ambiguous:")


def test_resolve_single_node_prefers_an_exact_name_over_a_substring():
from graphify.serve import _resolve_single_node

Expand Down
Loading