- scanner: gate the consent backstop with a per-(user,doc_type) one-shot marker so a standing admin-disable doesn't re-enqueue idempotent deletes every scan tick; the marker clears when the type is re-enabled. Derive _TEXT_BACKSTOP_DOC_TYPES from INDEXED_DOC_TYPES so new indexed types are covered automatically - semantic: extract _consent_narrowed_doc_types so the search-side narrowing is unit-testable; add tests for restrict/intersect/disjoint/empty - purge route: cap doc_types length (abuse guard) -> 400 - tests: one-shot + re-enable backstop, too-many-doc_types 400 Deferred (noted on PR): per-document allowed_doc_types call is cache-hot; purge "last error wins" — both logged. SonarCloud broad-except hotspots are deliberate (noqa BLE001), reviewable in the UI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Unit tests for the search-side consent narrowing in nc_semantic_search.
|
|
|
|
The narrowing logic (intersect requested doc_types with the admin allow-set,
|
|
or restrict to the allow-set when none requested) is extracted into
|
|
``_consent_narrowed_doc_types`` so it can be tested without exercising the full
|
|
search path. ``allowed is None`` (no restriction / fail-open) is handled by the
|
|
caller skipping this helper entirely.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from nextcloud_mcp_server.server.semantic import _consent_narrowed_doc_types
|
|
|
|
|
|
def test_none_request_restricts_to_allow_set():
|
|
# No explicit doc_types -> search exactly the allowed set (sorted).
|
|
assert _consent_narrowed_doc_types(None, frozenset({"file", "note"})) == [
|
|
"file",
|
|
"note",
|
|
]
|
|
|
|
|
|
def test_request_intersected_with_allow_set_preserves_order():
|
|
result = _consent_narrowed_doc_types(
|
|
["deck_card", "note", "file"], frozenset({"note", "file"})
|
|
)
|
|
assert result == ["note", "file"]
|
|
|
|
|
|
def test_disjoint_request_yields_empty():
|
|
# Caller short-circuits to an empty response on [].
|
|
assert _consent_narrowed_doc_types(["deck_card"], frozenset({"note"})) == []
|
|
|
|
|
|
def test_empty_allow_set_blocks_all():
|
|
assert _consent_narrowed_doc_types(None, frozenset()) == []
|
|
assert _consent_narrowed_doc_types(["note"], frozenset()) == []
|