Change-detectors, tautologies, source-reading tests, redundant duplicates, mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane ledger (category + reason for every removal).
99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
"""Plugin-registered auxiliary tasks merge into the built-in task list and ``_reset_aux_to_auto``."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.plugins import (
|
|
PluginContext,
|
|
PluginManager,
|
|
PluginManifest,
|
|
)
|
|
|
|
|
|
# ── Fixtures ─────────────────────────────────────────────────────────────────
|
|
|
|
|
|
@pytest.fixture
|
|
def patched_manager(monkeypatch):
|
|
"""Replace the module-level singleton with a fresh manager for the test.
|
|
|
|
Restored automatically after the test by monkeypatch.
|
|
"""
|
|
from hermes_cli import plugins as plugins_mod
|
|
|
|
fresh = PluginManager()
|
|
fresh._discovered = True
|
|
monkeypatch.setattr(plugins_mod, "_PLUGIN_MANAGER", fresh, raising=False)
|
|
|
|
def _stub_get_manager() -> PluginManager:
|
|
return fresh
|
|
|
|
monkeypatch.setattr(plugins_mod, "get_plugin_manager", _stub_get_manager)
|
|
monkeypatch.setattr(plugins_mod, "_ensure_plugins_discovered", _stub_get_manager)
|
|
yield fresh
|
|
|
|
|
|
# ── _all_aux_tasks merges built-in + plugin ──────────────────────────────────
|
|
|
|
|
|
def test_all_aux_tasks_includes_plugin_registered(patched_manager):
|
|
from hermes_cli.main_provider_setup import _AUX_TASKS, _all_aux_tasks
|
|
|
|
manifest = PluginManifest(name="hindsight")
|
|
ctx = PluginContext(manifest, patched_manager)
|
|
ctx.register_auxiliary_task(
|
|
key="memory_retain_filter",
|
|
display_name="Memory retain filter",
|
|
description="hindsight pre-retain dedup/extract",
|
|
)
|
|
|
|
merged = _all_aux_tasks()
|
|
keys = [k for k, _, _ in merged]
|
|
# Built-ins preserved (and come first)
|
|
builtin_keys = [k for k, _, _ in _AUX_TASKS]
|
|
assert keys[: len(builtin_keys)] == builtin_keys
|
|
# Plugin task appended
|
|
assert "memory_retain_filter" in keys
|
|
plugin_entry = next(t for t in merged if t[0] == "memory_retain_filter")
|
|
assert plugin_entry == (
|
|
"memory_retain_filter",
|
|
"Memory retain filter",
|
|
"hindsight pre-retain dedup/extract",
|
|
)
|
|
|
|
|
|
# ── _reset_aux_to_auto includes plugin tasks ─────────────────────────────────
|
|
|
|
|
|
def test_reset_aux_to_auto_resets_plugin_tasks(tmp_path, monkeypatch, patched_manager):
|
|
"""Plugin task with non-auto config gets reset alongside built-ins."""
|
|
from pathlib import Path
|
|
from hermes_cli.config import load_config, save_config
|
|
from hermes_cli.main_provider_setup import _reset_aux_to_auto
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
|
(tmp_path / ".hermes").mkdir(exist_ok=True)
|
|
|
|
manifest = PluginManifest(name="plug")
|
|
ctx = PluginContext(manifest, patched_manager)
|
|
ctx.register_auxiliary_task(
|
|
key="my_aux",
|
|
display_name="My Aux",
|
|
description="d",
|
|
)
|
|
|
|
# Manually configure the plugin task to non-auto
|
|
cfg = load_config()
|
|
aux = cfg.setdefault("auxiliary", {})
|
|
aux["my_aux"] = {"provider": "openrouter", "model": "gpt-4o", "base_url": "", "api_key": ""}
|
|
save_config(cfg)
|
|
|
|
n = _reset_aux_to_auto()
|
|
assert n >= 1
|
|
|
|
cfg = load_config()
|
|
assert cfg["auxiliary"]["my_aux"]["provider"] == "auto"
|
|
assert cfg["auxiliary"]["my_aux"]["model"] == ""
|