Hermes' on_session_end plugin hook fires at the end of every run_conversation call (turn_finalizer.py:490), not at true session end. This caused per-session state to be deleted every turn, making the sentinel trigger always fire — injecting on every user message. Remove the `_on_session_end` callback and its registration. State cleanup is handled by the existing lazy TTL (24h) + LRU cap (1024 sessions) in `_evict_if_needed()`.
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""Tests for plugin registration wiring."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
PLUGIN_DIR = Path(__file__).resolve().parent.parent
|
|
PLUGIN_INIT = PLUGIN_DIR / "__init__.py"
|
|
|
|
|
|
def _load_plugin():
|
|
spec = importlib.util.spec_from_file_location("hermes_currenttime_hint", PLUGIN_INIT)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules["hermes_currenttime_hint"] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
plugin = _load_plugin()
|
|
_on_pre_llm_call = plugin._on_pre_llm_call
|
|
register = plugin.register
|
|
|
|
|
|
class _FakeCtx:
|
|
"""Captures every ``register_hook`` call so tests can assert on them."""
|
|
|
|
def __init__(self) -> None:
|
|
self.hooks: dict[str, Any] = {}
|
|
|
|
def register_hook(self, name: str, callback: Any) -> None:
|
|
self.hooks[name] = callback
|
|
|
|
|
|
class TestRegister:
|
|
def test_registers_pre_llm_call(self) -> None:
|
|
ctx = _FakeCtx()
|
|
register(ctx)
|
|
assert "pre_llm_call" in ctx.hooks
|
|
assert ctx.hooks["pre_llm_call"] is _on_pre_llm_call
|
|
|
|
def test_registers_exactly_one_hook(self) -> None:
|
|
ctx = _FakeCtx()
|
|
register(ctx)
|
|
assert set(ctx.hooks.keys()) == {"pre_llm_call"}
|
|
|
|
|
|
class TestManifestMetadata:
|
|
"""Manifest hooks must match what ``register`` actually wires."""
|
|
|
|
def test_plugin_yaml_hooks_match_register(self) -> None:
|
|
yaml = pytest.importorskip("yaml")
|
|
|
|
manifest_path = PLUGIN_DIR / "plugin.yaml"
|
|
manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
|
|
|
|
declared = set(manifest.get("hooks", []))
|
|
assert declared == {"pre_llm_call"}
|
|
|
|
# And register actually wires them.
|
|
ctx = _FakeCtx()
|
|
register(ctx)
|
|
assert declared == set(ctx.hooks.keys())
|
|
|
|
def test_plugin_yaml_has_name_and_version(self) -> None:
|
|
yaml = pytest.importorskip("yaml")
|
|
|
|
manifest_path = PLUGIN_DIR / "plugin.yaml"
|
|
manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
|
|
assert manifest["name"] == "hermes-currenttime-hint"
|
|
assert "version" in manifest
|