Validate sessions with prepared downstream inputs
This commit is contained in:
@@ -4,11 +4,16 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
@@ -116,29 +121,75 @@ func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps comm
|
||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
||||
fail("config", effectiveErr)
|
||||
if configErr == nil && effectiveErr == nil {
|
||||
targets, targetErr := validationInspectionTargets(cfg, cfg.Session.SessionID)
|
||||
targets, targetErr := validationDownstreamTargets(cfg, cfg.Session.SessionID)
|
||||
if targetErr != nil {
|
||||
fail("scriptorium", targetErr)
|
||||
} else if len(targets) > 0 {
|
||||
runner := deps.newScriptorium()
|
||||
checked, checkErr := preflight.Check(ctx, runner, targets)
|
||||
hasInspectionError := false
|
||||
fail("preflight", targetErr)
|
||||
} else {
|
||||
var inspector scriptorium.Runner
|
||||
if len(targets.Scriptorium) > 0 {
|
||||
inspector = deps.newScriptorium()
|
||||
}
|
||||
var checker preflight.AuditaChecker
|
||||
var request audita.PolishRequest
|
||||
if targets.Polish {
|
||||
report.Findings = append(report.Findings, infoFinding("audita", "preflight uses a synthetic transcript, probes destinations, and may contact providers"))
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
local, present, loadErr := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, paths.ManifestPath)
|
||||
if loadErr != nil {
|
||||
fail("audita", fmt.Errorf("load prepared manifest; run prepare: %w", loadErr))
|
||||
targets.Polish = false
|
||||
} else if !present {
|
||||
fail("audita", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
targets.Polish = false
|
||||
} else if identityErr := (invocationIdentity{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID}).validateSessionManifest(local); identityErr != nil {
|
||||
fail("audita", fmt.Errorf("prepared manifest is invalid; run prepare: %w", identityErr))
|
||||
targets.Polish = false
|
||||
} else if local.Stages["prepare"] == nil || local.Stages["prepare"].Status != manifest.StatusSucceeded {
|
||||
fail("audita", fmt.Errorf("prepared inputs are not current; run prepare"))
|
||||
targets.Polish = false
|
||||
} else {
|
||||
root := artifacts.SessionValidationPolishDir(paths)
|
||||
request, _, loadErr = stage.BuildPolishRequest(paths, local, "", filepath.Join(root, "outputs", "transcripts", "polished.json"), filepath.Join(root, "logs"), filepath.Join(root, "debug"))
|
||||
if loadErr != nil {
|
||||
fail("audita", loadErr)
|
||||
targets.Polish = false
|
||||
} else {
|
||||
runner, runnerErr := deps.newAudita(cfg)
|
||||
if runnerErr != nil {
|
||||
fail("audita", runnerErr)
|
||||
targets.Polish = false
|
||||
} else {
|
||||
var ok bool
|
||||
checker, ok = runner.(preflight.AuditaChecker)
|
||||
if !ok || checker == nil {
|
||||
fail("audita", fmt.Errorf("audita runner does not support preflight"))
|
||||
targets.Polish = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checked, checkErr := preflight.CheckDownstream(ctx, inspector, checker, targets, request)
|
||||
hasError := false
|
||||
for _, item := range checked.Findings {
|
||||
message := formatPromptFinding(item)
|
||||
category, message := "scriptorium", formatPromptFinding(item)
|
||||
if item.Stage == "polish" {
|
||||
category, message = "audita", item.Message
|
||||
}
|
||||
switch item.Severity {
|
||||
case preflight.SeverityError:
|
||||
hasInspectionError = true
|
||||
report.Findings = append(report.Findings, errorFinding("scriptorium", message))
|
||||
hasError = true
|
||||
report.Findings = append(report.Findings, errorFinding(category, message))
|
||||
case preflight.SeverityWarning:
|
||||
report.Findings = append(report.Findings, warnFinding("scriptorium", message))
|
||||
report.Findings = append(report.Findings, warnFinding(category, message))
|
||||
default:
|
||||
report.Findings = append(report.Findings, infoFinding("scriptorium", message))
|
||||
report.Findings = append(report.Findings, infoFinding(category, message))
|
||||
}
|
||||
}
|
||||
if checkErr != nil {
|
||||
resultErr = errors.Join(resultErr, checkErr)
|
||||
if !hasInspectionError {
|
||||
report.Findings = append(report.Findings, errorFinding("scriptorium", checkErr.Error()))
|
||||
if !hasError {
|
||||
report.Findings = append(report.Findings, errorFinding("preflight", checkErr.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user