Finalize structured diagnostic aggregation
This commit is contained in:
@@ -49,10 +49,10 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
}
|
||||
citedTexts[spellIndex] = citedText
|
||||
}
|
||||
var warnings []contracts.Warning
|
||||
var warnings []diagnostics.Finding
|
||||
for spellIndex, spell := range req.Value.SpellCasts {
|
||||
if !spellAppearsInCitedText(citedTexts[spellIndex], spell) {
|
||||
warnings = append(warnings, contracts.Warning{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)))})
|
||||
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)))})
|
||||
}
|
||||
}
|
||||
return diagnostics.DataQualityResult(warnings)
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestValidatorWarnsWhenSpellDoesNotAppearInCitedText(t *testing.T) {
|
||||
if !result.Approved {
|
||||
t.Fatalf("Approved = false, want true")
|
||||
}
|
||||
if len(result.Warnings) != 0 || len(result.Diagnostics) != 1 {
|
||||
if len(result.Diagnostics) != 1 {
|
||||
t.Fatalf("Diagnostics = %#v, want one advisory", result.Diagnostics)
|
||||
}
|
||||
if result.Diagnostics[0].ReasonCode != ReasonCode || result.Diagnostics[0].Disposition != contracts.DiagnosticDispositionAdvisory {
|
||||
@@ -81,7 +81,7 @@ func TestValidatorBoundsHighCardinalitySpellFindings(t *testing.T) {
|
||||
Source: &source.SourceDocument{ID: "session", Units: []source.SourceUnit{{ID: 1, Text: "The party waits."}}},
|
||||
Value: dnd.SpellList{SpellCasts: casts},
|
||||
})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 0 || len(result.Diagnostics) != 1 {
|
||||
if err != nil || !result.Approved || len(result.Diagnostics) != 1 {
|
||||
t.Fatalf("Validate() = %#v, %v", result, err)
|
||||
}
|
||||
diagnostic := result.Diagnostics[0]
|
||||
|
||||
Reference in New Issue
Block a user