File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,7 @@ def _install_packages(self) -> None:
485485 logger .info ("[local_managed] installing packages via compute provider (%s): %s" , sandbox_type , pip_pkgs )
486486 try :
487487 try :
488+ # Raises RuntimeError when no event loop is currently running.
488489 asyncio .get_running_loop ()
489490 # We're in async context, run in a separate thread loop.
490491 import threading
Original file line number Diff line number Diff line change @@ -323,6 +323,24 @@ def test_local_install_packages_prefers_compute_and_skips_host(mock_subprocess_r
323323 mock_subprocess_run .assert_not_called ()
324324
325325
326+ @pytest .mark .asyncio
327+ @patch ("praisonai.integrations.managed_local.subprocess.run" )
328+ async def test_local_install_packages_prefers_compute_inside_running_loop (mock_subprocess_run ):
329+ """Compute install should also work when called inside an active event loop."""
330+ from praisonai .integrations .managed_local import LocalManagedAgent , LocalManagedConfig
331+
332+ managed = LocalManagedAgent (
333+ config = LocalManagedConfig (packages = {"pip" : ["requests" ]})
334+ )
335+ managed ._compute = object ()
336+ managed ._install_via_compute = AsyncMock (return_value = None )
337+
338+ managed ._install_packages ()
339+
340+ managed ._install_via_compute .assert_awaited_once_with (["requests" ])
341+ mock_subprocess_run .assert_not_called ()
342+
343+
326344@pytest .mark .asyncio
327345async def test_local_install_via_compute_quotes_package_names ():
328346 """Package names passed through shell command should be shell-escaped."""
You can’t perform that action at this time.
0 commit comments