-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintegration_test.go
More file actions
206 lines (173 loc) · 4.6 KB
/
integration_test.go
File metadata and controls
206 lines (173 loc) · 4.6 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package opik
import (
"context"
"os"
"testing"
"time"
)
// Integration tests for the Opik SDK.
// These tests require OPIK_API_KEY and OPIK_WORKSPACE environment variables.
// Run with: go test -v -run Integration
func skipIfNoCredentials(t *testing.T) {
t.Helper()
if os.Getenv("OPIK_API_KEY") == "" {
t.Skip("OPIK_API_KEY not set, skipping integration test")
}
if os.Getenv("OPIK_WORKSPACE") == "" {
t.Skip("OPIK_WORKSPACE not set, skipping integration test")
}
}
func TestIntegration_CreateClient(t *testing.T) {
skipIfNoCredentials(t)
client, err := NewClient(
WithProjectName("go-sdk-integration-tests"),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
if client == nil {
t.Fatal("Client is nil")
}
t.Logf("Client created successfully, URL: %s", client.Config().URL)
}
func TestIntegration_ListProjects(t *testing.T) {
skipIfNoCredentials(t)
client, err := NewClient()
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
ctx := context.Background()
projects, err := client.ListProjects(ctx, 1, 10)
if err != nil {
t.Fatalf("Failed to list projects: %v", err)
}
t.Logf("Found %d projects", len(projects))
for _, p := range projects {
t.Logf(" - %s (ID: %s)", p.Name, p.ID)
}
}
func TestIntegration_CreateTrace(t *testing.T) {
skipIfNoCredentials(t)
client, err := NewClient(
WithProjectName("go-sdk-integration-tests"),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
ctx := context.Background()
// Create a trace
trace, err := client.Trace(ctx, "integration-test-trace",
WithTraceInput(map[string]any{
"test": "integration",
"timestamp": time.Now().Format(time.RFC3339),
}),
WithTraceTags("integration-test", "go-sdk"),
)
if err != nil {
t.Fatalf("Failed to create trace: %v", err)
}
t.Logf("Created trace: %s", trace.ID())
// Verify trace ID is a valid UUID v7 (starts with timestamp-based prefix)
if trace.ID() == "" {
t.Fatal("Trace ID is empty")
}
}
func TestIntegration_CreateTraceWithSpan(t *testing.T) {
skipIfNoCredentials(t)
client, err := NewClient(
WithProjectName("go-sdk-integration-tests"),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
ctx := context.Background()
// Create a trace
trace, err := client.Trace(ctx, "integration-test-with-span",
WithTraceInput(map[string]any{
"prompt": "Test prompt for integration",
}),
WithTraceTags("integration-test", "go-sdk", "with-span"),
)
if err != nil {
t.Fatalf("Failed to create trace: %v", err)
}
t.Logf("Created trace: %s", trace.ID())
// Create a span within the trace
span, err := trace.Span(ctx, "test-llm-call",
WithSpanType(SpanTypeLLM),
WithSpanModel("test-model"),
WithSpanProvider("test-provider"),
WithSpanInput(map[string]any{
"messages": []map[string]string{
{"role": "user", "content": "Hello from integration test"},
},
}),
)
if err != nil {
t.Fatalf("Failed to create span: %v", err)
}
t.Logf("Created span: %s", span.ID())
// Simulate work
time.Sleep(50 * time.Millisecond)
// End span
err = span.End(ctx,
WithSpanOutput(map[string]any{
"response": "Integration test response",
}),
)
if err != nil {
t.Fatalf("Failed to end span: %v", err)
}
t.Log("Span ended successfully")
// End trace
err = trace.End(ctx,
WithTraceOutput(map[string]any{
"result": "success",
}),
)
if err != nil {
t.Fatalf("Failed to end trace: %v", err)
}
t.Log("Trace ended successfully")
}
func TestIntegration_AddFeedbackScore(t *testing.T) {
skipIfNoCredentials(t)
client, err := NewClient(
WithProjectName("go-sdk-integration-tests"),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
ctx := context.Background()
// Create a trace
trace, err := client.Trace(ctx, "integration-test-feedback",
WithTraceInput(map[string]any{"test": "feedback"}),
)
if err != nil {
t.Fatalf("Failed to create trace: %v", err)
}
t.Logf("Created trace: %s", trace.ID())
// Create a span
span, err := trace.Span(ctx, "llm-call-for-feedback",
WithSpanType(SpanTypeLLM),
)
if err != nil {
t.Fatalf("Failed to create span: %v", err)
}
// End span
err = span.End(ctx, WithSpanOutput(map[string]any{"response": "test"}))
if err != nil {
t.Fatalf("Failed to end span: %v", err)
}
// Add feedback score
err = span.AddFeedbackScore(ctx, "quality", 0.95, "Good response from integration test")
if err != nil {
t.Fatalf("Failed to add feedback score: %v", err)
}
t.Log("Feedback score added successfully")
// End trace
err = trace.End(ctx, WithTraceOutput(map[string]any{"result": "success"}))
if err != nil {
t.Fatalf("Failed to end trace: %v", err)
}
}