From 6db17b8211a99c070294437e8fca03a4ddcd0269 Mon Sep 17 00:00:00 2001 From: xiaoen <2768753269@qq.com> Date: Wed, 15 Apr 2026 22:23:47 +0800 Subject: [PATCH] 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 --- pkg/tools/delegate_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/tools/delegate_test.go b/pkg/tools/delegate_test.go index f1b4c456f..729c524a7 100644 --- a/pkg/tools/delegate_test.go +++ b/pkg/tools/delegate_test.go @@ -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{}