Files
hermes-agent/tests/hermes_cli/test_web_plugins_catalog.py
ethernet 284dbaf537 fix(pm): isolate bootstrap dependencies and unify YAML on ruamel
Activation reaches plugin discovery before the application dependencies
exist. Give PM its own locked Python project and runtime so it can install
or repair the application without importing that dependency tree.

Keep PM outside the application workspace. A shared uv workspace resolves
the application graph and cannot provide this isolation. Route mutations
through an isolated worker and preserve transaction callbacks, cancellation,
custom package registrations, and correlated receipts.

Use the same runtime builder for source installs and packaged payloads.
Keep offline wheelhouse support in that builder. Nix builds the independent
PM lock as a separate derivation. Refuse lazy-disabled bootstrap before
installing tools or dependencies.

Move first-party YAML readers and writers to ruamel. Keep the application
lock's transitive PyYAML requirements for third-party packages.

Verification:
- Focused canonical Python suite: 177 passed, 1 host-gated skip.
- Electron backend probes: 12 passed. Electron typecheck passed.
- Both uv locks, scoped lint, Bash syntax, and whitespace checks passed.
- Cold activation, corrupt-app repair, offline staging, and relocation ran.
- Built and exercised the Nix PM runtime and standalone YAML merge script.

Six broader caller test files retain the same 24 failing test IDs as an
archive of HEAD. The existing real-home guard blocks those tests before
they can exercise the affected paths. No full-suite pass is claimed.
Native Windows signing and full Bionic package execution remain unverified.
2026-09-11 12:23:51 -04:00

81 lines
3.9 KiB
Python

"""Dashboard plugin-catalog surface: GET /api/dashboard/plugins/catalog merges installed state (via the
shared install record) and the install endpoint has NO kill-list bypass."""
from __future__ import annotations
import json
import pytest
import hermes_yaml as yaml
from hermes_cli import plugin_catalog as pc_cat
VALID_SHA = "38fe0fb53eff98d477f807432e965429e665ca33"
OTHER_SHA = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@pytest.fixture
def client(monkeypatch, tmp_path, _isolate_hermes_home):
try:
from starlette.testclient import TestClient
except ImportError:
pytest.skip("fastapi/starlette not installed")
import hermes_state
from hermes_constants import get_hermes_home
from hermes_cli.web_server import app, _SESSION_HEADER_NAME, _SESSION_TOKEN
monkeypatch.setattr(hermes_state, "DEFAULT_DB_PATH", get_hermes_home() / "state.db")
catalog_dir = tmp_path / "catalog"
catalog_dir.mkdir()
(catalog_dir / "alpha-plugin.yaml").write_text(yaml.safe_dump({
"name": "alpha-plugin", "repo": "https://github.com/example/alpha-plugin", "sha": VALID_SHA,
"description": "d", "maintainer": "Example", "tier": "official",
"capabilities": {"provides_tools": ["tool_a"], "requires_env": ["EXAMPLE_API_KEY"]}}))
(catalog_dir / "removed.yaml").write_text(yaml.safe_dump({"removed": [
{"name": "bad-plugin", "repo": "https://github.com/evil/bad-plugin", "reason": "exfiltrated env vars"}]}))
monkeypatch.setattr(pc_cat, "get_catalog_dir", lambda: catalog_dir)
monkeypatch.setattr(pc_cat, "fetch_live_catalog", lambda **_: None)
c = TestClient(app)
c.headers[_SESSION_HEADER_NAME] = _SESSION_TOKEN
return c
def _install(name: str, sidecar: dict | None):
from hermes_constants import get_hermes_home
d = get_hermes_home() / "plugins" / name
d.mkdir(parents=True)
(d / "plugin.yaml").write_text(yaml.safe_dump({"name": name, "version": "1.0", "description": "x"}))
if sidecar:
(d.parent / ".install-metadata.json").write_text(json.dumps({name: {
"catalog_name": sidecar["catalog_name"], "revision": sidecar["sha"],
"catalog_tier": sidecar["tier"], "source": "https://github.com/example/alpha-plugin",
}}), encoding="utf-8")
def test_catalog_endpoint_merges_installed_state_from_sidecar(client):
from starlette.testclient import TestClient
from hermes_cli.web_server import app
assert TestClient(app).get("/api/dashboard/plugins/catalog").status_code == 401
# Manifest name differs from the catalog name (the common case): matched through the sidecar.
_install("alpha", {"catalog_name": "alpha-plugin", "sha": OTHER_SHA, "tier": "official"})
data = client.get("/api/dashboard/plugins/catalog").json()
[entry] = data["entries"]
assert (entry["name"], entry["sha_short"], entry["capabilities"]["provides_tools"]) == ("alpha-plugin", VALID_SHA[:7], ["tool_a"])
assert "tool_a" in entry["capability_summary"]
assert (entry["installed"], entry["installed_sha"], entry["update_available"]) == (True, OTHER_SHA, True)
assert entry["runtime_status"] == "inactive"
assert data["removed"][0]["reason"] == "exfiltrated env vars"
def test_install_endpoint_refuses_removed_plugins_with_no_bypass(client, monkeypatch):
from hermes_cli import plugins_cmd
monkeypatch.setattr(plugins_cmd, "_install_plugin_core", lambda *a, **k: pytest.fail("kill-listed install ran"))
for body in ({"identifier": "https://github.com/evil/bad-plugin.git"},
{"identifier": "", "catalog_name": "bad-plugin"}, {"identifier": "evil/bad-plugin"}):
resp = client.post("/api/dashboard/agent-plugins/install", json=body)
assert resp.status_code == 400, body
assert "removed" in resp.json()["detail"] or "not in the Hermes plugin catalog" in resp.json()["detail"]
assert client.post("/api/dashboard/agent-plugins/install", json={"identifier": ""}).status_code == 400