refactor: Update environment and Docker configuration files; remove unused MCP configuration tests

This commit is contained in:
OhMyApps
2025-06-25 17:42:58 +02:00
parent e4c2b36cb3
commit 8ff8e06bf9
5 changed files with 40 additions and 137 deletions

View File

@@ -153,3 +153,18 @@ LOG_LEVEL=DEBUG
# DISABLED_TOOLS=debug,tracer # Disable debug and tracer tools # DISABLED_TOOLS=debug,tracer # Disable debug and tracer tools
# DISABLED_TOOLS=planner,consensus # Disable planning tools # DISABLED_TOOLS=planner,consensus # Disable planning tools
# ===========================================
# Docker Configuration
# ===========================================
# Container name for Docker Compose
# Used when running with docker-compose.yml
COMPOSE_PROJECT_NAME=zen-mcp
# Timezone for Docker containers
# Ensures consistent time handling in containerized environments
TZ=UTC
# Maximum log file size (default: 10MB)
# Applicable when using file-based logging
LOG_MAX_SIZE=10MB

View File

@@ -11,7 +11,7 @@
```bash ```bash
# Copy environment template # Copy environment template
cp .env.docker.example .env cp .env.example .env
# Edit with your API keys (at least one required) # Edit with your API keys (at least one required)
# Required: GEMINI_API_KEY or OPENAI_API_KEY or XAI_API_KEY # Required: GEMINI_API_KEY or OPENAI_API_KEY or XAI_API_KEY

View File

