CODE STYLE FIXES: - Fixed line length violations by breaking long lines appropriately - Removed unused imports (os from installer.py and registry.py) - Removed unused variables (package_name in _create_pyproject_toml) - Fixed f-string usage (removed f-strings without placeholders) - Fixed import organization and removed redundant imports - Added missing newlines at end of files SPECIFIC FIXES: - cli.py: Split long option line, fixed f-string usage, added newline - installer.py: Removed unused imports/variables, fixed line breaks, improved validation logic - registry.py: Removed unused import/variable, broke long condition line - test files: Removed unused imports, fixed long assertion lines, added newlines All 24 tests still pass and flake8 now reports no violations. Code is now compliant with PEP 8 style guidelines. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
247 lines
7.5 KiB
Python
247 lines
7.5 KiB
Python
"""Tests for agent installer functionality."""
|
|
|
|
import json
|
|
import pytest
|
|
from pathlib import Path
|
|
from kaizen_agentic.installer import AgentInstaller, ProjectInitializer, InstallationConfig
|
|
from kaizen_agentic.registry import AgentRegistry
|
|
|
|
|
|
@pytest.fixture
|
|
def test_registry(tmp_path):
|
|
"""Create a test registry with sample agents."""
|
|
# Create test agents
|
|
agents_dir = tmp_path / "agents"
|
|
agents_dir.mkdir()
|
|
|
|
base_agent = """---
|
|
name: base-agent
|
|
description: Base test agent
|
|
---
|
|
|
|
# Base Agent
|
|
|
|
This is a base agent for testing.
|
|
"""
|
|
|
|
setup_agent = """---
|
|
name: setup-repository
|
|
description: Repository setup agent
|
|
---
|
|
|
|
# Setup Repository
|
|
|
|
Sets up repository structure.
|
|
"""
|
|
|
|
todo_agent = """---
|
|
name: todo-keeper
|
|
description: TODO management agent
|
|
---
|
|
|
|
# TODO Keeper
|
|
|
|
Manages TODO files.
|
|
"""
|
|
|
|
(agents_dir / "agent-base-agent.md").write_text(base_agent)
|
|
(agents_dir / "agent-setup-repository.md").write_text(setup_agent)
|
|
(agents_dir / "agent-todo-keeper.md").write_text(todo_agent)
|
|
|
|
return AgentRegistry(agents_dir)
|
|
|
|
|
|
def test_install_agents(test_registry, tmp_path):
|
|
"""Test installing agents into a project."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
config = InstallationConfig(
|
|
target_dir=project_dir,
|
|
create_backup=False,
|
|
update_docs=False
|
|
)
|
|
|
|
results = installer.install_agents(["base-agent"], config)
|
|
|
|
assert results["base-agent"] == "INSTALLED"
|
|
assert (project_dir / "agents" / "agent-base-agent.md").exists()
|
|
|
|
|
|
def test_install_agents_with_dependencies(test_registry, tmp_path):
|
|
"""Test installing agents with dependency resolution."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
config = InstallationConfig(
|
|
target_dir=project_dir,
|
|
create_backup=False,
|
|
update_docs=False
|
|
)
|
|
|
|
# Install an agent that depends on others
|
|
results = installer.install_agents(["setup-repository"], config)
|
|
|
|
assert "setup-repository" in results
|
|
assert results["setup-repository"] == "INSTALLED"
|
|
|
|
|
|
def test_list_installed_agents(test_registry, tmp_path):
|
|
"""Test listing installed agents."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
# Initially no agents
|
|
installed = installer.list_installed_agents(project_dir)
|
|
assert installed == []
|
|
|
|
# Install some agents
|
|
config = InstallationConfig(target_dir=project_dir, create_backup=False, update_docs=False)
|
|
installer.install_agents(["base-agent", "todo-keeper"], config)
|
|
|
|
# Check installed agents
|
|
installed = installer.list_installed_agents(project_dir)
|
|
assert "base-agent" in installed
|
|
assert "todo-keeper" in installed
|
|
assert len(installed) == 2
|
|
|
|
|
|
def test_update_agents(test_registry, tmp_path):
|
|
"""Test updating installed agents."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
# Install initial agents
|
|
config = InstallationConfig(target_dir=project_dir, create_backup=False, update_docs=False)
|
|
installer.install_agents(["base-agent"], config)
|
|
|
|
# Update all agents
|
|
results = installer.update_agents(project_dir)
|
|
assert "base-agent" in results
|
|
assert results["base-agent"] == "INSTALLED"
|
|
|
|
# Update specific agents
|
|
results = installer.update_agents(project_dir, ["base-agent"])
|
|
assert results["base-agent"] == "INSTALLED"
|
|
|
|
|
|
def test_remove_agents(test_registry, tmp_path):
|
|
"""Test removing agents from a project."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
# Install agents first
|
|
config = InstallationConfig(target_dir=project_dir, create_backup=False, update_docs=False)
|
|
installer.install_agents(["base-agent", "todo-keeper"], config)
|
|
|
|
# Remove an agent
|
|
results = installer.remove_agents(["base-agent"], project_dir)
|
|
assert results["base-agent"] == "REMOVED"
|
|
assert not (project_dir / "agents" / "agent-base-agent.md").exists()
|
|
|
|
# Try to remove non-existent agent
|
|
results = installer.remove_agents(["non-existent"], project_dir)
|
|
assert results["non-existent"] == "NOT_FOUND"
|
|
|
|
|
|
def test_validate_installation(test_registry, tmp_path):
|
|
"""Test validating agent installation."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
|
|
# Validate empty project
|
|
errors = installer.validate_installation(project_dir)
|
|
assert "project" in errors
|
|
assert "No agents directory found" in errors["project"]
|
|
|
|
# Install agents and validate
|
|
config = InstallationConfig(target_dir=project_dir, create_backup=False, update_docs=False)
|
|
installer.install_agents(["base-agent"], config)
|
|
|
|
errors = installer.validate_installation(project_dir)
|
|
assert len(errors) == 0 # Should be valid
|
|
|
|
|
|
def test_update_claude_config(test_registry, tmp_path):
|
|
"""Test updating Claude configuration."""
|
|
installer = AgentInstaller(test_registry)
|
|
project_dir = tmp_path / "test_project"
|
|
claude_config = project_dir / "claude_config.json"
|
|
|
|
config = InstallationConfig(
|
|
target_dir=project_dir,
|
|
claude_config_path=claude_config,
|
|
create_backup=False,
|
|
update_docs=False
|
|
)
|
|
|
|
installer.install_agents(["base-agent"], config)
|
|
|
|
# Check that config was created and updated
|
|
assert claude_config.exists()
|
|
with open(claude_config) as f:
|
|
config_data = json.load(f)
|
|
|
|
assert "agents" in config_data
|
|
assert "base-agent" in config_data["agents"]
|
|
assert config_data["agents"]["base-agent"]["enabled"] is True
|
|
|
|
|
|
def test_project_initializer(test_registry, tmp_path):
|
|
"""Test project initialization."""
|
|
initializer = ProjectInitializer(test_registry)
|
|
project_dir = tmp_path / "new_project"
|
|
|
|
initializer.init_project(
|
|
project_dir,
|
|
template="python-basic",
|
|
project_name="new_project"
|
|
)
|
|
|
|
# Check that project structure was created
|
|
assert project_dir.exists()
|
|
assert (project_dir / "src").exists()
|
|
assert (project_dir / "tests").exists()
|
|
assert (project_dir / "README.md").exists()
|
|
assert (project_dir / ".gitignore").exists()
|
|
assert (project_dir / "pyproject.toml").exists()
|
|
|
|
# Check that agents were installed
|
|
assert (project_dir / "agents").exists()
|
|
agents_installed = len([f for f in (project_dir / "agents").glob("agent-*.md")])
|
|
assert agents_installed > 0
|
|
|
|
|
|
def test_project_initializer_custom_agents(test_registry, tmp_path):
|
|
"""Test project initialization with custom agents."""
|
|
initializer = ProjectInitializer(test_registry)
|
|
project_dir = tmp_path / "custom_project"
|
|
|
|
initializer.init_project(
|
|
project_dir,
|
|
template="python-basic",
|
|
agent_names=["base-agent", "todo-keeper"],
|
|
project_name="custom_project"
|
|
)
|
|
|
|
# Check that specific agents were installed
|
|
assert (project_dir / "agents" / "agent-base-agent.md").exists()
|
|
assert (project_dir / "agents" / "agent-todo-keeper.md").exists()
|
|
|
|
|
|
def test_installation_config():
|
|
"""Test InstallationConfig creation."""
|
|
config = InstallationConfig(
|
|
target_dir=Path("/tmp/test"),
|
|
claude_config_path=Path("/tmp/test/claude.json"),
|
|
makefile_path=Path("/tmp/test/Makefile"),
|
|
update_docs=True,
|
|
create_backup=False
|
|
)
|
|
|
|
assert config.target_dir == Path("/tmp/test")
|
|
assert config.claude_config_path == Path("/tmp/test/claude.json")
|
|
assert config.makefile_path == Path("/tmp/test/Makefile")
|
|
assert config.update_docs is True
|
|
assert config.create_backup is False
|