Harden diagnostic handling and warning presentation

This commit is contained in:
2026-08-27 18:41:59 +00:00
parent 1025001f20
commit 079d5af337
67 changed files with 518 additions and 318 deletions

View File

@@ -49,13 +49,13 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
}
citedTexts[spellIndex] = citedText
}
var warnings []diagnostics.Finding
var findings []diagnostics.Finding
for spellIndex, spell := range req.Value.SpellCasts {
if !spellAppearsInCitedText(citedTexts[spellIndex], spell) {
warnings = append(warnings, diagnostics.Finding{Scope: fmt.Sprintf("spell_casts[%d]", spellIndex), ReasonCode: ReasonCode, Message: fmt.Sprintf("spell %s was not found in cited source text", diagnostics.Quote(strings.TrimSpace(spell.Spell)))})
findings = append(findings, diagnostics.Finding{Scope: fmt.Sprintf("spell_casts[%d]", spellIndex), ReasonCode: ReasonCode, Message: fmt.Sprintf("spell %s was not found in cited source text", diagnostics.Quote(strings.TrimSpace(spell.Spell)))})
}
}
return diagnostics.DataQualityResult(warnings)
return diagnostics.DataQualityResult(findings)
}
func spellAppearsInCitedText(citedText string, spell dnd.SpellCast) bool {
name := strings.TrimSpace(spell.Spell)

View File

@@ -10,7 +10,7 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
)
func TestValidatorApprovesWithoutWarningWhenSpellAppearsInCitedText(t *testing.T) {
func TestValidatorApprovesWithoutAdvisoryWhenSpellAppearsInCitedText(t *testing.T) {
result, err := New(Options{}).Validate(context.Background(), requestWithSpell(validDocument(), "Cure Wounds", 2))
if err != nil {
t.Fatalf("Validate() error = %v, want nil", err)
@@ -99,7 +99,7 @@ func TestValidatorIgnoresInvalidCitations(t *testing.T) {
}
}
func TestValidatorApprovesEmptySpellListWithoutWarning(t *testing.T) {
func TestValidatorApprovesEmptySpellListWithoutAdvisory(t *testing.T) {
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.SpellList]{Source: validDocument(), Value: dnd.SpellList{SpellCasts: []dnd.SpellCast{}}})
if err != nil {
t.Fatalf("Validate() error = %v, want nil", err)