Complete shared domain contract verification
This commit is contained in:
@@ -38,6 +38,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare NPC registry: %w", err)
|
||||
@@ -151,9 +154,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := itemregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare item registry: %w", err)
|
||||
@@ -93,9 +96,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
@@ -12,6 +13,15 @@ import (
|
||||
itemregistry "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/registry"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsCollectionSelectionOnRegistry(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
itemregistry.ReferenceSlot: {Items: []contracts.ReferenceItem{{Collections: []string{}}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil || !strings.Contains(err.Error(), itemregistry.ReferenceSlot) {
|
||||
t.Fatalf("expected registry selection error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorRejectsUnknownAndMismatchedItemPairs(t *testing.T) {
|
||||
id := itemidentity.DeriveID("Torch")
|
||||
content, err := itemcodec.New().Encode(dnd.ItemRegistry{Items: []dnd.Item{{ID: id, Name: "Torch", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}})
|
||||
|
||||
@@ -32,6 +32,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := locationregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare location registry: %w", err)
|
||||
@@ -94,9 +97,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare NPC registry: %w", err)
|
||||
@@ -137,9 +140,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare NPC registry: %w", err)
|
||||
@@ -103,9 +106,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
effective, err := spellcatalog.ResolveEffectiveCatalog(referenceSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,9 +109,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
spellreference "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/spells/catalog"
|
||||
)
|
||||
|
||||
func TestValidatorApprovesCanonicalNormalizedAndOverlayAliasNames(t *testing.T) {
|
||||
validator, err := New(Options{}, overlayReferences())
|
||||
func TestValidatorApprovesCanonicalNormalizedAndSharedGlossaryAliasNames(t *testing.T) {
|
||||
validator, err := New(Options{}, sharedGlossaryReferences())
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func TestValidatorDefersInvalidShape(t *testing.T) {
|
||||
func TestValidatorDoesNotMutateArtifactOrCatalog(t *testing.T) {
|
||||
value := spellList("Cure Wounds")
|
||||
before := value
|
||||
validator, err := New(Options{}, overlayReferences())
|
||||
validator, err := New(Options{}, sharedGlossaryReferences())
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func TestValidatorDoesNotMutateArtifactOrCatalog(t *testing.T) {
|
||||
t.Fatalf("Validate() = %#v and value = %#v, want approval without mutation", result, value)
|
||||
}
|
||||
if _, ok := validator.catalog.Lookup("Aegis of Emberfall"); !ok {
|
||||
t.Fatal("catalog lost overlay canonical name after mutating returned names")
|
||||
t.Fatal("catalog lost shared glossary canonical name after mutating returned names")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func validCast(name string) dnd.SpellCast {
|
||||
}
|
||||
}
|
||||
|
||||
func overlayReferences() contracts.ReferenceSet {
|
||||
func sharedGlossaryReferences() contracts.ReferenceSet {
|
||||
content := []byte(`{
|
||||
"schema_version": "maximumdirect.glossary.v1",
|
||||
"collections": {"spells": {"entries": [
|
||||
|
||||
Reference in New Issue
Block a user