Preserve diagnostic aggregation failures during finalization
This commit is contained in:
90
internal/framework/pipeline/runner_finalization_test.go
Normal file
90
internal/framework/pipeline/runner_finalization_test.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func overflowingInputDiagnostics() []contracts.ProducerDiagnostic {
|
||||
first := producerDiagnostic("first", "retained")
|
||||
first.OccurrenceCount = math.MaxInt
|
||||
first.OmittedSampleCount = math.MaxInt - 1
|
||||
second := producerDiagnostic("second", "overflow")
|
||||
second.ReasonCode = "another_reason"
|
||||
return []contracts.ProducerDiagnostic{first, second}
|
||||
}
|
||||
|
||||
func TestRunnerFinalizationPreservesPrefixAndExecutionFailure(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 1, orderedLaneSpec{"notes", "notes"})
|
||||
failure := errors.New("extraction failed")
|
||||
installExtractOperation(prepared, 0, func(context.Context, contracts.ExtractionInput) (erasedTypedResult, error) {
|
||||
return erasedTypedResult{}, failure
|
||||
})
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Diagnostics: overflowingInputDiagnostics()})
|
||||
if !errors.Is(err, failure) || !strings.Contains(err.Error(), "diagnostic occurrence count overflow") {
|
||||
t.Fatalf("Run() error = %v, want extraction failure and aggregation overflow", err)
|
||||
}
|
||||
if len(output.Diagnostics.Groups) != 1 || output.Diagnostics.Groups[0].OccurrenceCount != math.MaxInt {
|
||||
t.Fatalf("diagnostic prefix = %#v, want first group", output.Diagnostics.Groups)
|
||||
}
|
||||
if len(output.OutputFiles) != 0 {
|
||||
t.Fatal("failed run published output")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerFinalizationFailurePreventsEncoding(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 1, orderedLaneSpec{"notes", "notes"})
|
||||
encoder := &countingOrderedOutput{}
|
||||
prepared.output = encoder
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Diagnostics: overflowingInputDiagnostics()})
|
||||
if err == nil || !strings.Contains(err.Error(), "diagnostic occurrence count overflow") {
|
||||
t.Fatalf("Run() error = %v, want aggregation overflow", err)
|
||||
}
|
||||
if len(output.Diagnostics.Groups) != 1 || output.Diagnostics.Groups[0].OccurrenceCount != math.MaxInt {
|
||||
t.Fatalf("diagnostic prefix = %#v, want first group", output.Diagnostics.Groups)
|
||||
}
|
||||
if encoder.calls.Load() != 0 || len(output.OutputFiles) != 0 {
|
||||
t.Fatal("aggregation failure published output")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerFinalizationRetainsCancellation(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 1, orderedLaneSpec{"notes", "notes"})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
installExtractOperation(prepared, 0, func(context.Context, contracts.ExtractionInput) (erasedTypedResult, error) {
|
||||
cancel()
|
||||
return erasedTypedResult{}, context.Canceled
|
||||
})
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Diagnostics: overflowingInputDiagnostics()})
|
||||
if !errors.Is(err, context.Canceled) || !strings.Contains(err.Error(), "diagnostic occurrence count overflow") {
|
||||
t.Fatalf("Run() error = %v, want cancellation and aggregation overflow", err)
|
||||
}
|
||||
if len(output.Diagnostics.Groups) != 1 {
|
||||
t.Fatalf("diagnostic prefix = %#v, want first group", output.Diagnostics.Groups)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerFinalizationRetainsCaptureFailure(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 1, orderedLaneSpec{"notes", "notes"})
|
||||
cause := errors.New("capture failed")
|
||||
writer := &nativeEvidence{fail: func(name string) error {
|
||||
if name == "source/input.json" {
|
||||
return cause
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Diagnostics: overflowingInputDiagnostics(), Execution: contracts.ExecutionOptions{Capture: writer}})
|
||||
var captureErr *contracts.CaptureError
|
||||
if !errors.Is(err, cause) || !errors.As(err, &captureErr) || !strings.Contains(err.Error(), "diagnostic occurrence count overflow") {
|
||||
t.Fatalf("Run() error = %v, want capture failure and aggregation overflow", err)
|
||||
}
|
||||
if len(output.Diagnostics.Groups) != 1 {
|
||||
t.Fatalf("diagnostic prefix = %#v, want first group", output.Diagnostics.Groups)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user