Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(mcp): resolve Class.method and Class::method targets with no file (#3635)
Swati Ahujaf62ed457f6fa
diff --git a/packages/server/src/repowise/server/mcp_server/_symbol_lookup.py b/packages/server/src/repowise/server/mcp_server/_symbol_lookup.pyindex f6adfaf7d..d18c1cd8e 100644--- a/packages/server/src/repowise/server/mcp_server/_symbol_lookup.py+++ b/packages/server/src/repowise/server/mcp_server/_symbol_lookup.py@@ -22,6 +22,7 @@ from sqlalchemy import or_, selectfrom repowise.core.ingestion.symbol_identity import (base_symbol_id,id_segment_name,+ split_symbol_id,untyped_symbol_id,)from repowise.core.persistence.models import WikiSymbol@@ -234,13 +235,10 @@ async def resolve_symbol_rows(session, repo_id: str, symbol_id: str) -> list[Wikif rows:return order_candidates(rows, file_path)- if not name:- return []-variants = name_variants(name)# 2. Match on (file_path, qualified_name) across name variants.- if file_path:+ if file_path and name:res = await session.execute(select(WikiSymbol).where(WikiSymbol.repository_id == repo_id,@@ -285,4 +283,37 @@ async def resolve_symbol_rows(session, repo_id: str, symbol_id: str) -> list[Wikif rows:return order_candidates(rows, file_path)+ # 5. A qualified name with no file ("Client.send", "Command::Find"): the+ # head is a class, not a path, so match the qualified_name tail+ # repo-wide. qualified_name is module-prefixed and dotted.+ dotted = _pathless_qualified_name(symbol_id)+ if dotted:+ res = await session.execute(+ select(WikiSymbol).where(+ WikiSymbol.repository_id == repo_id,+ WikiSymbol.name == bare_name(dotted),+ or_(+ WikiSymbol.qualified_name == dotted,+ WikiSymbol.qualified_name.like(+ f"%.{escape_like(dotted)}", escape=LIKE_ESCAPE+ ),+ ),+ )+ )+ return order_candidates(list(res.scalars().all()), None)+return []+++def _pathless_qualified_name(symbol_id: str) -> str | None:+ """The dotted ``Class.method`` a path-less target names, else None.++ An overload discriminator is dropped, since qualified_name never carries+ one, so ``Validate::notNull#1`` answers with the whole overload set.+ """+ base = split_symbol_id(symbol_id)[0]+ head = base.partition("::")[0]+ if "/" in head or "\\" in head:+ return None+ dotted = name_variants(base)[0] if base else ""+ return dotted if "." in dotted else Nonediff --git a/packages/server/src/repowise/server/mcp_server/tool_context/targets.py b/packages/server/src/repowise/server/mcp_server/tool_context/targets.pyindex 3b56f58b0..2306f5478 100644--- a/packages/server/src/repowise/server/mcp_server/tool_context/targets.py+++ b/packages/server/src/repowise/server/mcp_server/tool_context/targets.py@@ -517,6 +517,9 @@ async def _resolve_one_target())sym_matches = list(res.scalars().all())+ if not sym_matches:+ # "Client.send": a qualified name with no file.+ sym_matches = await resolve_symbol_rows(session, repo_id, target)if not sym_matches:res = await session.execute(select(WikiSymbol)@@ -647,7 +650,9 @@ async def _resolve_one_target(collector=collector,as_of_ts=as_of_ts,)- if "error" not in card:+ # Only a file card is the degrade; a symbol card for the head+ # ("Command" of "Command::Nope") would claim the wrong symbol.+ if "error" not in card and card.get("type") == "file":card["target"] = targetcard["resolved_to"] = file_partcard["note"] = (diff --git a/tests/unit/server/mcp/test_pathless_qualified_symbol.py b/tests/unit/server/mcp/test_pathless_qualified_symbol.pynew file mode 100644index 000000000..7c7a1e3aa--- /dev/null+++ b/tests/unit/server/mcp/test_pathless_qualified_symbol.py@@ -0,0 +1,124 @@+"""A qualified name with no file (``Client.send``, ``Command::Find``) resolves.++Agents name methods the way their language writes them, rarely with the file.+Both get_symbol and get_context go through ``resolve_symbol_rows``, so the+lookup is pinned there and once through get_context's card.+"""++from __future__ import annotations++import pytest++from repowise.core.persistence.models import Repository, WikiSymbol+from repowise.server.mcp_server._symbol_lookup import resolve_symbol_rows+from repowise.server.mcp_server.tool_context.targets import _resolve_one_target+++async def repository(session, populated_db) -> Repository:+ repo = await session.get(Repository, populated_db)+ rows = [+ ("httpx/_client.py", "Client::send", "send", "httpx._client.Client.send", "python"),+ (+ "httpx/_models.py",+ "Response::raise_for_status",+ "raise_for_status",+ "httpx._models.Response.raise_for_status",+ "python",+ ),+ ("command.go", "Command", "Command", "command.Command", "go"),+ ("command.go", "Command::Find", "Find", "command.Command.Find", "go"),+ ("src/Op.java", "Op::PLUS::apply", "apply", "src.Op.Op.PLUS.apply", "java"),+ ("src/V.java", "V::put#1(String)", "put", "src.V.V.put", "java"),+ ("src/V.java", "V::put#1(int)", "put", "src.V.V.put", "java"),+ ]+ for line, (path, name_part, name, qualified, language) in enumerate(rows, 1):+ session.add(+ WikiSymbol(+ repository_id=repo.id,+ file_path=path,+ symbol_id=f"{path}::{name_part}",+ name=name,+ qualified_name=qualified,+ kind="method" if "::" in name_part else "struct",+ signature=name,+ start_line=line,+ end_line=line + 1,+ language=language,+ )+ )+ await session.flush()+ return repo+++async def _ids(session, repository, target) -> list[str]:+ return [r.symbol_id for r in await resolve_symbol_rows(session, repository.id, target)]+++ ("target", "expected"),+ [+ ("Client.send", "httpx/_client.py::Client::send"),+ ("Response.raise_for_status", "httpx/_models.py::Response::raise_for_status"),+ ("Command::Find", "command.go::Command::Find"),+ ("Command.Find", "command.go::Command::Find"),+ ("Op::PLUS::apply", "src/Op.java::Op::PLUS::apply"),+ ("Op.PLUS.apply", "src/Op.java::Op::PLUS::apply"),+ ],+)+async def test_a_pathless_qualified_name_resolves(session, repository, target, expected) -> None:+ assert await _ids(session, repository, target) == [expected]+++async def test_an_overload_set_answers_as_candidates(session, repository) -> None:+ """qualified_name carries no discriminator, so the set is the answer."""+ for target in ("V.put", "V::put#1"):+ assert sorted(await _ids(session, repository, target)) == [+ "src/V.java::V::put#1(String)",+ "src/V.java::V::put#1(int)",+ ]+++async def test_an_ambiguous_name_returns_every_candidate(session, repository) -> None:+ session.add(+ WikiSymbol(+ repository_id=repository.id,+ file_path="other/_client.py",+ symbol_id="other/_client.py::Client::send",+ name="send",+ qualified_name="other._client.Client.send",+ kind="method",+ start_line=1,+ end_line=2,+ language="python",+ )+ )+ await session.flush()+ assert sorted(await _ids(session, repository, "Client.send")) == [+ "httpx/_client.py::Client::send",+ "other/_client.py::Client::send",+ ]+++async def test_a_partial_class_name_does_not_match(session, repository) -> None:+ """``ient.send`` is not a tail of ``Client.send`` on a segment boundary."""+ assert await _ids(session, repository, "ient.send") == []+++async def _card(session, repository, target) -> dict:+ return await _resolve_one_target(session, repository, target, None, True, exclude_spec=None)++[email protected]("target", ["Command::Find", "Command.Find", "AuthService.login"])+async def test_get_context_serves_the_method_card(session, repository, target) -> None:+ card = await _card(session, repository, target)+ assert card["type"] == "symbol"+ assert card["docs"]["name"] == target.replace("::", ".").rsplit(".", 1)[1]+ assert "note" not in card+++async def test_an_unknown_method_is_not_served_as_its_class(session, repository) -> None:+ """The head of ``AuthService::Nope`` is a class, not a file, so no degrade."""+ card = await _card(session, repository, "AuthService::Nope")+ assert card.get("type") != "symbol"+ assert "No symbol matched" not in card.get("note", "")