mirror of
https://github.com/SuperClaude-Org/SuperClaude_Framework.git
synced 2025-12-29 16:16:08 +00:00
refactor: remove legacy setup/ system and dependent tests
Remove old installation system (setup/) that caused heavy token consumption: - Delete setup/core/ (installer, registry, validator) - Delete setup/components/ (agents, modes, commands installers) - Delete setup/cli/ (old CLI commands) - Delete setup/services/ (claude_md, config, files) - Delete setup/utils/ (logger, paths, security, etc.) Remove setup-dependent test files: - test_installer.py - test_get_components.py - test_mcp_component.py - test_install_command.py - test_mcp_docs_component.py Total: 38 files deleted New architecture (src/superclaude/) is self-contained and doesn't need setup/. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
import argparse
|
||||
from setup.cli.commands.install import get_components_to_install
|
||||
|
||||
|
||||
class TestGetComponents:
|
||||
@patch("setup.cli.commands.install.select_mcp_servers")
|
||||
def test_get_components_to_install_interactive_mcp(self, mock_select_mcp):
|
||||
# Arrange
|
||||
mock_registry = MagicMock()
|
||||
mock_config_manager = MagicMock()
|
||||
mock_config_manager._installation_context = {}
|
||||
mock_select_mcp.return_value = ["magic"]
|
||||
|
||||
args = argparse.Namespace(components=["mcp"])
|
||||
|
||||
# Act
|
||||
components = get_components_to_install(args, mock_registry, mock_config_manager)
|
||||
|
||||
# Assert
|
||||
mock_select_mcp.assert_called_once()
|
||||
assert "mcp" in components
|
||||
assert "mcp_docs" in components # Should be added automatically
|
||||
assert hasattr(mock_config_manager, "_installation_context")
|
||||
assert mock_config_manager._installation_context["selected_mcp_servers"] == [
|
||||
"magic"
|
||||
]
|
||||
@@ -1,67 +0,0 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock, ANY
|
||||
import argparse
|
||||
from setup.cli.commands import install
|
||||
|
||||
|
||||
class TestInstallCommand:
|
||||
@patch("setup.cli.commands.install.get_components_to_install")
|
||||
@patch("setup.cli.commands.install.ComponentRegistry")
|
||||
@patch("setup.cli.commands.install.ConfigService")
|
||||
@patch("setup.cli.commands.install.Validator")
|
||||
@patch("setup.cli.commands.install.display_installation_plan")
|
||||
@patch("setup.cli.commands.install.perform_installation")
|
||||
@patch("setup.cli.commands.install.confirm", return_value=True)
|
||||
@patch("setup.cli.commands.install.validate_system_requirements", return_value=True)
|
||||
@patch("pathlib.Path.home")
|
||||
def test_run_resolves_dependencies_before_planning(
|
||||
self,
|
||||
mock_home,
|
||||
mock_validate_reqs,
|
||||
mock_confirm,
|
||||
mock_perform,
|
||||
mock_display,
|
||||
mock_validator,
|
||||
mock_config,
|
||||
mock_registry_class,
|
||||
mock_get_components,
|
||||
tmp_path,
|
||||
):
|
||||
# Arrange
|
||||
mock_home.return_value = tmp_path
|
||||
install_dir = tmp_path / ".claude"
|
||||
|
||||
mock_args = argparse.Namespace(
|
||||
components=["mcp"],
|
||||
install_dir=install_dir,
|
||||
quiet=True, # to avoid calling display_header
|
||||
yes=True,
|
||||
force=False,
|
||||
dry_run=False,
|
||||
diagnose=False,
|
||||
list_components=False,
|
||||
)
|
||||
|
||||
mock_registry_instance = MagicMock()
|
||||
mock_registry_class.return_value = mock_registry_instance
|
||||
|
||||
mock_config_instance = MagicMock()
|
||||
mock_config.return_value = mock_config_instance
|
||||
mock_config_instance.validate_config_files.return_value = []
|
||||
|
||||
mock_get_components.return_value = ["mcp"]
|
||||
mock_registry_instance.resolve_dependencies.return_value = ["core", "mcp"]
|
||||
|
||||
# Act
|
||||
install.run(mock_args)
|
||||
|
||||
# Assert
|
||||
# Check that resolve_dependencies was called with the initial list
|
||||
mock_registry_instance.resolve_dependencies.assert_called_once_with(["mcp"])
|
||||
|
||||
# Check that display_installation_plan was not called because of quiet=True
|
||||
mock_display.assert_not_called()
|
||||
|
||||
# Check that perform_installation was called with the resolved list
|
||||
mock_perform.assert_called_once_with(["core", "mcp"], mock_args, ANY)
|
||||
@@ -1,96 +0,0 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import tarfile
|
||||
import tempfile
|
||||
from unittest.mock import MagicMock
|
||||
from setup.core.installer import Installer
|
||||
|
||||
|
||||
class TestInstaller:
|
||||
def test_create_backup_empty_dir(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir_str:
|
||||
temp_dir = Path(temp_dir_str)
|
||||
installer = Installer(install_dir=temp_dir)
|
||||
|
||||
backup_path = installer.create_backup()
|
||||
|
||||
assert backup_path is not None
|
||||
assert backup_path.exists()
|
||||
|
||||
# This is the crucial part: check if it's a valid tar file.
|
||||
# An empty file created with .touch() is not a valid tar file.
|
||||
try:
|
||||
with tarfile.open(backup_path, "r:gz") as tar:
|
||||
members = tar.getmembers()
|
||||
# An empty archive can have 0 members, or 1 member (the root dir)
|
||||
if len(members) == 1:
|
||||
assert members[0].name == "."
|
||||
else:
|
||||
assert len(members) == 0
|
||||
except tarfile.ReadError as e:
|
||||
pytest.fail(f"Backup file is not a valid tar.gz file: {e}")
|
||||
|
||||
def test_skips_already_installed_component(self):
|
||||
# Create a mock component that is NOT reinstallable
|
||||
mock_component = MagicMock()
|
||||
mock_component.get_metadata.return_value = {"name": "test_component"}
|
||||
mock_component.is_reinstallable.return_value = False
|
||||
mock_component.install.return_value = True
|
||||
mock_component.validate_prerequisites.return_value = (True, [])
|
||||
|
||||
installer = Installer()
|
||||
installer.register_component(mock_component)
|
||||
|
||||
# Simulate component is already installed
|
||||
installer.installed_components = {"test_component"}
|
||||
|
||||
installer.install_component("test_component", {})
|
||||
|
||||
# Assert that the install method was NOT called
|
||||
mock_component.install.assert_not_called()
|
||||
assert "test_component" in installer.skipped_components
|
||||
|
||||
def test_installs_reinstallable_component(self):
|
||||
# Create a mock component that IS reinstallable
|
||||
mock_component = MagicMock()
|
||||
mock_component.get_metadata.return_value = {"name": "reinstallable_component"}
|
||||
mock_component.is_reinstallable.return_value = True
|
||||
mock_component.install.return_value = True
|
||||
mock_component.validate_prerequisites.return_value = (True, [])
|
||||
|
||||
installer = Installer()
|
||||
installer.register_component(mock_component)
|
||||
|
||||
# Simulate component is already installed
|
||||
installer.installed_components = {"reinstallable_component"}
|
||||
|
||||
installer.install_component("reinstallable_component", {})
|
||||
|
||||
# Assert that the install method WAS called
|
||||
mock_component.install.assert_called_once()
|
||||
assert "reinstallable_component" not in installer.skipped_components
|
||||
|
||||
def test_post_install_validation_only_validates_updated_components(self):
|
||||
# Arrange
|
||||
installer = Installer()
|
||||
|
||||
mock_comp1 = MagicMock()
|
||||
mock_comp1.get_metadata.return_value = {"name": "comp1"}
|
||||
mock_comp1.validate_installation.return_value = (True, [])
|
||||
|
||||
mock_comp2 = MagicMock()
|
||||
mock_comp2.get_metadata.return_value = {"name": "comp2"}
|
||||
mock_comp2.validate_installation.return_value = (True, [])
|
||||
|
||||
installer.register_component(mock_comp1)
|
||||
installer.register_component(mock_comp2)
|
||||
|
||||
installer.updated_components = {"comp1"}
|
||||
|
||||
# Act
|
||||
installer._run_post_install_validation()
|
||||
|
||||
# Assert
|
||||
mock_comp1.validate_installation.assert_called_once()
|
||||
mock_comp2.validate_installation.assert_not_called()
|
||||
@@ -1,87 +0,0 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
from setup.components.mcp import MCPComponent
|
||||
|
||||
|
||||
class TestMCPComponent:
|
||||
@patch("setup.components.mcp.MCPComponent._post_install", return_value=True)
|
||||
@patch(
|
||||
"setup.components.mcp.MCPComponent.validate_prerequisites",
|
||||
return_value=(True, []),
|
||||
)
|
||||
@patch("setup.components.mcp.MCPComponent._install_mcp_server")
|
||||
def test_install_selected_servers_only(
|
||||
self, mock_install_mcp_server, mock_validate_prereqs, mock_post_install
|
||||
):
|
||||
mock_install_mcp_server.return_value = True
|
||||
|
||||
component = MCPComponent(install_dir=Path("/fake/dir"))
|
||||
component.installed_servers_in_session = []
|
||||
|
||||
# Simulate selecting only the 'magic' server
|
||||
config = {"selected_mcp_servers": ["magic"]}
|
||||
|
||||
success = component._install(config)
|
||||
|
||||
assert success is True
|
||||
assert component.installed_servers_in_session == ["magic"]
|
||||
|
||||
# Assert that _install_mcp_server was called exactly once
|
||||
assert mock_install_mcp_server.call_count == 1
|
||||
|
||||
# Assert that it was called with the correct server info
|
||||
called_args, _ = mock_install_mcp_server.call_args
|
||||
server_info_arg = called_args[0]
|
||||
|
||||
assert server_info_arg["name"] == "magic"
|
||||
assert server_info_arg["npm_package"] == "@21st-dev/magic"
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_validate_installation_success(self, mock_subprocess_run):
|
||||
component = MCPComponent(install_dir=Path("/fake/dir"))
|
||||
|
||||
# Mock settings manager
|
||||
component.settings_manager = MagicMock()
|
||||
component.settings_manager.is_component_installed.return_value = True
|
||||
component.settings_manager.get_component_version.return_value = (
|
||||
component.get_metadata()["version"]
|
||||
)
|
||||
component.settings_manager.get_metadata_setting.return_value = [
|
||||
"magic",
|
||||
"playwright",
|
||||
]
|
||||
|
||||
# Mock `claude mcp list` output
|
||||
mock_subprocess_run.return_value.returncode = 0
|
||||
mock_subprocess_run.return_value.stdout = "magic\nplaywright\n"
|
||||
|
||||
success, errors = component.validate_installation()
|
||||
|
||||
assert success is True
|
||||
assert not errors
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_validate_installation_failure(self, mock_subprocess_run):
|
||||
component = MCPComponent(install_dir=Path("/fake/dir"))
|
||||
|
||||
# Mock settings manager
|
||||
component.settings_manager = MagicMock()
|
||||
component.settings_manager.is_component_installed.return_value = True
|
||||
component.settings_manager.get_component_version.return_value = (
|
||||
component.get_metadata()["version"]
|
||||
)
|
||||
component.settings_manager.get_metadata_setting.return_value = [
|
||||
"magic",
|
||||
"playwright",
|
||||
]
|
||||
|
||||
# Mock `claude mcp list` output - 'playwright' is missing
|
||||
mock_subprocess_run.return_value.returncode = 0
|
||||
mock_subprocess_run.return_value.stdout = "magic\n"
|
||||
|
||||
success, errors = component.validate_installation()
|
||||
|
||||
assert success is False
|
||||
assert len(errors) == 1
|
||||
assert "playwright" in errors[0]
|
||||
@@ -1,41 +0,0 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
from setup.components.mcp_docs import MCPDocsComponent
|
||||
|
||||
|
||||
class TestMCPDocsComponent:
|
||||
@patch(
|
||||
"setup.components.mcp_docs.MCPDocsComponent._post_install", return_value=True
|
||||
)
|
||||
def test_install_calls_post_install_even_if_no_docs(self, mock_post_install):
|
||||
component = MCPDocsComponent(install_dir=Path("/fake/dir"))
|
||||
|
||||
# Simulate no servers selected
|
||||
config = {"selected_mcp_servers": []}
|
||||
|
||||
success = component._install(config)
|
||||
|
||||
assert success is True
|
||||
mock_post_install.assert_called_once()
|
||||
|
||||
@patch(
|
||||
"setup.components.mcp_docs.MCPDocsComponent._post_install", return_value=True
|
||||
)
|
||||
@patch(
|
||||
"setup.components.mcp_docs.MCPDocsComponent.get_files_to_install",
|
||||
return_value=[],
|
||||
)
|
||||
@patch("setup.core.base.Component.validate_prerequisites", return_value=(True, []))
|
||||
def test_install_calls_post_install_if_docs_not_found(
|
||||
self, mock_validate_prereqs, mock_get_files, mock_post_install
|
||||
):
|
||||
component = MCPDocsComponent(install_dir=Path("/tmp/fake_dir"))
|
||||
|
||||
# Simulate a server was selected, but the doc file doesn't exist
|
||||
config = {"selected_mcp_servers": ["some_server_with_no_doc_file"]}
|
||||
|
||||
success = component._install(config)
|
||||
|
||||
assert success is True
|
||||
mock_post_install.assert_called_once()
|
||||
Reference in New Issue
Block a user