(t *testing.T)
| 21 | } |
| 22 | |
| 23 | func TestEditTool_InputSchema(t *testing.T) { |
| 24 | tool, err := NewEditTool(nil) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Failed to create Edit tool: %v", err) |
| 27 | } |
| 28 | |
| 29 | schema := tool.InputSchema() |
| 30 | if schema == nil { |
| 31 | t.Fatal("Input schema should not be nil") |
| 32 | } |
| 33 | |
| 34 | properties, ok := schema["properties"].(map[string]any) |
| 35 | if !ok { |
| 36 | t.Fatal("Properties should be a map") |
| 37 | } |
| 38 | |
| 39 | // 验证必需字段存在 |
| 40 | requiredFields := []string{"file_path", "old_string", "new_string"} |
| 41 | for _, field := range requiredFields { |
| 42 | if _, exists := properties[field]; !exists { |
| 43 | t.Errorf("Required field '%s' should exist in properties", field) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // 验证可选字段存在 |
| 48 | optionalFields := []string{"replace_all", "preserve_indentation"} |
| 49 | for _, field := range optionalFields { |
| 50 | if _, exists := properties[field]; !exists { |
| 51 | t.Errorf("Optional field '%s' should exist in properties", field) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // 验证required字段 |
| 56 | required := schema["required"] |
| 57 | var requiredArray []any |
| 58 | switch v := required.(type) { |
| 59 | case []any: |
| 60 | requiredArray = v |
| 61 | case []string: |
| 62 | requiredArray = make([]any, len(v)) |
| 63 | for i, s := range v { |
| 64 | requiredArray[i] = s |
| 65 | } |
| 66 | default: |
| 67 | t.Fatal("Required should be an array") |
| 68 | } |
| 69 | |
| 70 | if len(requiredArray) != 3 { |
| 71 | t.Errorf("Expected 3 required fields, got %d", len(requiredArray)) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func TestEditTool_SimpleEdit(t *testing.T) { |
| 76 | if testing.Short() { |
nothing calls this directly
no test coverage detected