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

@@ -146,7 +146,7 @@ func TestEncodeReturnsLogicalFilesForNormalizedOutputs(t *testing.T) {
ValidatorName: "validator",
},
},
Warnings: []contracts.Warning{{ReasonCode: "warning", Message: "check source"}},
Diagnostics: warningDiagnostics("warning", "check source"),
}
result, err := New().Encode(context.Background(), req)
@@ -211,7 +211,7 @@ func TestEncodeIncludesRejectedAndWarningsWhenEmpty(t *testing.T) {
t.Fatalf("rejected = %#v, want empty array", got)
}
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
if got := warnings["warnings"].([]any); len(got) != 0 {
if got := warnings["groups"].([]any); len(got) != 0 {
t.Fatalf("warnings = %#v, want empty array", got)
}
}
@@ -665,7 +665,7 @@ func TestEncodeDoesNotMutateInputs(t *testing.T) {
Rejected: []contracts.RejectedOutput{
{Stage: "extract", LaneID: "spells", Message: "not accepted"},
},
Warnings: []contracts.Warning{{ReasonCode: "warning", Message: "message"}},
Diagnostics: warningDiagnostics("warning", "message"),
}
before := mustMarshal(t, req)
@@ -681,14 +681,14 @@ func TestEncodeDoesNotMutateInputs(t *testing.T) {
req.NormalizeOutputs[0].Artifact.Content[0] = '['
req.NormalizeOutputs[0].Artifact.Metadata["name"] = "changed"
req.Rejected[0].Message = "changed"
req.Warnings[0].Message = "changed"
req.Diagnostics.Groups[0].Samples[0].Message = "changed"
if !stdjson.Valid(fileBytes(t, result.Files, "lanes/spells.json")) {
t.Fatal("output changed after request mutation")
}
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
gotWarnings := warnings["warnings"].([]any)
if gotWarnings[0].(map[string]any)["message"] != "message" {
gotWarnings := warnings["groups"].([]any)
if gotWarnings[0].(map[string]any)["samples"].([]any)[0].(map[string]any)["message"] != "message" {
t.Fatalf("warnings output changed after request mutation: %#v", gotWarnings)
}
}
@@ -696,9 +696,7 @@ func TestEncodeDoesNotMutateInputs(t *testing.T) {
func TestOutputFilesDoNotContainWarnings(t *testing.T) {
result, err := New().Encode(context.Background(), contracts.OutputRequest{
NormalizeOutputs: []contracts.SerializedOutput{normalizeOutput("spells", `{"spell":"Shield"}`)},
Warnings: []contracts.Warning{
{ReasonCode: "pipeline-warning", Message: "warning"},
},
Diagnostics: warningDiagnostics("pipeline-warning", "warning"),
})
if err != nil {
t.Fatalf("Encode() error = %v, want nil", err)
@@ -710,6 +708,17 @@ func TestOutputFilesDoNotContainWarnings(t *testing.T) {
}
}
func warningDiagnostics(reasonCode, message string) contracts.DiagnosticCollection {
return contracts.DiagnosticCollection{Groups: []contracts.DiagnosticGroup{{
Disposition: contracts.DiagnosticDispositionWarning,
Category: contracts.DiagnosticCategoryDegradation,
ReasonCode: reasonCode,
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageChunk},
OccurrenceCount: 1,
Samples: []contracts.DiagnosticSample{{Scope: "test", Message: message}},
}}}
}
func normalizeOutput(laneID string, content string) contracts.SerializedOutput {
return contracts.SerializedOutput{
LaneID: laneID,