Flatten Notarius readiness failure aggregation
This commit is contained in:
@@ -26,7 +26,14 @@ adding caches, parallelism, limits, or new readiness requirements.
|
|||||||
|
|
||||||
## 1. Flatten Notarius Failure Aggregation
|
## 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
|
Evidence: [CheckNotarius](../../internal/preflight/downstream.go), especially
|
||||||
lines 55–62 and 87–89. The loop assigns
|
lines 55–62 and 87–89. The loop assigns
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, reque
|
|||||||
return result, fmt.Errorf("notarius preflight checker is required")
|
return result, fmt.Errorf("notarius preflight checker is required")
|
||||||
}
|
}
|
||||||
assessment, err := checker.Preflight(ctx, request)
|
assessment, err := checker.Preflight(ctx, request)
|
||||||
|
var failures []error
|
||||||
|
if err != nil {
|
||||||
|
failures = append(failures, err)
|
||||||
|
}
|
||||||
if assessment.InputDescription != "" {
|
if assessment.InputDescription != "" {
|
||||||
result.Findings = append(result.Findings, Finding{Severity: SeverityInfo, Stage: "extract", Message: "Notarius checked " + assessment.InputDescription + ": " + assessment.InputPath})
|
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" {
|
if check.Result == "failed" {
|
||||||
severity = SeverityError
|
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 {
|
if severity != SeverityInfo {
|
||||||
message := check.Message
|
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})
|
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) {
|
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)
|
err = fmt.Errorf("notarius readiness is incomplete or not ready for pipeline %q", request.PipelineID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package preflight
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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) {
|
func TestAuditaPreservesFailureAndCancellation(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
failure := errors.New("provider failure")
|
failure := errors.New("provider failure")
|
||||||
|
|||||||
Reference in New Issue
Block a user