diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 02490f57..13ecd53d 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -458,6 +458,10 @@ migration explanations are not stale references to delete. ## Stage 11 — Final Contract And Regression Pass +**Status:** Complete. Repository-wide tests, vet, and build passed. Maintained +example configurations and documentation links were checked; optional live and +cross-application evaluation was not run. + **Goal:** Finish the end-to-end sprint with all target behavior verified. **Work:** diff --git a/internal/cli/spell_catalog_correction_contract_test.go b/internal/cli/spell_catalog_correction_contract_test.go index 674de7c1..d74c2884 100644 --- a/internal/cli/spell_catalog_correction_contract_test.go +++ b/internal/cli/spell_catalog_correction_contract_test.go @@ -37,7 +37,7 @@ func TestProductionSpellCatalogValidationCoordinatesCorrections(t *testing.T) { wantRejected: true, }, { - name: "overlay spell becomes valid after correction", + name: "shared glossary spell becomes valid after correction", responses: []string{ productionSpellResponse("Unknown Spell"), productionSpellResponse("Aegis of Emberfall"), @@ -95,7 +95,7 @@ func TestProductionSpellCatalogValidationCoordinatesCorrections(t *testing.T) { } value := decodeAssembledOutput[dnd.SpellList](t, output.OutputFiles, "lanes/spells.json") if len(value.SpellCasts) != 1 || value.SpellCasts[0].Spell != tt.wantSpell { - t.Fatalf("normalized spell list = %#v, want accepted overlay spell", value) + t.Fatalf("normalized spell list = %#v, want accepted shared glossary spell", value) } if len(output.Diagnostics.Groups) != 2 || output.Diagnostics.Groups[0].ReasonCode != tt.wantAdvisoryCode { t.Fatalf("diagnostics = %#v, want terminal extract and normalize diagnostics", output.Diagnostics) diff --git a/internal/cli/spell_catalog_identity_contract_test.go b/internal/cli/spell_catalog_identity_contract_test.go index cbb6cd86..a1eb2991 100644 --- a/internal/cli/spell_catalog_identity_contract_test.go +++ b/internal/cli/spell_catalog_identity_contract_test.go @@ -23,12 +23,12 @@ func TestMaterializedSpellCatalogOrderingPreservesSemanticContents(t *testing.T) t.Fatal(err) } resolved := effective.ResolvedPipeline - overlayPath := filepath.Join(t.TempDir(), "catalog.json") + sharedGlossaryPath := filepath.Join(t.TempDir(), "catalog.json") for _, target := range []*pipeline.ResolvedReferenceTarget{&resolved.Steps[0].ArtifactLanes[0].ExtractReferences, &resolved.Steps[0].ArtifactLanes[0].NormalizeReferences} { matched := false for index := range target.Bindings { if target.Bindings[index].SlotName == spellcatalog.SpellCatalogReferenceSlot { - target.Bindings[index].Source = overlayPath + target.Bindings[index].Source = sharedGlossaryPath matched = true } } @@ -38,7 +38,7 @@ func TestMaterializedSpellCatalogOrderingPreservesSemanticContents(t *testing.T) } materialize := func(contents string) pipeline.ResolvedPipeline { t.Helper() - if err := os.WriteFile(overlayPath, []byte(contents), 0600); err != nil { + if err := os.WriteFile(sharedGlossaryPath, []byte(contents), 0600); err != nil { t.Fatal(err) } value, _, err := pipeline.MaterializeReferences(resolved, catalog, pipeline.ReferenceMaterializationOptions{ConfigPath: configPath, WorkingDir: filepath.Dir(configPath)}) @@ -47,7 +47,7 @@ func TestMaterializedSpellCatalogOrderingPreservesSemanticContents(t *testing.T) } return value } - first, second := materialize(reorderedOverlayA), materialize(reorderedOverlayB) + first, second := materialize(reorderedSharedGlossaryA), materialize(reorderedSharedGlossaryB) laneA, laneB := first.Steps[0].ArtifactLanes[0], second.Steps[0].ArtifactLanes[0] for _, pair := range [][2]pipeline.ResolvedReferenceTarget{ {laneA.ExtractReferences, laneB.ExtractReferences}, @@ -104,7 +104,7 @@ func TestConfiguredSpellCatalogBindingChangesResolvedPipelineIdentity(t *testing } } -func TestProductionOverlayRunAlignsGroundingAndValidation(t *testing.T) { +func TestProductionSharedGlossaryRunAlignsGroundingAndValidation(t *testing.T) { outputRoot := filepath.Join(t.TempDir(), "output") client := &productionFakeLLMClient{spellResponse: productionSpellResponse("Aegis of Emberfall")} configPath := writeProductionContractConfig(t, productionSpellCatalogContractConfig(t)+productionProviderConfiguration) @@ -130,7 +130,7 @@ func TestProductionOverlayRunAlignsGroundingAndValidation(t *testing.T) { } for _, fragment := range []string{`"canonical_name":"Aegis of Emberfall"`, `"aliases":["Emberfall Aegis"]`} { if !strings.Contains(prompt.String(), fragment) { - t.Fatalf("catalog prompt omitted overlay recognition %q", fragment) + t.Fatalf("catalog prompt omitted shared glossary recognition %q", fragment) } } artifact := readProductionJSON[dnd.SpellList](t, filepath.Join(report.OutputDirectory, "lanes", "spells.json")) @@ -139,7 +139,7 @@ func TestProductionOverlayRunAlignsGroundingAndValidation(t *testing.T) { } } -const reorderedOverlayA = `{ +const reorderedSharedGlossaryA = `{ "schema_version": "maximumdirect.glossary.v1", "collections": {"spells": {"entries": [ {"id":"a","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}, @@ -147,4 +147,4 @@ const reorderedOverlayA = `{ ]}} }` -const reorderedOverlayB = `{"collections":{"spells":{"entries":[{"aliases":["Cinder Shroud","Veil of Cinder"],"name":"Cinder Veil","id":"b","category":"spell"},{"aliases":["Emberfall Aegis"],"name":"Aegis of Emberfall","id":"a","category":"spell"}]}},"schema_version":"maximumdirect.glossary.v1"}` +const reorderedSharedGlossaryB = `{"collections":{"spells":{"entries":[{"aliases":["Cinder Shroud","Veil of Cinder"],"name":"Cinder Veil","id":"b","category":"spell"},{"aliases":["Emberfall Aegis"],"name":"Aegis of Emberfall","id":"a","category":"spell"}]}},"schema_version":"maximumdirect.glossary.v1"}` diff --git a/internal/modules/dnd/chunk/scenes/chunker.go b/internal/modules/dnd/chunk/scenes/chunker.go index cb2eddc3..4af3ad78 100644 --- a/internal/modules/dnd/chunk/scenes/chunker.go +++ b/internal/modules/dnd/chunk/scenes/chunker.go @@ -129,9 +129,6 @@ func Register(registry *pipeline.ChunkerRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/combatturns/extractor.go b/internal/modules/dnd/extract/combatturns/extractor.go index b708dded..30e7a33e 100644 --- a/internal/modules/dnd/extract/combatturns/extractor.go +++ b/internal/modules/dnd/extract/combatturns/extractor.go @@ -191,9 +191,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/enemyevents/extractor.go b/internal/modules/dnd/extract/enemyevents/extractor.go index b56dc8ae..64f2649b 100644 --- a/internal/modules/dnd/extract/enemyevents/extractor.go +++ b/internal/modules/dnd/extract/enemyevents/extractor.go @@ -157,9 +157,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/itemoccurrences/extractor.go b/internal/modules/dnd/extract/itemoccurrences/extractor.go index c7642b20..b7c9cc0f 100644 --- a/internal/modules/dnd/extract/itemoccurrences/extractor.go +++ b/internal/modules/dnd/extract/itemoccurrences/extractor.go @@ -151,9 +151,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/itemregistry/extractor.go b/internal/modules/dnd/extract/itemregistry/extractor.go index 62ce3598..1a2a88ad 100644 --- a/internal/modules/dnd/extract/itemregistry/extractor.go +++ b/internal/modules/dnd/extract/itemregistry/extractor.go @@ -106,9 +106,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/locationoccurrences/extractor.go b/internal/modules/dnd/extract/locationoccurrences/extractor.go index a118aa84..287625f5 100644 --- a/internal/modules/dnd/extract/locationoccurrences/extractor.go +++ b/internal/modules/dnd/extract/locationoccurrences/extractor.go @@ -151,9 +151,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/locationregistry/extractor.go b/internal/modules/dnd/extract/locationregistry/extractor.go index 3935472b..7de7338c 100644 --- a/internal/modules/dnd/extract/locationregistry/extractor.go +++ b/internal/modules/dnd/extract/locationregistry/extractor.go @@ -106,9 +106,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/npcoccurrences/extractor.go b/internal/modules/dnd/extract/npcoccurrences/extractor.go index 8cce7704..5b74072d 100644 --- a/internal/modules/dnd/extract/npcoccurrences/extractor.go +++ b/internal/modules/dnd/extract/npcoccurrences/extractor.go @@ -150,9 +150,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/npcregistry/extractor.go b/internal/modules/dnd/extract/npcregistry/extractor.go index 21f911c4..60788833 100644 --- a/internal/modules/dnd/extract/npcregistry/extractor.go +++ b/internal/modules/dnd/extract/npcregistry/extractor.go @@ -116,9 +116,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/scenedescriptions/extractor.go b/internal/modules/dnd/extract/scenedescriptions/extractor.go index 379505aa..98272987 100644 --- a/internal/modules/dnd/extract/scenedescriptions/extractor.go +++ b/internal/modules/dnd/extract/scenedescriptions/extractor.go @@ -148,9 +148,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/spells/extractor.go b/internal/modules/dnd/extract/spells/extractor.go index c1e0d7db..cc4b42a7 100644 --- a/internal/modules/dnd/extract/spells/extractor.go +++ b/internal/modules/dnd/extract/spells/extractor.go @@ -166,9 +166,6 @@ func Register(registry *pipeline.ExtractorRegistry) error { if err != nil { return nil, err } - if err := shared.ValidateReferenceSelections(request.References); err != nil { - return nil, err - } return New(options, request.References) }) } diff --git a/internal/modules/dnd/extract/spells/extractor_test.go b/internal/modules/dnd/extract/spells/extractor_test.go index 9d662bfd..edea8082 100644 --- a/internal/modules/dnd/extract/spells/extractor_test.go +++ b/internal/modules/dnd/extract/spells/extractor_test.go @@ -88,7 +88,7 @@ func TestExtractReturnsCanonicalSpellListFromPrivateResponse(t *testing.T) { func TestExtractPromptProjectsCanonicalNamesAndAliasesWithoutMetadata(t *testing.T) { client := &fakeSpellsLLMClient{response: extractionResponse{SpellCasts: []spellCastResponse{}}} - extractor := newExtractor(t, client, overlaySpellCatalogReference()) + extractor := newExtractor(t, client, sharedGlossarySpellCatalogReference()) if _, err := runExtraction(context.Background(), extractor, extractionRequest()); err != nil { t.Fatalf("Extract() error = %v, want nil", err) } @@ -127,7 +127,7 @@ func TestExtractUsesAliasRecognitionToRequestCanonicalSpellNames(t *testing.T) { request.Chunk.Content = []byte(`{"segments":[{"id":1,"text":"Aria invokes Emberfall Aegis."}]}`) request.SourceInput = spellChunkInput(request.Chunk) - result, err := runExtraction(context.Background(), newExtractor(t, client, overlaySpellCatalogReference()), request) + result, err := runExtraction(context.Background(), newExtractor(t, client, sharedGlossarySpellCatalogReference()), request) if err != nil { t.Fatalf("Extract() error = %v, want nil", err) } @@ -162,7 +162,7 @@ func TestExtractAliasOnlyCatalogChangesPromptMaterial(t *testing.T) { func TestNewRejectsMalformedCatalogBeforeLLMCall(t *testing.T) { client := &fakeSpellsLLMClient{} - _, err := New(Options{}, spellCatalogReference(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v2","catalogs":[]}`)) + _, err := New(Options{}, spellCatalogReference(`{"schema_version":"wrong","collections":{}}`)) if err == nil || !strings.Contains(err.Error(), "resolve effective spell catalog") { t.Fatalf("New() error = %v, want effective catalog error", err) } diff --git a/internal/modules/dnd/extract/spells/test_helpers_test.go b/internal/modules/dnd/extract/spells/test_helpers_test.go index 0f6df716..5c2859ba 100644 --- a/internal/modules/dnd/extract/spells/test_helpers_test.go +++ b/internal/modules/dnd/extract/spells/test_helpers_test.go @@ -161,7 +161,7 @@ func spellCatalogReference(content string) contracts.ReferenceSet { }} } -func overlaySpellCatalogReference() contracts.ReferenceSet { +func sharedGlossarySpellCatalogReference() contracts.ReferenceSet { return spellCatalogReference(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"aegis","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}]}}}`) } diff --git a/internal/modules/dnd/normalize/combatturns/normalizer.go b/internal/modules/dnd/normalize/combatturns/normalizer.go index 7c7fb3b2..9e272811 100644 --- a/internal/modules/dnd/normalize/combatturns/normalizer.go +++ b/internal/modules/dnd/normalize/combatturns/normalizer.go @@ -51,6 +51,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 + } npcResolver, err := npcregistry.NewResolver(referenceSet) if err != nil { return nil, normalizerErrorf("prepare NPC registry: %w", err) @@ -298,9 +301,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) }) } diff --git a/internal/modules/dnd/normalize/enemyevents/normalizer.go b/internal/modules/dnd/normalize/enemyevents/normalizer.go index 4c63eb3a..f7760324 100644 --- a/internal/modules/dnd/normalize/enemyevents/normalizer.go +++ b/internal/modules/dnd/normalize/enemyevents/normalizer.go @@ -49,6 +49,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 + } resolver, err := npcregistry.NewResolver(referenceSet) if err != nil { return nil, normalizerErrorf("prepare NPC registry: %w", err) @@ -262,9 +265,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) }) } diff --git a/internal/modules/dnd/normalize/itemoccurrences/normalizer.go b/internal/modules/dnd/normalize/itemoccurrences/normalizer.go index 2cb862f5..b842eab7 100644 --- a/internal/modules/dnd/normalize/itemoccurrences/normalizer.go +++ b/internal/modules/dnd/normalize/itemoccurrences/normalizer.go @@ -48,6 +48,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 + } resolver, err := itemregistry.NewResolver(referenceSet) if err != nil { return nil, normalizerErrorf("prepare item registry: %w", err) @@ -269,9 +272,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) }) } diff --git a/internal/modules/dnd/normalize/itemoccurrences/normalizer_test.go b/internal/modules/dnd/normalize/itemoccurrences/normalizer_test.go index 67748409..9c36cc84 100644 --- a/internal/modules/dnd/normalize/itemoccurrences/normalizer_test.go +++ b/internal/modules/dnd/normalize/itemoccurrences/normalizer_test.go @@ -3,6 +3,7 @@ package itemoccurrences import ( "context" "reflect" + "strings" "testing" "gitea.maximumdirect.net/eric/notarius/internal/core/source" @@ -13,6 +14,14 @@ import ( itemidentity "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/identity" ) +func TestConstructionRejectsCollectionSelectionOnRegistry(t *testing.T) { + refs := registryReferences(t) + refs.Slots[ItemRegistryReferenceSlot].Items[0].Collections = []string{} + if _, err := New(Options{}, refs); err == nil || !strings.Contains(err.Error(), ItemRegistryReferenceSlot) { + t.Fatalf("expected registry selection error, got %v", err) + } +} + func registryReferences(t *testing.T) contracts.ReferenceSet { t.Helper() content, err := itemcodec.New().Encode(dnd.ItemRegistry{Items: []dnd.Item{{ID: itemidentity.DeriveID("Torch"), Name: "Torch", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}) diff --git a/internal/modules/dnd/normalize/locationoccurrences/normalizer.go b/internal/modules/dnd/normalize/locationoccurrences/normalizer.go index 8724a5a9..e0f61d8e 100644 --- a/internal/modules/dnd/normalize/locationoccurrences/normalizer.go +++ b/internal/modules/dnd/normalize/locationoccurrences/normalizer.go @@ -51,6 +51,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 + } resolver, err := locationregistry.NewResolver(referenceSet) if err != nil { return nil, normalizerErrorf("prepare location registry: %w", err) @@ -320,9 +323,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) }) } diff --git a/internal/modules/dnd/normalize/npcoccurrences/normalizer.go b/internal/modules/dnd/normalize/npcoccurrences/normalizer.go index 7e2d585c..5161955e 100644 --- a/internal/modules/dnd/normalize/npcoccurrences/normalizer.go +++ b/internal/modules/dnd/normalize/npcoccurrences/normalizer.go @@ -48,6 +48,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 + } resolver, err := npcregistry.NewResolver(referenceSet) if err != nil { return nil, normalizerErrorf("prepare NPC registry: %w", err) @@ -239,9 +242,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) }) } diff --git a/internal/modules/dnd/normalize/spells/normalizer.go b/internal/modules/dnd/normalize/spells/normalizer.go index 548b777d..3513e882 100644 --- a/internal/modules/dnd/normalize/spells/normalizer.go +++ b/internal/modules/dnd/normalize/spells/normalizer.go @@ -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) }) } diff --git a/internal/modules/dnd/normalize/spells/normalizer_test.go b/internal/modules/dnd/normalize/spells/normalizer_test.go index 1b4937ab..ec3d044f 100644 --- a/internal/modules/dnd/normalize/spells/normalizer_test.go +++ b/internal/modules/dnd/normalize/spells/normalizer_test.go @@ -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"]}]}}}`) } diff --git a/internal/modules/dnd/shared/context_test.go b/internal/modules/dnd/shared/context_test.go index 0720b234..cc25fc20 100644 --- a/internal/modules/dnd/shared/context_test.go +++ b/internal/modules/dnd/shared/context_test.go @@ -1,12 +1,51 @@ package shared import ( + "reflect" "strings" "testing" "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts" ) +func TestEquivalentYAMLAndJSONProduceEquivalentContext(t *testing.T) { + jsonParty := `{"schema_version":"maximumdirect.rpg.party.v1","characters":{"a":{"character":{"name":"Aria","aliases":["Star"],"classes":[{"name":"Cleric","level":3}]},"player":{"name":"Alice"}}}}` + yamlParty := `schema_version: maximumdirect.rpg.party.v1 +characters: + a: + character: + name: Aria + aliases: [Star] + classes: [{name: Cleric, level: 3}] + player: {name: Alice} +` + jsonGlossary := `{"schema_version":"maximumdirect.glossary.v1","collections":{"setting":{"entries":[{"id":"tower","name":"Tower","category":"place","aliases":["Spire"]}]}}}` + yamlGlossary := `schema_version: maximumdirect.glossary.v1 +collections: + setting: + entries: + - {id: tower, name: Tower, category: place, aliases: [Spire]} +` + refs := func(media, party, glossary string) contracts.ReferenceSet { + return contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{ + "party": {Items: []contracts.ReferenceItem{{MediaType: media, Content: []byte(party)}}}, + "glossary": {Items: []contracts.ReferenceItem{{MediaType: media, Content: []byte(glossary)}}}, + }} + } + jsonContext, err := PrepareContext(refs("application/json", jsonParty, jsonGlossary)) + if err != nil { + t.Fatal(err) + } + yamlContext, err := PrepareContext(refs("application/yaml", yamlParty, yamlGlossary)) + if err != nil { + t.Fatal(err) + } + source := contracts.NewLLMInputMaterial("source", "text/plain", []byte("transcript"), "", "") + if !reflect.DeepEqual(jsonContext.Inputs(source), yamlContext.Inputs(source)) { + t.Fatal("equivalent documents produced different task material") + } +} + func contextReference(content string, collections []string) contracts.ResolvedReferenceSlot { return contracts.ResolvedReferenceSlot{Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte(content), Collections: collections}}} } diff --git a/internal/modules/dnd/validate/enemyevents/invariants/validator.go b/internal/modules/dnd/validate/enemyevents/invariants/validator.go index f07e7901..96d97610 100644 --- a/internal/modules/dnd/validate/enemyevents/invariants/validator.go +++ b/internal/modules/dnd/validate/enemyevents/invariants/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/itemoccurrences/registry/validator.go b/internal/modules/dnd/validate/itemoccurrences/registry/validator.go index bd98cbff..eb8368ae 100644 --- a/internal/modules/dnd/validate/itemoccurrences/registry/validator.go +++ b/internal/modules/dnd/validate/itemoccurrences/registry/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/itemoccurrences/registry/validator_test.go b/internal/modules/dnd/validate/itemoccurrences/registry/validator_test.go index 38994c55..969004f6 100644 --- a/internal/modules/dnd/validate/itemoccurrences/registry/validator_test.go +++ b/internal/modules/dnd/validate/itemoccurrences/registry/validator_test.go @@ -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}}}}}) diff --git a/internal/modules/dnd/validate/locationoccurrences/registry/validator.go b/internal/modules/dnd/validate/locationoccurrences/registry/validator.go index 63355675..d0df8f83 100644 --- a/internal/modules/dnd/validate/locationoccurrences/registry/validator.go +++ b/internal/modules/dnd/validate/locationoccurrences/registry/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/npcoccurrences/invariants/validator.go b/internal/modules/dnd/validate/npcoccurrences/invariants/validator.go index 69678dfc..52f88077 100644 --- a/internal/modules/dnd/validate/npcoccurrences/invariants/validator.go +++ b/internal/modules/dnd/validate/npcoccurrences/invariants/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/npcoccurrences/registry/validator.go b/internal/modules/dnd/validate/npcoccurrences/registry/validator.go index eb856147..75eab9c6 100644 --- a/internal/modules/dnd/validate/npcoccurrences/registry/validator.go +++ b/internal/modules/dnd/validate/npcoccurrences/registry/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/spells/catalog/validator.go b/internal/modules/dnd/validate/spells/catalog/validator.go index 91a4b7c7..752e9b37 100644 --- a/internal/modules/dnd/validate/spells/catalog/validator.go +++ b/internal/modules/dnd/validate/spells/catalog/validator.go @@ -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) }) } diff --git a/internal/modules/dnd/validate/spells/catalog/validator_test.go b/internal/modules/dnd/validate/spells/catalog/validator_test.go index 293b34d4..cb52fecb 100644 --- a/internal/modules/dnd/validate/spells/catalog/validator_test.go +++ b/internal/modules/dnd/validate/spells/catalog/validator_test.go @@ -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": [