-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration_test.go
More file actions
106 lines (101 loc) · 2.38 KB
/
Copy pathmigration_test.go
File metadata and controls
106 lines (101 loc) · 2.38 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
//go:build integration
package conformance
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/matdev83/go-llm-interactive-proxy/internal/refclient/refclienttest"
)
func TestMigration_pythonLIPGoldensParseAndShape(t *testing.T) {
t.Parallel()
root := refclienttest.ModuleRoot(t)
dir := filepath.Join(root, "testdata", "migration")
cases := []struct {
name string
want func(tb testing.TB, raw []byte)
}{
{
name: "python_lip_openai_responses_http_streaming.json",
want: func(tb testing.TB, raw []byte) {
tb.Helper()
var v struct {
Events []struct {
Type string `json:"type"`
} `json:"events"`
Done string `json:"done"`
}
if err := json.Unmarshal(raw, &v); err != nil {
tb.Fatal(err)
}
if len(v.Events) == 0 {
tb.Fatal("expected events")
}
if v.Done != "[DONE]" {
tb.Fatalf("done marker: %q", v.Done)
}
var sawCompleted bool
for _, e := range v.Events {
if e.Type == "response.completed" {
sawCompleted = true
}
}
if !sawCompleted {
tb.Fatal("expected response.completed event")
}
},
},
{
name: "python_lip_openai_responses_http_nonstream.json",
want: func(tb testing.TB, raw []byte) {
tb.Helper()
var v struct {
Object string `json:"object"`
Status string `json:"status"`
Output []any `json:"output"`
}
if err := json.Unmarshal(raw, &v); err != nil {
tb.Fatal(err)
}
if v.Object != "response" || v.Status != "completed" {
tb.Fatalf("object/status: %+v", v)
}
if len(v.Output) == 0 {
tb.Fatal("expected output")
}
},
},
{
name: "python_lip_anthropic_messages_nonstream.json",
want: func(tb testing.TB, raw []byte) {
tb.Helper()
var v struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []any `json:"content"`
}
if err := json.Unmarshal(raw, &v); err != nil {
tb.Fatal(err)
}
if v.ID == "" || v.Type != "message" || v.Role != "assistant" {
tb.Fatalf("header fields: %+v", v)
}
if len(v.Content) == 0 {
tb.Fatal("expected content blocks")
}
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
p := filepath.Join(dir, c.name)
raw, err := os.ReadFile(p)
if err != nil {
t.Fatal(err)
}
c.want(t, raw)
})
}
}