diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 31fae77..0b821bb 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -26,7 +26,14 @@ adding caches, parallelism, limits, or new readiness requirements. ## 1. Flatten Notarius Failure Aggregation -Status: Open for consideration. Priority: P3. +Status: Complete. Priority: P3. + +Completion: `CheckNotarius` now collects adapter and failed-check errors and +joins them once. Diagnostic rendering is linear in total message length rather +than repeatedly copying nested prefixes. Added coverage for multiple failed +checks, preserved warning severity, and typed adapter causes. Verified with +Go 1.27.4: `go test ./internal/preflight ./internal/adapters/notarius` and +`git diff --check`. Evidence: [CheckNotarius](../../internal/preflight/downstream.go), especially lines 55–62 and 87–89. The loop assigns diff --git a/internal/preflight/downstream.go b/internal/preflight/downstream.go index 07a0596..9845588 100644 --- a/internal/preflight/downstream.go +++ b/internal/preflight/downstream.go @@ -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) } diff --git a/internal/preflight/downstream_test.go b/internal/preflight/downstream_test.go index d2b3ffc..b458e6c 100644 --- a/internal/preflight/downstream_test.go +++ b/internal/preflight/downstream_test.go @@ -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 := ¬arius.FakeRunner{PreflightErr: adapterErr, PreflightResult: ¬arius.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")