Migrate scene descriptions to native correction with invariant-preserving final fallbacks
This commit is contained in:
@@ -32,12 +32,11 @@ func TestExtractMapsExactlyOneSceneToTheChunk(t *testing.T) {
|
||||
t.Fatalf("LLM calls = %d, want 1", len(client.requests))
|
||||
}
|
||||
completed := client.requests[0]
|
||||
if completed.StageName != Key || completed.PromptID != PromptID || completed.PromptVersion != SchemaVersion || completed.ProfileID != "profile-scene-descriptions" || completed.SessionID != "session-123" {
|
||||
t.Fatalf("LLM request identity = %#v", completed)
|
||||
if completed.Prompt.SessionID != request.SessionID || result.Outcome.Disposition != contracts.ProducerAccepted {
|
||||
t.Fatal("native session/outcome lost")
|
||||
}
|
||||
transcript := completed.Inputs["transcript"]
|
||||
if transcript.Name != "transcript" || transcript.MediaType != "application/json" || transcript.Digest != "sha256:chunk" || transcript.OriginURI != "file:///session-alpha.json" || string(transcript.Content) != string(request.Chunk.Content) {
|
||||
t.Fatalf("transcript input = %#v, want chunk-scoped material", transcript)
|
||||
if string(renderedInput(t, completed, "transcript")) != string(request.Chunk.Content) {
|
||||
t.Fatal("chunk-scoped material changed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +46,6 @@ func TestExtractPassesOptionalReferencesAndUsesEmptyPlaceholders(t *testing.T) {
|
||||
if _, err := newExtractor(t, client).Extract(context.Background(), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
for _, slot := range []string{"players", "party", "glossary"} {
|
||||
if got := string(client.requests[0].Inputs[slot].Content); got != " " {
|
||||
t.Fatalf("empty %s input = %q, want explicit placeholder", slot, got)
|
||||
}
|
||||
}
|
||||
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"players": {Slot: contracts.ReferenceSlot{Name: "players"}, Items: []contracts.ReferenceItem{{SlotName: "players", Content: []byte("Dana: Mira")}}},
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", Content: []byte("Mira: ranger")}}},
|
||||
@@ -61,23 +54,21 @@ func TestExtractPassesOptionalReferencesAndUsesEmptyPlaceholders(t *testing.T) {
|
||||
if _, err := newExtractor(t, client).Extract(context.Background(), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
inputs := client.requests[1].Inputs
|
||||
if string(inputs["players"].Content) != "Dana: Mira" || string(inputs["party"].Content) != "Mira: ranger" || string(inputs["glossary"].Content) != "Greencloak: local title" {
|
||||
t.Fatalf("reference inputs = %#v", inputs)
|
||||
var text string
|
||||
for _, message := range client.requests[1].Prompt.Messages {
|
||||
text += message.Content
|
||||
}
|
||||
if strings.Contains(string(inputs["transcript"].Content), "local title") {
|
||||
t.Fatal("transcript input contains reference content")
|
||||
for _, reference := range []string{"Dana: Mira", "Mira: ranger", "Greencloak: local title"} {
|
||||
if strings.Count(text, reference) != 1 {
|
||||
t.Fatalf("optional input not rendered once: %q", reference)
|
||||
}
|
||||
}
|
||||
if strings.Contains(string(renderedInput(t, client.requests[1], "transcript")), "local title") {
|
||||
t.Fatal("campaign context became evidence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractReturnsSemanticallyInvalidResponseForDeterministicValidation(t *testing.T) {
|
||||
schema, err := loadResponseSchema()
|
||||
if err != nil {
|
||||
t.Fatalf("loadResponseSchema() error = %v", err)
|
||||
}
|
||||
if err := validateJSONSchema(t, map[string]any{"kind": "narrative", "title": " ", "summary": ""}, schema.JSONSchema); err != nil {
|
||||
t.Fatalf("semantic candidate rejected by private schema: %v", err)
|
||||
}
|
||||
client := &fakeSceneDescriptionsLLMClient{response: extractionResponse{
|
||||
Kind: dnd.SceneKindNarrative, Title: " ", Summary: "",
|
||||
}}
|
||||
@@ -98,11 +89,11 @@ func TestExtractValidatesRequestsAndSurfacesProviderFailures(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
req contracts.TypedExtractionRequest
|
||||
req contracts.TypedExtractionRequest[dnd.SceneDescriptionList]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, req: request, want: "extractor"},
|
||||
{name: "nil LLM client", extractor: &Extractor{}, req: request, want: "LLM client"},
|
||||
{name: "nil LLM client", extractor: &Extractor{}, req: request, want: "native engine"},
|
||||
{name: "wrapped preflight failure", extractor: extractor, req: mismatchedSourceInputRequest(request), want: "must match chunk"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user