fix: address PR review feedback (round 3)

Bugs:
- assign_tag/remove_tag now call _unwrap_ocs to surface OCS-level errors
- trash_page changed to idempotentHint=False (trashing twice errors)
- WebDAV path parts stripped of slashes to prevent double-slash paths

Robustness:
- _unwrap_ocs uses ocs.get("data", {}) instead of ocs["data"]
- Unit test added for missing data key in OCS envelope

Minor:
- MCP error codes use -1 (project convention) instead of HTTP status codes
- update_collective docstring notes that emoji is required
- CollectiveTag.color validated as hex format via field_validator

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-03-25 13:25:09 +01:00
co-authored by Claude Opus 4.6
parent 44a27bd9e9
commit f3caad122d
4 changed files with 45 additions and 13 deletions
@@ -263,7 +263,7 @@ async def test_create_tag(mocker):
async def test_assign_tag(mocker):
"""Test assigning a tag to a page."""
mock_response = create_mock_response(status_code=200, json_data={})
mock_response = _ocs_response({})
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
@@ -278,7 +278,7 @@ async def test_assign_tag(mocker):
async def test_remove_tag(mocker):
"""Test removing a tag from a page."""
mock_response = create_mock_response(status_code=200, json_data={})
mock_response = _ocs_response({})
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
@@ -327,6 +327,25 @@ async def test_restore_page(mocker):
# --- Error Handling ---
async def test_ocs_missing_data_returns_empty(mocker):
"""Test that OCS envelope without 'data' key returns empty dict."""
mock_response = create_mock_response(
status_code=200,
json_data={
"ocs": {
"meta": {"status": "ok", "statuscode": 200},
}
},
)
mocker.patch.object(CollectivesClient, "_make_request", return_value=mock_response)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
# get_collectives accesses data["collectives"], which will KeyError on empty dict
# This tests that _unwrap_ocs itself doesn't crash — it returns {}
with pytest.raises(KeyError):
await client.get_collectives()
async def test_ocs_error_status_raises(mocker):
"""Test that OCS envelope with error statuscode raises OCSError."""
mock_response = create_mock_response(