fix(contacts): surface ORG/TITLE/NOTE/URL/CATEGORIES/PHOTO on read (refs #716)

PR #719 fixed the contact-create path so all documented fields persist to the
vCard, but the read path (list/search via MCP) still returned ``organization:
null`` / ``note: null`` / ``title: null`` because pythonvCard4 has no typed
parser for ORG/TITLE — they land in ``Contact.custom`` — and the server-side
mapper never read ``note``/``urls``/``categories``/``photo`` even when present.

Reads now surface what the write side persisted:

- ``client/contacts.py``: new ``_first_custom`` helper pulls raw values from
  ``Contact.custom`` for ORG/TITLE/unencoded PHOTO. ``list_contacts``
  extends its per-contact dict with org/title/note/url/categories/photo.
- ``server/contacts.py``: ``_raw_contact_to_model`` maps the new keys onto
  ``Contact.organization`` / ``.title`` / ``.note`` / ``.urls`` / ``.categories``
  / ``.photo``. URL accepts both list and plain-string shapes; categories
  accepts comma-separated strings for forward-compat.

Coverage:

- Unit: ``TestFirstCustom`` (five cases incl. bare-string library shape) and
  three new ``_raw_contact_to_model`` cases covering the full field set,
  plain-string URL, and comma-string categories.
- Integration: ``test_mcp_contacts_workflow`` now decodes the
  ``nc_contacts_search_contacts`` response and asserts
  ``organization`` / ``note`` round-trip — direct regression coverage for
  elvisdragonmao's report on issue #716.

Verified end-to-end against the local single-user docker stack: creating a
contact with ``{organization, title, note, url, categories}`` and reading it
back via ``nc_contacts_search_contacts`` returns every field populated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-05-21 10:07:47 +02:00
co-authored by Claude Opus 4.7
parent 04a6294cc5
commit 688a03f00a
5 changed files with 179 additions and 3 deletions
+26
View File
@@ -11,6 +11,7 @@ import pytest
from nextcloud_mcp_server.client.contacts import (
_build_contact_from_data,
_first_custom,
_normalize_contact_data,
_wrap_contact_field,
)
@@ -201,6 +202,31 @@ def test_missing_fn_logs_warning(caplog):
assert any("fn" in r.message.lower() for r in caplog.records)
class TestFirstCustom:
"""``_first_custom`` is the read-side companion to PR #719 — it pulls
ORG / TITLE / unencoded PHOTO out of pythonvCard4's ``custom`` dict because
the library has no typed parser for them.
"""
def test_returns_first_value_from_list(self):
assert _first_custom({"ORG": ["Acme Corp"]}, "ORG") == "Acme Corp"
def test_returns_first_value_when_library_uses_bare_string(self):
"""The library's typeshed allows ``str`` as a value shape too. Accept it
so we don't break if the parser changes shape upstream.
"""
assert _first_custom({"TITLE": "Engineer"}, "TITLE") == "Engineer"
def test_returns_none_for_missing_key(self):
assert _first_custom({"ORG": ["Acme"]}, "TITLE") is None
def test_returns_none_for_empty_list(self):
assert _first_custom({"ORG": []}, "ORG") is None
def test_returns_none_for_empty_string(self):
assert _first_custom({"ORG": ""}, "ORG") is None
class TestNormalizeContactData:
"""Direct tests for the alias helper — it's load-bearing for update_contact too."""