def test_delete_message(mongo_chat_store: MongoChatStore):
    """Test deleting a specific message from a chat session."""
    # Create a chat with multiple messages
    key = "test_delete_specific"
    messages = [
        ChatMessage(role="user", content="First message"),
        ChatMessage(role="assistant", content="Middle message to delete"),
        ChatMessage(role="user", content="Last message"),
    ]
    mongo_chat_store.set_messages(key=key, messages=messages)

    # Delete the middle message
    deleted_message = mongo_chat_store.delete_message(key=key, idx=1)

    # Verify the correct message was deleted
    assert deleted_message.role == "assistant"
    assert deleted_message.content == "Middle message to delete"

    # Verify the remaining messages are correct and reindexed
    remaining = mongo_chat_store.get_messages(key=key)
    assert len(remaining) == 2
    assert remaining[0].content == "First message"
    assert remaining[1].content == "Last message"
Test deleting a specific message from a chat session.
llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-mongo/tests/test_chat_store_mongo_chat_store.py