spec: update api consistency

Align optimistic locking conflict payload, update websocket docs, and adjust tests.
This commit is contained in:
beabigegg
2026-01-11 16:54:28 +08:00
parent f5f870da56
commit 2cb591ef23
9 changed files with 131 additions and 7 deletions

View File

@@ -407,10 +407,13 @@ async def update_task(
if task_data.version != task.version:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=(
f"Version conflict: current_version={task.version}, "
f"provided_version={task_data.version}"
),
detail={
"error": "conflict",
"message": "Task has been modified by another user. Please refresh and retry.",
"current_version": task.version,
"provided_version": task_data.version,
"your_version": task_data.version,
},
)
# Capture old values for audit and triggers

View File

@@ -168,7 +168,6 @@ async def websocket_notifications(
- Connect with: ws://host/ws/notifications?token=<jwt_token>
Messages sent by server:
- {"type": "auth_required"} - Sent when waiting for auth message
- {"type": "connected", "data": {"user_id": "...", "message": "..."}} - Connection success
- {"type": "unread_sync", "data": {"notifications": [...], "unread_count": N}} - All unread on connect
- {"type": "notification", "data": {...}} - New notification
@@ -356,7 +355,6 @@ async def websocket_project_sync(
- Connect with: ws://host/ws/projects/{project_id}?token=<jwt_token>
Messages sent by server:
- {"type": "auth_required"} - Sent when waiting for auth message
- {"type": "connected", "data": {"project_id": "...", "user_id": "..."}}
- {"type": "task_created", "data": {...}, "triggered_by": "..."}
- {"type": "task_updated", "data": {...}, "triggered_by": "..."}

View File

@@ -88,7 +88,11 @@ class TestOptimisticLocking:
)
assert response.status_code == 409
assert "conflict" in response.json().get("detail", "").lower() or "version" in response.json().get("detail", "").lower()
detail = response.json().get("detail")
assert isinstance(detail, dict)
assert detail.get("error") == "conflict"
assert detail.get("current_version") == 5
assert detail.get("provided_version") == 1
def test_update_without_version_succeeds(self, client, admin_token, db):
"""Test that update without version (for backward compatibility) still works."""