Skip to content

Commit e9b2ef9

Browse files
test: cover async loop install path and clarify loop detection
Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/be07f0d7-3e03-4987-808d-5f87bfcae00b Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com>
1 parent d091c16 commit e9b2ef9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/praisonai/praisonai/integrations/managed_local.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

src/praisonai/tests/unit/integrations/test_managed_agents.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
327345
async def test_local_install_via_compute_quotes_package_names():
328346
"""Package names passed through shell command should be shell-escaped."""

0 commit comments

Comments
 (0)