Complete shared domain contract verification
This commit is contained in:
@@ -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:**
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"}`
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"]}]}}}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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}}}}})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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"]}]}}}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -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}}}
|
||||
}
|
||||
|
||||
@@ -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