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(search): scan slash-containing literal queries (#4230)
Vamsi-258143acf0625d3b
diff --git a/packages/server/src/repowise/server/mcp_server/_line_hits.py b/packages/server/src/repowise/server/mcp_server/_line_hits.pyindex 03b089f25..cddd1b8b3 100644--- a/packages/server/src/repowise/server/mcp_server/_line_hits.py+++ b/packages/server/src/repowise/server/mcp_server/_line_hits.py@@ -95,6 +95,8 @@ def _literal(query: str) -> tuple[str, bool] | None:return m.group(2), Falseif len(q) >= 2 and _TOKEN.match(q) and not q.endswith("."):return q, True+ if len(q) >= 2 and "/" in q and q.strip("./") and not any(char.isspace() for char in q):+ return q, Falseif _is_code_shaped(q):return q, Falsereturn None@@ -419,9 +421,13 @@ async def attach_line_hits(async def _attach(response: dict, query: str, mode: str, names: Container[str] | None, repo: str | None) -> None:- if repo == "all" or mode == "path":+ if repo == "all":returnliteral = _literal(query)+ if mode == "path" and (+ response.get("results") or literal is None or "/" not in literal[0]+ ):+ returncandidates = _identifier_candidates(query, mode, names)if literal and not literal[1] and not _QUOTED.match(query.strip()):# Code punctuation names the text itself: an identifier inside itdiff --git a/tests/unit/server/mcp/test_search_line_hits.py b/tests/unit/server/mcp/test_search_line_hits.pyindex cc1b2428f..c3f513051 100644--- a/tests/unit/server/mcp/test_search_line_hits.py+++ b/tests/unit/server/mcp/test_search_line_hits.py@@ -9,7 +9,7 @@ from datetime import UTC, datetimeimport pytest-from repowise.core.persistence.models import GraphEdge, GraphNode+from repowise.core.persistence.models import GraphEdge, GraphNode, Pagefrom repowise.server.mcp_server import _edit_sites, _line_hits, _meta, _statefrom repowise.server.mcp_server._budget import enforce_response_budgetfrom repowise.server.mcp_server.tool_search import search_codebase@@ -26,6 +26,7 @@ _FILES = {" print('hello there')\n"" return backend_of('m')\n""x = 147821\n"+ 'USER_AGENT = "acme-cli/0.1.0"\n'),}@@ -137,6 +138,60 @@ async def test_literal_number_is_scanned_with_definition_first(tree):assert out["complete"] is True+async def test_slash_literal_falls_back_from_path_mode(tree):+ out = await search_codebase("acme-cli/0.1.0")++ assert _rows(out) == [("app/widget.py", 8, "definition")]+ assert out["complete"] is True+++async def test_slash_literal_is_scanned_in_hybrid_mode(tree):+ out = await search_codebase("acme-cli/0.1.0", mode="hybrid")++ assert _rows(out) == [("app/widget.py", 8, "definition")]+ assert out["complete"] is True+++async def test_matching_path_query_does_not_add_line_hits(tree, session, setup_mcp):+ # Path mode matches indexed file pages, so the file needs one to be found.+ session.add(+ Page(+ id="file_page:app/widget.py",+ repository_id=setup_mcp,+ page_type="file_page",+ title="Widget",+ content="# Widget",+ target_path="app/widget.py",+ source_hash="widget",+ model_name="mock",+ provider_name="mock",+ generation_level=2,+ confidence=0.8,+ freshness_status="fresh",+ metadata_json="{}",+ created_at=_NOW,+ updated_at=_NOW,+ )+ )+ await session.commit()+ out = await search_codebase("app/widget.py", mode="path")++ assert any(result["path"] == "app/widget.py" for result in out["results"])+ assert "lines" not in out++[email protected]("query", ["SomeName", "./", "../"])+async def test_unmatched_path_query_only_falls_back_for_slash_literals(tree, query):+ out = await search_codebase(query, mode="path")++ assert out["results"] == []+ assert "lines" not in out++@pytest.mark.asyncioasync def test_quoted_string_is_scanned_as_a_substring(tree):out = await search_codebase('"hello there"')