Add native Notarius readiness checks
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notarius"
|
||||
)
|
||||
|
||||
// AuditaChecker performs native processing preflight.
|
||||
@@ -16,9 +17,63 @@ type AuditaChecker interface {
|
||||
// Targets identifies downstream checks selected for this invocation.
|
||||
type Targets struct {
|
||||
Polish bool
|
||||
Notarius bool
|
||||
Scriptorium []Target
|
||||
}
|
||||
|
||||
// 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) {
|
||||
result := Result{}
|
||||
if checker == nil {
|
||||
return result, fmt.Errorf("notarius preflight checker is required")
|
||||
}
|
||||
assessment, err := checker.Preflight(ctx, request)
|
||||
if assessment.InputDescription != "" {
|
||||
result.Findings = append(result.Findings, Finding{Severity: SeverityInfo, Stage: "extract", Message: "Notarius checked " + assessment.InputDescription + ": " + assessment.InputPath})
|
||||
}
|
||||
if assessment.DebugDirectory != "" {
|
||||
result.Findings = append(result.Findings, Finding{Severity: SeverityInfo, Stage: "extract", Message: "Notarius preflight debug: " + assessment.DebugDirectory})
|
||||
}
|
||||
for _, check := range assessment.Checks {
|
||||
severity := SeverityInfo
|
||||
if check.Result == "warning" {
|
||||
severity = SeverityWarning
|
||||
}
|
||||
if check.Result == "failed" {
|
||||
severity = SeverityError
|
||||
err = errors.Join(err, fmt.Errorf("Notarius check %q failed: %s", check.ID, check.Message))
|
||||
}
|
||||
if severity != SeverityInfo {
|
||||
message := check.Message
|
||||
if len(check.Scope) > 0 && string(check.Scope) != "{}" {
|
||||
message += " (scope=" + string(check.Scope) + ")"
|
||||
}
|
||||
result.Findings = append(result.Findings, Finding{Severity: severity, Stage: "extract", IssueCode: check.Code, Name: check.ID, Message: message})
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
if err == nil {
|
||||
available := make(map[string]bool, len(assessment.Lanes))
|
||||
for _, lane := range assessment.Lanes {
|
||||
available[lane] = true
|
||||
}
|
||||
for _, lane := range request.RequiredLanes {
|
||||
if !available[lane] {
|
||||
err = fmt.Errorf("notarius inspection does not include required lane %q", lane)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
result.Findings = append(result.Findings, Finding{Severity: SeverityError, Stage: "extract", Message: "notarius preflight: " + err.Error()})
|
||||
return result, fmt.Errorf("notarius preflight: %w", err)
|
||||
}
|
||||
return result, ctx.Err()
|
||||
}
|
||||
|
||||
// CheckDownstream runs the selected checks and retains tool-specific findings.
|
||||
func CheckDownstream(ctx context.Context, inspector Inspector, checker AuditaChecker, targets Targets, polish audita.PolishRequest) (Result, error) {
|
||||
result, scriptErr := Check(ctx, inspector, targets.Scriptorium)
|
||||
|
||||
Reference in New Issue
Block a user