2026-08-05 19:27:49 +00:00
package itemregistry
import (
"encoding/json"
"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"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/identity"
)
func TestModuleRegistrationMetadataAndRedaction ( t * testing . T ) {
if _ , err := New ( nil , Options { } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "LLM client" ) {
t . Fatalf ( "New(nil) error = %v, want client rejection" , err )
}
if _ , err := New ( & fakeItemsLLMClient { } , Options { } , contracts . ReferenceSet { } , contracts . ReferenceSet { } ) ; err == nil || ! strings . Contains ( err . Error ( ) , "at most one" ) {
t . Fatalf ( "New() error = %v, want reference-set rejection" , err )
}
2026-08-26 23:55:23 +00:00
want := pipeline . ModuleSpec { Key : Key , Stage : pipeline . StageExtract , ExecutionClass : contracts . ExecutionClassLLMBacked , CorrectionProtocol : contracts . CorrectionProtocolSingleResponseV1 , Requires : [ ] string { "chunks" , "source.transcript" } , Provides : [ ] string { "dnd.item_registry" } , ArtifactKind : dnd . ItemRegistryKind , ReferenceSlots : referenceSlots ( ) }
2026-08-05 19:27:49 +00:00
if got := ModuleSpec ( ) ; ! reflect . DeepEqual ( got , want ) {
t . Fatalf ( "ModuleSpec() = %#v, want %#v" , got , want )
}
registry := pipeline . NewExtractorRegistry ( )
if err := Register ( registry ) ; err != nil {
t . Fatalf ( "Register() error = %v" , err )
}
if got , ok := registry . Spec ( Key ) ; ! ok || ! reflect . DeepEqual ( got , want ) {
t . Fatalf ( "registry spec = %#v, present = %t" , got , ok )
}
if err := Register ( nil ) ; err == nil || ! strings . Contains ( err . Error ( ) , "extractor registry" ) {
t . Fatalf ( "Register(nil) error = %v, want registry rejection" , err )
}
if _ , err := DecodeOptions ( map [ string ] any { "unknown" : true } ) ; err == nil {
t . Fatal ( "DecodeOptions() accepted unknown option" )
}
references := contracts . ReferenceSet { Slots : map [ string ] contracts . ResolvedReferenceSlot {
"glossary" : { Items : [ ] contracts . ReferenceItem { { Content : [ ] byte ( "secret-campaign-context" ) } } } ,
} }
metadata := newExtractor ( t , & fakeItemsLLMClient { } , references ) . ManifestMetadata ( )
for key , value := 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 ,
"identity_policy" : identity . Policy , "mapping_policy" : mappingPolicy ,
} {
if metadata [ key ] != value {
t . Fatalf ( "metadata[%q] = %#v, want %q" , key , metadata [ key ] , value )
}
}
encoded , err := json . Marshal ( metadata )
if err != nil || strings . Contains ( string ( encoded ) , "secret-campaign-context" ) || strings . Contains ( string ( encoded ) , "session-items" ) {
t . Fatalf ( "manifest metadata = %s, want static redacted provenance only" , encoded )
}
if got := newExtractor ( t , & fakeItemsLLMClient { } ) . CheckpointFingerprints ( ) ; len ( got ) != 4 || got [ 0 ] . Name != "prompt" || got [ 1 ] . Name != "response_schema" || got [ 2 ] . Value != identity . Policy || got [ 3 ] . Value != mappingPolicy {
t . Fatalf ( "CheckpointFingerprints() = %#v" , got )
}
}