summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/devin/test-devin-plugin.sh63
-rw-r--r--tests/hermes/__init__.py0
-rw-r--r--tests/hermes/conftest.py30
-rw-r--r--tests/hermes/test_bootstrap.py98
-rw-r--r--tests/hermes/test_plugin.py142
-rw-r--r--tests/version-bump/test-bump-version.sh76
-rwxr-xr-xtests/writing-skills/test-render-graphs.sh113
7 files changed, 522 insertions, 0 deletions
diff --git a/tests/devin/test-devin-plugin.sh b/tests/devin/test-devin-plugin.sh
new file mode 100755
index 0000000..16ea31f
--- /dev/null
+++ b/tests/devin/test-devin-plugin.sh
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+# Validate the Devin CLI integration. `devin plugins install obra/superpowers`
+# reads `.devin-plugin/plugin.json` and auto-discovers the co-located `skills/`
+# directory; Devin CLI surfaces every installed skill's name + description in
+# the system prompt at session start and invokes them via its native `skill`
+# tool, and its system prompt already documents its own tools (subagent
+# profiles, todo tracking, question prompts), so there is no hook, injector,
+# or tool-mapping scaffold to test. What IS Devin-specific is the manifest.
+#
+# Mirrors tests/kimi/test-plugin-manifest.sh. CI-safe: does not require
+# `devin` installed.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+
+MANIFEST="$REPO_ROOT/.devin-plugin/plugin.json"
+
+fail() { echo "FAIL: $*" >&2; exit 1; }
+
+echo "test-devin-plugin: checking Devin CLI manifest"
+
+# --- Manifest is valid and matches the repo version -------------------------
+[ -f "$MANIFEST" ] || fail "manifest missing at $MANIFEST"
+
+python3 - "$MANIFEST" <<'PY'
+import json
+import sys
+from pathlib import Path
+
+manifest_path = Path(sys.argv[1])
+manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
+repo_root = manifest_path.parents[1]
+
+if manifest.get("name") != "superpowers":
+ raise AssertionError(f"plugin name: expected 'superpowers', got {manifest.get('name')!r}")
+
+package = json.loads((repo_root / "package.json").read_text(encoding="utf-8"))
+if manifest.get("version") != package.get("version"):
+ raise AssertionError(
+ f"manifest version {manifest.get('version')!r} != package.json version {package.get('version')!r}"
+ )
+
+# Devin CLI plugins carry skills only (auto-discovered from ./skills/); the
+# manifest supports metadata + dependency lists, nothing executable.
+unsupported = ["skills", "hooks", "commands", "sessionStart", "contextFileName", "inject"]
+present = sorted(field for field in unsupported if field in manifest)
+if present:
+ raise AssertionError("unsupported Devin manifest fields present: " + ", ".join(present))
+
+version_config = json.loads((repo_root / ".version-bump.json").read_text(encoding="utf-8"))
+entries = version_config.get("files")
+if not isinstance(entries, list) or not any(
+ entry.get("path") == ".devin-plugin/plugin.json" and entry.get("field") == "version"
+ for entry in entries
+ if isinstance(entry, dict)
+):
+ raise AssertionError(".version-bump.json must update .devin-plugin/plugin.json version")
+
+print("Devin plugin manifest looks good")
+PY
+
+echo "PASS: Devin CLI plugin valid (manifest)"
diff --git a/tests/hermes/__init__.py b/tests/hermes/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/hermes/__init__.py
diff --git a/tests/hermes/conftest.py b/tests/hermes/conftest.py
new file mode 100644
index 0000000..561cd8c
--- /dev/null
+++ b/tests/hermes/conftest.py
@@ -0,0 +1,30 @@
+from pathlib import Path
+
+import pytest
+from unittest.mock import MagicMock
+
+
+@pytest.fixture
+def mock_ctx():
+ ctx = MagicMock()
+ ctx._hooks = {}
+ ctx._skills = {}
+
+ def register_hook(event, fn):
+ ctx._hooks[event] = fn
+
+ def register_skill(name, path):
+ # Mimic hermes' real register_skill, which calls path.exists() and
+ # therefore breaks on a str (the bug that silently disabled the whole
+ # plugin, found 2026-07-23). Keeping that fidelity here means a
+ # regression to str paths fails these tests instead of failing
+ # silently inside hermes.
+ if not isinstance(path, Path):
+ raise AttributeError(
+ f"register_skill requires a pathlib.Path, got {type(path).__name__}"
+ )
+ ctx._skills[name] = path
+
+ ctx.register_hook.side_effect = register_hook
+ ctx.register_skill.side_effect = register_skill
+ return ctx
diff --git a/tests/hermes/test_bootstrap.py b/tests/hermes/test_bootstrap.py
new file mode 100644
index 0000000..8b60153
--- /dev/null
+++ b/tests/hermes/test_bootstrap.py
@@ -0,0 +1,98 @@
+import importlib
+import os
+import sys
+
+import pytest
+
+sys.path.insert(0, os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "../../.hermes-plugin")
+))
+
+BOOTSTRAP_MARKER = "superpowers:using-superpowers bootstrap for hermes"
+
+# Hermes spills injected context over 10,000 chars to a file, which breaks
+# inline injection semantics. The bootstrap must stay under it with margin.
+HERMES_CONTEXT_SPILL_LIMIT = 10_000
+
+
+def _load():
+ if "__init__" in sys.modules:
+ del sys.modules["__init__"]
+ return importlib.import_module("__init__")
+
+
+def _bootstrap():
+ m = _load()
+ return m._build_bootstrap(m._skills_dir())
+
+
+class TestStripFrontmatter:
+ def test_strips_yaml_block(self):
+ m = _load()
+ content = "---\nname: foo\ndescription: bar\n---\n# Body\nContent here"
+ assert m._strip_frontmatter(content) == "# Body\nContent here"
+
+ def test_no_frontmatter_returns_trimmed_content(self):
+ m = _load()
+ content = "# No frontmatter\nJust content"
+ assert m._strip_frontmatter(content) == "# No frontmatter\nJust content"
+
+ def test_strips_surrounding_whitespace_from_body(self):
+ m = _load()
+ content = "---\nname: foo\n---\n\n\n# Body\n\n"
+ assert m._strip_frontmatter(content) == "# Body"
+
+
+class TestSkillsDirResolution:
+ def test_repo_layout_resolves(self):
+ # The repo checkout IS the git-clone layout: .hermes-plugin/ and
+ # skills/ are siblings, so resolution must succeed from here.
+ m = _load()
+ skills = m._skills_dir()
+ assert os.path.isfile(
+ os.path.join(skills, "using-superpowers", "SKILL.md")
+ )
+
+
+class TestBootstrapContent:
+ def test_marker_and_wrapper(self):
+ content = _bootstrap()
+ assert BOOTSTRAP_MARKER in content
+ assert content.startswith("<EXTREMELY_IMPORTANT>")
+ assert content.rstrip().endswith("</EXTREMELY_IMPORTANT>")
+
+ def test_contains_using_superpowers_body(self):
+ content = _bootstrap()
+ # A distinctive line from the skill body proves the real SKILL.md was
+ # embedded, not a stub.
+ assert "You have superpowers" in content
+ assert "## The Rule" in content
+
+ def test_frontmatter_stripped(self):
+ content = _bootstrap()
+ assert "---\nname:" not in content
+
+ def test_tool_mapping_sourced_from_reference_file(self):
+ m = _load()
+ content = _bootstrap()
+ ref = os.path.join(
+ m._skills_dir(), "using-superpowers", "references", "hermes-tools.md"
+ )
+ with open(ref, encoding="utf-8") as f:
+ ref_text = f.read().strip()
+ # The mapping is included verbatim from the reference file — the
+ # single source, not a drift-prone inline copy.
+ assert ref_text in content
+ assert "read_file" in content
+
+ def test_skill_view_guidance_present(self):
+ content = _bootstrap()
+ assert 'skill_view("superpowers:brainstorming")' in content
+
+ def test_under_hermes_context_spill_limit(self):
+ content = _bootstrap()
+ assert len(content) < HERMES_CONTEXT_SPILL_LIMIT, (
+ f"bootstrap is {len(content)} chars; hermes spills injected "
+ f"context over {HERMES_CONTEXT_SPILL_LIMIT} to a file, which "
+ "breaks inline injection"
+ )
diff --git a/tests/hermes/test_plugin.py b/tests/hermes/test_plugin.py
new file mode 100644
index 0000000..9c6c4f0
--- /dev/null
+++ b/tests/hermes/test_plugin.py
@@ -0,0 +1,142 @@
+import importlib
+import importlib.util
+import os
+import shutil
+import sys
+from pathlib import Path
+
+import pytest
+
+# Point at the plugin directory
+_PLUGIN_DIR = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "../../.hermes-plugin")
+)
+sys.path.insert(0, _PLUGIN_DIR)
+
+BOOTSTRAP_MARKER = "superpowers:using-superpowers bootstrap for hermes"
+
+
+def _load_plugin():
+ """Re-import plugin module fresh."""
+ if "__init__" in sys.modules:
+ del sys.modules["__init__"]
+ return importlib.import_module("__init__")
+
+
+def _fire_pre_llm(ctx, **kwargs):
+ hook = ctx._hooks["pre_llm_call"]
+ defaults = {
+ "session_id": "s1",
+ "user_message": "hi",
+ "conversation_history": [],
+ "is_first_turn": False,
+ "model": "test-model",
+ "platform": "cli",
+ }
+ defaults.update(kwargs)
+ return hook(**defaults)
+
+
+class TestPluginRegistration:
+ def test_register_attaches_only_pre_llm_call_hook(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ assert list(mock_ctx._hooks.keys()) == ["pre_llm_call"]
+
+ def test_register_registers_every_stock_skill_as_path(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ # The conftest mock raises on non-Path (mirroring hermes' real
+ # register_skill), so reaching these asserts proves every
+ # registration passed a pathlib.Path.
+ assert "using-superpowers" in mock_ctx._skills
+ assert "brainstorming" in mock_ctx._skills
+ for name, path in mock_ctx._skills.items():
+ assert isinstance(path, Path)
+ assert path.name == "SKILL.md"
+ assert path.parent.name == name
+ assert path.is_file()
+
+ def test_registered_skills_match_skill_directories(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ skills_root = plugin._skills_dir()
+ expected = {
+ entry
+ for entry in os.listdir(skills_root)
+ if os.path.isfile(os.path.join(skills_root, entry, "SKILL.md"))
+ }
+ assert set(mock_ctx._skills.keys()) == expected
+
+
+class TestBootstrapInjection:
+ def test_first_turn_returns_bootstrap_context(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ result = _fire_pre_llm(mock_ctx, is_first_turn=True)
+ assert isinstance(result, dict)
+ content = result["context"]
+ assert BOOTSTRAP_MARKER in content
+ assert content.startswith("<EXTREMELY_IMPORTANT>")
+ assert content.rstrip().endswith("</EXTREMELY_IMPORTANT>")
+
+ def test_later_turns_return_none(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ assert _fire_pre_llm(mock_ctx, is_first_turn=False) is None
+ assert _fire_pre_llm(mock_ctx, is_first_turn=None) is None
+
+ def test_hook_tolerates_future_kwargs(self, mock_ctx):
+ plugin = _load_plugin()
+ plugin.register(mock_ctx)
+ result = _fire_pre_llm(
+ mock_ctx, is_first_turn=True, telemetry_schema_version=3
+ )
+ assert BOOTSTRAP_MARKER in result["context"]
+
+
+class TestLayoutResolution:
+ def _stage(self, tmp_path, layout):
+ """Copy the plugin module + a minimal skills tree in the given layout."""
+ src_skills = Path(_PLUGIN_DIR).parent / "skills"
+ if layout == "clone":
+ plugdir = tmp_path / "superpowers" / ".hermes-plugin"
+ else: # flat: module at the plugin dir root, skills nested inside it
+ plugdir = tmp_path / "superpowers"
+ skills = tmp_path / "superpowers" / "skills"
+ plugdir.mkdir(parents=True, exist_ok=True)
+ shutil.copy(Path(_PLUGIN_DIR) / "__init__.py", plugdir / "__init__.py")
+ for skill in ("using-superpowers", "brainstorming"):
+ shutil.copytree(src_skills / skill, skills / skill)
+ return plugdir
+
+ def _load_from(self, plugdir):
+ spec = importlib.util.spec_from_file_location(
+ f"hermes_plugin_test_{plugdir.parent.name}_{plugdir.name}",
+ plugdir / "__init__.py",
+ )
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod
+
+ def test_clone_layout_resolves_sibling_skills(self, tmp_path, mock_ctx):
+ # git-clone install: .hermes-plugin/ and skills/ are siblings.
+ plugdir = self._stage(tmp_path, "clone")
+ mod = self._load_from(plugdir)
+ mod.register(mock_ctx)
+ assert "using-superpowers" in mock_ctx._skills
+
+ def test_flat_layout_resolves_nested_skills(self, tmp_path, mock_ctx):
+ # flattened install: module at the plugin dir root, skills/ inside it.
+ plugdir = self._stage(tmp_path, "flat")
+ mod = self._load_from(plugdir)
+ mod.register(mock_ctx)
+ assert "using-superpowers" in mock_ctx._skills
+
+ def test_missing_skills_raises_loudly(self, tmp_path, mock_ctx):
+ plugdir = tmp_path / "superpowers"
+ plugdir.mkdir(parents=True)
+ shutil.copy(Path(_PLUGIN_DIR) / "__init__.py", plugdir / "__init__.py")
+ mod = self._load_from(plugdir)
+ with pytest.raises(RuntimeError, match="cannot find the skills"):
+ mod.register(mock_ctx)
diff --git a/tests/version-bump/test-bump-version.sh b/tests/version-bump/test-bump-version.sh
new file mode 100644
index 0000000..195d88a
--- /dev/null
+++ b/tests/version-bump/test-bump-version.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+SCRIPT_SOURCE="$REPO_ROOT/scripts/bump-version.sh"
+TEST_ROOT="$(mktemp -d)"
+
+cleanup() {
+ rm -rf "$TEST_ROOT"
+}
+trap cleanup EXIT
+
+fail() {
+ echo "FAIL: $*" >&2
+ exit 1
+}
+
+make_fixture() {
+ local repo="$1"
+ local yaml_body="$2"
+
+ mkdir -p "$repo/scripts" "$repo/.hermes-plugin"
+ cp "$SCRIPT_SOURCE" "$repo/scripts/bump-version.sh"
+ cat >"$repo/.version-bump.json" <<'JSON'
+{
+ "files": [
+ { "path": "package.json", "field": "version" },
+ { "path": ".hermes-plugin/plugin.yaml", "field": "version" }
+ ],
+ "audit": { "exclude": [] }
+}
+JSON
+ cat >"$repo/package.json" <<'JSON'
+{
+ "name": "fixture",
+ "version": "1.2.3"
+}
+JSON
+ printf '%s\n' "$yaml_body" >"$repo/.hermes-plugin/plugin.yaml"
+}
+
+happy_repo="$TEST_ROOT/happy"
+make_fixture "$happy_repo" $'name: superpowers\nversion: 1.2.3'
+
+/bin/bash "$happy_repo/scripts/bump-version.sh" --check >"$TEST_ROOT/check.out"
+/bin/bash "$happy_repo/scripts/bump-version.sh" --audit >"$TEST_ROOT/audit.out"
+/bin/bash "$happy_repo/scripts/bump-version.sh" 2.3.4 >"$TEST_ROOT/bump.out"
+
+[[ "$(jq -r '.version' "$happy_repo/package.json")" == "2.3.4" ]] \
+ || fail "JSON manifest was not bumped"
+[[ "$(yq -r '.version' "$happy_repo/.hermes-plugin/plugin.yaml")" == "2.3.4" ]] \
+ || fail "YAML manifest was not bumped"
+
+jq -e '
+ any(.files[];
+ .path == ".hermes-plugin/plugin.yaml" and .field == "version")
+' "$REPO_ROOT/.version-bump.json" >/dev/null \
+ || fail "Hermes manifest is not registered"
+
+invalid_repo="$TEST_ROOT/invalid"
+make_fixture "$invalid_repo" $'name: superpowers\nversion: 123'
+cp "$invalid_repo/package.json" "$TEST_ROOT/package.before"
+cp "$invalid_repo/.hermes-plugin/plugin.yaml" "$TEST_ROOT/plugin.before"
+
+if /bin/bash "$invalid_repo/scripts/bump-version.sh" 2.3.4 \
+ >"$TEST_ROOT/invalid.out" 2>&1; then
+ fail "bump accepted a non-string YAML version"
+fi
+
+cmp -s "$TEST_ROOT/package.before" "$invalid_repo/package.json" \
+ || fail "JSON manifest changed before YAML validation failed"
+cmp -s "$TEST_ROOT/plugin.before" "$invalid_repo/.hermes-plugin/plugin.yaml" \
+ || fail "invalid YAML manifest changed"
+
+echo "Version-bump tests passed"
diff --git a/tests/writing-skills/test-render-graphs.sh b/tests/writing-skills/test-render-graphs.sh
new file mode 100755
index 0000000..349cd47
--- /dev/null
+++ b/tests/writing-skills/test-render-graphs.sh
@@ -0,0 +1,113 @@
+#!/usr/bin/env bash
+set -u
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+SCRIPT_UNDER_TEST="$REPO_ROOT/skills/writing-skills/render-graphs.js"
+NODE_BIN="$(command -v node)"
+
+PASSES=0
+FAILURES=0
+TEST_ROOT="$(mktemp -d)"
+
+cleanup() {
+ rm -rf "$TEST_ROOT"
+}
+trap cleanup EXIT
+
+pass() {
+ echo " [PASS] $1"
+ PASSES=$((PASSES + 1))
+}
+
+fail() {
+ echo " [FAIL] $1"
+ FAILURES=$((FAILURES + 1))
+}
+
+assert_contains() {
+ local haystack="$1"
+ local needle="$2"
+ local description="$3"
+
+ if printf '%s' "$haystack" | grep -Fq -- "$needle"; then
+ pass "$description"
+ else
+ fail "$description"
+ echo " expected to find: $needle"
+ fi
+}
+
+assert_not_contains() {
+ local haystack="$1"
+ local needle="$2"
+ local description="$3"
+
+ if printf '%s' "$haystack" | grep -Fq -- "$needle"; then
+ fail "$description"
+ echo " did not expect to find: $needle"
+ else
+ pass "$description"
+ fi
+}
+
+fixture="$TEST_ROOT/fixture-skill"
+mkdir -p "$fixture" "$TEST_ROOT/empty-path"
+cat >"$fixture/SKILL.md" <<'EOF'
+---
+name: fixture-skill
+---
+
+# Fixture Skill
+
+```dot
+digraph fixture_graph {
+ start -> end;
+}
+```
+EOF
+
+echo "Writing-skills render-graphs tests"
+
+missing_dot_output="$(PATH="$TEST_ROOT/empty-path" "$NODE_BIN" "$SCRIPT_UNDER_TEST" "$fixture" 2>&1)"
+missing_dot_status=$?
+
+if [[ "$missing_dot_status" -ne 0 ]]; then
+ pass "missing Graphviz exits non-zero"
+else
+ fail "missing Graphviz exits non-zero"
+fi
+assert_contains "$missing_dot_output" "Error: graphviz (dot) not found." "missing Graphviz reports install guidance"
+assert_not_contains "$missing_dot_output" "ReferenceError: require is not defined" "script runs as an ES module"
+
+render_output="$("$NODE_BIN" "$SCRIPT_UNDER_TEST" "$fixture" 2>&1)"
+render_status=$?
+
+if [[ "$render_status" -eq 0 ]]; then
+ pass "fixture diagram renders"
+else
+ fail "fixture diagram renders"
+ printf '%s\n' "$render_output"
+fi
+
+assert_contains "$render_output" "Found 1 diagram(s)" "reports discovered diagram"
+assert_contains "$render_output" "Rendered: fixture_graph.svg" "reports rendered SVG"
+
+if [[ -f "$fixture/diagrams/fixture_graph.svg" ]]; then
+ pass "writes SVG output"
+else
+ fail "writes SVG output"
+fi
+
+if [[ -f "$fixture/diagrams/fixture_graph.svg" ]] && grep -Fq "<svg" "$fixture/diagrams/fixture_graph.svg"; then
+ pass "SVG output has SVG markup"
+else
+ fail "SVG output has SVG markup"
+fi
+
+echo
+echo "Results: $PASSES passed, $FAILURES failed"
+
+if [[ "$FAILURES" -gt 0 ]]; then
+ exit 1
+fi