feat: Enhance integration tests for backend execution flows and initialization
This commit is contained in:
parent
7d9efc5a38
commit
ac91362bd2
1 changed files with 59 additions and 1 deletions
|
|
@ -1,12 +1,70 @@
|
||||||
"""Integration tests for end-to-end execution flows."""
|
"""Integration tests for end-to-end execution flows."""
|
||||||
|
|
||||||
import pytest
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_simple_backend_execution_flow(real_config):
|
async def test_simple_backend_execution_flow(real_config):
|
||||||
"""Test complete flow: code submission → execution → result return."""
|
"""Test complete flow: code submission → execution → result return."""
|
||||||
pytest.skip("TODO: Phase 5.4 - Requires proper container registration and security setup")
|
# 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
|
@pytest.mark.asyncio
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue