80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
|
|
"""Registry lazy-loading performance tests (WP-0001 T06)."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from kaizen_agentic.installer import AgentInstaller, InstallationConfig
|
||
|
|
from kaizen_agentic.registry import AgentDefinition, AgentRegistry
|
||
|
|
|
||
|
|
|
||
|
|
def _write_agent(path: Path, name: str) -> None:
|
||
|
|
path.write_text(
|
||
|
|
f"""---
|
||
|
|
name: {name}
|
||
|
|
description: Agent {name}
|
||
|
|
category: testing
|
||
|
|
---
|
||
|
|
|
||
|
|
# {name}
|
||
|
|
""",
|
||
|
|
encoding="utf-8",
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def large_registry(tmp_path: Path) -> AgentRegistry:
|
||
|
|
agents_dir = tmp_path / "agents"
|
||
|
|
agents_dir.mkdir()
|
||
|
|
for index in range(15):
|
||
|
|
_write_agent(agents_dir / f"agent-agent-{index}.md", f"agent-{index}")
|
||
|
|
_write_agent(agents_dir / "agent-tdd-workflow.md", "tdd-workflow")
|
||
|
|
return AgentRegistry(agents_dir)
|
||
|
|
|
||
|
|
|
||
|
|
def test_registry_indexes_without_full_parse(large_registry: AgentRegistry):
|
||
|
|
assert len(large_registry.agent_names()) == 16
|
||
|
|
assert large_registry._agents == {}
|
||
|
|
|
||
|
|
|
||
|
|
def test_get_agent_loads_only_requested_agent(large_registry: AgentRegistry):
|
||
|
|
with patch.object(
|
||
|
|
AgentDefinition,
|
||
|
|
"from_file",
|
||
|
|
wraps=AgentDefinition.from_file,
|
||
|
|
) as mock_from_file:
|
||
|
|
agent = large_registry.get_agent("tdd-workflow")
|
||
|
|
|
||
|
|
assert agent is not None
|
||
|
|
assert agent.name == "tdd-workflow"
|
||
|
|
assert mock_from_file.call_count == 1
|
||
|
|
|
||
|
|
|
||
|
|
def test_install_single_agent_parses_minimal_subset(
|
||
|
|
large_registry: AgentRegistry, tmp_path: Path
|
||
|
|
):
|
||
|
|
installer = AgentInstaller(large_registry)
|
||
|
|
project_dir = tmp_path / "project"
|
||
|
|
|
||
|
|
with patch.object(
|
||
|
|
AgentDefinition,
|
||
|
|
"from_file",
|
||
|
|
wraps=AgentDefinition.from_file,
|
||
|
|
) as mock_from_file:
|
||
|
|
results = installer.install_agents(
|
||
|
|
["tdd-workflow"],
|
||
|
|
InstallationConfig(
|
||
|
|
target_dir=project_dir,
|
||
|
|
create_backup=False,
|
||
|
|
update_docs=False,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert results["tdd-workflow"] == "INSTALLED"
|
||
|
|
assert (project_dir / "agents" / "agent-tdd-workflow.md").exists()
|
||
|
|
# resolve_dependencies loads only the target agent, not the full fleet
|
||
|
|
assert mock_from_file.call_count == 1
|