import asyncio

import pytest

from clarabot_nano.utility import parse_environment_flag
from clarabot_nano_tests.testing.gateway import start_nano_wait_ready


@pytest.mark.skipif(not parse_environment_flag("CBNANO_RUN_DBG_INSTANCE"), reason="not running for debug")
@pytest.mark.asyncio
async def test_run_debug(reset_user_app_dirs, dev_nano_root_dir, testing_server_manager, testing_server_user0):
    """
    Run the whole nano instance for debugging and development of depending components.
    """
    print("Bootstrapping new Nano instance...")
    async with start_nano_wait_ready(testing_server_manager, reset_user_app_dirs, dev_nano_root_dir) as (pm, _):
        print("Nano ready!")
        print("Test user-0:", testing_server_user0["email"], testing_server_user0["password"])
        try:
            while pm.p.poll() is None:
                await asyncio.sleep(1)
        finally:
            print("Cleaning up...")
