Replace session validation with standalone preflight
This commit is contained in:
@@ -19,6 +19,7 @@ func newApplication(deps commandDependencies, executor pipelineExecutor) (*comma
|
||||
commandkit.Completion("narratio"),
|
||||
commandkit.WithInvocationFeature(configurationCommand(deps), bootstrapFeature()),
|
||||
executionCommand("run", "Execute a session pipeline.", false, deps, executor),
|
||||
preflightCommand(deps),
|
||||
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts.",
|
||||
artifactCatalogCommand(deps),
|
||||
executionCommand("regenerate", "Rebuild extraction and analysis artifacts.", true, deps, executor),
|
||||
@@ -28,7 +29,6 @@ func newApplication(deps commandDependencies, executor pipelineExecutor) (*comma
|
||||
restoreCommand(deps),
|
||||
cleanCommand(deps),
|
||||
sessionInitializationCommand(deps),
|
||||
sessionValidationCommand(deps),
|
||||
sessionStateCommand("status", true, deps),
|
||||
sessionStateCommand("artifacts", false, deps),
|
||||
commandkit.Group("locks", "Manage remote publication locks.",
|
||||
|
||||
@@ -182,7 +182,7 @@ func TestNativeTreeRejectsRemovedRoutesAndMissingOperandsBeforeAcquisition(t *te
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cases := [][]string{{"run"}, {"artifacts", "regenerate"}, {"session", "init"}, {"session", "validate"}, {"session", "status"}, {"session", "plan"}, {"session", "artifacts"}, {"session", "restore"}, {"session", "clean"}, {"session", "locks", "list"}, {"session", "locks", "add"}, {"session", "locks", "remove"}, {"run-stage"}, {"analyze"}, {"publish"}, {"regenerate-artifacts"}, {"clean"}, {"plan"}, {"status"}, {"resume"}, {"lock"}, {"unlock"}, {"config", "artifacts"}, {"run", "session", "--session-id", "session"}, {"session", "status", "session", "--manifest", "manifest.json"}}
|
||||
cases := [][]string{{"run"}, {"preflight"}, {"artifacts", "regenerate"}, {"session", "init"}, {"session", "validate", "session"}, {"session", "status"}, {"session", "plan"}, {"session", "artifacts"}, {"session", "restore"}, {"session", "clean"}, {"session", "locks", "list"}, {"session", "locks", "add"}, {"session", "locks", "remove"}, {"run-stage"}, {"analyze"}, {"publish"}, {"regenerate-artifacts"}, {"clean"}, {"plan"}, {"status"}, {"resume"}, {"lock"}, {"unlock"}, {"config", "artifacts"}, {"run", "session", "--session-id", "session"}, {"session", "status", "session", "--manifest", "manifest.json"}}
|
||||
for _, args := range cases {
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := application.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
@@ -34,7 +33,7 @@ func configureNotariusProbe(t *testing.T, cfg *config.Config) {
|
||||
cfg.Pipeline.Notarius = &config.NotariusConfig{Enabled: true, Binary: binary, ConfigPath: path, PipelineID: "campaign", WorkingDirectory: dir, Timeout: "1m", Outputs: map[string]config.NotariusOutputConfig{"events": {LaneID: "events"}}}
|
||||
}
|
||||
|
||||
func TestSessionValidationUsesPreparedNotariusProbeWithoutChangingManifest(t *testing.T) {
|
||||
func TestPreflightReportsNotariusProbe(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
@@ -42,20 +41,16 @@ func TestSessionValidationUsesPreparedNotariusProbeWithoutChangingManifest(t *te
|
||||
}
|
||||
configureNotariusProbe(t, cfg)
|
||||
paths := seedValidationPrepared(t, cfg)
|
||||
before, err := os.ReadFile(paths.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
native := ¬arius.FakeRunner{PreflightResult: ¬arius.ReadinessResult{Pipeline: "campaign", Lanes: []string{"events"}, InspectionComplete: true, AssessmentComplete: true, Ready: true, Checks: []notarius.ReadinessCheck{{ID: "cache", Result: "warning", Message: "cache inaccessible"}}}}
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||
deps.newNotarius = func() notarius.Runner { return native }
|
||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Valid || len(native.PreflightRequests) != 1 {
|
||||
report, err := inspectConfiguredForTest(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Ready || len(native.PreflightRequests) != 1 {
|
||||
t.Fatalf("report=%#v requests=%#v err=%v", report, native.PreflightRequests, err)
|
||||
}
|
||||
request := native.PreflightRequests[0]
|
||||
if !strings.Contains(request.InputDescription, "synthetic") || !strings.HasPrefix(request.OutputRoot, artifacts.SessionValidationNotariusDir(paths)) {
|
||||
if !strings.Contains(request.InputDescription, "synthetic") || !strings.HasPrefix(request.OutputRoot, artifacts.SessionInvocationProbeDir(paths, report.RunID, "notarius")) {
|
||||
t.Fatalf("probe = %#v", request)
|
||||
}
|
||||
if !findingMatches(report.Findings, "INFO", "notarius", "synthetic transcript") {
|
||||
@@ -64,10 +59,7 @@ func TestSessionValidationUsesPreparedNotariusProbeWithoutChangingManifest(t *te
|
||||
if !findingMatches(report.Findings, "WARN", "notarius", "cache inaccessible") {
|
||||
t.Fatalf("cache warning missing: %#v", report.Findings)
|
||||
}
|
||||
after, err := os.ReadFile(paths.ManifestPath)
|
||||
if err != nil || !bytes.Equal(before, after) {
|
||||
t.Fatalf("manifest changed: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNotariusPreflightFollowsPrepareAndSkipsReusedWork(t *testing.T) {
|
||||
|
||||
@@ -458,15 +458,12 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := executeWithDependencies([]string{"session", "validate", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &stdout, &stderr, deps, executePlan)
|
||||
code := executeWithDependencies([]string{"preflight", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &stdout, &stderr, deps, executePlan)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
||||
}
|
||||
if !findingMatches(decodeNativeReport[sessionValidationReport](t, stdout.Bytes()).Findings, "OK", "audio", "") {
|
||||
t.Fatalf("stdout = %q, want OK audio", stdout.String())
|
||||
}
|
||||
if !findingMatches(decodeNativeReport[sessionValidationReport](t, stdout.Bytes()).Findings, "OK", "inputs", "players:") || !findingMatches(decodeNativeReport[sessionValidationReport](t, stdout.Bytes()).Findings, "OK", "inputs", "party:") {
|
||||
t.Fatalf("stdout = %q, want players and party input findings", stdout.String())
|
||||
if !decodeNativeReport[sessionReadinessReport](t, stdout.Bytes()).Ready {
|
||||
t.Fatalf("stdout = %q, want ready", stdout.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,19 +1097,16 @@ func TestExecuteSessionValidateReportsPreviousStateFindingAndReturnsFindingError
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := executeWithDependencies([]string{
|
||||
"session", "validate", "2026-05-03",
|
||||
"preflight", "2026-05-03",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
||||
}, &stdout, &stderr, deps, executePlan)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
if !findingMatches(decodeNativeReport[sessionValidationReport](t, stdout.Bytes()).Findings, "ERROR", "previous", "") {
|
||||
if !findingMatches(decodeNativeReport[sessionReadinessReport](t, stdout.Bytes()).Findings, "ERROR", "preparation", "") {
|
||||
t.Fatalf("stdout = %q, want previous finding error", stdout.String())
|
||||
}
|
||||
if !strings.Contains(stdout.String(), "remote current commit pointer missing") {
|
||||
t.Fatalf("stdout = %q, want missing commit pointer finding", stdout.String())
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "remote current commit pointer missing") {
|
||||
t.Fatalf("stderr = %q, want finding error summary", stderr.String())
|
||||
}
|
||||
|
||||
84
internal/app/preflight_command_test.go
Normal file
84
internal/app/preflight_command_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestPreflightCommandReportsNativeFormats(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
provider := &audita.FakeRunner{}
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return provider, nil }
|
||||
app, err := newApplication(deps, executePlan)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, format := range []string{"json", "yaml", "text", "auto"} {
|
||||
t.Run(format, func(t *testing.T) {
|
||||
var out, diagnostics bytes.Buffer
|
||||
args := []string{"preflight", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session}
|
||||
if format != "auto" {
|
||||
args = append(args, "--format", format)
|
||||
}
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if outcome.Status != 0 {
|
||||
t.Fatalf("outcome=%+v diagnostics=%s", outcome, diagnostics.String())
|
||||
}
|
||||
var report map[string]any
|
||||
if format == "json" {
|
||||
err = json.Unmarshal(out.Bytes(), &report)
|
||||
} else {
|
||||
err = yaml.Unmarshal(out.Bytes(), &report)
|
||||
}
|
||||
if err != nil || report["ready"] != true || report["session_id"] != "2026-05-03" || report["checks"] == nil {
|
||||
t.Fatalf("report=%+v output=%s error=%v", report, out.String(), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
provider.PreflightErr = errors.New("synthetic provider failure")
|
||||
var out, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"preflight", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--quiet", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, provider.PreflightErr) || !strings.Contains(diagnostics.String(), "synthetic provider failure") {
|
||||
t.Fatalf("outcome=%+v report=%s diagnostics=%s", outcome, out.String(), diagnostics.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreflightHelpDoesNotAcquireConfiguration(t *testing.T) {
|
||||
app, err := newApplication(commandDependencies{
|
||||
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||
t.Fatal("help acquired configuration")
|
||||
return nil, nil
|
||||
},
|
||||
}, executePlan)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, args := range [][]string{{"--help"}, {"preflight", "--help"}, {"session", "--help"}} {
|
||||
var out, diagnostics bytes.Buffer
|
||||
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if result.Status != 0 {
|
||||
t.Fatalf("args=%v outcome=%+v diagnostics=%s", args, result, diagnostics.String())
|
||||
}
|
||||
if len(args) == 1 && !strings.Contains(out.String(), "preflight") {
|
||||
t.Fatalf("root help=%s", out.String())
|
||||
}
|
||||
if args[0] == "session" && strings.Contains(out.String(), "validate") {
|
||||
t.Fatalf("session help=%s", out.String())
|
||||
}
|
||||
if args[0] == "preflight" && (!strings.Contains(out.String(), "writes state") || !strings.Contains(out.String(), "providers")) {
|
||||
t.Fatalf("preflight help=%s", out.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notarius"
|
||||
"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"
|
||||
)
|
||||
import "go.maximumdirect.net/commandkit"
|
||||
|
||||
type sessionInspectionInput struct {
|
||||
Selection configurationSelection
|
||||
@@ -25,14 +8,6 @@ type sessionInspectionInput struct {
|
||||
Remote commandkit.Supplied[bool]
|
||||
}
|
||||
|
||||
type sessionValidationReport struct {
|
||||
Campaign string `json:"campaign"`
|
||||
SessionID string `json:"session_id"`
|
||||
SessionSource string `json:"session_source,omitempty"`
|
||||
Valid bool `json:"valid"`
|
||||
Findings []finding `json:"findings"`
|
||||
}
|
||||
|
||||
func sessionInspectionSpec(name, summary string, remoteOption bool) commandkit.CommandSpec[*sessionInspectionInput] {
|
||||
common := newConfigurationFlags(func(input **sessionInspectionInput) *configurationSelection { return &(*input).Selection })
|
||||
flags := []commandkit.Flag[*sessionInspectionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||
@@ -50,259 +25,3 @@ func sessionInspectionSpec(name, summary string, remoteOption bool) commandkit.C
|
||||
CheckInput: func(input *sessionInspectionInput) error { return checkConfigurationSelection(input.Selection) },
|
||||
}
|
||||
}
|
||||
|
||||
func sessionValidationCommand(deps commandDependencies) commandkit.Command {
|
||||
spec := sessionInspectionSpec("validate", "Check session readiness without executing work.", false)
|
||||
spec.Run = func(invocation commandkit.Invocation, input *sessionInspectionInput) commandkit.Outcome {
|
||||
report, err := validateSelectedSession(invocation.Context, input, withCommandReporting(deps, invocation))
|
||||
if report != nil {
|
||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||
}
|
||||
return reportOperationOutcome(invocation, err)
|
||||
}
|
||||
return commandkit.NewCommand(spec)
|
||||
}
|
||||
|
||||
func validateSelectedSession(ctx context.Context, input *sessionInspectionInput, deps commandDependencies) (report *sessionValidationReport, err error) {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
acquired := newConfigurationAcquisition(input.Selection, deps)
|
||||
acquired.previousSessionID = input.PreviousSession.Value
|
||||
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||
cfg, err := acquired.Domain(ctx)
|
||||
if err != nil {
|
||||
return &sessionValidationReport{Campaign: input.Selection.Campaign.Value, SessionID: input.Selection.Session.Value, Findings: []finding{errorFinding("config", err.Error())}}, err
|
||||
}
|
||||
return inspectSessionValidation(ctx, cfg, deps)
|
||||
}
|
||||
|
||||
func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps commandDependencies) (report *sessionValidationReport, resultErr error) {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
report = &sessionValidationReport{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, SessionSource: sessionSourceSummary(cfg), Findings: []finding{}}
|
||||
fail := func(category string, err error) {
|
||||
if err != nil {
|
||||
report.Findings = append(report.Findings, errorFinding(category, err.Error()))
|
||||
resultErr = errors.Join(resultErr, err)
|
||||
}
|
||||
}
|
||||
configErr := config.Validate(cfg)
|
||||
if configErr != nil {
|
||||
fail("config", configErr)
|
||||
} else {
|
||||
report.Findings = append(report.Findings, okFinding("config", "resolved pipeline, campaign, and session config"))
|
||||
}
|
||||
for _, check := range inspectStableInputs(cfg) {
|
||||
if check.Err != nil {
|
||||
fail("inputs", fmt.Errorf("%s: %w", check.Name, check.Err))
|
||||
} else {
|
||||
report.Findings = append(report.Findings, okFinding("inputs", check.Name+": "+check.Path))
|
||||
}
|
||||
}
|
||||
local := inspectLocalAudioPresence(cfg)
|
||||
if local.Checked {
|
||||
if local.Err != nil {
|
||||
fail("audio", local.Err)
|
||||
} else {
|
||||
report.Findings = append(report.Findings, okFinding("audio", fmt.Sprintf("%d local audio file(s)", len(local.Paths))))
|
||||
}
|
||||
}
|
||||
store, storeErr := objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||
fail("storage", storeErr)
|
||||
if cfg.Session.Inputs.AudioS3 != nil {
|
||||
if storeErr != nil {
|
||||
report.Findings = append(report.Findings, errorFinding("audio", "remote audio cannot be checked because storage is unavailable"))
|
||||
} else {
|
||||
remote := inspectRemoteAudioPresence(ctx, cfg, store)
|
||||
if remote.Err != nil {
|
||||
fail("audio", remote.Err)
|
||||
} else {
|
||||
report.Findings = append(report.Findings, okFinding("audio", fmt.Sprintf("%d remote .flac object(s)", len(remote.Keys))))
|
||||
}
|
||||
}
|
||||
}
|
||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
||||
fail("config", effectiveErr)
|
||||
if configErr == nil && effectiveErr == nil {
|
||||
targets, targetErr := enabledDownstreamTargets(cfg, cfg.Session.SessionID)
|
||||
if targetErr != nil {
|
||||
fail("preflight", targetErr)
|
||||
} else {
|
||||
probeStore := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
paths := probeStore.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if targets.Polish || targets.Notarius {
|
||||
// Check presence only before locking. Prepared evidence is read below
|
||||
// while locked; missing preparation must not bootstrap a workspace.
|
||||
_, statErr := os.Stat(paths.ManifestPath)
|
||||
if statErr == nil {
|
||||
lock, lockErr := probeStore.AcquireSessionLockForContext(ctx, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if lockErr != nil {
|
||||
fail("workspace", fmt.Errorf("acquire validation session lock: %w", lockErr))
|
||||
targets.Polish, targets.Notarius = false, false
|
||||
} else {
|
||||
defer func() {
|
||||
fail("workspace", probeStore.ReleaseSessionLock(lock))
|
||||
report.Valid = resultErr == nil
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
if errors.Is(statErr, os.ErrNotExist) {
|
||||
if targets.Polish {
|
||||
fail("audita", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
}
|
||||
if targets.Notarius {
|
||||
fail("notarius", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
}
|
||||
} else {
|
||||
fail("workspace", fmt.Errorf("inspect prepared manifest: %w", statErr))
|
||||
}
|
||||
targets.Polish, targets.Notarius = false, false
|
||||
}
|
||||
}
|
||||
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"))
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var native notarius.ReadinessChecker
|
||||
var probe stage.NotariusReadiness
|
||||
if targets.Notarius {
|
||||
local, present, loadErr := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, paths.ManifestPath)
|
||||
switch {
|
||||
case loadErr != nil:
|
||||
fail("notarius", fmt.Errorf("load prepared manifest; run prepare: %w", loadErr))
|
||||
targets.Notarius = false
|
||||
case !present:
|
||||
fail("notarius", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
targets.Notarius = false
|
||||
default:
|
||||
identityErr := (invocationIdentity{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID}).validateSessionManifest(local)
|
||||
if identityErr != nil {
|
||||
fail("notarius", fmt.Errorf("prepared manifest is invalid; run prepare: %w", identityErr))
|
||||
targets.Notarius = false
|
||||
} else if local.Stages["prepare"] == nil || local.Stages["prepare"].Status != manifest.StatusSucceeded {
|
||||
fail("notarius", fmt.Errorf("prepared inputs are not current; run prepare"))
|
||||
targets.Notarius = false
|
||||
} else {
|
||||
probe, loadErr = stage.BuildNotariusReadiness(cfg, paths, local, artifacts.SessionValidationNotariusDir(paths), true, false)
|
||||
if loadErr != nil {
|
||||
fail("notarius", loadErr)
|
||||
targets.Notarius = false
|
||||
} else {
|
||||
var ok bool
|
||||
native, ok = deps.newNotarius().(notarius.ReadinessChecker)
|
||||
if !ok || native == nil {
|
||||
fail("notarius", fmt.Errorf("notarius runner does not support preflight"))
|
||||
targets.Notarius = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checked, checkErr := preflight.Check(ctx, inspector, targets.Scriptorium)
|
||||
if targets.Polish && ctx.Err() == nil {
|
||||
auditaResult, auditaErr := preflight.CheckAudita(ctx, checker, request)
|
||||
checked.Findings = append(checked.Findings, auditaResult.Findings...)
|
||||
checkErr = errors.Join(checkErr, auditaErr)
|
||||
}
|
||||
if targets.Notarius && ctx.Err() == nil {
|
||||
nativeResult, nativeErr := preflight.CheckNotarius(ctx, native, probe.Request)
|
||||
checked.Findings = append(checked.Findings, nativeResult.Findings...)
|
||||
if verifyErr := probe.VerifyReferences(); verifyErr != nil {
|
||||
nativeErr = errors.Join(nativeErr, fmt.Errorf("verify Notarius probe references: %w", verifyErr))
|
||||
}
|
||||
checkErr = errors.Join(checkErr, nativeErr)
|
||||
}
|
||||
hasError := false
|
||||
for _, item := range checked.Findings {
|
||||
category, message := "scriptorium", formatPromptFinding(item)
|
||||
if item.Stage == "polish" {
|
||||
category, message = "audita", item.Message
|
||||
} else if item.Stage == "extract" {
|
||||
category, message = "notarius", item.Message
|
||||
}
|
||||
switch item.Severity {
|
||||
case preflight.SeverityError:
|
||||
hasError = true
|
||||
report.Findings = append(report.Findings, errorFinding(category, message))
|
||||
case preflight.SeverityWarning:
|
||||
report.Findings = append(report.Findings, warnFinding(category, message))
|
||||
default:
|
||||
report.Findings = append(report.Findings, infoFinding(category, message))
|
||||
}
|
||||
}
|
||||
if checkErr != nil {
|
||||
resultErr = errors.Join(resultErr, checkErr)
|
||||
if !hasError {
|
||||
report.Findings = append(report.Findings, errorFinding("preflight", checkErr.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if effectiveErr == nil {
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective))
|
||||
if len(previous.Requirements) == 0 {
|
||||
report.Findings = append(report.Findings, okFinding("previous", "no previous-session artifacts required"))
|
||||
} else if previous.Err != nil {
|
||||
fail("previous", previous.Err)
|
||||
} else {
|
||||
for _, requirement := range previous.Requirements {
|
||||
message := fmt.Sprintf("%s required=%t", requirement.Name, requirement.Required)
|
||||
if !requirement.Required && previousRequirementSkipped(previous.SkippedMissing, requirement.Name) {
|
||||
message += " unavailable"
|
||||
}
|
||||
report.Findings = append(report.Findings, okFinding("previous", message))
|
||||
}
|
||||
}
|
||||
}
|
||||
locks := inspectRemoteLocks(ctx, cfg, store)
|
||||
if locks.Err != nil {
|
||||
fail("locks", locks.Err)
|
||||
} else if len(locks.Locks) == 0 {
|
||||
report.Findings = append(report.Findings, okFinding("locks", "no publish locks"))
|
||||
} else {
|
||||
for _, lock := range locks.Locks {
|
||||
report.Findings = append(report.Findings, warnFinding("locks", fmt.Sprintf("%s locked: %s", lock.Source, strings.TrimSpace(lock.Reason))))
|
||||
}
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
report.Findings = append(report.Findings, infoFinding("workspace", "manifest path: "+paths.ManifestPath))
|
||||
report.Valid = resultErr == nil
|
||||
return report, resultErr
|
||||
}
|
||||
|
||||
@@ -36,23 +36,23 @@ func TestSessionValidationCommandReturnsFindingsWithoutRuntimeState(t *testing.T
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outcome := app.Execute(context.Background(), []string{"session", "validate", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
outcome := app.Execute(context.Background(), []string{"preflight", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status != 1 {
|
||||
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||
}
|
||||
var report sessionValidationReport
|
||||
var report sessionReadinessReport
|
||||
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if report.Valid || report.SessionID != "2026-05-03" || len(report.Findings) == 0 {
|
||||
if report.Ready || report.SessionID != "2026-05-03" || len(report.Findings) == 0 {
|
||||
t.Fatalf("report=%#v", report)
|
||||
}
|
||||
if !errors.Is(outcome.Cause, os.ErrNotExist) {
|
||||
t.Fatalf("missing input cause not retained: %v", outcome.Cause)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||||
t.Fatalf("preflight created runtime state: %v", err)
|
||||
if _, err := os.Stat(paths.ManifestPath); err != nil {
|
||||
t.Fatalf("preflight did not persist failure: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,15 +60,15 @@ func TestSessionValidationCommandReportsNativeConfigurationFailure(t *testing.T)
|
||||
pipeline := filepath.Join(t.TempDir(), "invalid.yml")
|
||||
mustWriteTestFile(t, pipeline, "unknown_field: value\n")
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := Execute(context.Background(), []string{"session", "validate", "session", "--config", pipeline, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
outcome := Execute(context.Background(), []string{"preflight", "session", "--config", pipeline, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status != 2 {
|
||||
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||
}
|
||||
var report sessionValidationReport
|
||||
var report sessionReadinessReport
|
||||
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if report.Valid || len(report.Findings) != 1 || report.Findings[0].Category != "config" {
|
||||
if report.Ready || len(report.Findings) != 1 || report.Findings[0].Category != "configuration" {
|
||||
t.Fatalf("report=%#v", report)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func TestExecuteSessionSubcommandsAcceptPositionalSessionID(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "validate",
|
||||
args: []string{"session", "validate", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath},
|
||||
args: []string{"preflight", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath},
|
||||
},
|
||||
{
|
||||
name: "status",
|
||||
|
||||
@@ -31,7 +31,7 @@ func (r *validationReportRunner) InspectRequirements(ctx context.Context, req sc
|
||||
return scriptorium.RequirementsReport{Complete: true}, ctx.Err()
|
||||
}
|
||||
|
||||
func TestSessionValidationSharesPromptFindingsAndLeavesNoWorkspace(t *testing.T) {
|
||||
func TestPreflightSharesPromptFindings(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
@@ -42,8 +42,8 @@ func TestSessionValidationSharesPromptFindingsAndLeavesNoWorkspace(t *testing.T)
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Valid || len(fake.RequirementsRequests) == 0 {
|
||||
report, err := inspectConfiguredForTest(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Ready || len(fake.RequirementsRequests) == 0 {
|
||||
t.Fatalf("report = %+v, error = %v", report, err)
|
||||
}
|
||||
targets, err := enabledInspectionTargets(cfg, cfg.Session.SessionID)
|
||||
@@ -60,7 +60,7 @@ func TestSessionValidationSharesPromptFindingsAndLeavesNoWorkspace(t *testing.T)
|
||||
}
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := os.Stat(filepath.Join(paths.RunsDir, ".validation", "polish")); err != nil {
|
||||
if _, err := os.Stat(artifacts.SessionInvocationProbeDir(paths, report.RunID, "audita")); err != nil {
|
||||
t.Fatalf("probe namespace: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func TestSessionValidationFailuresRemainFailuresInQuietMode(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out, diag bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"session", "validate", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--quiet", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diag})
|
||||
outcome := app.Execute(context.Background(), []string{"preflight", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--quiet", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diag})
|
||||
if outcome.Status == 0 || outcome.Cause == nil || !strings.Contains(outcome.Cause.Error(), tc.expected) {
|
||||
t.Fatalf("outcome = %+v, diagnostics = %q", outcome, diag.String())
|
||||
}
|
||||
@@ -115,8 +115,8 @@ func TestSessionValidationReportsOptionalSourceAndDisabledPrerequisite(t *testin
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Valid {
|
||||
report, err := inspectConfiguredForTest(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Ready {
|
||||
t.Fatalf("optional source warning should remain valid: report = %+v, err = %v", report, err)
|
||||
}
|
||||
if !findingMatches(report.Findings, "WARN", "scriptorium", "may be omitted") {
|
||||
@@ -147,11 +147,18 @@ func TestSessionValidationSkipsInspectorWithoutTargets(t *testing.T) {
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||
deps.newScriptorium = func() scriptorium.Runner { t.Fatal("unexpected inspector"); return nil }
|
||||
if _, err := inspectSessionValidation(context.Background(), cfg, deps); err != nil {
|
||||
if _, err := inspectConfiguredForTest(context.Background(), cfg, deps); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func inspectConfiguredForTest(ctx context.Context, cfg *config.Config, deps commandDependencies) (*sessionReadinessReport, error) {
|
||||
report := &sessionReadinessReport{Preparation: preparationAssessment{Outcome: "not_attempted"}}
|
||||
err := inspectConfiguredSessionReadiness(ctx, cfg, normalizeCommandDependencies(deps), report)
|
||||
report.Ready = err == nil
|
||||
return report, err
|
||||
}
|
||||
|
||||
func seedValidationPrepared(t *testing.T, cfg *config.Config) artifacts.SessionPaths {
|
||||
t.Helper()
|
||||
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
@@ -177,84 +184,6 @@ func seedValidationPrepared(t *testing.T, cfg *config.Config) artifacts.SessionP
|
||||
return paths
|
||||
}
|
||||
|
||||
func TestSessionValidationUsesPreparedGlossariesWithoutChangingState(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := seedValidationPrepared(t, cfg)
|
||||
before, err := os.ReadFile(paths.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := cfg.StableInputs.GlossaryFile.Path
|
||||
if err := os.Remove(source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fake := &audita.FakeRunner{}
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return fake, nil }
|
||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Valid || len(fake.PreflightRequests) != 1 {
|
||||
t.Fatalf("report=%+v calls=%d err=%v", report, len(fake.PreflightRequests), err)
|
||||
}
|
||||
req := fake.PreflightRequests[0]
|
||||
root := artifacts.SessionValidationPolishDir(paths)
|
||||
if req.OutputProcessedPath != filepath.Join(root, "outputs", "transcripts", "polished.json") || req.ReportDir != filepath.Join(root, "logs") || req.WorkDir != filepath.Join(root, "debug") || len(req.GlossaryFiles) != 4 {
|
||||
t.Fatalf("probe request: %+v", req)
|
||||
}
|
||||
after, err := os.ReadFile(paths.ManifestPath)
|
||||
if err != nil || !bytes.Equal(before, after) {
|
||||
t.Fatalf("manifest changed: %v", err)
|
||||
}
|
||||
entries, err := os.ReadDir(paths.RunsDir)
|
||||
if err != nil || len(entries) != 1 || entries[0].Name() != ".validation" {
|
||||
t.Fatalf("runs: %+v %v", entries, err)
|
||||
}
|
||||
if _, err := os.Stat(req.OutputProcessedPath); !os.IsNotExist(err) {
|
||||
t.Fatalf("processing output exists: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionValidationReportsPreparedAndProviderFailures(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
fake := &audita.FakeRunner{}
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return fake, nil }
|
||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err == nil || report.Valid || !strings.Contains(err.Error(), "run prepare") || len(fake.PreflightRequests) != 0 {
|
||||
t.Fatalf("missing evidence: %+v %v", report, err)
|
||||
}
|
||||
missingPaths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := os.Lstat(missingPaths.Root); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("missing preparation created a workspace: %v", err)
|
||||
}
|
||||
paths := seedValidationPrepared(t, cfg)
|
||||
failure := errors.New("synthetic provider failure")
|
||||
fake.PreflightErr = failure
|
||||
report, err = inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if !errors.Is(err, failure) || report.Valid || !findingMatches(report.Findings, "ERROR", "audita", "synthetic provider failure") {
|
||||
t.Fatalf("provider: %+v %v", report, err)
|
||||
}
|
||||
fake.PreflightErr = nil
|
||||
if err := os.RemoveAll(filepath.Join(paths.RunsDir, ".validation")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(paths.RunsDir, ".validation"), []byte("conflict"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
count := len(fake.PreflightRequests)
|
||||
report, err = inspectSessionValidation(context.Background(), cfg, deps)
|
||||
if err == nil || report.Valid || len(fake.PreflightRequests) != count {
|
||||
t.Fatalf("destination: %+v %v", report, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionValidationStopsChecksOnCancellation(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
@@ -267,8 +196,8 @@ func TestSessionValidationStopsChecksOnCancellation(t *testing.T) {
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return fake, nil }
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
report, err := inspectSessionValidation(ctx, cfg, deps)
|
||||
if !errors.Is(err, context.Canceled) || report.Valid || len(fake.PreflightRequests) != 0 {
|
||||
report, err := inspectConfiguredForTest(ctx, cfg, deps)
|
||||
if !errors.Is(err, context.Canceled) || report.Ready || len(fake.PreflightRequests) != 0 {
|
||||
t.Fatalf("cancelled: %+v %v", report, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,22 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
func preflightCommand(deps commandDependencies) commandkit.Command {
|
||||
spec := sessionInspectionSpec("preflight", "Prepare session inputs and check readiness.", false)
|
||||
spec.Description = "Preparation writes state and downloads inputs; readiness checks may contact providers."
|
||||
spec.Run = func(invocation commandkit.Invocation, input *sessionInspectionInput) commandkit.Outcome {
|
||||
report, err := preflightSelectedSession(invocation.Context, input, withCommandReporting(deps, invocation))
|
||||
if report != nil {
|
||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||
}
|
||||
return reportOperationOutcome(invocation, err)
|
||||
}
|
||||
return commandkit.NewCommand(spec)
|
||||
}
|
||||
|
||||
type preparationAssessment struct {
|
||||
Outcome string `json:"outcome"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
@@ -50,9 +64,13 @@ func preflightSelectedSession(ctx context.Context, input *sessionInspectionInput
|
||||
}
|
||||
report.Campaign, report.SessionID, report.SessionSource = cfg.Session.Campaign, cfg.Session.SessionID, sessionSourceSummary(cfg)
|
||||
report.Checks = append(report.Checks, readinessCheck{Group: "configuration", Outcome: "succeeded"})
|
||||
return report, inspectConfiguredSessionReadiness(ctx, cfg, deps, report)
|
||||
}
|
||||
|
||||
func inspectConfiguredSessionReadiness(ctx context.Context, cfg *config.Config, deps commandDependencies, report *sessionReadinessReport) error {
|
||||
plan, err := BuildBoundedPlan("prepare", "prepare")
|
||||
if err != nil {
|
||||
return report, err
|
||||
return err
|
||||
}
|
||||
invocationDeps := invocationDependencies{newAudita: deps.newAudita, newNotarius: deps.newNotarius, newScriptorium: deps.newScriptorium,
|
||||
newObjectStore: func(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) {
|
||||
@@ -69,7 +87,7 @@ func preflightSelectedSession(ctx context.Context, input *sessionInspectionInput
|
||||
// Finalization and lock-release failures may be joined after the checks.
|
||||
report.Findings = append(report.Findings, errorFinding("preflight", err.Error()))
|
||||
}
|
||||
return report, err
|
||||
return err
|
||||
}
|
||||
|
||||
func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadinessReport, deps commandDependencies) error {
|
||||
|
||||
@@ -55,7 +55,14 @@ func TestSessionValidationHoldsLockUntilProbeFilesAreFinished(t *testing.T) {
|
||||
cfg.Pipeline.Publish = &config.PublishConfig{Enabled: boolPtr(true), UploadRun: boolPtr(true)}
|
||||
cfg.Pipeline.Storage.Backend = config.StorageBackendS3
|
||||
cfg.Pipeline.Storage.S3 = &config.StorageS3Config{Bucket: "archive", RootPrefix: "dnd"}
|
||||
paths := seedValidationPrepared(t, cfg)
|
||||
plan, err := BuildBoundedPlan("prepare", "prepare")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = executePlan(context.Background(), cfg, plan, RunOptions{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
m, err := (&manifest.LocalStore{}).Load(context.Background(), paths.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -94,7 +101,7 @@ func TestSessionValidationHoldsLockUntilProbeFilesAreFinished(t *testing.T) {
|
||||
}
|
||||
deps.newNotarius = func() notarius.Runner { return &lockedNotariusProbe{check: check} }
|
||||
done := make(chan error, 1)
|
||||
go func() { _, err := inspectSessionValidation(ctx, cfg, deps); done <- err }()
|
||||
go func() { _, err := inspectConfiguredForTest(ctx, cfg, deps); done <- err }()
|
||||
select {
|
||||
case <-entered:
|
||||
case err := <-done:
|
||||
@@ -146,8 +153,8 @@ func TestSessionValidationCancellationWhileSessionIsLocked(t *testing.T) {
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return probe, nil }
|
||||
deps.newScriptorium = func() scriptorium.Runner { return &scriptorium.FakeRunner{} }
|
||||
report, err := inspectSessionValidation(ctx, cfg, deps)
|
||||
if !errors.Is(err, context.DeadlineExceeded) || report.Valid || len(probe.PreflightRequests) != 0 {
|
||||
report, err := inspectConfiguredForTest(ctx, cfg, deps)
|
||||
if !errors.Is(err, context.DeadlineExceeded) || report.Ready || len(probe.PreflightRequests) != 0 {
|
||||
t.Fatalf("waiting validation: %+v, %v", report, err)
|
||||
}
|
||||
if _, err := os.Lstat(paths.RunsDir); !errors.Is(err, os.ErrNotExist) {
|
||||
|
||||
@@ -36,16 +36,6 @@ type SessionPaths struct {
|
||||
RestoreMarkerPath string
|
||||
}
|
||||
|
||||
// SessionValidationPolishDir identifies the temporary destination-probe namespace.
|
||||
func SessionValidationPolishDir(paths SessionPaths) string {
|
||||
return filepath.Join(paths.RunsDir, ".validation", "polish")
|
||||
}
|
||||
|
||||
// SessionValidationNotariusDir identifies the explicit readiness probe namespace.
|
||||
func SessionValidationNotariusDir(paths SessionPaths) string {
|
||||
return filepath.Join(paths.RunsDir, ".validation", "notarius")
|
||||
}
|
||||
|
||||
// SessionInvocationProbeDir keeps automatic readiness outside actual attempts.
|
||||
func SessionInvocationProbeDir(paths SessionPaths, runID, application string) string {
|
||||
return filepath.Join(paths.RunsDir, ".preflight", runID, application)
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestNotariusReadinessUsesSyntheticInputWhenFutureTranscriptIsUnknown(t *tes
|
||||
mode := "bypass"
|
||||
env.Config.Pipeline.Notarius.Cache = &mode
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
probe, err := BuildNotariusReadiness(env.Config, paths, m, artifacts.SessionValidationNotariusDir(paths), false, true)
|
||||
probe, err := BuildNotariusReadiness(env.Config, paths, m, artifacts.SessionInvocationProbeDir(paths, "test-run", "notarius"), false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func TestNotariusReadinessRejectsMissingPreparedReference(t *testing.T) {
|
||||
env, m, _ := nativeExtractFixture(t)
|
||||
env.Config.Pipeline.Notarius.References = map[string]string{"party": artifactpolicy.SourceInputParty}
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
if _, err := BuildNotariusReadiness(env.Config, paths, m, artifacts.SessionValidationNotariusDir(paths), true, false); err == nil || !strings.Contains(err.Error(), "prepare") {
|
||||
if _, err := BuildNotariusReadiness(env.Config, paths, m, artifacts.SessionInvocationProbeDir(paths, "test-run", "notarius"), true, false); err == nil || !strings.Contains(err.Error(), "prepare") {
|
||||
t.Fatalf("missing reference error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user