@@ -145,3 +145,53 @@ func TestToolErrorHandling(t *testing.T) {
145145 }
146146 })
147147}
148+
149+ func TestValidateToolName (t * testing.T ) {
150+ t .Run ("valid" , func (t * testing.T ) {
151+ validTests := []struct {
152+ label string
153+ toolName string
154+ }{
155+ {"simple alphanumeric names" , "getUser" },
156+ {"names with underscores" , "get_user_profile" },
157+ {"names with dashes" , "user-profile-update" },
158+ {"names with dots" , "admin.tools.list" },
159+ {"mixed character names" , "DATA_EXPORT_v2.1" },
160+ {"single character names" , "a" },
161+ {"128 character names" , strings .Repeat ("a" , 128 )},
162+ }
163+ for _ , test := range validTests {
164+ t .Run (test .label , func (t * testing.T ) {
165+ if err := validateToolName (test .toolName ); err != nil {
166+ t .Errorf ("validateToolName(%q) = %v, want nil" , test .toolName , err )
167+ }
168+ })
169+ }
170+ })
171+
172+ t .Run ("invalid" , func (t * testing.T ) {
173+ invalidTests := []struct {
174+ label string
175+ toolName string
176+ wantErrContaining string
177+ }{
178+ {"empty names" , "" , "tool name cannot be empty" },
179+ {"names longer than 128 characters" , strings .Repeat ("a" , 129 ), "tool name exceeds maximum length of 128 characters (current: 129)" },
180+ {"names with spaces" , "get user profile" , `tool name contains invalid characters: " "` },
181+ {"names with commas" , "get,user,profile" , `tool name contains invalid characters: ","` },
182+ {"names with forward slashes" , "user/profile/update" , `tool name contains invalid characters: "/"` },
183+ {
"names with other special chars" ,
"[email protected] " ,
`tool name contains invalid characters: "@"` },
184+ {"names with multiple invalid chars" , "user name@domain,com" , `tool name contains invalid characters: " ", "@", ","` },
185+ {"names with unicode characters" , "user-ñame" , `tool name contains invalid characters: "ñ"` },
186+ }
187+ for _ , test := range invalidTests {
188+ t .Run (test .label , func (t * testing.T ) {
189+ if err := validateToolName (test .toolName ); err == nil || ! strings .Contains (err .Error (), test .wantErrContaining ) {
190+ t .Errorf ("validateToolName(%q) = %v, want error containing %q" , test .toolName , err , test .wantErrContaining )
191+ }
192+ })
193+ }
194+
195+ })
196+
197+ }
0 commit comments