-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtooling_test.go
More file actions
109 lines (86 loc) · 2.44 KB
/
tooling_test.go
File metadata and controls
109 lines (86 loc) · 2.44 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package tooling
import (
"context"
"testing"
"github.com/openai/openai-go/v2/packages/param"
)
func TestSpecToResponseTool_MCP(t *testing.T) {
spec := Spec{
Kind: ToolKindMCP,
MCP: &MCPOptions{
ServerLabel: "deepwiki",
ServerURL: param.NewOpt("https://mcp.deepwiki.com/mcp"),
ApprovalPolicy: "never",
},
}
tool, err := spec.ToResponseTool()
if err != nil {
t.Fatalf("ToResponseTool returned error: %v", err)
}
if tool.OfMcp == nil {
t.Fatalf("expected MCP tool variant, got nil")
}
if tool.OfMcp.ServerLabel != spec.MCP.ServerLabel {
t.Errorf("ServerLabel = %q, want %q", tool.OfMcp.ServerLabel, spec.MCP.ServerLabel)
}
if tool.OfMcp.ServerURL != spec.MCP.ServerURL {
t.Errorf("ServerURL = %q, want %q", tool.OfMcp.ServerURL, spec.MCP.ServerURL)
}
approval := tool.OfMcp.RequireApproval.OfMcpToolApprovalSetting
if !approval.Valid() {
t.Fatalf("expected approval setting to be set")
}
if approval.Value != spec.MCP.ApprovalPolicy {
t.Errorf("ApprovalPolicy = %q, want %q", approval.Value, spec.MCP.ApprovalPolicy)
}
}
func TestSpecToResponseTool_Invalid(t *testing.T) {
spec := Spec{Kind: ToolKindMCP}
if _, err := spec.ToResponseTool(); err == nil {
t.Fatalf("expected error when MCP options missing")
}
}
func TestStaticProviderTools(t *testing.T) {
specs := []Spec{
{
Kind: ToolKindMCP,
MCP: &MCPOptions{
ServerLabel: "deepwiki",
ServerURL: param.NewOpt("https://mcp.deepwiki.com/mcp"),
ApprovalPolicy: "never",
},
},
}
provider := NewStaticProvider(specs)
specs[0].MCP.ServerLabel = "modified"
tools, err := provider.Tools(context.Background())
if err != nil {
t.Fatalf("Tools returned error: %v", err)
}
if len(tools) != 1 {
t.Fatalf("expected 1 tool, got %d", len(tools))
}
got := tools[0].OfMcp
if got == nil {
t.Fatalf("expected MCP tool variant, got nil")
}
if got.ServerLabel != "deepwiki" {
t.Errorf("ServerLabel = %q, want %q", got.ServerLabel, "deepwiki")
}
}
func TestStaticProviderTools_InvalidSpec(t *testing.T) {
provider := NewStaticProvider([]Spec{{Kind: ToolKindMCP}})
if _, err := provider.Tools(context.Background()); err == nil {
t.Fatalf("expected error for invalid spec")
}
}
func TestStaticProviderNil(t *testing.T) {
var provider *StaticProvider
tools, err := provider.Tools(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tools != nil {
t.Fatalf("expected nil tools, got %v", tools)
}
}