chore: initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMalformedInitialToolArguments(t *testing.T) {
|
||||
for _, bad := range []string{`null`, `[]`, `12`, `"not-an-object"`} {
|
||||
src := `data: {"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"tool1","name":"fn","input":` + bad + `}}` + "\n\n"
|
||||
_, err := Stream(context.Background(), io.Discard, strings.NewReader(src), Anthropic, Chat, "m")
|
||||
if err == nil || !strings.Contains(err.Error(), "tool input must be an object") {
|
||||
t.Fatalf("input %s: %v", bad, err)
|
||||
}
|
||||
}
|
||||
for _, field := range []string{``, `,"arguments":null`, `,"arguments":{}`, `,"arguments":12`} {
|
||||
src := `data: {"type":"response.output_item.added","output_index":0,"item":{"type":"function_call","call_id":"call1","name":"fn"` + field + `}}` + "\n\n"
|
||||
_, err := Stream(context.Background(), io.Discard, strings.NewReader(src), Responses, Chat, "m")
|
||||
if err == nil || !strings.Contains(err.Error(), "function arguments must be a string") {
|
||||
t.Fatalf("field %s: %v", field, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeNodeLimit(t *testing.T) {
|
||||
dense := `{"model":"m","pad":[` + strings.Repeat("0,", maxJSONNodes) + `0]}`
|
||||
if _, err := ConvertRequest(Chat, Chat, []byte(dense), "m"); err == nil || !strings.Contains(err.Error(), "exceeds") {
|
||||
t.Fatalf("dense body accepted: %v", err)
|
||||
}
|
||||
under := `{"model":"m","pad":[` + strings.Repeat("0,", maxJSONNodes/2) + `0]}`
|
||||
if _, err := ConvertRequest(Chat, Chat, []byte(under), "m"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ConvertRequest(Chat, Chat, []byte(`{"broken":`), "m"); err == nil || strings.Contains(err.Error(), "exceeds") {
|
||||
t.Fatalf("malformed JSON misreported: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user