import os

import pytest
from langflow.initial_setup.setup import load_starter_projects
from langflow.load import aload_flow_from_json
from lfx.graph import Graph

# TODO: UPDATE BASIC EXAMPLE
# def test_load_flow_from_json():
#     """Test loading a flow from a json file"""
#     loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH)
#     assert loaded is not None
#     assert isinstance(loaded, Graph)


# def test_load_flow_from_json_with_tweaks():
#     """Test loading a flow from a json file and applying tweaks"""
#     tweaks = {"dndnode_82": {"model_name": "gpt-3.5-turbo-16k-0613"}}
#     loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH, tweaks=tweaks)
#     assert loaded is not None
#     assert isinstance(loaded, Graph)


@pytest.mark.skipif(
    os.environ.get("CI") == "true",
    reason="Flaky on CI due to SystemError: Resource temporarily unavailable",
)
async def test_load_flow_from_json_object():
    """Test loading a flow from a json file and applying tweaks."""
    result = await load_starter_projects()
    project = result[0][1]
    loaded = await aload_flow_from_json(project)
    assert loaded is not None
    assert isinstance(loaded, Graph)
