def test_add_message(mongo_chat_store: MongoChatStore):
    """Test adding a message to an existing chat session."""
    # Create a chat with initial messages
    key = "test_add_message"
    initial_messages = [ChatMessage(role="user", content="Initial message")]
    mongo_chat_store.set_messages(key=key, messages=initial_messages)

    # Add a new message
    new_message = ChatMessage(role="assistant", content="Response to initial message")
    mongo_chat_store.add_message(key=key, message=new_message)

    # Retrieve all messages
    messages = mongo_chat_store.get_messages(key=key)

    # Verify the new message was added
    assert len(messages) == 2
    assert messages[0].role == "user"
    assert messages[0].content == "Initial message"
    assert messages[1].role == "assistant"
    assert messages[1].content == "Response to initial message"
Test adding a message to an existing chat session.
llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-mongo/tests/test_chat_store_mongo_chat_store.py