diff --git a/graphify/serve.py b/graphify/serve.py index 22e44640bd..e1604b47b0 100644 --- a/graphify/serve.py +++ b/graphify/serve.py @@ -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: diff --git a/tests/test_serve.py b/tests/test_serve.py index c0e9a8e1b7..11422c0f8d 100644 --- a/tests/test_serve.py +++ b/tests/test_serve.py @@ -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