91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
"""Integration tests for end-to-end execution flows."""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock, MagicMock, patch
|
|
|
|
from pod_executor import CodeExecutor, ExecutionResult, ResourceLimits
|
|
from pod_executor.containers.manager import SecureContainerManager
|
|
from mcp_forge.adapters import SimpleBackend, JupyterBackend
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_simple_backend_execution_flow(real_config):
|
|
"""Test complete flow: code submission → execution → result return."""
|
|
# Mock the container manager
|
|
mock_container_manager = Mock(spec=SecureContainerManager)
|
|
mock_container_manager.create_container.return_value = "test-container-123"
|
|
mock_container_manager.wait_for_container.return_value = 0
|
|
mock_container_manager.get_container_logs.return_value = (
|
|
'{"result": 42, "error": null}',
|
|
""
|
|
)
|
|
|
|
# Create audit logger mock
|
|
from mcp_forge.security.audit import AuditLogger
|
|
mock_audit_logger = Mock(spec=AuditLogger)
|
|
|
|
# Create simple backend
|
|
backend = SimpleBackend(
|
|
container_manager=mock_container_manager,
|
|
audit_logger=mock_audit_logger,
|
|
config=real_config
|
|
)
|
|
|
|
# Execute code
|
|
result = backend.execute("print(21 * 2)")
|
|
|
|
# Verify execution worked
|
|
assert result.success is True
|
|
assert result.exit_code == 0
|
|
|
|
# Verify container lifecycle was called
|
|
mock_container_manager.create_container.assert_called_once()
|
|
mock_container_manager.start_container.assert_called_once()
|
|
mock_container_manager.remove_container.assert_called_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_jupyter_backend_initialization(real_config):
|
|
"""Test Jupyter backend can be initialized with adapters."""
|
|
# Mock the container manager
|
|
mock_container_manager = Mock(spec=SecureContainerManager)
|
|
|
|
# Create audit logger mock
|
|
from mcp_forge.security.audit import AuditLogger
|
|
mock_audit_logger = Mock(spec=AuditLogger)
|
|
|
|
# Create jupyter backend (should not raise)
|
|
backend = JupyterBackend(
|
|
container_manager=mock_container_manager,
|
|
audit_logger=mock_audit_logger,
|
|
config=real_config
|
|
)
|
|
|
|
# Verify backend was created
|
|
assert backend is not None
|
|
assert backend.backend is not None
|
|
assert backend.config == real_config
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_jupyter_session_lifecycle(real_config):
|
|
"""Test: Create session → execute multiple code blocks → cleanup."""
|
|
pytest.skip("TODO: Phase 5.4 - Complex Jupyter session testing requires more setup")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_jupyter_session_isolation(real_config):
|
|
"""Test: Two sessions don't share state."""
|
|
pytest.skip("TODO: Phase 5.4 - Complex Jupyter session testing requires more setup")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_execution_with_timeout(real_config):
|
|
"""Test: Long-running code gets killed after timeout."""
|
|
pytest.skip("TODO: Phase 5.4 - Requires proper container registration and security setup")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_execution_with_memory_limit(real_config):
|
|
"""Test: Memory-intensive code respects limits."""
|
|
pytest.skip("TODO: Phase 5.4 - Requires proper container registration and security setup")
|