async def test_main_calls_setup_flow_when_no_settings(
        self,
        mock_parse_args,
        mock_setup_config,
        mock_get_instance,
        mock_run_setup_flow,
        mock_print,
    ):
        """Test that main calls run_setup_flow when no settings are found and exits."""
        # Setup
        mock_args = MagicMock()
        mock_config = MagicMock(spec=OpenHandsConfig)
        mock_settings_store = AsyncMock(spec=FileSettingsStore)

        # Settings load returns None (no settings)
        mock_settings_store.load = AsyncMock(return_value=None)

        mock_parse_args.return_value = mock_args
        mock_setup_config.return_value = mock_config
        mock_get_instance.return_value = mock_settings_store

        # Mock run_setup_flow to return True (settings configured successfully)
        mock_run_setup_flow.return_value = True

        # Import here to avoid circular imports during patching
        from openhands.cli.main import main

        # Execute
        loop = asyncio.get_event_loop()
        await main(loop)

        # Verify
        mock_run_setup_flow.assert_called_once_with(mock_config, mock_settings_store)
        # Verify that load was called once (before setup)
        self.assertEqual(mock_settings_store.load.call_count, 1)
        # Verify that print_formatted_text was called for success messages
        self.assertGreaterEqual(mock_print.call_count, 2)
Test that main calls run_setup_flow when no settings are found and exits.
tests/unit/test_cli_setup_flow.py