Complete D&D entity contract audit
This commit is contained in:
@@ -136,76 +136,6 @@ func TestProductionCatalogCoversMaintainedConfigurations(t *testing.T) {
|
||||
assertProductionContains(t, "location occurrence normalizer variants", registries.Normalizers.RegisteredArtifactKinds(locationoccurrencenormalize.Key), []contracts.ArtifactKind{dnd.LocationOccurrenceListKind})
|
||||
assertProductionContains(t, "enemy event normalizer variants", registries.Normalizers.RegisteredArtifactKinds(enemyeventnormalize.Key), []contracts.ArtifactKind{dnd.EnemyEventListKind})
|
||||
|
||||
wantChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/spells/shape"),
|
||||
pipeline.Binding("extract/dnd/spells/catalog"),
|
||||
pipeline.Binding("extract/dnd/spells/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/spells/source_relatedness"),
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageExtract, spells.Key); !reflect.DeepEqual(got, wantChain) {
|
||||
t.Fatalf("spell validator chain = %#v, want %#v", got, wantChain)
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageNormalize, spellnormalize.Key); !reflect.DeepEqual(got, wantChain) {
|
||||
t.Fatalf("spell normalize validator chain = %#v, want %#v", got, wantChain)
|
||||
}
|
||||
combatExtractChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/shape"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/source_relatedness"),
|
||||
}
|
||||
combatNormalizeChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/shape"),
|
||||
pipeline.Binding("normalize/dnd/combat-turns/invariants"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/combat-turns/source_relatedness"),
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageExtract, combatextract.Key); !reflect.DeepEqual(got, combatExtractChain) {
|
||||
t.Fatalf("combat extract validator chain = %#v, want %#v", got, combatExtractChain)
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageNormalize, combatnormalize.Key); !reflect.DeepEqual(got, combatNormalizeChain) {
|
||||
t.Fatalf("combat normalize validator chain = %#v, want %#v", got, combatNormalizeChain)
|
||||
}
|
||||
itemOccurrenceExtractChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/shape"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/registry"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/source_relatedness"),
|
||||
}
|
||||
itemOccurrenceNormalizeChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/shape"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/registry"),
|
||||
pipeline.Binding("normalize/dnd/item-occurrences/invariants"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/item-occurrences/source_relatedness"),
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageExtract, itemoccurrenceextract.Key); !reflect.DeepEqual(got, itemOccurrenceExtractChain) {
|
||||
t.Fatalf("item occurrence extract validator chain = %#v, want %#v", got, itemOccurrenceExtractChain)
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageNormalize, itemoccurrencenormalize.Key); !reflect.DeepEqual(got, itemOccurrenceNormalizeChain) {
|
||||
t.Fatalf("item occurrence normalize validator chain = %#v, want %#v", got, itemOccurrenceNormalizeChain)
|
||||
}
|
||||
enemyEventExtractChain := []pipeline.ModuleBinding{
|
||||
pipeline.Binding("generic/valid_json"),
|
||||
pipeline.Binding("extract/dnd/enemy-events/shape"),
|
||||
pipeline.Binding("extract/dnd/enemy-events/engagements"),
|
||||
pipeline.Binding("extract/dnd/enemy-events/source_refs"),
|
||||
pipeline.Binding("generic/valid_json_schema"),
|
||||
pipeline.Binding("extract/dnd/enemy-events/source_relatedness"),
|
||||
}
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageExtract, enemyeventextract.Key); !reflect.DeepEqual(got, enemyEventExtractChain) {
|
||||
t.Fatalf("enemy event extract validator chain = %#v, want %#v", got, enemyEventExtractChain)
|
||||
}
|
||||
|
||||
catalog := catalogFromRegistries(registries)
|
||||
for _, test := range []struct {
|
||||
stage pipeline.ModuleStage
|
||||
@@ -281,13 +211,6 @@ func TestProductionCatalogCoversMaintainedConfigurations(t *testing.T) {
|
||||
if !ok || enemyEventCodecSpec.Kind != dnd.EnemyEventListKind || enemyEventCodecSpec.Schema.ID != enemyeventcodec.SchemaID {
|
||||
t.Fatalf("enemy event codec spec = %#v, ok=%t, want typed D&D enemy-event codec", enemyEventCodecSpec, ok)
|
||||
}
|
||||
if got := catalog.ValidatorChains.Validators(pipeline.StageExtract, spells.Key); !reflect.DeepEqual(got, wantChain) {
|
||||
t.Fatalf("catalog validator chain = %#v, want %#v", got, wantChain)
|
||||
}
|
||||
if got := catalog.ValidatorChains.Validators(pipeline.StageNormalize, spellnormalize.Key); !reflect.DeepEqual(got, wantChain) {
|
||||
t.Fatalf("catalog spell normalize validator chain = %#v, want %#v", got, wantChain)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDefaultCLICompositionValidatesRepresentativeConfiguration(t *testing.T) {
|
||||
|
||||
@@ -173,7 +173,7 @@ func (r *Registry) NPCs() []dnd.NPC {
|
||||
return cloneNPCs(r.list.NPCs)
|
||||
}
|
||||
|
||||
// List returns a defensive copy of the validated NPC list.
|
||||
// List returns a defensive copy of the validated NPC registry entries.
|
||||
func (r *Registry) List() dnd.NPCRegistry {
|
||||
if r == nil {
|
||||
return dnd.NPCRegistry{}
|
||||
|
||||
@@ -75,7 +75,7 @@ func registerModules(registries pipeline.Registries) error {
|
||||
{name: "spell-list appendorder merger", register: func() error {
|
||||
return appendorder.RegisterTyped(registries.Mergers, dnd.SpellListKind, appendSpellLists)
|
||||
}},
|
||||
{name: "npc-list appendorder merger", register: func() error {
|
||||
{name: "npc registry appendorder merger", register: func() error {
|
||||
return appendorder.RegisterTyped(registries.Mergers, dnd.NPCRegistryKind, appendNPCRegistries)
|
||||
}},
|
||||
{name: "combat-turn-list appendorder merger", register: func() error {
|
||||
@@ -115,7 +115,7 @@ func registerModules(registries pipeline.Registries) error {
|
||||
{name: "spell-list noop normalizer", register: func() error {
|
||||
return noop.RegisterTyped[dnd.SpellList](registries.Normalizers, dnd.SpellListKind)
|
||||
}},
|
||||
{name: "npc-list noop normalizer", register: func() error {
|
||||
{name: "npc registry noop normalizer", register: func() error {
|
||||
return noop.RegisterTyped[dnd.NPCRegistry](registries.Normalizers, dnd.NPCRegistryKind)
|
||||
}},
|
||||
{name: "combat-turn-list noop normalizer", register: func() error {
|
||||
|
||||
@@ -3,7 +3,6 @@ package register
|
||||
import (
|
||||
"io/fs"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -324,18 +323,6 @@ func TestRegisterAddsDNDFamily(t *testing.T) {
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageMerge, occurrenceextract.Key); got != nil {
|
||||
t.Fatalf("NPC occurrence merge validator chain = %#v, want absent", got)
|
||||
}
|
||||
assertAssetNamesContain(t, assets.SchemaFS, []string{
|
||||
"dnd_scenes_llm.v1.json",
|
||||
"dnd_spells_llm.v1.json",
|
||||
"dnd_npc_registry_llm.v1.json",
|
||||
"dnd_combat_turns_llm.v1.json",
|
||||
"dnd_enemy_events_llm.v1.json",
|
||||
"dnd_item_occurrences_llm.v1.json",
|
||||
"dnd_npc_occurrences_llm.v1.json",
|
||||
"dnd_scene_descriptions_llm.v1.json",
|
||||
"dnd_location_registry_llm.v1.json",
|
||||
"dnd_location_occurrences_llm.v1.json",
|
||||
})
|
||||
if spec, ok := registries.Chunkers.Spec("dnd/scenes"); !ok || spec.Key != "dnd/scenes" {
|
||||
t.Fatalf("scene chunker spec = %#v, present = %t; want family-owned spec", spec, ok)
|
||||
}
|
||||
@@ -346,10 +333,10 @@ func TestRegisterAddsDNDFamily(t *testing.T) {
|
||||
t.Fatalf("spell normalizer spec = %#v, present = %t; want dnd spell-list artifact", spec, ok)
|
||||
}
|
||||
if spec, ok := registries.Extractors.Spec(npcextract.Key); !ok || spec.ArtifactKind != dnd.NPCRegistryKind {
|
||||
t.Fatalf("NPC extractor spec = %#v, present = %t; want dnd NPC-list artifact", spec, ok)
|
||||
t.Fatalf("NPC extractor spec = %#v, present = %t; want D&D NPC registry artifact", spec, ok)
|
||||
}
|
||||
if spec, ok := registries.Normalizers.Spec(npcnormalize.Key); !ok || spec.ArtifactKind != dnd.NPCRegistryKind || spec.Stage != pipeline.StageNormalize {
|
||||
t.Fatalf("NPC normalizer spec = %#v, present = %t; want dnd NPC-list artifact", spec, ok)
|
||||
t.Fatalf("NPC normalizer spec = %#v, present = %t; want D&D NPC registry artifact", spec, ok)
|
||||
}
|
||||
if spec, ok := registries.Extractors.Spec(combatextract.Key); !ok || spec.ArtifactKind != dnd.CombatTurnListKind {
|
||||
t.Fatalf("combat extractor spec = %#v, present = %t; want dnd combat-turn-list artifact", spec, ok)
|
||||
@@ -862,30 +849,3 @@ func assertContainsArtifactKinds(t *testing.T, got, want []contracts.ArtifactKin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertAssetNamesContain(t *testing.T, getFS func() (fs.FS, error), want []string) {
|
||||
t.Helper()
|
||||
fSys, err := getFS()
|
||||
if err != nil {
|
||||
t.Fatalf("asset filesystem error = %v, want nil", err)
|
||||
}
|
||||
var got []string
|
||||
if err := fs.WalkDir(fSys, ".", func(path string, entry fs.DirEntry, err error) error {
|
||||
if err == nil && !entry.IsDir() {
|
||||
got = append(got, path)
|
||||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("walk assets: %v", err)
|
||||
}
|
||||
sort.Strings(got)
|
||||
seen := make(map[string]struct{}, len(got))
|
||||
for _, name := range got {
|
||||
seen[name] = struct{}{}
|
||||
}
|
||||
for _, name := range want {
|
||||
if _, ok := seen[name]; !ok {
|
||||
t.Fatalf("asset names = %#v, want required asset %q", got, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@ func registerValidators(registries pipeline.Registries) error {
|
||||
{name: "spell-list always reject validator", register: func() error {
|
||||
return alwaysreject.RegisterTyped[dnd.SpellList](registries.Validators, dnd.SpellListKind)
|
||||
}},
|
||||
{name: "npc-list always accept validator", register: func() error {
|
||||
{name: "npc registry always accept validator", register: func() error {
|
||||
return alwaysaccept.RegisterTyped[dnd.NPCRegistry](registries.Validators, dnd.NPCRegistryKind)
|
||||
}},
|
||||
{name: "npc-list always reject validator", register: func() error {
|
||||
{name: "npc registry always reject validator", register: func() error {
|
||||
return alwaysreject.RegisterTyped[dnd.NPCRegistry](registries.Validators, dnd.NPCRegistryKind)
|
||||
}},
|
||||
{name: "combat-turn-list always accept validator", register: func() error {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
const (
|
||||
Key = "normalize/dnd/npc-occurrences/invariants"
|
||||
ReasonCode = "invalid_npc_interaction_normalization"
|
||||
ReasonCode = "invalid_npc_occurrence_normalization"
|
||||
policy = "dnd.npc_occurrences.validator.normalized.v1"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
const (
|
||||
Key = "extract/dnd/npc-occurrences/registry"
|
||||
ReasonCode = "invalid_npc_interaction_registry"
|
||||
ReasonCode = "invalid_npc_occurrence_registry"
|
||||
policy = "dnd.npc_occurrences.validator.registry.v1"
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
const (
|
||||
Key = "extract/dnd/npc-occurrences/shape"
|
||||
ReasonCode = "invalid_npc_interaction_shape"
|
||||
ReasonCode = "invalid_npc_occurrence_shape"
|
||||
policy = "dnd.npc_occurrences.validator.shape.v1"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
const (
|
||||
Key = "extract/dnd/npc-occurrences/source_refs"
|
||||
ReasonCode = "invalid_npc_interaction_source_refs"
|
||||
ReasonCode = "invalid_npc_occurrence_source_refs"
|
||||
policy = "dnd.npc_occurrences.validator.source_refs.v2"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
|
||||
const (
|
||||
Key = "extract/dnd/npc-occurrences/source_relatedness"
|
||||
WarningReasonCode = "npc_interaction_not_near_source"
|
||||
OmittedReasonCode = "npc_interaction_relatedness_warnings_omitted"
|
||||
WarningReasonCode = "npc_occurrence_not_near_source"
|
||||
OmittedReasonCode = "npc_occurrence_relatedness_warnings_omitted"
|
||||
policy = "dnd.npc_occurrences.validator.source_relatedness.v2"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package identity validates the stable identity invariants of D&D NPC lists.
|
||||
// Package identity validates the stable identity invariants of D&D NPC registries.
|
||||
package identity
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user