Factor the Audita readiness check
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Standalone Session Preflight Implementation Plan
|
# Standalone Session Preflight Implementation Plan
|
||||||
|
|
||||||
Status: Planned; implementation has not begun.
|
Status: In progress.
|
||||||
|
|
||||||
## Scope And Working Instructions
|
## Scope And Working Instructions
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ this sprint.
|
|||||||
|
|
||||||
## Stage 1: Factor Native Check Operations And Preserve Findings
|
## Stage 1: Factor Native Check Operations And Preserve Findings
|
||||||
|
|
||||||
Status: Pending.
|
Status: Complete. Verified with `GOTOOLCHAIN=go1.27.4 go test ./internal/preflight ./internal/adapters/audita ./internal/adapters/notarius` and `git diff --check`.
|
||||||
|
|
||||||
Read `internal/preflight/{types,check,downstream}.go`, their tests, and
|
Read `internal/preflight/{types,check,downstream}.go`, their tests, and
|
||||||
[Preflight Internals](../internal/preflight.md). Inspect the Audita and Notarius
|
[Preflight Internals](../internal/preflight.md). Inspect the Audita and Notarius
|
||||||
|
|||||||
@@ -21,6 +21,23 @@ type Targets struct {
|
|||||||
Scriptorium []Target
|
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
|
// CheckNotarius retains native warnings and incomplete evidence separately
|
||||||
// from the success decision; a ready assessment never overrides process failure.
|
// from the success decision; a ready assessment never overrides process failure.
|
||||||
func CheckNotarius(ctx context.Context, checker notarius.ReadinessChecker, request notarius.ReadinessRequest) (Result, error) {
|
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 {
|
if !targets.Polish {
|
||||||
return result, scriptErr
|
return result, scriptErr
|
||||||
}
|
}
|
||||||
if checker == nil {
|
auditaResult, auditaErr := CheckAudita(ctx, checker, polish)
|
||||||
return result, errors.Join(scriptErr, fmt.Errorf("audita preflight checker is required"))
|
result.Findings = append(result.Findings, auditaResult.Findings...)
|
||||||
}
|
return result, errors.Join(scriptErr, auditaErr)
|
||||||
_, 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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
|||||||
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
||||||
return audita.PreflightResult{ExitCode: 2}, failure
|
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") {
|
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)
|
t.Fatalf("failure: %+v %v", result, err)
|
||||||
}
|
}
|
||||||
@@ -87,8 +87,21 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
|||||||
called = true
|
called = true
|
||||||
return audita.PreflightResult{}, nil
|
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 {
|
if !errors.Is(err, context.Canceled) || called {
|
||||||
t.Fatalf("cancellation: called=%v err=%v", called, err)
|
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