mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-12 22:14:37 +00:00
- Add GrantChecker interface with cache + event-bus invalidation for revalidating MCP tool grants at execution time (not just dispatch) - Move toolGroups from package-level global to per-Registry field; Clone() gives each agent Loop isolated tool groups, eliminating cross-agent race condition - BridgeTool.Execute rechecks grant validity before executing MCP methods; uses serverID field for cache key - Wire MCPGrantChecker through ResolverDeps to MCP Manager and LoopConfig - Add integration test for grant revocation scenarios - Update policy functions to accept *Registry parameter
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package tools
|
|
|
|
import "testing"
|
|
|
|
func TestRegistry_RegisterToolGroup(t *testing.T) {
|
|
reg := NewRegistry()
|
|
|
|
// Register a new MCP group
|
|
reg.RegisterToolGroup("mcp:postgres", []string{"mcp_pg__query", "mcp_pg__list_tables"})
|
|
|
|
members, ok := reg.GetToolGroup("mcp:postgres")
|
|
if !ok {
|
|
t.Fatal("expected mcp:postgres group to exist")
|
|
}
|
|
if len(members) != 2 {
|
|
t.Errorf("expected 2 members, got %d", len(members))
|
|
}
|
|
|
|
// Unregister
|
|
reg.UnregisterToolGroup("mcp:postgres")
|
|
if _, ok := reg.GetToolGroup("mcp:postgres"); ok {
|
|
t.Error("expected mcp:postgres group to be removed")
|
|
}
|
|
}
|
|
|
|
func TestRegistry_RegisterToolGroup_UsedInExpand(t *testing.T) {
|
|
reg := NewRegistry()
|
|
reg.RegisterToolGroup("mcp:test", []string{"mcp_test__tool_a", "mcp_test__tool_b"})
|
|
defer reg.UnregisterToolGroup("mcp:test")
|
|
|
|
available := []string{"mcp_test__tool_a", "mcp_test__tool_b", "read_file", "exec"}
|
|
expanded := expandSpec(reg, available, []string{"group:mcp:test"})
|
|
|
|
if len(expanded) != 2 {
|
|
t.Errorf("expected 2 tools from group:mcp:test, got %d: %v", len(expanded), expanded)
|
|
}
|
|
|
|
// Verify it works with subtractSpec too
|
|
remaining := subtractSpec(reg, available, []string{"group:mcp:test"})
|
|
if len(remaining) != 2 {
|
|
t.Errorf("expected 2 remaining after subtract, got %d: %v", len(remaining), remaining)
|
|
}
|
|
}
|