Preserve native null aliases in prepared glossaries

This commit is contained in:
2026-11-27 21:18:00 +00:00
parent 447888e062
commit eb5e912fa3
7 changed files with 74 additions and 6 deletions

View File

@@ -322,6 +322,6 @@ Material: `internal/glossary/glossary-v1.schema.json`.
SPDX-License-Identifier: CC0-1.0 SPDX-License-Identifier: CC0-1.0
License and notices: [CC0 1.0](licenses/CC0-1.0.txt) | License and notices: [CC0 1.0](licenses/CC0-1.0.txt) |
[LICENSE](https://forge.maximumdirect.net/eric/narratio-reference-catalog/src/commit/ecad94a5a53f87847b1fd81fd042eee9c8d3ea08/LICENSE). [LICENSE](https://forge.maximumdirect.net/eric/narratio-reference-catalog/src/commit/a1a87edafd59a1de545a1c0b4efe5feeb80348e0/LICENSE).
[Source](https://forge.maximumdirect.net/eric/narratio-reference-catalog/src/commit/ecad94a5a53f87847b1fd81fd042eee9c8d3ea08). [Source](https://forge.maximumdirect.net/eric/narratio-reference-catalog/src/commit/a1a87edafd59a1de545a1c0b4efe5feeb80348e0).

View File

@@ -73,7 +73,14 @@ outcome where the selected value is invalid before domain selection.
Priority: P2 Priority: P2
Status: Pending Status: Complete
Catalog commit `a1a87edafd59a1de545a1c0b4efe5feeb80348e0` corrects
the canonical schema and format description. Narratio pins its verbatim copy
and updated notices. File/inline preparation tests preserve omitted, null, empty,
and populated aliases; schema tests retain invalid-type/null-scalar rejection.
Focused tests and controlled real-Audita/catalog compatibility checks passed
with Go 1.27.4, including native inspection/preflight with null aliases.
Affected stages: 1, 2, and 5. This is an inadvertently strengthened input Affected stages: 1, 2, and 5. This is an inadvertently strengthened input
restriction in the shared schema and its embedded copy. restriction in the shared schema and its embedded copy.

View File

@@ -180,7 +180,7 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
})) }))
defer server.Close() defer server.Close()
cfg := testConfig(t) cfg := testConfig(t)
mustWriteTestFile(t, *cfg.Session.Inputs.GlossaryFile, "campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Silver Watch, category: organization}]\n") mustWriteTestFile(t, *cfg.Session.Inputs.GlossaryFile, "campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Silver Watch, category: organization, aliases: null}]\n")
settingPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "setting.yml") settingPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "setting.yml")
spellsPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "spells.yml") spellsPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "spells.yml")
mustWriteTestFile(t, settingPath, "setting: {instruction: Preserve place names., entries: [{id: harbor, name: Harbor, category: place}]}\n") mustWriteTestFile(t, settingPath, "setting: {instruction: Preserve place names., entries: [{id: harbor, name: Harbor, category: place}]}\n")

View File

