Files
mcp-nextcloud/tests/unit/server/test_semantic_consent_narrowing.py
Chris CoutinhoandClaude Opus 4.8 d0db530ac9 fix(vector-sync): address round-5 review — partial-failure signal, markers
- purge route: include a "failed" key in the 200 body listing requested doc
  types that were not purged, so Astrolabe knows consent isn't yet enforced
  for them (scanner backstop still catches up)
- tests: add @pytest.mark.unit / module-level pytestmark to the new test
  modules so they run under `pytest -m unit`; add a partial-failure route test
- capabilities: comment why the cache is keyed per-user despite a global value
- semantic/scanner: doc/comment clarifications (sorted-order, eviction timing)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 01:47:44 +02:00

42 lines
1.4 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
import pytest
from nextcloud_mcp_server.server.semantic import _consent_narrowed_doc_types
pytestmark = pytest.mark.unit
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()) == []