async def test_dump_load_store(chat_store: SQLAlchemyChatStore):
    """Test dumping and loading the store."""
    # Add some messages
    await chat_store.add_message(
        "dump_user1", ChatMessage(role="user", content="message1")
    )
    await chat_store.add_message(
        "dump_user2", ChatMessage(role="user", content="message2")
    )

    # Dump the store
    store_dict = chat_store.model_dump()

    # ensure it's valid json
    _ = json.dumps(store_dict)

    # Load the store
    loaded_store = SQLAlchemyChatStore.model_validate(store_dict)

    # verify the loaded store is equivalent to the original store
    assert loaded_store.table_name == chat_store.table_name
    assert loaded_store.async_database_uri == chat_store.async_database_uri

    # verify the messages are the same
    messages = await loaded_store.get_messages("dump_user1")
    assert len(messages) == 1
    assert messages[0].content == "message1"

    messages = await loaded_store.get_messages("dump_user2")
    assert len(messages) == 1
    assert messages[0].content == "message2"
Test dumping and loading the store.
llama-index-core/tests/storage/chat_store/test_sql.py