2026-07-25 21:49:24 +00:00
package itemevents
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"
)
func TestConstructorSpecOptionsAndMetadata ( t * testing . T ) {
if _ , err := New ( nil , Options { } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "LLM client" ) {
t . Fatalf ( "New(nil) error = %v" , err )
}
if _ , err := New ( & fakeItemEventsLLMClient { } , Options { } , contracts . ReferenceSet { } , contracts . ReferenceSet { } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "at most one reference set" ) {
t . Fatalf ( "New() error = %v" , err )
}
want := pipeline . ModuleSpec {
2026-08-03 16:49:51 +00:00
Key : Key , Stage : pipeline . StageExtract , ExecutionClass : contracts . ExecutionClassLLMBacked , Requires : [ ] string { "chunks" , "source.transcript" } , Provides : [ ] string { "dnd.item_events" } , ArtifactKind : dnd . ItemEventListKind ,
2026-07-25 21:49:24 +00:00
ReferenceSlots : [ ] contracts . ReferenceSlot {
{ Name : "glossary" , Description : referenceSlotDescriptions . Glossary , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
{ Name : "party" , Description : referenceSlotDescriptions . Party , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
{ Name : "players" , Description : referenceSlotDescriptions . Players , AcceptedMediaTypes : [ ] string { "application/json" , "application/x-yaml" , "application/yaml" , "text/markdown" , "text/plain" } } ,
{ Name : "roster" , Description : referenceSlotDescriptions . Roster , 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 )
}
if _ , err := DecodeOptions ( map [ string ] any { "unexpected" : true } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "unknown option" ) {
t . Fatalf ( "DecodeOptions() error = %v" , err )
}
registry := pipeline . NewExtractorRegistry ( )
if err := Register ( registry ) ; err != nil {
t . Fatal ( err )
}
if got , ok := registry . Spec ( Key ) ; ! ok || ! reflect . DeepEqual ( got , want ) {
t . Fatalf ( "registry spec = %#v, %t" , got , ok )
}
extractor := newExtractor ( t , & fakeItemEventsLLMClient { } )
metadata := extractor . ManifestMetadata ( )
for key , want := range map [ string ] string {
"prompt_id" : PromptID , "prompt_version" : SchemaVersion , "response_schema_key" : string ( ResponseSchemaKey ) , "response_schema_id" : ResponseSchemaID ,
"response_schema_name" : ResponseSchemaName , "response_schema_version" : SchemaVersion , "mapping_policy" : mappingPolicy ,
} {
if metadata [ key ] != want {
t . Fatalf ( "metadata[%q] = %#v, want %q" , key , metadata [ key ] , want )
}
}
for _ , key := range [ ] string { "prompt_sha256" , "response_schema_sha256" } {
if value , ok := metadata [ key ] . ( string ) ; ! ok || ! strings . HasPrefix ( value , "sha256:" ) {
t . Fatalf ( "metadata[%q] = %#v" , key , metadata [ key ] )
}
}
if got := extractor . CheckpointFingerprints ( ) ; ! reflect . DeepEqual ( got , [ ] pipeline . CheckpointFingerprint {
{ Name : "prompt" , Value : metadata [ "prompt_sha256" ] . ( string ) } ,
{ Name : "response_schema" , Value : metadata [ "response_schema_sha256" ] . ( string ) } ,
{ Name : "mapping_policy" , Value : mappingPolicy } ,
} ) {
t . Fatalf ( "CheckpointFingerprints() = %#v" , got )
}
}