fix(search): cap path_prefixes server-side; unify Iterable typing

Round 3 review follow-ups:
- Enforce the folder cap (MAX_PATH_PREFIXES=20) inside normalize_path_prefixes
  so the REST/viz endpoints are bounded too, not just the MCP tool's Field
  and the PHP client. Single server-side enforcement point; the MCP tool's
  Field(max_length=...) now references the same constant.
- Widen the SearchAlgorithm ABC and both concrete implementations'
  path_prefixes param to Iterable[str] | None, matching the widening of
  build_base_filter_conditions from the prior round.
- Add a normalize_path_prefixes cap test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-03 13:18:52 +02:00
co-authored by Claude Opus 4.8
parent ea108140ab
commit 9c0c6a0c50
6 changed files with 37 additions and 9 deletions
+10
View File
@@ -9,6 +9,7 @@ from qdrant_client.models import FieldCondition, Filter, MatchText, Range
from nextcloud_mcp_server.search import access_filter
from nextcloud_mcp_server.search.access_filter import (
MAX_PATH_PREFIXES,
build_base_filter_conditions,
build_ownership_filter,
clear_accessible_owners_cache,
@@ -377,3 +378,12 @@ class TestNormalizePathPrefixes:
" /Projects ", ["/Archive", "/Projects", " ", "/Specs"]
)
assert result == ["/Projects", "/Archive", "/Specs"]
@pytest.mark.unit
def test_caps_at_max_path_prefixes(self) -> None:
# A huge list is truncated to MAX_PATH_PREFIXES so no caller can build
# an unbounded OR-clause; the first N (order-preserving) survive.
folders = [f"/dir{i}" for i in range(MAX_PATH_PREFIXES + 30)]
result = normalize_path_prefixes(None, folders)
assert len(result) == MAX_PATH_PREFIXES
assert result == folders[:MAX_PATH_PREFIXES]