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 {
2026-11-26 03:04:54 +00:00
"transcript" : promptkit . Inline ( ` { "sentinel":"spell-transcript-sentinel"} ` ) ,
"spell_catalog" : promptkit . Inline ( ` { "sentinel":"spell-catalog-sentinel"} ` ) ,
"npc_registry" : promptkit . Inline ( ` { "sentinel":"spell-npcs-sentinel"} ` ) ,
2026-11-22 00:02:13 +00:00
"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
2026-11-26 03:04:54 +00:00
for _ , sentinel := range [ ] string { "spell-transcript-sentinel" , "spell-catalog-sentinel" , "spell-npcs-sentinel" } {
var count int
for _ , message := range prepared . Messages {
count += strings . Count ( message . Content , sentinel )
}
if count != 1 {
t . Fatalf ( "input %q rendered %d times" , sentinel , count )
2026-11-22 00:02:13 +00:00
}
}
} 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-11-26 03:04:54 +00:00
for _ , sentinel := range [ ] string { "spell-transcript-sentinel" , "spell-catalog-sentinel" , "spell-npcs-sentinel" } {
if strings . Contains ( prepared . Messages [ 0 ] . Content , sentinel ) {
t . Fatalf ( "correction repeated input %q" , sentinel )
}
}
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
}
}