@@ -13,8 +13,64 @@ import (
"gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/config"
"gitea.maximumdirect.net/eric/narratio/internal/manifest" "gitea.maximumdirect.net/eric/narratio/internal/manifest"
"gitea.maximumdirect.net/eric/narratio/internal/stage" "gitea.maximumdirect.net/eric/narratio/internal/stage"
"gopkg.in/yaml.v3"
) )
func TestPreparedGlossaryAliasPresence(t *testing.T) {
for _, mode := range []string{"file", "inline"} {
for _, aliases := range []string{"", ", aliases: null", ", aliases: []", ", aliases: [Watcher]"} {
t.Run(mode+"/"+aliases, func(t *testing.T) {
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
entry := "{id: watch, name: Watch, category: person" + aliases + "}"
if mode == "file" {
mustWriteTestFile(t, filepath.Join(filepath.Dir(campaign), "glossary.yml"), "campaign: {entries: ["+entry+"]}\n")
} else {
mustWriteTestFile(t, session, "session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n glossary_file: null\n glossary: {entries: ["+entry+"]}\n")
}
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
if err != nil {
t.Fatal(err)
}
prepare, err := stage.Select("prepare")
if err != nil {
t.Fatal(err)
}
if _, err := executeStages(context.Background(), cfg, []stage.Stage{prepare}, RunOptions{}); err != nil {
t.Fatal(err)
}
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
data, err := os.ReadFile(filepath.Join(paths.InputsDir, "glossaries", "campaign.yml"))
if err != nil {
t.Fatal(err)
}
var doc map[string]struct {
Entries []map[string]any `yaml:"entries"`
}
if err := yaml.Unmarshal(data, &doc); err != nil {
t.Fatal(err)
}
entries := doc["campaign"].Entries
if len(entries) != 1 {
t.Fatalf("entries: %s", data)
}
value, present := entries[0]["aliases"]
if present != (aliases != "") {
t.Fatalf("presence lost: %s", data)
}
if aliases == ", aliases: null" && value != nil {
t.Fatalf("null lost: %s", data)
}
if aliases == ", aliases: []" && len(value.([]any)) != 0 {
t.Fatalf("empty list lost: %s", data)
}
if aliases == ", aliases: [Watcher]" && fmt.Sprint(value) != "[Watcher]" {
t.Fatalf("aliases lost: %s", data)
}
})
}
}
}
func TestSelectedCatalogSourcesBeforePreparation(t *testing.T) { func TestSelectedCatalogSourcesBeforePreparation(t *testing.T) {
for _, group := range []struct{ name, selector string }{{"settings", "setting"}, {"systems", "system"}} { for _, group := range []struct{ name, selector string }{{"settings", "setting"}, {"systems", "system"}} {
for _, tc := range []struct { for _, tc := range []struct {

View File

@@ -28,7 +28,7 @@
"type": "string" "type": "string"
}, },
"aliases": { "aliases": {
"type": "array", "type": ["array", "null"],
"items": { "items": {
"type": "string", "type": "string",
"minLength": 1 "minLength": 1

View File

@@ -49,7 +49,7 @@ func (entry Entry) MarshalJSON() ([]byte, error) {
} }
// CatalogRevision identifies the upstream source of the embedded schema. // CatalogRevision identifies the upstream source of the embedded schema.
const CatalogRevision = "ecad94a5a53f87847b1fd81fd042eee9c8d3ea08" const CatalogRevision = "a1a87edafd59a1de545a1c0b4efe5feeb80348e0"
//go:embed glossary-v1.schema.json //go:embed glossary-v1.schema.json
var schemaData []byte var schemaData []byte

View File

@@ -14,6 +14,11 @@ func TestValidation(t *testing.T) {
partial, valid bool partial, valid bool
}{ }{
{"empty", "party: {entries: []}", false, true}, {"empty", "party: {entries: []}", false, true},
{"null aliases", "party: {entries: [{id: a, name: A, category: person, aliases: null}]}", false, true},
{"invalid aliases", "party: {entries: [{id: a, name: A, category: person, aliases: wrong}]}", false, false},
{"invalid alias item", "party: {entries: [{id: a, name: A, category: person, aliases: [null]}]}", false, false},
{"null description", "party: {entries: [{id: a, name: A, category: person, description: null}]}", false, false},
{"null instruction", "party: {instruction: null, entries: []}", false, false},
{"missing entries", "party: {instruction: hi}", false, false}, {"missing entries", "party: {instruction: hi}", false, false},
{"instruction only", "instruction: hi", true, true}, {"instruction only", "instruction: hi", true, true},
{"optional and extensions", "party: {entries: [{id: a, name: A, category: person, aliases: [Alias], plural: People, description: text, extra: {rank: 2}}]}", false, true}, {"optional and extensions", "party: {entries: [{id: a, name: A, category: person, aliases: [Alias], plural: People, description: text, extra: {rank: 2}}]}", false, true},