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

@@ -46,6 +46,10 @@ func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, reque
return result, fmt.Errorf("notarius preflight checker is required")
}
assessment, err := checker.Preflight(ctx, request)
var failures []error
if err != nil {
failures = append(failures, err)
}
if assessment.InputDescription != "" {
result.Findings = append(result.Findings, Finding{Severity: SeverityInfo, Stage: "extract", Message: "Notarius checked " + assessment.InputDescription + ": " + assessment.InputPath})
}
@@ -59,7 +63,7 @@ func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, reque
}
if check.Result == "failed" {
severity = SeverityError
err = errors.Join(err, fmt.Errorf("Notarius check %q failed: %s", check.ID, check.Message))
failures = append(failures, fmt.Errorf("Notarius check %q failed: %s", check.ID, check.Message))
}
if severity != SeverityInfo {
message := check.Message
@@ -69,6 +73,7 @@ func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, reque
result.Findings = append(result.Findings, Finding{Severity: severity, Stage: "extract", IssueCode: check.Code, Name: check.ID, Message: message})
}
}
err = errors.Join(failures...)
if err == nil && (!assessment.InspectionComplete || !assessment.AssessmentComplete || assessment.Pipeline != request.PipelineID || !assessment.Ready) {
err = fmt.Errorf("notarius readiness is incomplete or not ready for pipeline %q", request.PipelineID)
}

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")