@@ -166,6 +166,7 @@ func validateAgentPolicies(cfg *Config) error {
166166func validateSingleAgentPolicy (policyID string , policy * AgentPolicy , servers map [string ]* ServerConfig ) error {
167167 formattedPolicyID := util .HashIdentifierForLog (policyID )
168168 serverSet := make (map [string ]struct {}, len (policy .Servers ))
169+ serverIDs := make ([]string , 0 , len (policy .Servers ))
169170 for _ , serverID := range policy .Servers {
170171 trimmed := strings .TrimSpace (serverID )
171172 if trimmed == "" {
@@ -178,8 +179,9 @@ func validateSingleAgentPolicy(policyID string, policy *AgentPolicy, servers map
178179 return fmt .Errorf ("gateway.agent_policies[%q].servers references unknown server %q" , formattedPolicyID , trimmed )
179180 }
180181 serverSet [trimmed ] = struct {}{}
182+ serverIDs = append (serverIDs , trimmed )
181183 }
182- if duplicate , found := util .FindDuplicate (policy . Servers ); found {
184+ if duplicate , found := util .FindDuplicate (serverIDs ); found {
183185 return fmt .Errorf ("gateway.agent_policies[%q].servers must not contain duplicate server %q" , formattedPolicyID , duplicate )
184186 }
185187
@@ -190,6 +192,7 @@ func validateSingleAgentPolicy(policyID string, policy *AgentPolicy, servers map
190192 if _ , ok := serverSet [serverID ]; ! ok {
191193 return fmt .Errorf ("gateway.agent_policies[%q].tools references server %q that is not in the policy's servers list" , formattedPolicyID , serverID )
192194 }
195+ toolNames := make ([]string , 0 , len (tools ))
193196 for _ , toolName := range tools {
194197 trimmed := strings .TrimSpace (toolName )
195198 if trimmed == "" {
@@ -198,8 +201,9 @@ func validateSingleAgentPolicy(policyID string, policy *AgentPolicy, servers map
198201 if trimmed != toolName {
199202 return fmt .Errorf ("gateway.agent_policies[%q].tools[%q] entries must not contain surrounding whitespace" , formattedPolicyID , serverID )
200203 }
204+ toolNames = append (toolNames , trimmed )
201205 }
202- if duplicate , found := util .FindDuplicate (tools ); found {
206+ if duplicate , found := util .FindDuplicate (toolNames ); found {
203207 return fmt .Errorf ("gateway.agent_policies[%q].tools[%q] must not contain duplicate tool %q" , formattedPolicyID , serverID , duplicate )
204208 }
205209 }
0 commit comments