Bound D&D normalization diagnostics
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
|
||||
spellcatalog "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/spells/catalog"
|
||||
"golang.org/x/text/cases"
|
||||
)
|
||||
@@ -26,6 +27,7 @@ const (
|
||||
ReasonCodeSpellNameUnresolved = "spell_name_unresolved"
|
||||
ReasonCodeSourceReferencesNormalized = "source_references_normalized"
|
||||
ReasonCodeDuplicateSpellCastCollapsed = "duplicate_spell_cast_collapsed"
|
||||
ReasonCodeWarningsOmitted = "spell_normalization_warnings_omitted"
|
||||
)
|
||||
|
||||
var requiredCapabilities = []string{"merged"}
|
||||
@@ -102,7 +104,10 @@ func (n *Normalizer) Normalize(ctx context.Context, req contracts.TypedNormalize
|
||||
value, warnings := normalizeSpellList(req.MergeOutput.Value, n.effectiveCatalog, order)
|
||||
value, duplicateWarnings := collapseDuplicateSpellCasts(value, index, n.effectiveCatalog)
|
||||
warnings = append(warnings, duplicateWarnings...)
|
||||
return contracts.TypedNormalizeResult[dnd.SpellList]{Value: value, Warnings: warnings}, nil
|
||||
return contracts.TypedNormalizeResult[dnd.SpellList]{
|
||||
Value: value,
|
||||
Warnings: diagnostics.LimitWarnings(warnings, "spell_casts", ReasonCodeWarningsOmitted),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatalog, order shared.SourceRefOrder) (dnd.SpellList, []contracts.Warning) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
|
||||
spellcatalog "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/spells/catalog"
|
||||
)
|
||||
|
||||
@@ -162,6 +163,30 @@ func TestNormalizeCanonicalizesNamesAndReportsUnresolvedNames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeLimitsWarningsWithoutChangingSpellValues(t *testing.T) {
|
||||
input := dnd.SpellList{SpellCasts: make([]dnd.SpellCast, diagnostics.MaxWarnings+1)}
|
||||
for index := range input.SpellCasts {
|
||||
input.SpellCasts[index].Spell = fmt.Sprintf("Unknown Spell %d", index)
|
||||
}
|
||||
result, err := newNormalizer(t).Normalize(context.Background(), normalizeRequest(input))
|
||||
if err != nil {
|
||||
t.Fatalf("Normalize() error = %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(result.Value, input) {
|
||||
t.Fatalf("normalized value = %#v, want unresolved spell values preserved", result.Value)
|
||||
}
|
||||
if len(result.Warnings) != diagnostics.MaxWarnings {
|
||||
t.Fatalf("warning count = %d, want %d", len(result.Warnings), diagnostics.MaxWarnings)
|
||||
}
|
||||
if first := result.Warnings[0]; first.Scope != "spell_casts[0]" || first.ReasonCode != ReasonCodeSpellNameUnresolved {
|
||||
t.Fatalf("first warning = %#v, want first input warning", first)
|
||||
}
|
||||
summary := result.Warnings[len(result.Warnings)-1]
|
||||
if summary.Scope != "spell_casts" || summary.ReasonCode != ReasonCodeWarningsOmitted || summary.Message != "2 additional warning(s) omitted" {
|
||||
t.Fatalf("warning summary = %#v", summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeBoundsUnicodeNamesAndQuotesCanonicalReplacement(t *testing.T) {
|
||||
longName := strings.Repeat("火", 140)
|
||||
reference := spellCatalogReference(fmt.Sprintf(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v1","catalogs":[{"id":"campaign.long","ruleset":"dnd-5e-2014","source":{"title":"Private campaign source"},"spells":[{"name":%q,"aliases":["long alias"]}]}]}`, longName))
|
||||
|
||||
Reference in New Issue
Block a user