Classify remaining D&D producer diagnostics
This commit is contained in:
@@ -25,7 +25,6 @@ const (
|
||||
ReasonCodeSourceRefsNormalized = "source_references_normalized"
|
||||
ReasonCodeEventsReordered = "enemy_events_reordered"
|
||||
ReasonCodeDuplicateCollapsed = "duplicate_enemy_event_collapsed"
|
||||
ReasonCodeWarningsOmitted = "enemy_event_normalization_warnings_omitted"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -106,7 +105,11 @@ func (n *Normalizer) Normalize(ctx context.Context, req contracts.TypedNormalize
|
||||
index := source.NewDocumentIndex(req.Source)
|
||||
order := shared.NewSourceRefOrderFromIndex(index)
|
||||
value, warnings := normalizeList(req.MergeOutput.Value, order, registry)
|
||||
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{Value: value, Warnings: warnings}, nil
|
||||
diagnosticGroups, err := diagnostics.NormalizationDiagnostics(warnings)
|
||||
if err != nil {
|
||||
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{}, normalizerErrorf("collect diagnostics: %w", err)
|
||||
}
|
||||
return contracts.TypedNormalizeResult[dnd.EnemyEventList]{Value: value, Diagnostics: diagnosticGroups}, nil
|
||||
}
|
||||
|
||||
type normalizedRecord struct {
|
||||
@@ -163,7 +166,7 @@ func normalizeList(input dnd.EnemyEventList, order shared.SourceRefOrder, regist
|
||||
|
||||
output, duplicateWarnings := collapseDuplicates(records)
|
||||
warnings = append(warnings, duplicateWarnings...)
|
||||
return dnd.EnemyEventList{Events: output}, diagnostics.LimitWarnings(warnings, "enemy_events", ReasonCodeWarningsOmitted)
|
||||
return dnd.EnemyEventList{Events: output}, warnings
|
||||
}
|
||||
|
||||
func normalizeEvent(input dnd.EnemyEvent, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.EnemyEvent, *nameCanonicalization, bool) {
|
||||
|
||||
@@ -38,8 +38,8 @@ func TestNormalizeCanonicalizesSubjectsEvidenceOrderAndDuplicates(t *testing.T)
|
||||
t.Fatalf("normalized events = %#v", got)
|
||||
}
|
||||
for _, reason := range []string{ReasonCodeNameCanonicalized, ReasonCodeSourceRefsNormalized, ReasonCodeEventsReordered, ReasonCodeDuplicateCollapsed} {
|
||||
if !hasWarning(result.Warnings, reason) {
|
||||
t.Fatalf("warnings = %#v, missing %q", result.Warnings, reason)
|
||||
if !hasDiagnostic(result.Diagnostics, reason) {
|
||||
t.Fatalf("diagnostics = %#v, missing %q", result.Diagnostics, reason)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(input.Events[0].SourceRefs, originalRefs) {
|
||||
@@ -93,7 +93,7 @@ func TestNormalizePreservesDistinctEvidenceWhenEncodedKeysCoincide(t *testing.T)
|
||||
}}
|
||||
|
||||
result, err := newNormalizer(t, npcReferences(t)).Normalize(context.Background(), normalizeRequest(document, input, contracts.ReferenceSet{}))
|
||||
if err != nil || len(result.Value.Events) != 2 || hasWarning(result.Warnings, ReasonCodeDuplicateCollapsed) {
|
||||
if err != nil || len(result.Value.Events) != 2 || hasDiagnostic(result.Diagnostics, ReasonCodeDuplicateCollapsed) {
|
||||
t.Fatalf("Normalize() = %#v, %v; want distinct evidence observations retained", result, err)
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func TestNormalizeIsIdempotentAndPreservesEmptyRepresentation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := normalizer.Normalize(context.Background(), normalizeRequest(testDocument(), first.Value, contracts.ReferenceSet{}))
|
||||
if err != nil || !reflect.DeepEqual(second.Value, first.Value) || len(second.Warnings) != 0 {
|
||||
if err != nil || !reflect.DeepEqual(second.Value, first.Value) || len(second.Diagnostics) != 0 {
|
||||
t.Fatalf("second normalization = %#v, %v", second, err)
|
||||
}
|
||||
}
|
||||
@@ -170,8 +170,8 @@ func TestNormalizerContractAndWarningBound(t *testing.T) {
|
||||
input.Events[index] = dnd.EnemyEvent{Name: " ÁRIA ", Kind: dnd.EnemyEventKindEngaged, SourceRefs: []source.SourceRef{{SourceID: document.ID, StartUnitID: count - index, EndUnitID: count - index}}}
|
||||
}
|
||||
result, err := normalizer.Normalize(context.Background(), normalizeRequest(document, input, contracts.ReferenceSet{}))
|
||||
if err != nil || len(result.Warnings) != diagnostics.MaxWarnings || result.Warnings[len(result.Warnings)-1].ReasonCode != ReasonCodeWarningsOmitted {
|
||||
t.Fatalf("warnings = %#v, %v", result.Warnings, err)
|
||||
if err != nil || len(result.Warnings) != 0 || len(result.Diagnostics) == 0 {
|
||||
t.Fatalf("diagnostics = %#v, %v", result.Diagnostics, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +212,9 @@ func npcReferences(t *testing.T) contracts.ReferenceSet {
|
||||
}}}
|
||||
}
|
||||
|
||||
func hasWarning(warnings []contracts.Warning, reason string) bool {
|
||||
for _, warning := range warnings {
|
||||
if warning.ReasonCode == reason {
|
||||
func hasDiagnostic(diagnostics []contracts.ProducerDiagnostic, reason string) bool {
|
||||
for _, diagnostic := range diagnostics {
|
||||
if diagnostic.ReasonCode == reason && diagnostic.Disposition == contracts.DiagnosticDispositionObservation {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user