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

@@ -17,7 +17,7 @@ func TestRunnerHandlesRetryableNormalizeFallbacks(t *testing.T) {
validator *preparedValidator
wantCalls int
wantItem string
wantWarnings []string
wantMessages []string
wantRejected int
wantDebug []string
wantCheckpoint int
@@ -30,7 +30,7 @@ func TestRunnerHandlesRetryableNormalizeFallbacks(t *testing.T) {
},
wantCalls: 1,
wantItem: "fallback",
wantWarnings: []string{"ordinary", "fallback-warning"},
wantMessages: []string{"ordinary", "fallback-warning"},
wantDebug: []string{`"another_attempt":false`, `"fallback_accepted":true`},
wantCheckpoint: 1,
},
@@ -41,11 +41,11 @@ func TestRunnerHandlesRetryableNormalizeFallbacks(t *testing.T) {
if attempt == 1 {
return retryableNormalizeResult("discarded", "discarded-ordinary", "discarded-fallback")
}
return erasedTypedResult{Value: codecNotes{Items: []string{"accepted"}}, Warnings: []contracts.Warning{{Scope: "accepted", ReasonCode: "ordinary", Message: "accepted-warning"}}}
return erasedTypedResult{Value: codecNotes{Items: []string{"accepted"}}, Diagnostics: []contracts.ProducerDiagnostic{producerDiagnostic("accepted", "accepted-warning")}}
},
wantCalls: 2,
wantItem: "accepted",
wantWarnings: []string{"accepted-warning"},
wantMessages: []string{"accepted-warning"},
wantDebug: []string{`"another_attempt":true`, `"fallback_accepted":false`},
wantCheckpoint: 1,
},
@@ -57,7 +57,7 @@ func TestRunnerHandlesRetryableNormalizeFallbacks(t *testing.T) {
},
wantCalls: 2,
wantItem: "fallback-2",
wantWarnings: []string{"ordinary-2", "fallback-warning-2"},
wantMessages: []string{"ordinary-2", "fallback-warning-2"},
wantDebug: []string{`"another_attempt":false`, `"fallback_accepted":true`},
wantCheckpoint: 1,
},
@@ -140,12 +140,14 @@ func TestRunnerHandlesRetryableNormalizeFallbacks(t *testing.T) {
if got := firstNote(normalized); got != tc.wantItem {
t.Fatalf("normalized item = %q, want %q", got, tc.wantItem)
}
gotWarnings := make([]string, len(output.Warnings))
for index, warning := range output.Warnings {
gotWarnings[index] = warning.Message
var gotMessages []string
for _, group := range output.Diagnostics.Groups {
for _, sample := range group.Samples {
gotMessages = append(gotMessages, sample.Message)
}
}
if strings.Join(gotWarnings, "|") != strings.Join(tc.wantWarnings, "|") {
t.Fatalf("durable warnings = %#v, want %#v", gotWarnings, tc.wantWarnings)
if strings.Join(gotMessages, "|") != strings.Join(tc.wantMessages, "|") {
t.Fatalf("durable diagnostics = %#v, want %#v", gotMessages, tc.wantMessages)
}
})
}
@@ -262,12 +264,12 @@ func TestRunnerValidatesNormalizeRetryDiagnostics(t *testing.T) {
func retryableNormalizeResult(item, ordinary, fallback string) erasedTypedResult {
return erasedTypedResult{
Value: codecNotes{Items: []string{item}},
Warnings: []contracts.Warning{{Scope: "attempt", ReasonCode: "ordinary", Message: ordinary}},
Value: codecNotes{Items: []string{item}},
Diagnostics: []contracts.ProducerDiagnostic{producerDiagnostic("attempt", ordinary)},
Retry: &contracts.NormalizeRetry{
ReasonCode: "retryable_normalization",
Message: "safe fallback is available",
FallbackWarnings: []contracts.Warning{{Scope: "fallback", ReasonCode: "fallback", Message: fallback}},
ReasonCode: "retryable_normalization",
Message: "safe fallback is available",
FallbackDiagnostics: []contracts.ProducerDiagnostic{producerDiagnostic("fallback", fallback)},
},
}
}