@@ -2,7 +2,6 @@
Complete configuration test for Docker MCP Complete configuration test for Docker MCP
""" """
import json
import os import os
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
@@ -13,52 +12,6 @@ import pytest
class TestDockerMCPConfiguration: class TestDockerMCPConfiguration:
"""Docker MCP configuration tests""" """Docker MCP configuration tests"""
def test_mcp_config_zen_docker_complete(self):
"""Test complete zen-docker configuration"""
project_root = Path(__file__).parent.parent
mcp_path = project_root / ".vscode" / "mcp.json"
if not mcp_path.exists():
pytest.skip("mcp.json not found")
# Load and clean JSON
with open(mcp_path, encoding="utf-8") as f:
content = f.read()
# Remove JSON comments
lines = []
for line in content.split("\n"):
if "//" in line:
line = line[: line.index("//")]
lines.append(line)
clean_content = "\n".join(lines)
config = json.loads(clean_content)
# Check zen-docker structure
assert "servers" in config
servers = config["servers"]
if "zen-docker" in servers:
zen_docker = servers["zen-docker"]
# Required checks
assert zen_docker["command"] == "docker"
args = zen_docker["args"]
# Essential arguments for MCP
required_args = ["run", "--rm", "-i"]
for arg in required_args:
assert arg in args, f"Argument {arg} missing"
# zen-mcp-server image
assert "zen-mcp-server:latest" in args
# Environment variables
if "env" in zen_docker:
env = zen_docker["env"]
assert "DOCKER_BUILDKIT" in env
def test_dockerfile_configuration(self): def test_dockerfile_configuration(self):
"""Test Dockerfile configuration""" """Test Dockerfile configuration"""
project_root = Path(__file__).parent.parent project_root = Path(__file__).parent.parent
@@ -87,7 +40,7 @@ class TestDockerMCPConfiguration:
def test_environment_file_template(self): def test_environment_file_template(self):
"""Test environment file template""" """Test environment file template"""
project_root = Path(__file__).parent.parent project_root = Path(__file__).parent.parent
env_example = project_root / ".env.docker.example" env_example = project_root / ".env.example"
if env_example.exists(): if env_example.exists():
content = env_example.read_text() content = env_example.read_text()
@@ -98,6 +51,11 @@ class TestDockerMCPConfiguration:
for var in essential_vars: for var in essential_vars:
assert f"{var}=" in content, f"Variable {var} missing" assert f"{var}=" in content, f"Variable {var} missing"
# Docker-specific variables should also be present
docker_vars = ["COMPOSE_PROJECT_NAME", "TZ", "LOG_MAX_SIZE"]
for var in docker_vars:
assert f"{var}=" in content, f"Docker variable {var} missing"
def test_logs_directory_setup(self): def test_logs_directory_setup(self):
"""Test logs directory setup""" """Test logs directory setup"""
project_root = Path(__file__).parent.parent project_root = Path(__file__).parent.parent
@@ -216,7 +174,6 @@ class TestIntegrationChecks:
# MCP integration checks # MCP integration checks
checks = { checks = {
"mcp_config": (project_root / ".vscode" / "mcp.json").exists(),
"dockerfile": (project_root / "Dockerfile").exists(), "dockerfile": (project_root / "Dockerfile").exists(),
"server_script": (project_root / "server.py").exists(), "server_script": (project_root / "server.py").exists(),
"logs_dir": (project_root / "logs").exists() or True, "logs_dir": (project_root / "logs").exists() or True,

View File

@@ -56,7 +56,7 @@ class TestDockerConfiguration:
def test_environment_file_template(self): def test_environment_file_template(self):
"""Test that an .env file template exists""" """Test that an .env file template exists"""
env_example_path = self.project_root / ".env.docker.example" env_example_path = self.project_root / ".env.example"
if env_example_path.exists(): if env_example_path.exists():
content = env_example_path.read_text() content = env_example_path.read_text()
@@ -306,7 +306,6 @@ def temp_project_dir():
temp_path = Path(temp_dir) temp_path = Path(temp_dir)
# Create base structure # Create base structure
(temp_path / ".vscode").mkdir()
(temp_path / "logs").mkdir() (temp_path / "logs").mkdir()
# Create base files # Create base files
@@ -327,32 +326,6 @@ class TestIntegration:
def test_complete_docker_setup_validation(self, temp_project_dir): def test_complete_docker_setup_validation(self, temp_project_dir):
"""Test complete integration of Docker setup""" """Test complete integration of Docker setup"""
# Create a complete MCP configuration
mcp_config = {
"servers": {
"zen-docker": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--env-file",
str(temp_project_dir / ".env"),
"-v",
f"{temp_project_dir / 'logs'}:/app/logs",
"zen-mcp-server:latest",
"python",
"server.py",
],
"env": {"DOCKER_BUILDKIT": "1"},
}
}
}
mcp_config_path = temp_project_dir / ".vscode" / "mcp.json"
with open(mcp_config_path, "w") as f:
json.dump(mcp_config, f, indent=2)
# Create an .env file # Create an .env file
env_content = """ env_content = """
GEMINI_API_KEY=test_key GEMINI_API_KEY=test_key
@@ -361,19 +334,28 @@ LOG_LEVEL=INFO
(temp_project_dir / ".env").write_text(env_content) (temp_project_dir / ".env").write_text(env_content)
# Validate that everything is in place # Validate that everything is in place
assert mcp_config_path.exists()
assert (temp_project_dir / ".env").exists() assert (temp_project_dir / ".env").exists()
assert (temp_project_dir / "Dockerfile").exists() assert (temp_project_dir / "Dockerfile").exists()
assert (temp_project_dir / "logs").exists() assert (temp_project_dir / "logs").exists()
# Validate MCP configuration # Validate basic Docker command structure
with open(mcp_config_path) as f: docker_cmd = [
loaded_config = json.load(f) "docker",
"run",
"--rm",
"-i",
"--env-file",
".env",
"zen-mcp-server:latest",
"python",
"server.py",
]
assert "zen-docker" in loaded_config["servers"] # Basic structure checks
zen_docker = loaded_config["servers"]["zen-docker"] assert docker_cmd[0] == "docker"
assert zen_docker["command"] == "docker" assert "run" in docker_cmd
assert "--env-file" in zen_docker["args"] assert "--rm" in docker_cmd
assert "--env-file" in docker_cmd
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -24,7 +24,6 @@ class TestDockerMCPValidation:
"""Setup automatic for each test""" """Setup automatic for each test"""
self.project_root = Path(__file__).parent.parent self.project_root = Path(__file__).parent.parent
self.dockerfile_path = self.project_root / "Dockerfile" self.dockerfile_path = self.project_root / "Dockerfile"
self.mcp_config_path = self.project_root / ".vscode" / "mcp.json"
def test_dockerfile_exists_and_valid(self): def test_dockerfile_exists_and_valid(self):
"""Test Dockerfile existence and validity""" """Test Dockerfile existence and validity"""
@@ -34,35 +33,6 @@ class TestDockerMCPValidation:
assert "FROM python:" in content, "Python base required" assert "FROM python:" in content, "Python base required"
assert "server.py" in content, "server.py must be copied" assert "server.py" in content, "server.py must be copied"
def test_mcp_configuration_structure(self):
"""Test MCP configuration structure"""
if not self.mcp_config_path.exists():
pytest.skip("mcp.json non trouvé")
with open(self.mcp_config_path, encoding="utf-8") as f:
content = f.read()
# Nettoyer les commentaires JSON
lines = []
for line in content.split("\n"):
if "//" in line:
line = line[: line.index("//")]
lines.append(line)
clean_content = "\n".join(lines)
config = json.loads(clean_content)
assert "servers" in config, "Section servers requise"
servers = config["servers"]
# Check zen-docker configuration
if "zen-docker" in servers:
zen_docker = servers["zen-docker"]
assert zen_docker["command"] == "docker", "Commande docker requise"
args = zen_docker["args"]
assert "run" in args, "Argument run requis"
assert "--rm" in args, "Argument --rm requis"
assert "-i" in args, "Argument -i requis"
@patch("subprocess.run") @patch("subprocess.run")
def test_docker_command_validation(self, mock_run): def test_docker_command_validation(self, mock_run):
"""Test validation commande Docker""" """Test validation commande Docker"""
@@ -88,27 +58,6 @@ class TestDockerMCPValidation:
has_key = any(os.getenv(var) for var in required_vars) has_key = any(os.getenv(var) for var in required_vars)
assert not has_key, "No key should be present" assert not has_key, "No key should be present"
def test_mcp_json_syntax(self):
"""Test MCP JSON file syntax"""
if not self.mcp_config_path.exists():
pytest.skip("mcp.json non trouvé")
try:
with open(self.mcp_config_path, encoding="utf-8") as f:
content = f.read()
# Supprimer commentaires pour validation JSON
lines = []
for line in content.split("\n"):
if "//" in line:
line = line[: line.index("//")]
lines.append(line)
clean_content = "\n".join(lines)
json.loads(clean_content)
except json.JSONDecodeError as e:
pytest.fail(f"JSON invalide: {e}")
def test_docker_security_configuration(self): def test_docker_security_configuration(self):
"""Test Docker security configuration""" """Test Docker security configuration"""
if not self.dockerfile_path.exists(): if not self.dockerfile_path.exists():