File size: 2,244 Bytes
5a55e77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package tools

import (
	"testing"
)

func TestGetBuiltinTools_Count(t *testing.T) {
	tools := GetBuiltinTools()
	if len(tools) != 6 {
		t.Errorf("len(GetBuiltinTools()) = %d, want 6", len(tools))
	}
}

func TestGetBuiltinTools_AllFunction(t *testing.T) {
	for _, tool := range GetBuiltinTools() {
		if tool.Type != "function" {
			t.Errorf("tool %q Type = %q, want %q", tool.Function.Name, tool.Type, "function")
		}
	}
}

func TestGetBuiltinTools_Names(t *testing.T) {
	expected := map[string]bool{
		"get_current_time":  true,
		"calculate":         true,
		"search_web":        true,
		"query_database":    true,
		"file_operations":   true,
		"call_external_api": true,
	}

	tools := GetBuiltinTools()
	for _, tool := range tools {
		name := tool.Function.Name
		if !expected[name] {
			t.Errorf("unexpected tool name: %q", name)
		}
		delete(expected, name)
	}

	for name := range expected {
		t.Errorf("missing tool: %q", name)
	}
}

func TestGetBuiltinTools_HaveDescriptions(t *testing.T) {
	for _, tool := range GetBuiltinTools() {
		if tool.Function.Description == "" {
			t.Errorf("tool %q has empty description", tool.Function.Name)
		}
	}
}

func TestGetBuiltinTools_HaveParameters(t *testing.T) {
	for _, tool := range GetBuiltinTools() {
		if tool.Function.Parameters == nil {
			t.Errorf("tool %q has nil parameters", tool.Function.Name)
		}
		params, ok := tool.Function.Parameters.(map[string]interface{})
		if !ok {
			t.Errorf("tool %q parameters is not a map", tool.Function.Name)
			continue
		}
		if params["type"] != "object" {
			t.Errorf("tool %q parameters.type = %v, want %q", tool.Function.Name, params["type"], "object")
		}
		if _, ok := params["properties"]; !ok {
			t.Errorf("tool %q parameters missing 'properties'", tool.Function.Name)
		}
	}
}

func TestGetBuiltinTools_NoDuplicateNames(t *testing.T) {
	seen := make(map[string]bool)
	for _, tool := range GetBuiltinTools() {
		if seen[tool.Function.Name] {
			t.Errorf("duplicate tool name: %q", tool.Function.Name)
		}
		seen[tool.Function.Name] = true
	}
}

func TestGetBuiltinTools_ReturnsNewSlice(t *testing.T) {
	a := GetBuiltinTools()
	b := GetBuiltinTools()
	if &a[0] == &b[0] {
		t.Error("GetBuiltinTools should return a new slice each call")
	}
}