Skip to content
28 changes: 24 additions & 4 deletions backend/routers/chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio

Check warning on line 1 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / PR Metadata Preflight

Large changed file

backend/routers/chat.py is 1734 lines; consider splitting files over 800 lines.

Check warning on line 1 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / Hygiene

Large changed file

backend/routers/chat.py is 1734 lines; consider splitting files over 800 lines.
import binascii
import json
import tempfile
Expand Down Expand Up @@ -280,7 +280,7 @@


@router.post('/v2/messages', tags=['chat'], response_model=ResponseMessage)
def send_message(

Check warning on line 283 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / PR Metadata Preflight

Long function

send_message is 280 lines; consider extracting focused helpers over 150 lines.

Check warning on line 283 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / Hygiene

Long function

send_message is 280 lines; consider extracting focused helpers over 150 lines.
data: SendMessageRequest,
plugin_id: Optional[str] = None,
app_id: Optional[str] = None,
Expand Down Expand Up @@ -784,7 +784,7 @@
504: {"model": TranscriptionErrorResponse, "description": "Provider timeout"},
},
)
async def transcribe_voice_message(

Check warning on line 787 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / PR Metadata Preflight

Long function

transcribe_voice_message is 300 lines; consider extracting focused helpers over 150 lines.

Check warning on line 787 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / Hygiene

Long function

transcribe_voice_message is 300 lines; consider extracting focused helpers over 150 lines.
request: Request,
uid: str = Depends(auth.with_rate_limit(auth.get_current_user_uid, "voice:transcribe")),
x_app_platform: Optional[str] = Header(None, alias='X-App-Platform'),
Expand Down Expand Up @@ -1087,7 +1087,7 @@


@router.websocket("/v2/voice-message/transcribe-stream")
async def transcribe_voice_message_stream(

Check warning on line 1090 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / PR Metadata Preflight

Long function

transcribe_voice_message_stream is 353 lines; consider extracting focused helpers over 150 lines.

Check warning on line 1090 in backend/routers/chat.py

View workflow job for this annotation

GitHub Actions / Hygiene

Long function

transcribe_voice_message_stream is 353 lines; consider extracting focused helpers over 150 lines.
websocket: WebSocket,
uid: str = Depends(auth.get_current_user_uid_ws_listen),
language: str = 'en',
Expand Down Expand Up @@ -1502,7 +1502,12 @@
# CLEANUP: Remove after new app goes to prod ----------------------------------------------------------


@router.post('/v1/files', response_model=List[FileChat], tags=['chat'])
@router.post(
'/v1/files',
response_model=List[FileChat],
tags=['chat'],
operation_id='upload_file_chat_v1_files_post',
)
@max_part_size(CHAT_FILE_MAX_PART_SIZE)
def upload_file_chat_v1(
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
files: List[UploadFile] = File(...),
Expand Down Expand Up @@ -1558,7 +1563,12 @@
return response


@router.post('/v1/messages/{message_id}/report', tags=['chat'], response_model=dict)
@router.post(
'/v1/messages/{message_id}/report',
tags=['chat'],
response_model=dict,
operation_id='report_message_v1_messages__message_id__report_post',
)
def report_message_v1(message_id: str, uid: str = Depends(auth.get_current_user_uid)):
result = chat_db.get_message(uid, message_id)
if result is None:
Expand All @@ -1572,7 +1582,12 @@
return {'message': 'Message reported'}


@router.delete('/v1/messages', tags=['chat'], response_model=Message)
@router.delete(
'/v1/messages',
tags=['chat'],
response_model=Message,
operation_id='clear_chat_messages_v1_messages_delete',
)
def clear_chat_messages_v1(
plugin_id: Optional[str] = None, app_id: Optional[str] = None, uid: str = Depends(auth.get_current_user_uid)
):
Expand Down Expand Up @@ -1604,7 +1619,12 @@
return initial_message_util(uid, compat_app_id)


@router.post('/v1/initial-message', tags=['chat'], response_model=Message)
@router.post(
'/v1/initial-message',
tags=['chat'],
response_model=Message,
operation_id='create_initial_message_v1_initial_message_post',
)
def create_initial_message_v1(
plugin_id: Optional[str] = None,
app_id: Optional[str] = None,
Expand Down
20 changes: 20 additions & 0 deletions backend/tests/unit/test_chat_operation_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from fastapi.routing import APIRoute

from routers.chat import router

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pre-mock the chat router's heavy dependencies

In the file-isolated backend unit runner, collecting this test imports the full routers.chat dependency graph at module scope—including provider SDKs, native audio packages, and LLM modules—before a fixture can isolate them. This makes a route-metadata test unnecessarily dependent on the complete production import environment and can fail during collection when any transitive dependency is unavailable; load the router through a fixture with the existing chat-router stubbing harness instead.

AGENTS.md reference: backend/AGENTS.md:L220-L220

Useful? React with 👍 / 👎.



def test_legacy_v1_chat_operation_ids_are_preserved_after_ruff_renames():
operation_ids = {
(route.path, method): route.operation_id
for route in router.routes
if isinstance(route, APIRoute)
for method in route.methods
}

assert operation_ids[('/v1/files', 'POST')] == 'upload_file_chat_v1_files_post'
assert (
operation_ids[('/v1/messages/{message_id}/report', 'POST')]
== 'report_message_v1_messages__message_id__report_post'
)
assert operation_ids[('/v1/messages', 'DELETE')] == 'clear_chat_messages_v1_messages_delete'
assert operation_ids[('/v1/initial-message', 'POST')] == 'create_initial_message_v1_initial_message_post'
Loading