Complete shared domain contract verification

This commit is contained in:
2026-11-29 18:28:59 +00:00
parent 9dc976afaf
commit 41a5c43561
33 changed files with 126 additions and 97 deletions

View File

@@ -46,6 +46,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
if len(references) == 1 {
referenceSet = references[0]
}
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
return nil, err
}
effectiveCatalog, err := spellcatalog.ResolveEffectiveCatalog(referenceSet)
if err != nil {
return nil, normalizerErrorf("resolve effective spell catalog: %w", err)
@@ -256,9 +259,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
if err != nil {
return nil, err
}
if err := shared.ValidateReferenceSelections(request.References); err != nil {
return nil, err
}
return New(options, request.References)
})
}

View File

@@ -54,7 +54,7 @@ func TestModuleContractAndStrictOptions(t *testing.T) {
}
}
func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
func TestNewBuildsEmbeddedAndSharedGlossaryCatalogs(t *testing.T) {
base, err := New(Options{})
if err != nil {
t.Fatalf("New() error = %v, want nil", err)
@@ -69,15 +69,15 @@ func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
t.Fatalf("apostrophe lookup = %q, %t, want canonical curly apostrophe spelling", canonical, ok)
}
overlay, err := New(Options{}, overlayReference())
sharedGlossary, err := New(Options{}, sharedGlossaryReference())
if err != nil {
t.Fatalf("New(overlay) error = %v, want nil", err)
t.Fatalf("New(shared glossary) error = %v, want nil", err)
}
if got := overlay.effectiveCatalog.CollectionNames(); !reflect.DeepEqual(got, []string{"spells"}) {
if got := sharedGlossary.effectiveCatalog.CollectionNames(); !reflect.DeepEqual(got, []string{"spells"}) {
t.Fatalf("collection names = %#v, want spells", got)
}
if canonical, ok := overlay.effectiveCatalog.Lookup(" emberfall aegis "); !ok || canonical != "Aegis of Emberfall" {
t.Fatalf("overlay alias lookup = %q, %t, want Aegis of Emberfall", canonical, ok)
if canonical, ok := sharedGlossary.effectiveCatalog.Lookup(" emberfall aegis "); !ok || canonical != "Aegis of Emberfall" {
t.Fatalf("shared glossary alias lookup = %q, %t, want Aegis of Emberfall", canonical, ok)
}
}
@@ -91,7 +91,7 @@ func TestNewRejectsInvalidCatalogReferencesDuringConstruction(t *testing.T) {
t.Fatalf("New(invalid reference) error = %v, want media type failure", err)
}
tooMany := overlayReference()
tooMany := sharedGlossaryReference()
slot := tooMany.Slots[spellcatalog.SpellCatalogReferenceSlot]
slot.Items = append(slot.Items, slot.Items[0])
tooMany.Slots[spellcatalog.SpellCatalogReferenceSlot] = slot
@@ -452,7 +452,7 @@ func TestNormalizeDuplicateOutputDoesNotShareInputSlices(t *testing.T) {
func newNormalizer(t *testing.T) *Normalizer {
t.Helper()
normalizer, err := New(Options{}, overlayReference())
normalizer, err := New(Options{}, sharedGlossaryReference())
if err != nil {
t.Fatalf("New() error = %v, want nil", err)
}
@@ -502,7 +502,7 @@ func diagnosticByReason(diagnostics []contracts.ProducerDiagnostic, reason strin
return nil
}
func overlayReference() contracts.ReferenceSet {
func sharedGlossaryReference() contracts.ReferenceSet {
return spellCatalogReference(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"aegis","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}]}}}`)
}