fix(plugins): await async handlers in CLI and TUI dispatch
This commit is contained in:
@@ -21,6 +21,7 @@ from hermes_cli.plugins import (
|
||||
get_plugin_command_handler,
|
||||
get_plugin_commands,
|
||||
get_pre_tool_call_block_message,
|
||||
resolve_plugin_command_result,
|
||||
discover_plugins,
|
||||
invoke_hook,
|
||||
)
|
||||
@@ -1061,6 +1062,27 @@ class TestPluginCommands:
|
||||
assert mgr._plugin_commands["cmd-b"]["plugin"] == "plugin-b"
|
||||
|
||||
|
||||
class TestPluginCommandResultResolution:
|
||||
def test_returns_sync_values_unchanged(self):
|
||||
assert resolve_plugin_command_result("ok") == "ok"
|
||||
|
||||
def test_awaits_async_result_without_running_loop(self):
|
||||
async def _handler():
|
||||
return "async-ok"
|
||||
|
||||
assert resolve_plugin_command_result(_handler()) == "async-ok"
|
||||
|
||||
def test_awaits_async_result_with_running_loop(self, monkeypatch):
|
||||
class _Loop:
|
||||
pass
|
||||
|
||||
async def _handler():
|
||||
return "threaded-ok"
|
||||
|
||||
monkeypatch.setattr("hermes_cli.plugins.asyncio.get_running_loop", lambda: _Loop())
|
||||
assert resolve_plugin_command_result(_handler()) == "threaded-ok"
|
||||
|
||||
|
||||
# ── TestPluginDispatchTool ────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
@@ -594,6 +594,24 @@ def test_command_dispatch_returns_skill_payload(server):
|
||||
assert result["name"] == "hermes-agent-dev"
|
||||
|
||||
|
||||
def test_command_dispatch_awaits_async_plugin_handler(server):
|
||||
async def _handler(arg):
|
||||
return f"async:{arg}"
|
||||
|
||||
with patch(
|
||||
"hermes_cli.plugins.get_plugin_command_handler",
|
||||
lambda name: _handler if name == "async-cmd" else None,
|
||||
):
|
||||
resp = server.handle_request({
|
||||
"id": "r-plugin",
|
||||
"method": "command.dispatch",
|
||||
"params": {"name": "async-cmd", "arg": "hello"},
|
||||
})
|
||||
|
||||
assert "error" not in resp
|
||||
assert resp["result"] == {"type": "plugin", "output": "async:hello"}
|
||||
|
||||
|
||||
# ── dispatch(): pool routing for long handlers (#12546) ──────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user