2026-07-05 18:13:10 +00:00
package spells
import (
"context"
2026-11-22 00:02:13 +00:00
"reflect"
2026-07-05 18:13:10 +00:00
"strings"
"testing"
2026-11-22 00:02:13 +00:00
"go.maximumdirect.net/promptkit"
2026-07-05 18:13:10 +00:00
)
2026-11-22 00:02:13 +00:00
func TestSpellPromptPairSharesNativeContractAndDefaultProfile ( t * testing . T ) {
client := & fakeSpellsLLMClient { }
engine := newSpellEngine ( t , client )
var initial promptkit . PreparedRun
for _ , id := range [ ] string { PromptID , CorrectionPromptID } {
inputs := map [ string ] promptkit . ArtifactRef { "guidance" : promptkit . Inline ( "Fix the rejected cast." ) }
if id == PromptID {
inputs = map [ string ] promptkit . ArtifactRef {
"transcript" : promptkit . Inline ( ` { "units":[1,2]} ` ) ,
"spell_catalog" : promptkit . Inline ( ` { "spells":[]} ` ) ,
"npc_registry" : promptkit . Inline ( ` { "npcs":[]} ` ) ,
"players" : promptkit . Inline ( " " ) , "party" : promptkit . Inline ( " " ) , "glossary" : promptkit . Inline ( " " ) ,
}
2026-07-21 14:22:46 +00:00
}
2026-11-22 00:02:13 +00:00
handle , err := engine . PrepareExecution ( context . Background ( ) , promptkit . RunRequest { PromptID : id , APIKey : "test-only" , Inputs : inputs } )
if err != nil {
t . Fatal ( err )
}
prepared := handle . Details ( )
handle . Discard ( )
if prepared . SelectedProfileID != "notarius/dnd-extraction" {
t . Fatalf ( "unexpected default profile %q" , prepared . SelectedProfileID )
}
if prepared . StructuredOutput == nil || prepared . OutputContract . SchemaPath != "dnd/spells/schemas/dnd_spells_llm.v1.json" {
t . Fatal ( "missing native spell response schema" )
}
if id == PromptID {
initial = prepared
var system string
for _ , message := range prepared . Messages {
if message . Role == "system" {
system += message . Content
}
}
if ! strings . Contains ( system , "canonical spelling exactly" ) || ! strings . Contains ( system , "in-world caster" ) {
t . Fatal ( "enduring spell constraints missing from initial system context" )
}
} else {
if ! reflect . DeepEqual ( initial . OutputContract , prepared . OutputContract ) || len ( prepared . Messages ) != 1 || prepared . Messages [ 0 ] . Role != "user" || ! strings . Contains ( prepared . Messages [ 0 ] . Content , "Fix the rejected cast." ) {
t . Fatal ( "correction must supply only findings and a replacement assignment with the same contract" )
}
2026-07-05 18:13:10 +00:00
}
}
2026-11-22 00:02:13 +00:00
if len ( client . requests ) != 0 {
t . Fatal ( "preparation invoked generation" )
2026-07-05 18:13:10 +00:00
}
}