Adds the seven §10.2 hook-point modules + five env vars so Astrolabe Cloud can offload document processing to the external document-processor / embedding gateway. Purely additive: with every setting unset the server behaves exactly as today, so self-hosters are unaffected (Deck #92). Hook points (all default to current monolith behavior): - config: EMBEDDING_PROVIDER, INGEST_MODE, STATUS_BACKEND, COLLECTION_METADATA_SOURCE, FACT_EVENT_EMITTER (+ supporting settings), validated in Settings.__post_init__ (fail-fast STATUS_BACKEND=local with INGEST_MODE=external); shared canonical.py. - vector/payload_keys.py + acl_hash.py: cross-impl NAMESPACE/point_id (§2.2) and BLAKE2b-128 ACL hash (§11), pinned by fixtures shared with the document-processor repo. - embedding/gateway_client.py: OpenAI-compatible GatewayProvider authenticating via M2M OIDC client-credentials (separate realm); manual-only registry entry. - vector/collection_metadata.py: sentinel-point / API metadata source with env fallback. - vector/queue/: hexagonal ingest producer ports + memory/NATS adapters (Postgres seam); INGEST_MODE=external publishes mcp.ingest.requested.{tenant} instead of the in-memory stream and skips the in-process processor pool. The lifespan becomes a composition root across both deployment branches. - vector/queue/status.py: STATUS_BACKEND=bus subscriber feeding a StatusStore the vector-sync status endpoint reads. - admin/payload_backfill.py: POST /api/v1/admin/payload-backfill (admin scope); processor writes the new payload keys; query-side ACL pre-filter gated behind ACL_PREFILTER_ENABLED (default off). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
"""Admin payload-backfill endpoint (design §10.2)."""
|
|
|
|
import json
|
|
|
|
from nextcloud_mcp_server.api.management import AdminScopeRequired
|
|
from nextcloud_mcp_server.config import Settings
|
|
|
|
|
|
def _request(mocker):
|
|
return mocker.MagicMock()
|
|
|
|
|
|
async def test_backfill_requires_admin_scope(mocker):
|
|
from nextcloud_mcp_server.admin import payload_backfill as mod
|
|
|
|
mocker.patch.object(
|
|
mod, "require_admin_scope", side_effect=AdminScopeRequired("nope")
|
|
)
|
|
resp = await mod.handle_payload_backfill(_request(mocker))
|
|
assert resp.status_code == 403
|
|
|
|
|
|
async def test_backfill_unauthorized_on_auth_error(mocker):
|
|
from nextcloud_mcp_server.admin import payload_backfill as mod
|
|
|
|
mocker.patch.object(mod, "require_admin_scope", side_effect=ValueError("no token"))
|
|
resp = await mod.handle_payload_backfill(_request(mocker))
|
|
assert resp.status_code == 401
|
|
|
|
|
|
async def test_backfill_happy_path_sets_keys_and_sentinel(mocker):
|
|
from nextcloud_mcp_server.admin import payload_backfill as mod
|
|
|
|
mocker.patch.object(mod, "require_admin_scope", return_value="admin")
|
|
mocker.patch.object(
|
|
mod, "get_settings", return_value=Settings(vector_sync_enabled=True)
|
|
)
|
|
qdrant = mocker.AsyncMock()
|
|
mocker.patch.object(mod, "get_qdrant_client", return_value=qdrant)
|
|
embed = mocker.MagicMock()
|
|
embed.get_dimension.return_value = 4
|
|
mocker.patch(
|
|
"nextcloud_mcp_server.embedding.get_embedding_service", return_value=embed
|
|
)
|
|
# upsert_sentinel uses the same qdrant client; it is an AsyncMock so .upsert
|
|
# is awaitable. Patch upsert_sentinel to assert it was invoked.
|
|
sentinel = mocker.patch.object(mod, "upsert_sentinel", new=mocker.AsyncMock())
|
|
|
|
resp = await mod.handle_payload_backfill(_request(mocker))
|
|
assert resp.status_code == 200
|
|
body = json.loads(resp.body)
|
|
assert body["status"] == "ok"
|
|
# processor_version, pipeline_tier, embedding_identity → 3 set_payload calls.
|
|
assert qdrant.set_payload.await_count == 3
|
|
sentinel.assert_awaited_once()
|
|
assert body["sentinel_upserted"] is True
|