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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user