Flatten Notarius readiness failure aggregation

This commit is contained in:
2026-11-30 17:07:48 +00:00
parent f292edfe5c
commit c11b4ac309
3 changed files with 52 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package preflight
import (
"context"
"errors"
"os"
"strings"
"testing"
@@ -65,6 +66,43 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
}
}
func TestNotariusPreservesMultipleFailuresAndAdapterCause(t *testing.T) {
cause := errors.New("provider unavailable")
adapterErr := &os.PathError{Op: "probe", Path: "synthetic", Err: cause}
fake := &notarius.FakeRunner{PreflightErr: adapterErr, PreflightResult: &notarius.ReadinessResult{
Checks: []notarius.ReadinessCheck{
{ID: "provider", Result: "failed", Message: "provider check failed"},
{ID: "output", Result: "failed", Message: "output check failed"},
{ID: "cache", Result: "warning", Message: "cache unavailable"},
},
}}
result, err := CheckNotarius(context.Background(), fake, notarius.ReadinessRequest{})
var typed *os.PathError
if !errors.Is(err, cause) || !errors.As(err, &typed) || typed != adapterErr {
t.Fatalf("adapter cause lost: %v", err)
}
for _, message := range []string{"provider check failed", "output check failed"} {
if !strings.Contains(err.Error(), message) {
t.Fatalf("missing failure %q: %v", message, err)
}
}
for _, check := range fake.PreflightResult.Checks {
found := false
for _, finding := range result.Findings {
if finding.Name == check.ID && finding.Message == check.Message {
want := SeverityError
if check.Result == "warning" {
want = SeverityWarning
}
found = finding.Severity == want
}
}
if !found {
t.Fatalf("missing or reclassified check %q: %+v", check.ID, result.Findings)
}
}
}
func TestAuditaPreservesFailureAndCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
failure := errors.New("provider failure")