| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestAnnotateToolSchemaErrorNamesMCPSource(t *testing.T) { |
| 10 | err := &APIError{ |
| 11 | Provider: "mimo", |
| 12 | Status: 400, |
| 13 | Body: `{"error":{"message":"Tool 1 function has invalid 'parameters' schema"}}`, |
| 14 | } |
| 15 | tools := []ToolSchema{ |
| 16 | {Name: "read_file"}, |
| 17 | {Name: "mcp__filesystem__search"}, |
| 18 | } |
| 19 | |
| 20 | got := AnnotateToolSchemaError(err, tools) |
| 21 | var apiErr *APIError |
| 22 | if !errors.As(got, &apiErr) { |
| 23 | t.Fatalf("AnnotateToolSchemaError() = %T, want *APIError", got) |
| 24 | } |
| 25 | for _, want := range []string{`Reasonix tool "mcp__filesystem__search"`, `MCP server "filesystem"`, `tool "search"`} { |
| 26 | if !strings.Contains(apiErr.ToolContext, want) { |
| 27 | t.Errorf("ToolContext = %q, want %q", apiErr.ToolContext, want) |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestAnnotateToolSchemaErrorLeavesUnrelatedErrorsUnchanged(t *testing.T) { |
| 33 | tests := []error{ |
| 34 | errors.New("network down"), |
| 35 | &APIError{Provider: "mimo", Status: 429, Body: "Tool 0 function failed"}, |
| 36 | &APIError{Provider: "mimo", Status: 400, Body: "other bad request"}, |
| 37 | &APIError{Provider: "mimo", Status: 400, Body: "Tool 9 function has invalid schema"}, |
| 38 | } |
| 39 | tools := []ToolSchema{{Name: "read_file"}} |
| 40 | for _, err := range tests { |
| 41 | if got := AnnotateToolSchemaError(err, tools); got != err { |
| 42 | t.Errorf("AnnotateToolSchemaError(%v) changed unrelated error to %v", err, got) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |