2026-07-23 20:09:59 +00:00
package scenedescriptions
import (
"reflect"
"strings"
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
)
2026-11-25 15:48:32 +00:00
func TestNewRejectsAmbiguousReferences ( t * testing . T ) {
if _ , err := New ( Options { } , contracts . ReferenceSet { } , contracts . ReferenceSet { } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "at most one reference set" ) {
2026-07-23 20:09:59 +00:00
t . Fatalf ( "New() error = %v, want reference-set error" , err )
}
if got := newExtractor ( t , & fakeSceneDescriptionsLLMClient { } ) . Key ( ) ; got != Key {
t . Fatalf ( "Key() = %q, want %q" , got , Key )
}
}
func TestModuleSpecAndReferenceSlots ( t * testing . T ) {
want := pipeline . ModuleSpec {
2026-11-22 01:26:49 +00:00
Key : Key , Stage : pipeline . StageExtract , ExecutionClass : contracts . ExecutionClassLLMBacked , Prompts : [ ] string { PromptID , CorrectionPromptID } , Requires : [ ] string { "chunks" , "source.transcript" } , Provides : [ ] string { "dnd.scene_descriptions" } , ArtifactKind : dnd . SceneDescriptionListKind ,
2026-07-23 20:09:59 +00:00
ReferenceSlots : [ ] contracts . ReferenceSlot {
{ Name : "glossary" , Description : "Optional campaign glossary reference material used only to disambiguate scene descriptions." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
{ Name : "party" , Description : "Optional party roster reference material used only to disambiguate scene descriptions." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
{ Name : "players" , Description : "Optional player list reference material used only to disambiguate scene descriptions." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
} ,
}
if got := ModuleSpec ( ) ; ! reflect . DeepEqual ( got , want ) {
t . Fatalf ( "ModuleSpec() = %#v, want %#v" , got , want )
}
got := ModuleSpec ( )
got . Requires [ 0 ] = "changed"
got . Provides [ 0 ] = "changed"
got . ReferenceSlots [ 0 ] . AcceptedMediaTypes [ 0 ] = "changed"
if ! reflect . DeepEqual ( ModuleSpec ( ) , want ) {
t . Fatal ( "ModuleSpec() returned mutable shared slices" )
}
if slots := newExtractor ( t , & fakeSceneDescriptionsLLMClient { } ) . ReferenceSlots ( ) ; ! reflect . DeepEqual ( slots , want . ReferenceSlots ) {
t . Fatalf ( "ReferenceSlots() = %#v, want %#v" , slots , want . ReferenceSlots )
}
}
func TestRegisterStoresTypedModuleSpecAndOptionsAreStrict ( t * testing . T ) {
registry := pipeline . NewExtractorRegistry ( )
if err := Register ( registry ) ; err != nil {
t . Fatalf ( "Register() error = %v, want nil" , err )
}
if got , ok := registry . Spec ( Key ) ; ! ok || ! reflect . DeepEqual ( got , ModuleSpec ( ) ) {
t . Fatalf ( "registry.Spec(%q) = %#v, present = %t" , Key , got , ok )
}
if err := Register ( nil ) ; err == nil || ! strings . Contains ( err . Error ( ) , "extractor registry" ) {
t . Fatalf ( "Register(nil) error = %v, want registry error" , err )
}
if _ , err := DecodeOptions ( map [ string ] any { "unexpected" : true } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "unknown option" ) {
t . Fatalf ( "DecodeOptions() error = %v, want strict options error" , err )
}
}