mcp-forge/tests/server/test_server_integration.py
2026-02-07 07:45:57 +01:00

86 lines
3.1 KiB
Python

"""Integration tests for MCP Forge Server - tests real component initialization."""
import pytest
from pathlib import Path
from unittest.mock import patch
from mcp_forge.server.server import ForgeServer
from mcp_forge.config.schema import (
ForgeConfig, ServerConfig, SecurityConfig, ExecutionConfig, SessionConfig,
ImageConfig, VolumeConfig, EnvironmentBuilderConfig, PackageValidationConfig
)
@pytest.fixture
def real_config(tmp_path):
"""Real configuration with all required fields."""
# Create required files
(tmp_path / "allowlist.txt").write_text("requests\npandas\nnumpy\n")
(tmp_path / "blocklist.txt").write_text("")
config = ForgeConfig(
server=ServerConfig(
host="localhost",
port=3000,
podman_socket=Path("/run/user/1000/podman/podman.sock")
),
security=SecurityConfig(
audit_log=tmp_path / "audit.log",
enforce_resource_limits=True,
allow_network=False
),
execution=ExecutionConfig(
default_backend="simple",
default_timeout=300,
max_timeout=1800,
default_memory="512m",
max_memory="2g"
),
images=ImageConfig(
allowed_python_versions=["3.11", "3.12"],
default_base_image="python:3.11"
),
sessions=SessionConfig(
max_concurrent=10,
idle_timeout=3600
),
volumes=VolumeConfig(
base_path=tmp_path / "volumes"
),
environment_builder=EnvironmentBuilderConfig(
uv_cache_path=tmp_path / "cache",
build_rate_limit={"requests": 5, "period": 60},
package_validation=PackageValidationConfig(
allowlist_path=tmp_path / "allowlist.txt",
blocklist_path=tmp_path / "blocklist.txt"
)
),
mcp_tools={}
)
return config
@pytest.mark.asyncio
async def test_server_can_initialize_with_minimal_mocking(real_config):
"""Test that ForgeServer can initialize with real component instances."""
# Only mock the podman library since we don't have a real Podman socket
with patch('mcp_forge.podman.client.BasePodmanClient'):
# This should succeed if all parameter mismatches are fixed
server = ForgeServer(config=real_config)
# Verify all components were created
assert server.audit_logger is not None
assert server.operation_validator is not None
assert server.podman_client is not None
assert server.container_manager is not None
assert server.client_manager is not None
assert server.bridge_server is not None
assert server.simple_backend is not None
assert server.kernel_manager is not None
assert server.session_manager is not None
assert server.jupyter_backend is not None
assert server.environment_builder is not None
# Sub-components created by EnvironmentBuilder
assert server.package_validator is not None
assert server.uv_installer is not None
assert server.image_builder is not None