Factor the Audita readiness check
This commit is contained in:
@@ -21,6 +21,23 @@ type Targets struct {
|
||||
Scriptorium []Target
|
||||
}
|
||||
|
||||
// CheckAudita runs the native provider check and retains its failure finding.
|
||||
func CheckAudita(ctx context.Context, checker AuditaChecker, request audita.PolishRequest) (Result, error) {
|
||||
var result Result
|
||||
if err := ctx.Err(); err != nil {
|
||||
return result, err
|
||||
}
|
||||
if checker == nil {
|
||||
return result, fmt.Errorf("audita preflight checker is required")
|
||||
}
|
||||
_, err := checker.Preflight(ctx, request)
|
||||
if err != nil {
|
||||
result.Findings = append(result.Findings, Finding{Severity: SeverityError, Stage: "polish", Message: "audita preflight: " + err.Error()})
|
||||
return result, errors.Join(fmt.Errorf("audita preflight: %w", err), ctx.Err())
|
||||
}
|
||||
return result, ctx.Err()
|
||||
}
|
||||
|
||||
// CheckNotarius retains native warnings and incomplete evidence separately
|
||||
// from the success decision; a ready assessment never overrides process failure.
|
||||
func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, request notarius.ReadinessRequest) (Result, error) {
|
||||
@@ -83,16 +100,7 @@ func CheckDownstream(ctx context.Context, inspector Inspector, checker AuditaChe
|
||||
if !targets.Polish {
|
||||
return result, scriptErr
|
||||
}
|
||||
if checker == nil {
|
||||
return result, errors.Join(scriptErr, fmt.Errorf("audita preflight checker is required"))
|
||||
}
|
||||
_, err := checker.Preflight(ctx, polish)
|
||||
if err != nil {
|
||||
result.Findings = append(result.Findings, Finding{Severity: SeverityError, Stage: "polish", Message: "audita preflight: " + err.Error()})
|
||||
return result, errors.Join(scriptErr, fmt.Errorf("audita preflight: %w", err))
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return result, errors.Join(scriptErr, err)
|
||||
}
|
||||
return result, scriptErr
|
||||
auditaResult, auditaErr := CheckAudita(ctx, checker, polish)
|
||||
result.Findings = append(result.Findings, auditaResult.Findings...)
|
||||
return result, errors.Join(scriptErr, auditaErr)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
||||
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
||||
return audita.PreflightResult{ExitCode: 2}, failure
|
||||
})
|
||||
result, err := CheckDownstream(context.Background(), nil, checker, Targets{Polish: true}, audita.PolishRequest{})
|
||||
result, err := CheckAudita(context.Background(), checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, failure) || len(result.Findings) != 1 || result.Findings[0].Severity != SeverityError || !strings.Contains(result.Findings[0].Message, "provider refused") {
|
||||
t.Fatalf("failure: %+v %v", result, err)
|
||||
}
|
||||
@@ -87,8 +87,21 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
||||
called = true
|
||||
return audita.PreflightResult{}, nil
|
||||
})
|
||||
_, err = CheckDownstream(ctx, nil, checker, Targets{Polish: true}, audita.PolishRequest{})
|
||||
_, err = CheckAudita(ctx, checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, context.Canceled) || called {
|
||||
t.Fatalf("cancellation: called=%v err=%v", called, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditaPreservesFailureAndCancellation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
failure := errors.New("provider failure")
|
||||
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
||||
cancel()
|
||||
return audita.PreflightResult{}, failure
|
||||
})
|
||||
result, err := CheckAudita(ctx, checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, failure) || !errors.Is(err, context.Canceled) || len(result.Findings) != 1 || result.Findings[0].Severity != SeverityError {
|
||||
t.Fatalf("result = %+v, error = %v", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user