Finalize structured diagnostic aggregation

This commit is contained in:
2026-08-27 16:40:17 +00:00
parent 480680b257
commit 4dbbf68051
112 changed files with 656 additions and 893 deletions

View File

@@ -2,7 +2,6 @@ package diagnostics
import (
"fmt"
"reflect"
"strings"
"testing"
"unicode/utf8"
@@ -30,30 +29,8 @@ func TestAggregateEnforcesByteBudgetAndReportsOmissions(t *testing.T) {
}
}
func TestLimitWarningsBoundsOutputAndReportsOmissions(t *testing.T) {
warnings := make([]contracts.Warning, MaxWarnings+3)
for index := range warnings {
warnings[index] = contracts.Warning{ReasonCode: fmt.Sprintf("warning-%d", index)}
}
before := append([]contracts.Warning(nil), warnings...)
got := LimitWarnings(warnings, "records", "warnings_omitted")
if len(got) != MaxWarnings {
t.Fatalf("LimitWarnings() count = %d, want %d", len(got), MaxWarnings)
}
summary := got[len(got)-1]
wantOmitted := len(warnings) - (MaxWarnings - 1)
if summary.Scope != "records" || summary.ReasonCode != "warnings_omitted" ||
summary.Message != fmt.Sprintf("%d additional warning(s) omitted", wantOmitted) {
t.Fatalf("summary = %#v", summary)
}
if !reflect.DeepEqual(warnings, before) {
t.Fatal("LimitWarnings() mutated its input")
}
}
func TestDataQualityResultGroupsFindingsWithoutWarnings(t *testing.T) {
result, err := DataQualityResult([]contracts.Warning{
result, err := DataQualityResult([]Finding{
{Scope: "records[0]", ReasonCode: "not_near_source", Message: "first"},
{Scope: "records[0]", ReasonCode: "not_near_source", Message: "first"},
{Scope: "records[1]", ReasonCode: "not_near_source", Message: "second"},
@@ -61,7 +38,7 @@ func TestDataQualityResultGroupsFindingsWithoutWarnings(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !result.Approved || len(result.Warnings) != 0 || len(result.Diagnostics) != 1 {
if !result.Approved || len(result.Diagnostics) != 1 {
t.Fatalf("result = %#v", result)
}
diagnostic := result.Diagnostics[0]
@@ -71,9 +48,9 @@ func TestDataQualityResultGroupsFindingsWithoutWarnings(t *testing.T) {
}
func TestCollectGroupsNormalizationFindingsWithBoundedSamples(t *testing.T) {
findings := make([]contracts.Warning, 5)
findings := make([]Finding, 5)
for index := range findings {
findings[index] = contracts.Warning{
findings[index] = Finding{
Scope: fmt.Sprintf("records[%d]", index),
ReasonCode: "record_normalized",
Message: fmt.Sprintf("record %d normalized", index),
@@ -94,7 +71,7 @@ func TestCollectGroupsNormalizationFindingsWithBoundedSamples(t *testing.T) {
}
func TestNormalizationDiagnosticsCombinesQualityAndCleanupWithoutWarnings(t *testing.T) {
groups, err := NormalizationDiagnostics([]contracts.Warning{
groups, err := NormalizationDiagnostics([]Finding{
{Scope: "spell_casts[0]", ReasonCode: "spell_name_canonicalized", Message: "canonicalized spell name"},
{Scope: "spell_casts[1]", ReasonCode: "spell_name_unresolved", Message: "spell was not in the catalog"},
}, "spell_name_unresolved")