refactor: Update environment and Docker configuration files; remove unused MCP configuration tests
This commit is contained in:
15
.env.example
15
.env.example
@@ -153,3 +153,18 @@ LOG_LEVEL=DEBUG
|
||||
# DISABLED_TOOLS=debug,tracer # Disable debug and tracer 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
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
```bash
|
||||
# Copy environment template
|
||||
cp .env.docker.example .env
|
||||
cp .env.example .env
|
||||
|
||||
# Edit with your API keys (at least one required)
|
||||
# Required: GEMINI_API_KEY or OPENAI_API_KEY or XAI_API_KEY
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Complete configuration test for Docker MCP
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
@@ -13,52 +12,6 @@ import pytest
|
||||
class TestDockerMCPConfiguration:
|
||||
"""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):
|
||||
"""Test Dockerfile configuration"""
|
||||
project_root = Path(__file__).parent.parent
|
||||
@@ -87,7 +40,7 @@ class TestDockerMCPConfiguration:
|
||||
def test_environment_file_template(self):
|
||||
"""Test environment file template"""
|
||||
project_root = Path(__file__).parent.parent
|
||||
env_example = project_root / ".env.docker.example"
|
||||
env_example = project_root / ".env.example"
|
||||
|
||||
if env_example.exists():
|
||||
content = env_example.read_text()
|
||||
@@ -98,6 +51,11 @@ class TestDockerMCPConfiguration:
|
||||
for var in essential_vars:
|
||||
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):
|
||||
"""Test logs directory setup"""
|
||||
project_root = Path(__file__).parent.parent
|
||||
@@ -216,7 +174,6 @@ class TestIntegrationChecks:
|
||||
|
||||
# MCP integration checks
|
||||
checks = {
|
||||
"mcp_config": (project_root / ".vscode" / "mcp.json").exists(),
|
||||
"dockerfile": (project_root / "Dockerfile").exists(),
|
||||
"server_script": (project_root / "server.py").exists(),
|
||||
"logs_dir": (project_root / "logs").exists() or True,
|
||||
|
||||
@@ -56,7 +56,7 @@ class TestDockerConfiguration:
|
||||
|
||||
def test_environment_file_template(self):
|
||||
"""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():
|
||||
content = env_example_path.read_text()
|
||||
@@ -306,7 +306,6 @@ def temp_project_dir():
|
||||
temp_path = Path(temp_dir)
|
||||
|
||||
# Create base structure
|
||||
(temp_path / ".vscode").mkdir()
|
||||
(temp_path / "logs").mkdir()
|
||||
|
||||
# Create base files
|
||||
@@ -327,32 +326,6 @@ class TestIntegration:
|
||||
|
||||
def test_complete_docker_setup_validation(self, temp_project_dir):
|
||||
"""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
|
||||
env_content = """
|
||||
GEMINI_API_KEY=test_key
|
||||
@@ -361,19 +334,28 @@ LOG_LEVEL=INFO
|
||||
(temp_project_dir / ".env").write_text(env_content)
|
||||
|
||||
# Validate that everything is in place
|
||||
assert mcp_config_path.exists()
|
||||
assert (temp_project_dir / ".env").exists()
|
||||
assert (temp_project_dir / "Dockerfile").exists()
|
||||
assert (temp_project_dir / "logs").exists()
|
||||
|
||||
# Validate MCP configuration
|
||||
with open(mcp_config_path) as f:
|
||||
loaded_config = json.load(f)
|
||||
# Validate basic Docker command structure
|
||||
docker_cmd = [
|
||||
"docker",
|
||||
"run",
|
||||
"--rm",
|
||||
"-i",
|
||||
"--env-file",
|
||||
".env",
|
||||
"zen-mcp-server:latest",
|
||||
"python",
|
||||
"server.py",
|
||||
]
|
||||
|
||||
assert "zen-docker" in loaded_config["servers"]
|
||||
zen_docker = loaded_config["servers"]["zen-docker"]
|
||||
assert zen_docker["command"] == "docker"
|
||||
assert "--env-file" in zen_docker["args"]
|
||||
# Basic structure checks
|
||||
assert docker_cmd[0] == "docker"
|
||||
assert "run" in docker_cmd
|
||||
assert "--rm" in docker_cmd
|
||||
assert "--env-file" in docker_cmd
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -24,7 +24,6 @@ class TestDockerMCPValidation:
|
||||
"""Setup automatic for each test"""
|
||||
self.project_root = Path(__file__).parent.parent
|
||||
self.dockerfile_path = self.project_root / "Dockerfile"
|
||||
self.mcp_config_path = self.project_root / ".vscode" / "mcp.json"
|
||||
|
||||
def test_dockerfile_exists_and_valid(self):
|
||||
"""Test Dockerfile existence and validity"""
|
||||
@@ -34,35 +33,6 @@ class TestDockerMCPValidation:
|
||||
assert "FROM python:" in content, "Python base required"
|
||||
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")
|
||||
def test_docker_command_validation(self, mock_run):
|
||||
"""Test validation commande Docker"""
|
||||
@@ -88,27 +58,6 @@ class TestDockerMCPValidation:
|
||||
has_key = any(os.getenv(var) for var in required_vars)
|
||||
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):
|
||||
"""Test Docker security configuration"""
|
||||
if not self.dockerfile_path.exists():
|
||||
|
||||
Reference in New Issue
Block a user