Recognize spells from shared glossary documents

This commit is contained in:
2026-11-29 18:04:00 +00:00
parent d406aa6cd2
commit f84e737b2a
12 changed files with 215 additions and 558 deletions

View File

@@ -359,7 +359,7 @@ func TestProductionSpellNormalizerRejectsInvalidCatalogReferencesBeforeExecution
t.Fatalf("MaterializeReferences() error = %v, want malformed JSON to reach preparation", err)
}
_, err = pipeline.Prepare(materialized, components.registries, pipeline.ModuleDependencies{Engine: productionNativeEngine(t, &productionFakeLLMClient{})})
for _, fragment := range []string{`pipeline "dnd-session"`, `lane "spells"`, "normalize", `module "dnd/spells"`, "decode spell catalog overlay"} {
for _, fragment := range []string{`pipeline "dnd-session"`, `lane "spells"`, "normalize", `module "dnd/spells"`, "invalid JSON syntax"} {
if err == nil || !strings.Contains(err.Error(), fragment) {
t.Fatalf("Prepare() error = %v, want context fragment %q", err, fragment)
}
@@ -388,7 +388,7 @@ func TestProductionSpellNormalizerRejectsInvalidCatalogReferencesBeforeExecution
t.Fatal(err)
}
content := productionSpellCatalogContractConfig(t)
catalogSource := repositoryPath("examples", "dnd-complete", "spell-catalog.json")
catalogSource := loadMaintainedExample(t, writeProductionContractConfig(t, content)).Pipelines["dnd-session"].Artifacts["spells"].Extract.References["spell_catalog"].Path
content = strings.Replace(content, catalogSource, "__extract_catalog__", 1)
content = replaceRequiredOnce(t, content, catalogSource, catalogPath)
content = replaceRequiredOnce(t, content, "__extract_catalog__", catalogSource)
@@ -622,6 +622,10 @@ func maintainedExampleFiles(t *testing.T) []maintainedExample {
func productionSpellCatalogContractConfig(t *testing.T) string {
t.Helper()
catalogPath := filepath.Join(t.TempDir(), "spell-catalog.json")
if err := os.WriteFile(catalogPath, []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"aegis","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}]}}}`), 0o600); err != nil {
t.Fatal(err)
}
return fmt.Sprintf(`version: 6
pipelines:
dnd-session:
@@ -644,7 +648,7 @@ pipelines:
references:
spell_catalog:
path: %q
`, repositoryPath("examples", "dnd-complete", "party.txt"), repositoryPath("examples", "dnd-complete", "glossary.txt"), repositoryPath("examples", "dnd-complete", "spell-catalog.json"), repositoryPath("examples", "dnd-complete", "spell-catalog.json"))
`, repositoryPath("examples", "dnd-complete", "party.txt"), repositoryPath("examples", "dnd-complete", "glossary.txt"), catalogPath, catalogPath)
}
func writeProductionSpellCatalogContractConfig(t *testing.T) string {

View File

@@ -68,7 +68,7 @@ func TestMaterializedSpellCatalogOrderingPreservesSemanticContents(t *testing.T)
if err != nil {
t.Fatal(err)
}
if catalogA.Digest() != catalogB.Digest() || !reflect.DeepEqual(catalogA.OverlayIDs(), []string{"campaign.a", "campaign.b"}) || !reflect.DeepEqual(catalogB.OverlayIDs(), catalogA.OverlayIDs()) || !reflect.DeepEqual(catalogA.PromptSpells(), catalogB.PromptSpells()) {
if catalogA.Digest() != catalogB.Digest() || !reflect.DeepEqual(catalogA.CollectionNames(), []string{"spells"}) || !reflect.DeepEqual(catalogB.CollectionNames(), catalogA.CollectionNames()) || !reflect.DeepEqual(catalogA.PromptSpells(), catalogB.PromptSpells()) {
t.Fatal("catalog ordering changed semantic recognition")
}
}
@@ -76,7 +76,8 @@ func TestMaterializedSpellCatalogOrderingPreservesSemanticContents(t *testing.T)
func TestConfiguredSpellCatalogBindingChangesResolvedPipelineIdentity(t *testing.T) {
base := productionSpellCatalogContractConfig(t)
changed := strings.Replace(base, repositoryPath("examples", "dnd-complete", "spell-catalog.json"), filepath.Join(t.TempDir(), "alternate-spell-catalog.json"), 1)
source := loadMaintainedExample(t, writeProductionContractConfig(t, base)).Pipelines["dnd-session"].Artifacts["spells"].Extract.References["spell_catalog"].Path
changed := strings.Replace(base, source, filepath.Join(t.TempDir(), "alternate-spell-catalog.json"), 1)
if changed == base {
t.Fatal("production configuration did not contain the maintained catalog binding")
}
@@ -139,11 +140,11 @@ func TestProductionOverlayRunAlignsGroundingAndValidation(t *testing.T) {
}
const reorderedOverlayA = `{
"schema_version": "notarius.dnd.spell-catalog-overlay.v1",
"catalogs": [
{"id":"campaign.a","ruleset":"dnd-5e-2014","source":{"title":"Campaign A"},"spells":[{"name":"Aegis of Emberfall","aliases":["Emberfall Aegis"]}]},
{"id":"campaign.b","ruleset":"dnd-5e-2014","source":{"title":"Campaign B"},"spells":[{"name":"Cinder Veil","aliases":["Veil of Cinder","Cinder Shroud"]}]}
]
"schema_version": "maximumdirect.glossary.v1",
"collections": {"spells": {"entries": [
{"id":"a","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]},
{"id":"b","name":"Cinder Veil","category":"spell","aliases":["Veil of Cinder","Cinder Shroud"]}
]}}
}`
const reorderedOverlayB = `{"catalogs":[{"spells":[{"aliases":["Cinder Shroud","Veil of Cinder"],"name":"Cinder Veil"}],"source":{"title":"Campaign B"},"ruleset":"dnd-5e-2014","id":"campaign.b"},{"spells":[{"aliases":["Emberfall Aegis"],"name":"Aegis of Emberfall"}],"source":{"title":"Campaign A"},"ruleset":"dnd-5e-2014","id":"campaign.a"}],"schema_version":"notarius.dnd.spell-catalog-overlay.v1"}`
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"}`