From 9fa17c133b3135a65c157cba3d7a15c220062df0 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 3 Aug 2026 17:38:04 +0530 Subject: [PATCH] test(dashboard): cover install-hook invalidation of plugins hub cache --- .../hermes_cli/test_plugins_hub_perf_guard.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/hermes_cli/test_plugins_hub_perf_guard.py b/tests/hermes_cli/test_plugins_hub_perf_guard.py index dbd9d251bd..7ef83c4afb 100644 --- a/tests/hermes_cli/test_plugins_hub_perf_guard.py +++ b/tests/hermes_cli/test_plugins_hub_perf_guard.py @@ -95,3 +95,45 @@ def test_plugins_hub_short_ttl_cache_collapses_duplicate_fetches(monkeypatch): assert calls["discover"] == 1 assert first is second + + +def test_plugin_install_endpoint_invalidates_hub_cache(monkeypatch): + import asyncio + + from hermes_cli.web_models import _AgentPluginInstallBody + + tools_registry.invalidate_check_fn_cache() + web_server._invalidate_plugins_hub_cache() + + calls = {"discover": 0} + + def discover_all_plugins(): + calls["discover"] += 1 + return list(_PLUGIN_ROW) + + _patch_minimal_hub_dependencies( + monkeypatch, + check_fn=lambda: True, + discover_all_plugins=discover_all_plugins, + ) + + # Prime the TTL cache; a plain fetch must be served from it. + web_server._merged_plugins_hub(force_refresh=True) + web_server._merged_plugins_hub() + assert calls["discover"] == 1 + + # Simulate a successful install through the endpoint; its invalidation + # hook must drop the memoized payload so the next fetch rebuilds. + monkeypatch.setattr(web_server, "_require_token", lambda _request: None) + monkeypatch.setattr( + plugins_cmd, "dashboard_install_plugin", lambda *a, **k: {"ok": True} + ) + + asyncio.run( + web_server.post_agent_plugin_install( + object(), _AgentPluginInstallBody(identifier="demo") + ) + ) + + web_server._merged_plugins_hub() + assert calls["discover"] == 2