104 lines
3.2 KiB
Python
104 lines
3.2 KiB
Python
"""Tests for plugin loading."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from openharness.config.settings import Settings
|
|
from openharness.hooks.loader import load_hook_registry
|
|
from openharness.plugins import load_plugins
|
|
from openharness.skills import load_skill_registry
|
|
|
|
|
|
def _write_plugin(root: Path) -> None:
|
|
plugin_dir = root / "example-plugin"
|
|
deploy_dir = plugin_dir / "skills" / "deploy"
|
|
deploy_dir.mkdir(parents=True)
|
|
command_dir = plugin_dir / "commands" / "ops" / "restart"
|
|
command_dir.mkdir(parents=True)
|
|
agents_dir = plugin_dir / "agents" / "review"
|
|
agents_dir.mkdir(parents=True)
|
|
(plugin_dir / "plugin.json").write_text(
|
|
json.dumps(
|
|
{
|
|
"name": "example",
|
|
"version": "1.0.0",
|
|
"description": "Example plugin",
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
(deploy_dir / "SKILL.md").write_text(
|
|
"# Deploy\nDeploy with care\n",
|
|
encoding="utf-8",
|
|
)
|
|
(command_dir / "SKILL.md").write_text(
|
|
"---\n"
|
|
"description: Restart services safely\n"
|
|
"---\n\n"
|
|
"# Restart\n\nRun the restart workflow.\n",
|
|
encoding="utf-8",
|
|
)
|
|
(agents_dir / "reviewer.md").write_text(
|
|
"---\n"
|
|
"description: Review code changes\n"
|
|
"---\n\n"
|
|
"# Reviewer\n\nReview the proposed changes.\n",
|
|
encoding="utf-8",
|
|
)
|
|
(plugin_dir / "hooks.json").write_text(
|
|
json.dumps(
|
|
{
|
|
"session_start": [
|
|
{"type": "command", "command": "printf start"}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
(plugin_dir / "mcp.json").write_text(
|
|
json.dumps(
|
|
{
|
|
"mcpServers": {
|
|
"demo": {"type": "stdio", "command": "python", "args": ["demo.py"]}
|
|
}
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def test_load_plugins_from_project_dir(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", str(tmp_path / "config"))
|
|
project = tmp_path / "repo"
|
|
plugins_root = project / ".openharness" / "plugins"
|
|
plugins_root.mkdir(parents=True)
|
|
_write_plugin(plugins_root)
|
|
|
|
plugins = load_plugins(Settings(), project)
|
|
|
|
assert len(plugins) == 1
|
|
plugin = plugins[0]
|
|
assert plugin.manifest.name == "example"
|
|
assert plugin.skills[0].name == "Deploy"
|
|
assert {command.name for command in plugin.commands} == {"example:ops:restart"}
|
|
assert {agent.name for agent in plugin.agents} == {"example:review:reviewer"}
|
|
assert "session_start" in plugin.hooks
|
|
assert "demo" in plugin.mcp_servers
|
|
|
|
|
|
def test_plugin_skills_and_hooks_are_merged(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", str(tmp_path / "config"))
|
|
project = tmp_path / "repo"
|
|
plugins_root = project / ".openharness" / "plugins"
|
|
plugins_root.mkdir(parents=True)
|
|
_write_plugin(plugins_root)
|
|
|
|
skills = load_skill_registry(project).list_skills()
|
|
assert any(skill.name == "Deploy" and skill.source == "plugin" for skill in skills)
|
|
|
|
plugins = load_plugins(Settings(), project)
|
|
hooks = load_hook_registry(Settings(), plugins)
|
|
assert "session_start" in hooks.summary()
|