fixing ruff suggestions and tests needed updating.
All checks were successful
CI / Lint (push) Successful in 1m39s
CI / Test (push) Successful in 1m37s
CI / Release (push) Successful in 6s
CI / Notify (push) Successful in 1s

This commit is contained in:
2026-02-18 07:37:13 -05:00
parent 24a4098c9a
commit a1cf87909d
3 changed files with 40 additions and 17 deletions

View File

@@ -86,7 +86,7 @@ class TestChatHandler:
def test_init(self, handler):
"""Test handler initialization."""
assert handler.subject == "ai.chat.request"
assert handler.subject == "ai.chat.user.*.message"
assert handler.queue_group == "chat-handlers"
assert handler.chat_settings.service_name == "chat-handler"
@@ -111,12 +111,15 @@ class TestChatHandler:
result = await handler.handle_message(mock_nats_message, mock_chat_request)
# Verify
assert result["request_id"] == "test-request-123"
assert result["user_id"] == "test-user-1"
assert result["success"] is True
assert "response" in result
assert result["response"] == "Machine learning is a subset of AI that..."
assert "sources" in result # include_sources is True by default
assert result["response_text"] == result["response"]
assert result["used_rag"] is True
assert isinstance(result["rag_sources"], list)
# Verify pipeline was called
# Verify RAG pipeline was called (enable_rag=True in fixture)
handler.embeddings.embed_single.assert_called_once()
handler.milvus.search_with_texts.assert_called_once()
handler.reranker.rerank.assert_called_once()
@@ -142,7 +145,9 @@ class TestChatHandler:
result = await handler.handle_message(mock_nats_message, mock_chat_request)
assert "sources" not in result
# New response format doesn't have a separate "sources" key;
# rag_sources is always present (may be empty)
assert "rag_sources" in result
@pytest.mark.asyncio
async def test_handle_message_with_tts(
@@ -180,7 +185,10 @@ class TestChatHandler:
"""Test LLM is called with custom system prompt."""
request = {
"request_id": "test-123",
"query": "Hello",
"user_id": "user-42",
"message": "Hello",
"premium": True,
"enable_rag": True,
"system_prompt": "You are a pirate. Respond like one.",
}