Add request preparation baseline and boundary tests
This commit is contained in:
@@ -1113,6 +1113,13 @@ func TestOpenAICompatibleClientRejectsInvalidExtraParamsBeforeProviderCall(t *te
|
||||
}{
|
||||
{name: "empty key", extraParams: map[string]any{"": "empty"}, want: "key must not be empty"},
|
||||
{name: "unserializable value", extraParams: map[string]any{"bad": math.Inf(1)}, want: "JSON-serializable"},
|
||||
{
|
||||
name: "nested unserializable value",
|
||||
extraParams: map[string]any{
|
||||
"nested": map[string]any{"values": []any{"valid", math.NaN()}},
|
||||
},
|
||||
want: "extra_params.nested",
|
||||
},
|
||||
}
|
||||
for _, key := range []string{
|
||||
"model",
|
||||
@@ -1161,6 +1168,56 @@ func TestOpenAICompatibleClientRejectsInvalidExtraParamsBeforeProviderCall(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAICompatibleClientClassifiesSchemaEncodingFailures(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
extraParams map[string]any
|
||||
want error
|
||||
unwanted error
|
||||
}{
|
||||
{
|
||||
name: "serializable extra keeps full-request failure",
|
||||
extraParams: map[string]any{"client_option": "accepted"},
|
||||
want: ErrRequestFailed,
|
||||
unwanted: ErrInvalidRequest,
|
||||
},
|
||||
{
|
||||
name: "invalid extra keeps invalid-request failure",
|
||||
extraParams: map[string]any{"nested": map[string]any{"bad": math.Inf(1)}},
|
||||
want: ErrInvalidRequest,
|
||||
unwanted: ErrRequestFailed,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
provider := newRecordingProvider(t)
|
||||
client := newProviderClient(t, provider, OpenAICompatibleConfig{})
|
||||
request := ordinaryGenerateRequest()
|
||||
request.Target.ExtraParams = tc.extraParams
|
||||
request.StructuredOutput = &domain.StructuredOutputSpec{
|
||||
Type: domain.StructuredOutputJSONSchema,
|
||||
JSONSchema: &domain.StructuredOutputJSONSpec{
|
||||
Name: "invalid-schema",
|
||||
Strict: true,
|
||||
Schema: json.RawMessage("{"),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := client.Generate(context.Background(), request)
|
||||
if err == nil || !errors.Is(err, tc.want) {
|
||||
t.Fatalf("error = %v, want identity %v", err, tc.want)
|
||||
}
|
||||
if errors.Is(err, tc.unwanted) {
|
||||
t.Fatalf("error = %v, unexpectedly has identity %v", err, tc.unwanted)
|
||||
}
|
||||
if calls := provider.requestCount(); calls != 0 {
|
||||
t.Fatalf("provider calls = %d, want 0", calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func checkConfiguredModelFallback(t *testing.T) {
|
||||
provider := newRecordingProvider(t)
|
||||
client := newProviderClient(t, provider, OpenAICompatibleConfig{Model: "default-model"})
|
||||
|
||||
Reference in New Issue
Block a user