Prepare both smoke output validators

This commit is contained in:
2026-11-05 20:00:33 +00:00
parent d78474a3bf
commit 4b4ce43796
3 changed files with 32 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package usecase
import (
"context"
"errors"
"reflect"
"strings"
"testing"
@@ -102,6 +103,7 @@ func TestSmokeStructuredInferenceCaseUsesPrivatePreparedSchema(t *testing.T) {
}{
{name: "matches", content: caseValue.expectedContent, wantValidJSON: true, wantSchemaMatched: boolPointer(true)},
{name: "valid JSON misses schema", content: `{"status":"other"}`, wantValidJSON: true, wantSchemaMatched: boolPointer(false)},
{name: "scalar JSON misses schema", content: `42`, wantValidJSON: true, wantSchemaMatched: boolPointer(false)},
{name: "additional property misses schema", content: additionalPropertyContent, wantValidJSON: true, wantSchemaMatched: boolPointer(false)},
{name: "invalid JSON", content: `{invalid`, wantSchemaMatched: nil},
{name: "empty content", content: "", wantSchemaMatched: nil},
@@ -125,3 +127,19 @@ func TestSmokeStructuredInferenceCaseUsesPrivatePreparedSchema(t *testing.T) {
t.Fatalf("facts were populated without generated content: %+v", noResponseFacts)
}
}
func TestSmokeStructuredInferenceCaseHonorsCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
if _, err := prepareSmokeInferenceCase(ctx, domain.SmokeTestStructuredOutput, domain.SmokeTestTarget{}, 0); !errors.Is(err, context.Canceled) {
t.Fatalf("prepare error = %v, want cancellation", err)
}
caseValue, err := prepareSmokeInferenceCase(context.Background(), domain.SmokeTestStructuredOutput, domain.SmokeTestTarget{}, 0)
if err != nil {
t.Fatal(err)
}
facts, err := caseValue.evaluate(ctx, &domain.GenerateResponse{Content: `{"status":"ok"}`})
if !errors.Is(err, context.Canceled) || facts.ValidJSON != nil || facts.SchemaMatched != nil {
t.Fatalf("evaluation facts = %+v, error = %v", facts, err)
}
}