fix(plugins): validate's capability probe offers ctx.llm, ctx.state and the other service properties

The probe's stand-in PluginContext answered only real method names; every
public PROPERTY of the real context (llm, state, platform_actions,
subagent_lifecycle, delegation_backends) raised AttributeError. A plugin that
captures `ctx.llm` in register() (the documented route for plugin model
calls) therefore failed `hermes plugins validate` and the catalog's
pinned-source check with "register() raised: llm", although the real loader
loads it fine. The parent now also sends the real property names, and the
probe hands back an inert service whose methods are no-ops for them.
This commit is contained in:
Teknium
2026-11-10 10:53:18 -08:00
parent a2250fed0d
commit 067dd0fb66
2 changed files with 37 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import subprocess
import sys
import tempfile
from dataclasses import dataclass, field
from functools import cached_property
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
@@ -219,6 +220,9 @@ options = json.loads(sys.argv[3])
# Public method names of the real PluginContext, computed by the parent so the
# stub's attribute surface cannot drift from the class plugins run against.
context_methods = set(options["context_methods"])
# Service properties (``ctx.llm``, ``ctx.state``, ...): plugins capture them in register() and
# use them later, so the probe hands back an inert service whose methods are no-ops.
context_properties = set(options.get("context_properties", ()))
provider_kind = options["kind"] == "model-provider"
recorded = {"tools": [], "hooks": [], "middleware": [], "commands": [], "providers": [], "trusted_inbound": []}
@@ -265,9 +269,22 @@ class RecordingContext:
return None
return _noop
if name in context_properties:
return _InertService()
raise AttributeError(name)
class _InertService:
def __getattr__(self, name):
if name.startswith("__"):
raise AttributeError(name)
def _noop(*args, **kwargs):
return None
return _noop
def emit(payload):
print(sentinel + json.dumps(payload))
@@ -330,11 +347,12 @@ emit(recorded)
def _probe_options(manifest: dict) -> dict:
from hermes_cli.plugins import PluginContext
public = [n for n in dir(PluginContext) if not n.startswith("_")]
return {
"kind": str(manifest.get("kind") or ""),
"context_methods": sorted(
n for n in dir(PluginContext)
if not n.startswith("_") and callable(getattr(PluginContext, n))
"context_methods": sorted(n for n in public if callable(getattr(PluginContext, n))),
"context_properties": sorted(
n for n in public if isinstance(getattr(PluginContext, n), (property, cached_property))
),
}

View File

@@ -225,6 +225,22 @@ class TestCapabilityProbe:
assert report.ok, report.failures
def test_probe_context_offers_the_real_service_properties(self, tmp_path):
"""``ctx.llm`` / ``ctx.state`` are real PluginContext properties plugins capture in register();
the probe must hand back an object, not raise, or every such plugin fails admission."""
d = _make_plugin(
tmp_path,
manifest={**BASE_MANIFEST, "provides_tools": ["t"]},
init_py=(
"def register(ctx):\n"
" llm, state = ctx.llm, ctx.state\n"
" assert llm is not None and state is not None\n"
" ctx.register_tool('t', schema={}, handler=lambda **kw: llm.complete('x'))\n"),
)
report = validate_plugin_dir(d)
assert report.ok, report.failures
class TestModelProviderKind:
def test_import_time_register_provider_is_the_entry_point(self, tmp_path):
"""``kind: model-provider`` plugins register at import via providers.register_provider and