fix: resolve CI/CD issues - all tests pass locally

This commit is contained in:
Developer
2026-02-05 13:32:25 +00:00
parent 155bc36ded
commit 1da735b646
30 changed files with 3982 additions and 605 deletions

View File

@@ -1,101 +1,134 @@
"""Tests for configuration handling."""
"""Tests for configuration management."""
import tempfile
from pathlib import Path
import os
import yaml
import pytest
from project_scaffold_cli.config import Config
from mcp_server_cli.config import (
ConfigManager,
create_config_template,
load_config_from_path,
)
from mcp_server_cli.models import AppConfig, LocalLLMConfig, ServerConfig
class TestConfig:
"""Test Config class."""
class TestConfigManager:
"""Tests for ConfigManager."""
def test_default_config(self):
"""Test default configuration."""
config = Config()
assert config.author is None
assert config.email is None
assert config.license is None
assert config.description is None
def test_load_default_config(self, tmp_path):
"""Test loading default configuration."""
config_path = tmp_path / "config.yaml"
config_path.write_text("")
def test_config_from_yaml(self):
"""Test loading configuration from YAML file."""
config_content = {
"project": {
"author": "Test Author",
"email": "test@example.com",
"license": "MIT",
"description": "Test description",
},
"defaults": {
"language": "python",
"ci": "github",
},
}
manager = ConfigManager(config_path)
config = manager.load()
with tempfile.TemporaryDirectory() as tmpdir:
config_file = Path(tmpdir) / "project.yaml"
with open(config_file, "w") as f:
yaml.dump(config_content, f)
assert isinstance(config, AppConfig)
assert config.server.port == 3000
assert config.server.host == "127.0.0.1"
config = Config.load(str(config_file))
def test_load_config_with_values(self, tmp_path):
"""Test loading configuration with custom values."""
config_file = tmp_path / "config.yaml"
config_file.write_text("""
server:
host: "127.0.0.1"
port: 8080
log_level: "DEBUG"
assert config.author == "Test Author"
assert config.email == "test@example.com"
assert config.license == "MIT"
assert config.description == "Test description"
assert config.default_language == "python"
assert config.default_ci == "github"
llm:
enabled: false
base_url: "http://localhost:11434"
model: "llama2"
def test_config_save(self):
"""Test saving configuration to file."""
config = Config(
author="Test Author",
email="test@example.com",
license="MIT",
default_language="go",
security:
allowed_commands:
- ls
- cat
- echo
blocked_paths:
- /etc
- /root
""")
manager = ConfigManager(config_file)
config = manager.load()
assert config.server.port == 8080
assert config.server.host == "127.0.0.1"
assert config.server.log_level == "DEBUG"
class TestConfigFromPath:
"""Tests for loading config from path."""
def test_load_from_path_success(self, tmp_path):
"""Test successful config loading from path."""
config_file = tmp_path / "config.yaml"
config_file.write_text("server:\n port: 8080")
config = load_config_from_path(str(config_file))
assert config.server.port == 8080
def test_load_from_path_not_found(self):
"""Test loading from nonexistent path."""
with pytest.raises(FileNotFoundError):
load_config_from_path("/nonexistent/path/config.yaml")
class TestConfigTemplate:
"""Tests for configuration template."""
def test_create_template(self):
"""Test creating a config template."""
template = create_config_template()
assert "server" in template
assert "llm" in template
assert "security" in template
assert "tools" in template
def test_template_has_required_fields(self):
"""Test that template has all required fields."""
template = create_config_template()
assert template["server"]["port"] == 3000
assert "allowed_commands" in template["security"]
class TestConfigValidation:
"""Tests for configuration validation."""
def test_valid_config(self):
"""Test creating a valid config."""
config = AppConfig(
server=ServerConfig(port=4000, host="localhost"),
llm=LocalLLMConfig(enabled=True, base_url="http://localhost:1234"),
)
assert config.server.port == 4000
assert config.llm.enabled is True
with tempfile.TemporaryDirectory() as tmpdir:
config_file = Path(tmpdir) / "config.yaml"
config.save(config_file)
def test_config_with_empty_tools(self):
"""Test config with empty tools list."""
config = AppConfig(tools=[])
assert len(config.tools) == 0
assert config_file.exists()
with open(config_file, "r") as f:
saved_data = yaml.safe_load(f)
class TestEnvVarMapping:
"""Tests for environment variable mappings."""
assert saved_data["project"]["author"] == "Test Author"
assert saved_data["defaults"]["language"] == "go"
def test_get_env_var_name(self):
"""Test environment variable name generation."""
manager = ConfigManager()
assert manager.get_env_var_name("server.port") == "MCP_SERVER_PORT"
assert manager.get_env_var_name("host") == "MCP_HOST"
def test_get_template_dirs(self):
"""Test getting template directories."""
config = Config()
dirs = config.get_template_dirs()
assert len(dirs) > 0
assert any("project-scaffold" in d for d in dirs)
def test_get_custom_templates_dir(self):
"""Test getting custom templates directory."""
config = Config()
custom_dir = config.get_custom_templates_dir()
assert "project-scaffold" in custom_dir
def test_get_template_vars(self):
"""Test getting template variables for language."""
config = Config(
template_vars={
"python": {"version": "3.11"},
"nodejs": {"version": "16"},
}
)
python_vars = config.get_template_vars("python")
assert python_vars.get("version") == "3.11"
nodejs_vars = config.get_template_vars("nodejs")
assert nodejs_vars.get("version") == "16"
other_vars = config.get_template_vars("go")
assert other_vars == {}
def test_get_from_env(self):
"""Test getting values from environment."""
manager = ConfigManager()
os.environ["MCP_TEST_VAR"] = "test_value"
try:
result = manager.get_from_env("test_var")
assert result == "test_value"
finally:
del os.environ["MCP_TEST_VAR"]