Round-1 review on PR #893: - _drop_reason now descends through nested ExceptionGroups to the first leaf (was single-level), so a doubly-wrapped cause isn't mislabelled "other"; added a nested-group test. Commented why both the httpx and openai isinstance branches exist (raw Nextcloud-API errors vs SDK-wrapped variants). - Documented that generate() intentionally shares the broadened transient retry (RAG sampling path), with the worst-case latency note. - Added a docstring note to process_document on how the provider-level retry (5x) layers over the outer loop (3x in-process / 1x procrastinate). - Added test_embed_batch_retries_on_connection_error for the batch path. - Renamed test_retry_reraises_non_rate_limit_immediately -> test_retry_reraises_when_predicate_returns_false (it tests the predicate, not a specific status). SonarCloud: - S5708 (BLOCKER) on the helper's dynamic `except exception_type`: the type is constrained to BaseException/tuple by the signature; suppressed with a justified NOSONAR. - S7503 (async without await) in the embed-retry test: use AsyncMock side_effect instead of a hand-rolled async function. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
"""Unit tests for the embed-drop classifier (card 309).
|
|
|
|
``processor._drop_reason`` maps a terminal indexing failure to a metric label
|
|
so the transient backend-pod-rollover causes (connection / timeout) are
|
|
alertable on ``astrolabe_vector_ingest_dropped_total`` distinctly from
|
|
persistent faults.
|
|
"""
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from nextcloud_mcp_server.vector import processor
|
|
|
|
|
|
def _req() -> httpx.Request:
|
|
return httpx.Request("POST", "http://gw/v1/embeddings")
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_httpx_connect_and_timeout_classified():
|
|
assert processor._drop_reason(httpx.ConnectError("refused")) == "connection"
|
|
assert processor._drop_reason(httpx.ReadTimeout("slow")) == "timeout"
|
|
assert processor._drop_reason(httpx.ConnectTimeout("slow")) == "timeout"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_openai_errors_classified():
|
|
from openai import (
|
|
APIConnectionError,
|
|
APITimeoutError,
|
|
InternalServerError,
|
|
RateLimitError,
|
|
)
|
|
|
|
req = _req()
|
|
assert processor._drop_reason(APIConnectionError(request=req)) == "connection"
|
|
assert processor._drop_reason(APITimeoutError(request=req)) == "timeout"
|
|
assert (
|
|
processor._drop_reason(
|
|
RateLimitError("rl", response=httpx.Response(429, request=req), body=None)
|
|
)
|
|
== "rate_limit"
|
|
)
|
|
assert (
|
|
processor._drop_reason(
|
|
InternalServerError(
|
|
"boom", response=httpx.Response(503, request=req), body=None
|
|
)
|
|
)
|
|
== "server"
|
|
)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_exception_group_unwraps_to_leaf():
|
|
group = BaseExceptionGroup(
|
|
"unhandled errors in a TaskGroup", [httpx.ConnectError("refused")]
|
|
)
|
|
assert processor._drop_reason(group) == "connection"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_nested_exception_group_descends_to_leaf():
|
|
"""A doubly-wrapped group must still classify by its leaf, not 'other'."""
|
|
nested = BaseExceptionGroup(
|
|
"outer", [BaseExceptionGroup("inner", [httpx.ReadTimeout("slow")])]
|
|
)
|
|
assert processor._drop_reason(nested) == "timeout"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_qdrant_namespace_classified():
|
|
from qdrant_client.http.exceptions import UnexpectedResponse
|
|
|
|
exc = UnexpectedResponse(500, "err", b"", headers=None)
|
|
assert processor._drop_reason(exc) == "qdrant"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_unknown_error_falls_back_to_other():
|
|
assert processor._drop_reason(ValueError("nope")) == "other"
|