45 lines
1.9 KiB
Go
45 lines
1.9 KiB
Go
package itemregistry
|
|
|
|
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 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")
|
|
}
|
|
}
|
|
|
|
func TestModuleRegistrationAndNativeDependencies(t *testing.T) {
|
|
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one") {
|
|
t.Fatalf("New() error = %v, want reference-set rejection", err)
|
|
}
|
|
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.item_registry"}, ArtifactKind: dnd.ItemRegistryKind, ReferenceSlots: referenceSlots()}
|
|
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")
|
|
}
|
|
|
|
}
|