Publish grouped warning and diagnostic files

This commit is contained in:
2026-08-27 16:43:09 +00:00
parent 4dbbf68051
commit 54de2b816a
5 changed files with 193 additions and 20 deletions

View File

@@ -155,6 +155,7 @@ func TestEncodeReturnsLogicalFilesForNormalizedOutputs(t *testing.T) {
}
wantNames := []string{
"diagnostics.json",
"index.json",
"lanes/notes_items.json",
"lanes/spells.json",
@@ -216,6 +217,49 @@ func TestEncodeIncludesRejectedAndWarningsWhenEmpty(t *testing.T) {
}
}
func TestEncodePublishesVersionedDiagnosticPartitions(t *testing.T) {
diagnostics := contracts.DiagnosticCollection{
Groups: []contracts.DiagnosticGroup{
{
Disposition: contracts.DiagnosticDispositionWarning,
Category: contracts.DiagnosticCategoryDegradation,
ReasonCode: "degraded",
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageChunk},
OccurrenceCount: 2,
Samples: []contracts.DiagnosticSample{{Scope: "chunk", Message: "degraded"}},
OmittedSampleCount: 1,
},
{
Disposition: contracts.DiagnosticDispositionAdvisory,
Category: contracts.DiagnosticCategoryDataQuality,
ReasonCode: "unrelated",
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageExtract},
OccurrenceCount: 3,
Samples: []contracts.DiagnosticSample{{Scope: "items[0]", Message: "unrelated"}},
OmittedSampleCount: 2,
},
},
Truncated: true,
UnrepresentedOccurrenceCount: 5,
}
result, err := New().Encode(context.Background(), contracts.OutputRequest{Diagnostics: diagnostics})
if err != nil {
t.Fatalf("Encode() error = %v", err)
}
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
if warnings["schema_version"] != warningsSchemaVersion || warnings["group_count"] != float64(1) || warnings["occurrence_count"] != float64(2) || len(warnings["groups"].([]any)) != 1 {
t.Fatalf("warnings file = %#v", warnings)
}
publishedDiagnostics := decodeObject(t, fileBytes(t, result.Files, "diagnostics.json"))
if publishedDiagnostics["schema_version"] != diagnosticsSchemaVersion || publishedDiagnostics["group_count"] != float64(1) || publishedDiagnostics["occurrence_count"] != float64(8) || publishedDiagnostics["truncated"] != true || publishedDiagnostics["unrepresented_occurrence_count"] != float64(5) || len(publishedDiagnostics["groups"].([]any)) != 1 {
t.Fatalf("diagnostics file = %#v", publishedDiagnostics)
}
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
if index["warnings_file"] != "warnings.json" || index["diagnostics_file"] != "diagnostics.json" {
t.Fatalf("index = %#v", index)
}
}
func TestEncodeChunkMapExportIsOptIn(t *testing.T) {
artifact := acceptedChunkMapArtifact(t)
request := contracts.OutputRequest{
@@ -234,7 +278,7 @@ func TestEncodeChunkMapExportIsOptIn(t *testing.T) {
if err != nil {
t.Fatalf("Encode() error = %v, want nil", err)
}
if got, want := outputFileNames(result.Files), []string{"index.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
if got, want := outputFileNames(result.Files), []string{"diagnostics.json", "index.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
t.Fatalf("file names = %#v, want %#v", got, want)
}
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
@@ -257,7 +301,7 @@ func TestEncodeIncludesValidatedChunkMap(t *testing.T) {
if err != nil {
t.Fatalf("Encode() error = %v, want nil", err)
}
if got, want := outputFileNames(result.Files), []string{"chunk-map.json", "index.json", "lanes/spells.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
if got, want := outputFileNames(result.Files), []string{"chunk-map.json", "diagnostics.json", "index.json", "lanes/spells.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
t.Fatalf("file names = %#v, want %#v", got, want)
}
chunkMapFile := fileBytes(t, result.Files, chunkMapFileName)