Files
mcp-nextcloud/tests/unit/vector/test_errors.py
T
Chris CoutinhoandClaude Opus 4.8 a188e9fced fix(vector): guard unbound doc_task + address review nits (#891)
Round-1 review on PR #891:
- Guard processor_task's broad except handler against an unbound doc_task
  (mirrors multi_user_processor_task): initialise doc_task=None before the loop
  and branch the error log. Fixes a latent NameError if receive() raises a
  non-TimeoutError/EndOfStream before the first document binds. Regression test
  added.
- Drop the unnecessary `from __future__ import annotations` in vector/_errors.py
  and express format_exception_group's non-group fast path as an explicit
  isinstance check.
- Add a copy_resource Destination-header encoding test (analogue to MOVE);
  strengthen the ExceptionGroup test to assert the full leaf repr survives.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 05:31:56 +02:00

45 lines
1.5 KiB
Python

"""Unit tests for vector-sync error formatting (card 309)."""
import httpx
import pytest
from nextcloud_mcp_server.vector._errors import format_exception_group
@pytest.mark.unit
def test_format_plain_exception_returns_repr():
exc = httpx.ConnectError("Connection error")
assert format_exception_group(exc) == repr(exc)
@pytest.mark.unit
def test_format_exception_group_names_leaf_cause():
"""A single-child group must surface the real ConnectError, not the group's
useless 'unhandled errors in a TaskGroup' default message."""
leaf = httpx.ConnectError("Connection error")
group = BaseExceptionGroup("unhandled errors in a TaskGroup", [leaf])
formatted = format_exception_group(group)
assert "ConnectError" in formatted
# Assert the full leaf repr survives, not just the type name -- guards a
# future format change that kept the type but dropped the message.
assert repr(leaf) in formatted
assert "unhandled errors in a TaskGroup" not in formatted
assert "1 sub-exception" in formatted
@pytest.mark.unit
def test_format_nested_exception_group_flattens_all_leaves():
inner = BaseExceptionGroup(
"inner", [ValueError("bad value"), httpx.ConnectError("conn")]
)
outer = BaseExceptionGroup("outer", [inner, RuntimeError("boom")])
formatted = format_exception_group(outer)
assert "ValueError" in formatted
assert "ConnectError" in formatted
assert "RuntimeError" in formatted
assert "3 sub-exception(s)" in formatted