test(vector): close generate()/drop-counter test gaps + https mock URLs (#893)

Round-2 review on PR #893:
- Add test_generate_retries_on_connection_error (generate() shares the transient
  retry; guards the decorator against accidental removal).
- Add test_process_document_records_drop_on_exhausted_retries: drives
  process_document to retry-exhaustion and asserts record_ingest_dropped is
  called once with the classified reason (processor-level coverage, not just the
  _drop_reason unit).
- Note in _drop_reason that a multi-failure group is labelled by its first leaf
  (best-effort, no "mixed" bucket).

SonarCloud: the quality gate was failing on new_security_hotspots_reviewed
(S5332 "use https") from http:// URLs in the test _req() helpers — switched to
https:// (mirrors commit 98c9d58e).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-11 06:09:59 +02:00
co-authored by Claude Opus 4.8
parent 6c99906ed4
commit 8f7a8432f5
3 changed files with 58 additions and 3 deletions
+24 -1
View File
@@ -338,7 +338,7 @@ async def test_openai_close(mock_openai_client):
def _req():
import httpx
return httpx.Request("POST", "http://gw/v1/embeddings")
return httpx.Request("POST", "https://gw/v1/embeddings")
@pytest.mark.unit
@@ -434,3 +434,26 @@ async def test_embed_batch_retries_on_connection_error(mock_openai_client, monke
assert embeddings == [[0.4, 0.5, 0.6]]
assert tokens == 7
assert create.await_count == 2
@pytest.mark.unit
async def test_generate_retries_on_connection_error(mock_openai_client, monkeypatch):
"""generate() shares the transient retry (RAG sampling survives a rollover)."""
from openai import APIConnectionError
from nextcloud_mcp_server.providers import _retry
monkeypatch.setattr(_retry.anyio, "sleep", AsyncMock(return_value=None))
choice = MagicMock()
choice.message.content = "Generated response"
mock_response = MagicMock()
mock_response.choices = [choice]
create = AsyncMock(side_effect=[APIConnectionError(request=_req()), mock_response])
mock_openai_client.chat.completions.create = create
provider = OpenAIProvider(api_key="test-key", generation_model="gpt-4o-mini")
text = await provider.generate("prompt")
assert text == "Generated response"
assert create.await_count == 2