From 0e57be75beb3c1831fd3bc245b753a5f698db91a Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Tue, 14 Jul 2026 15:33:00 +0200 Subject: [PATCH] fix: normalize path prefix in wiki search so tenant filtering matches get_wikijs_namespace() returns '/users/{user}' with a leading slash while Wiki.js search results carry paths without one, so the prefix filter in search_pages rejected every result - wiki search returned empty for every tenant. Found by cross-repo integration verification; the librarian now gets real search results. Compare slash-normalized on both sides. Co-Authored-By: Claude Fable 5 --- src/clients/wikijs_client.py | 8 ++++++-- tests/test_wikijs_pagination.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/clients/wikijs_client.py b/src/clients/wikijs_client.py index ed54d7e..f479511 100644 --- a/src/clients/wikijs_client.py +++ b/src/clients/wikijs_client.py @@ -594,9 +594,13 @@ class WikiJSClient: data = await self._execute_query(gql_query, {"query": query}) results = data.get("pages", {}).get("search", {}).get("results", []) - # Filter by path prefix if provided + # Filter by path prefix if provided. Wiki.js returns paths WITHOUT a + # leading slash while get_wikijs_namespace() produces one WITH it, so + # compare slash-normalized (the mismatch made this filter reject every + # result, returning an empty search for every tenant). if path_prefix: - results = [r for r in results if r["path"].startswith(path_prefix)] + prefix = path_prefix.lstrip("/") + results = [r for r in results if r["path"].lstrip("/").startswith(prefix)] return results diff --git a/tests/test_wikijs_pagination.py b/tests/test_wikijs_pagination.py index 47d1425..eb9c0be 100644 --- a/tests/test_wikijs_pagination.py +++ b/tests/test_wikijs_pagination.py @@ -9,6 +9,7 @@ These tests mock the GraphQL layer. """ import pytest +from unittest.mock import AsyncMock from src.clients.wikijs_client import WikiJSClient @@ -125,3 +126,22 @@ class TestListPagesLimitAfterFilter: pages = await client.list_pages(limit=10) assert pages[0]["tags"] == [] + + +class TestSearchPagesPrefixNormalization: + """search_pages must match Wiki.js paths (no leading slash) against + get_wikijs_namespace prefixes (leading slash).""" + + @pytest.mark.asyncio + async def test_slashed_prefix_matches_unslashed_paths(self): + client = WikiJSClient("http://wiki.test", "k") + client._execute_query = AsyncMock(return_value={ + "pages": {"search": {"results": [ + {"id": "399", "path": "users/llm_tester/docker-guide", + "title": "Docker Guide", "description": ""}, + {"id": "1", "path": "users/jpmschweitzer/other", + "title": "Other", "description": ""}, + ]}} + }) + results = await client.search_pages("docker", path_prefix="/users/llm_tester") + assert [r["id"] for r in results] == ["399"]