fix: address PR review feedback (round 8)

- Fix inconsistent error code in set_collective_emoji (400 → -32603)
- Allow clearing emoji via set_collective_emoji(emoji=None)
- Remove destructiveHint from trash operations (soft deletes are recoverable)
- Change delete_collective to idempotentHint=False (requires trash precondition)
- Add restore_collective and get_trashed_collectives tools
- Add unit tests for ValueError guard, clear-emoji path, and new tools
- Add integration test for full trash/restore/delete lifecycle
- Verify move_page returns new title in response message

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-03-27 11:26:26 +01:00
co-authored by Claude Opus 4.6
parent 7224a2ebe3
commit cb16060b1b
6 changed files with 223 additions and 12 deletions
@@ -453,3 +453,67 @@ async def test_get_page_404(mocker):
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
with pytest.raises(httpx.HTTPStatusError):
await client.get_page(collective_id=1, page_id=999)
# --- Additional coverage ---
async def test_update_collective_no_fields_raises_value_error(mocker):
"""Test that update_collective raises ValueError when called with no fields."""
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
with pytest.raises(ValueError, match="At least one field"):
await client.update_collective(collective_id=1)
async def test_set_page_emoji_clear(mocker):
"""Test that set_page_emoji sends null emoji to clear it."""
page = _sample_page(10, "Test Page")
page["emoji"] = None
mock_response = _ocs_response({"page": page})
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
result = await client.set_page_emoji(collective_id=1, page_id=10, emoji=None)
assert result["emoji"] is None
call_args = mock_request.call_args
assert call_args[1]["json"] == {"emoji": None}
async def test_get_trashed_collectives(mocker):
"""Test listing trashed collectives."""
mock_response = _ocs_response(
{"collectives": [_sample_collective(1, "Trashed Wiki")]}
)
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
result = await client.get_trashed_collectives()
assert len(result) == 1
assert result[0]["name"] == "Trashed Wiki"
call_args = mock_request.call_args
assert "/collectives/trash" in call_args[0][1]
assert call_args[0][0] == "GET"
async def test_restore_collective(mocker):
"""Test restoring a collective from trash."""
mock_response = _ocs_response(
{"collective": _sample_collective(5, "Restored Wiki")}
)
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
result = await client.restore_collective(collective_id=5)
assert result["name"] == "Restored Wiki"
call_args = mock_request.call_args
assert call_args[0][0] == "PATCH"
assert "/collectives/trash/5" in call_args[0][1]