test(tools): verify normalization prevents self-delegation bypass

Add table-driven test with case and whitespace variants (ALPHA,
" Alpha ", "  alpha  ") that should all be caught by the self-check
after normalization.

Ref: #2148
This commit is contained in:
xiaoen
2026-04-15 22:23:47 +08:00
parent df486b9939
commit 6db17b8211
+20
View File
@@ -272,6 +272,26 @@ func TestDelegateTool_Execute_SelfDelegation(t *testing.T) {
}
}
func TestDelegateTool_Execute_SelfDelegation_Normalized(t *testing.T) {
tool := NewDelegateTool()
tool.SetSpawner(&delegateMockSpawner{})
tool.SetSelfAgentID("alpha") // stored normalized
// Case-insensitive and whitespace variants should still be caught
variants := []string{"ALPHA", " Alpha ", " alpha "}
for _, v := range variants {
t.Run(v, func(t *testing.T) {
result := tool.Execute(context.Background(), map[string]any{
"agent_id": v,
"task": "test",
})
if !result.IsError {
t.Errorf("agent_id=%q should be caught as self-delegation", v)
}
})
}
}
// nilResultSpawner always returns (nil, nil).
type nilResultSpawner struct{}