Files
mcp-nextcloud/tests/unit/test_app_context_task_producer.py
T
Chris CoutinhoandClaude Opus 4.8 cfdef3c2c5 fix: address PR #836 review — forward task_producer to MCP contexts + cleanups
🔴 nc_get_vector_sync_status reported pending=0 for INGEST_QUEUE=postgres: the
AppContext/OAuthAppContext per-session yields snapshotted the stream fields but
never forwarded task_producer, so lifespan_ctx.task_producer was always None.
Convert task_producer to a @property that reads _vector_sync_state live (like
eviction_task_group), removing the snapshot field so the yields can't drop it.
Add a regression test pinning the contract on both contexts.

🟡 Remove the unused _RECLAIM_TASK_NAME constant.
🟡 get_procrastinate_conninfo: warn + document that DATABASE_URL query params
   (application_name, connect_timeout, …) are dropped.
🟡 worker: open the procrastinate App once — apply_ingest_queue_schema gains
   manage_connection=False so the worker reuses its own open connector instead
   of a redundant open/close before run_worker_async.

🟢 Clarify the apply-schema broad-except comment (non-race errors re-raise) and
   document the deliberate Any typing in ingest_status.get_ingest_pending.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 12:40:50 +02:00

35 lines
1.3 KiB
Python

"""Regression test for the lifespan context `task_producer` exposure (Deck #183).
`nc_get_vector_sync_status` reads `lifespan_ctx.task_producer` for postgres-backend
job counts. It was previously a snapshot dataclass field the per-session yields
forgot to populate, so the tool always reported `pending=0` on the postgres
backend. It is now a `@property` that reads the module singleton live (like
`eviction_task_group`); these tests pin that contract.
"""
from typing import cast
import pytest
import nextcloud_mcp_server.app as app_module
from nextcloud_mcp_server.app import AppContext, OAuthAppContext
from nextcloud_mcp_server.client import NextcloudClient
pytestmark = pytest.mark.unit
def test_app_context_task_producer_reads_vector_sync_state(monkeypatch):
sentinel = object()
monkeypatch.setattr(app_module._vector_sync_state, "task_producer", sentinel)
ctx = AppContext(client=cast(NextcloudClient, None))
assert ctx.task_producer is sentinel
def test_oauth_app_context_task_producer_reads_vector_sync_state(monkeypatch):
sentinel = object()
monkeypatch.setattr(app_module._vector_sync_state, "task_producer", sentinel)
ctx = OAuthAppContext(
nextcloud_host="https://example.test", token_verifier=object()
)
assert ctx.task_producer is sentinel