2026-08-05 18:38:22 +00:00
package npcregistry
2026-07-21 02:24:26 +00:00
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-29 18:09:09 +00:00
func TestConstructionRejectsInvalidPartyReference ( t * testing . T ) {
refs := contracts . ReferenceSet { Slots : map [ string ] contracts . ResolvedReferenceSlot {
"party" : { Items : [ ] contracts . ReferenceItem { { MediaType : "application/json" , Content : [ ] byte ( "{}" ) } } } ,
} }
if _ , err := New ( Options { } , refs ) ; err == nil {
t . Fatal ( "invalid party accepted during construction" )
}
}
2026-11-25 15:40:30 +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-21 02:24:26 +00:00
t . Fatalf ( "New() error = %v, want reference-set error" , err )
}
if got := newExtractor ( t , & fakeNPCsLLMClient { } ) . Key ( ) ; got != Key {
t . Fatalf ( "Key() = %q, want %q" , got , Key )
}
}
func TestModuleSpecAndReferenceSlots ( t * testing . T ) {
got := ModuleSpec ( )
want := pipeline . ModuleSpec {
2026-11-22 00:50:54 +00:00
Key : Key ,
Stage : pipeline . StageExtract ,
ExecutionClass : contracts . ExecutionClassLLMBacked ,
2026-11-28 04:11:33 +00:00
Prompts : [ ] string { PromptID , CorrectionPromptID } , InitialPrompts : [ ] string { PromptID } ,
Requires : [ ] string { "chunks" , "source.transcript" } ,
Provides : [ ] string { "dnd.npc_registry" } ,
ArtifactKind : dnd . NPCRegistryKind ,
2026-07-21 02:24:26 +00:00
ReferenceSlots : [ ] contracts . ReferenceSlot {
2026-11-29 18:09:09 +00:00
{ Name : "glossary" , Description : "Optional campaign glossary reference material used only for NPC disambiguation." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" } } ,
{ Name : "party" , Description : "Optional party roster reference material used only for NPC disambiguation." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" } } ,
2026-07-21 02:24:26 +00:00
{ Name : "players" , Description : "Optional player list reference material used only for NPC disambiguation." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
2026-11-29 18:09:09 +00:00
{ Name : "roster" , Description : "Deprecated alias for party roster reference material used only for NPC disambiguation." , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" } } ,
2026-07-21 02:24:26 +00:00
} ,
}
if ! reflect . DeepEqual ( got , want ) {
t . Fatalf ( "ModuleSpec() = %#v, want %#v" , got , want )
}
2026-11-22 00:50:54 +00:00
got . Prompts [ 0 ] = "changed"
2026-07-21 02:24:26 +00:00
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" )
}
extractor := newExtractor ( t , & fakeNPCsLLMClient { } )
if ! reflect . DeepEqual ( extractor . ReferenceSlots ( ) , want . ReferenceSlots ) {
t . Fatalf ( "ReferenceSlots() = %#v, want %#v" , extractor . ReferenceSlots ( ) , want . ReferenceSlots )
}
}
func TestRegisterStoresTypedModuleSpec ( t * testing . T ) {
registry := pipeline . NewExtractorRegistry ( )
if err := Register ( registry ) ; err != nil {
t . Fatalf ( "Register() error = %v, want nil" , err )
}
got , ok := registry . Spec ( Key )
if ! 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 )
}
}