mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix: make tool registry reads thread-safe
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""Tests for toolsets.py — toolset resolution, validation, and composition."""
|
||||
|
||||
import pytest
|
||||
|
||||
from tools.registry import ToolRegistry
|
||||
from toolsets import (
|
||||
TOOLSETS,
|
||||
get_toolset,
|
||||
@@ -15,6 +14,18 @@ from toolsets import (
|
||||
)
|
||||
|
||||
|
||||
def _dummy_handler(args, **kwargs):
|
||||
return "{}"
|
||||
|
||||
|
||||
def _make_schema(name: str, description: str = "test tool"):
|
||||
return {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
}
|
||||
|
||||
|
||||
class TestGetToolset:
|
||||
def test_known_toolset(self):
|
||||
ts = get_toolset("web")
|
||||
@@ -52,6 +63,25 @@ class TestResolveToolset:
|
||||
def test_unknown_toolset_returns_empty(self):
|
||||
assert resolve_toolset("nonexistent") == []
|
||||
|
||||
def test_plugin_toolset_uses_registry_snapshot(self, monkeypatch):
|
||||
reg = ToolRegistry()
|
||||
reg.register(
|
||||
name="plugin_b",
|
||||
toolset="plugin_example",
|
||||
schema=_make_schema("plugin_b", "B"),
|
||||
handler=_dummy_handler,
|
||||
)
|
||||
reg.register(
|
||||
name="plugin_a",
|
||||
toolset="plugin_example",
|
||||
schema=_make_schema("plugin_a", "A"),
|
||||
handler=_dummy_handler,
|
||||
)
|
||||
|
||||
monkeypatch.setattr("tools.registry.registry", reg)
|
||||
|
||||
assert resolve_toolset("plugin_example") == ["plugin_a", "plugin_b"]
|
||||
|
||||
def test_all_alias(self):
|
||||
tools = resolve_toolset("all")
|
||||
assert len(tools) > 10 # Should resolve all tools from all toolsets
|
||||
@@ -141,3 +171,20 @@ class TestToolsetConsistency:
|
||||
# All platform toolsets should be identical
|
||||
for ts in tool_sets[1:]:
|
||||
assert ts == tool_sets[0]
|
||||
|
||||
|
||||
class TestPluginToolsets:
|
||||
def test_get_all_toolsets_includes_plugin_toolset(self, monkeypatch):
|
||||
reg = ToolRegistry()
|
||||
reg.register(
|
||||
name="plugin_tool",
|
||||
toolset="plugin_bundle",
|
||||
schema=_make_schema("plugin_tool", "Plugin tool"),
|
||||
handler=_dummy_handler,
|
||||
)
|
||||
|
||||
monkeypatch.setattr("tools.registry.registry", reg)
|
||||
|
||||
all_toolsets = get_all_toolsets()
|
||||
assert "plugin_bundle" in all_toolsets
|
||||
assert all_toolsets["plugin_bundle"]["tools"] == ["plugin_tool"]
|
||||
|
||||
Reference in New Issue
Block a user