def test_delete_last_message(mongo_chat_store: MongoChatStore):
    """Test deleting the last message from a chat session."""
    # Create a chat with messages
    key = "test_delete_last"
    messages = [
        ChatMessage(role="user", content="First message"),
        ChatMessage(role="assistant", content="Last message to delete"),
    ]
    mongo_chat_store.set_messages(key=key, messages=messages)

    # Delete the last message
    deleted = mongo_chat_store.delete_last_message(key=key)

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

    # Verify only the first message remains
    remaining = mongo_chat_store.get_messages(key=key)
    assert len(remaining) == 1
    assert remaining[0].content == "First message"
Test deleting the last 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