-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Problem
PR #589 unified the /api/chat and /api/conversations routers but did not include API router tests for the 8 new endpoints. These endpoints need comprehensive test coverage before the deprecated chat router can be removed.
Endpoints Requiring Tests
The following endpoints in backend/rag_solution/router/conversation_router.py need API tests:
- POST /{session_id}/messages - Add message to session
- POST /{session_id}/process - Process user message with LLM (token-consuming)
- POST /{session_id}/summaries - Create conversation summary
- GET /{session_id}/summaries - Get conversation summaries
- POST /{session_id}/context-summarization - Context-aware summarization
- GET /{session_id}/context-threshold - Check context window threshold
- POST /{session_id}/conversation-suggestions - Enhanced suggestions
- POST /{session_id}/enhanced-export - Enhanced export with filters
Test Requirements
For each endpoint, tests should cover:
1. Authentication & Authorization
- Valid authenticated user can access
- Unauthenticated request returns 401
- User cannot access other users' sessions (403)
2. Input Validation
- Valid input succeeds
- Invalid UUID returns 400
- Missing required fields return 422
- Invalid data types return 422
3. Success Cases
- Endpoint returns expected schema
- Data is correctly persisted (where applicable)
- Response includes proper status codes (200, 201)
4. Error Cases
- Session not found returns 404
- Database errors return 500
- Service errors are handled gracefully
5. Business Logic
- LLM integration works (for
/processendpoint) - Summaries are created correctly
- Context threshold calculation is accurate
- Export includes requested data
Implementation Plan
File to Create: tests/api/test_conversation_router.py
Estimated Size: ~300-400 lines (8 endpoints × ~40 lines per endpoint)
Test Structure:
import pytest
from fastapi.testclient import TestClient
from uuid import uuid4
class TestConversationRouterAuth:
"""Test authentication and authorization."""
def test_unauthenticated_request_returns_401(self, client):
"""All endpoints require authentication."""
# Test each endpoint without auth token
def test_unauthorized_access_returns_403(self, client, test_user):
"""Users cannot access other users' sessions."""
# Create session for user A, try to access with user B
class TestAddMessage:
"""Test POST /{session_id}/messages endpoint."""
def test_add_message_success(self, client, test_session, auth_headers):
"""Successfully add message to session."""
def test_add_message_invalid_session_returns_404(self, client, auth_headers):
"""Invalid session ID returns 404."""
def test_add_message_missing_content_returns_422(self, client, test_session, auth_headers):
"""Missing message content returns 422."""
class TestProcessMessage:
"""Test POST /{session_id}/process endpoint."""
def test_process_message_success(self, client, test_session, auth_headers, mock_llm):
"""Successfully process message with LLM."""
def test_process_message_consumes_tokens(self, client, test_session, auth_headers, mock_llm):
"""Verify token tracking for LLM calls."""
# ... similar classes for each endpointFixtures Needed:
client: FastAPI TestClienttest_user: Test user with UUIDtest_session: Test conversation sessionauth_headers: Authorization headers with JWT tokenmock_llm: Mocked LLM provider for testingtest_db: Test database session
Acceptance Criteria
- All 8 endpoints have comprehensive test coverage
- Tests cover authentication, validation, success, and error cases
- Tests use proper fixtures and mocks (no real LLM calls)
- All tests pass in CI
- Test coverage for conversation_router.py reaches 80%+
- Tests are documented with clear descriptions
Related
- Depends On: PR feat: Implement Phase 4 Router Unification (Issue #558) #589 (Router Unification)
- Blocks: Removal of deprecated
chat_router.py - Related: Issue Phase 4: Conversation Router Unification #558 (Router Unification)
Priority
HIGH - These tests are required before we can safely remove the deprecated chat router and complete the Phase 4 refactoring.
Estimated Effort
2-3 hours of focused development + testing