Add request preparation baseline and boundary tests

This commit is contained in:
2026-10-09 00:25:21 +00:00
parent f1e1a45a05
commit 3f157150e4
2 changed files with 176 additions and 0 deletions

View File

@@ -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"})