test(tools): add unit tests for error handling functions
* Implement tests for error functions like errRequiredField, errInvalidField, and errEntityNotFound. * Ensure proper metadata is returned for various error scenarios. * Validate error handling in CRM, Files, and other tools. * Introduce tests for parsing stored file IDs and UUIDs. * Enhance coverage for helper functions related to project resolution and session management.
This commit is contained in:
@@ -36,10 +36,10 @@ type AddSkillOutput struct {
|
||||
|
||||
func (t *SkillsTool) AddSkill(ctx context.Context, _ *mcp.CallToolRequest, in AddSkillInput) (*mcp.CallToolResult, AddSkillOutput, error) {
|
||||
if strings.TrimSpace(in.Name) == "" {
|
||||
return nil, AddSkillOutput{}, errInvalidInput("name is required")
|
||||
return nil, AddSkillOutput{}, errRequiredField("name")
|
||||
}
|
||||
if strings.TrimSpace(in.Content) == "" {
|
||||
return nil, AddSkillOutput{}, errInvalidInput("content is required")
|
||||
return nil, AddSkillOutput{}, errRequiredField("content")
|
||||
}
|
||||
if in.Tags == nil {
|
||||
in.Tags = []string{}
|
||||
@@ -110,10 +110,10 @@ type AddGuardrailOutput struct {
|
||||
|
||||
func (t *SkillsTool) AddGuardrail(ctx context.Context, _ *mcp.CallToolRequest, in AddGuardrailInput) (*mcp.CallToolResult, AddGuardrailOutput, error) {
|
||||
if strings.TrimSpace(in.Name) == "" {
|
||||
return nil, AddGuardrailOutput{}, errInvalidInput("name is required")
|
||||
return nil, AddGuardrailOutput{}, errRequiredField("name")
|
||||
}
|
||||
if strings.TrimSpace(in.Content) == "" {
|
||||
return nil, AddGuardrailOutput{}, errInvalidInput("content is required")
|
||||
return nil, AddGuardrailOutput{}, errRequiredField("content")
|
||||
}
|
||||
severity := strings.TrimSpace(in.Severity)
|
||||
if severity == "" {
|
||||
@@ -122,7 +122,11 @@ func (t *SkillsTool) AddGuardrail(ctx context.Context, _ *mcp.CallToolRequest, i
|
||||
switch severity {
|
||||
case "low", "medium", "high", "critical":
|
||||
default:
|
||||
return nil, AddGuardrailOutput{}, errInvalidInput("severity must be one of: low, medium, high, critical")
|
||||
return nil, AddGuardrailOutput{}, errInvalidField(
|
||||
"severity",
|
||||
"severity must be one of: low, medium, high, critical",
|
||||
"pass one of: low, medium, high, critical",
|
||||
)
|
||||
}
|
||||
if in.Tags == nil {
|
||||
in.Tags = []string{}
|
||||
@@ -231,7 +235,7 @@ type ListProjectSkillsInput struct {
|
||||
}
|
||||
|
||||
type ListProjectSkillsOutput struct {
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
Skills []ext.AgentSkill `json:"skills"`
|
||||
}
|
||||
|
||||
@@ -302,7 +306,7 @@ type ListProjectGuardrailsInput struct {
|
||||
}
|
||||
|
||||
type ListProjectGuardrailsOutput struct {
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
Guardrails []ext.AgentGuardrail `json:"guardrails"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user