MCPcopy Create free account
hub / github.com/astercloud/aster / TestReadTool_InputSchema

Function TestReadTool_InputSchema

pkg/tools/builtin/read_test.go:28–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestReadTool_InputSchema(t *testing.T) {
29 tool, err := NewReadTool(nil)
30 if err != nil {
31 t.Fatalf("Failed to create Read tool: %v", err)
32 }
33
34 schema := tool.InputSchema()
35 if schema == nil {
36 t.Fatal("Input schema should not be nil")
37 }
38
39 // 验证schema类型
40 if schemaType, ok := schema["type"].(string); !ok || schemaType != "object" {
41 t.Errorf("Expected schema type 'object', got %v", schema["type"])
42 }
43
44 // 验证必需字段
45 properties, ok := schema["properties"].(map[string]any)
46 if !ok {
47 t.Fatal("Properties should be a map")
48 }
49
50 if _, exists := properties["file_path"]; !exists {
51 t.Error("file_path property should exist")
52 }
53
54 required := schema["required"]
55 if required == nil {
56 t.Fatal("Required field should not be nil")
57 }
58
59 // 尝试类型转换,但不强制要求特定类型
60 switch req := required.(type) {
61 case []any:
62 if len(req) == 0 || req[0] != "file_path" {
63 t.Error("file_path should be required")
64 }
65 case []string:
66 if len(req) == 0 || req[0] != "file_path" {
67 t.Error("file_path should be required")
68 }
69 default:
70 t.Logf("Required field type: %T", required)
71 // 尝试转换为字符串切片进行检查
72 if reqStr, ok := required.([]string); ok && len(reqStr) > 0 && reqStr[0] == "file_path" {
73 // 正确
74 } else {
75 t.Error("file_path should be required")
76 }
77 }
78}
79
80func TestReadTool_Success(t *testing.T) {
81 tool, err := NewReadTool(nil)

Callers

nothing calls this directly

Calls 3

InputSchemaMethod · 0.95
NewReadToolFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected