Document standalone preflight and complete verification
This commit is contained in:
@@ -40,6 +40,7 @@ func checkDownstreamReadiness(runtime *invocationRuntime, targets preflight.Targ
|
||||
result.Checks = append(result.Checks, readinessCheck{Group: group, Outcome: "blocked", Message: "prepared inputs are unavailable"})
|
||||
}
|
||||
if len(targets.Scriptorium) > 0 && runtime.ctx.Err() == nil {
|
||||
runtime.env.Progress("checking prompt requirements")
|
||||
if runtime.env.Scriptorium == nil {
|
||||
runtime.env.Scriptorium = runtime.dependencies.newScriptorium()
|
||||
}
|
||||
@@ -50,6 +51,7 @@ func checkDownstreamReadiness(runtime *invocationRuntime, targets preflight.Targ
|
||||
if !prepared {
|
||||
blocked("audita")
|
||||
} else {
|
||||
runtime.env.Progress("checking Audita readiness")
|
||||
var err error
|
||||
if runtime.env.Audita == nil {
|
||||
runtime.env.Audita, err = runtime.dependencies.newAudita(runtime.cfg)
|
||||
@@ -69,6 +71,7 @@ func checkDownstreamReadiness(runtime *invocationRuntime, targets preflight.Targ
|
||||
err = fmt.Errorf("build audita preflight: %w", buildErr)
|
||||
} else {
|
||||
checked, err = preflight.CheckAudita(runtime.ctx, checker, request)
|
||||
checked.Findings = append([]preflight.Finding{{Severity: preflight.SeverityInfo, Stage: "polish", Message: "Audita checks a synthetic transcript and may contact providers"}}, checked.Findings...)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +82,7 @@ func checkDownstreamReadiness(runtime *invocationRuntime, targets preflight.Targ
|
||||
if !prepared {
|
||||
blocked("notarius")
|
||||
} else {
|
||||
runtime.env.Progress("checking Notarius readiness")
|
||||
if runtime.env.Notarius == nil {
|
||||
runtime.env.Notarius = runtime.dependencies.newNotarius()
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestDownstreamReadinessContinuesAfterIndependentFailures(t *testing.T) {
|
||||
provider := &audita.FakeRunner{PreflightErr: auditaFailure}
|
||||
runtime := &invocationRuntime{ctx: context.Background(), cfg: cfg, paths: paths, manifest: m, identity: invocationIdentity{RunID: "probe"}, env: &stage.Env{Scriptorium: inspector, Audita: provider}, dependencies: invocationDependencies{}.normalized()}
|
||||
result, err := checkDownstreamReadiness(runtime, preflight.Targets{Polish: true, Scriptorium: []preflight.Target{{Stage: "trim"}}}, true, false, false)
|
||||
if !errors.Is(err, scriptFailure) || !errors.Is(err, auditaFailure) || len(result.Checks) != 2 || len(result.Findings) != 2 || len(provider.PreflightRequests) != 1 {
|
||||
if !errors.Is(err, scriptFailure) || !errors.Is(err, auditaFailure) || len(result.Checks) != 2 || len(result.Findings) != 3 || len(provider.PreflightRequests) != 1 {
|
||||
t.Fatalf("result = %+v, error = %v", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ func TestPreflightCommandReportsNativeFormats(t *testing.T) {
|
||||
if format != "auto" {
|
||||
args = append(args, "--format", format)
|
||||
}
|
||||
if format == "json" {
|
||||
args = append(args, "--progress")
|
||||
}
|
||||
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())
|
||||
@@ -45,6 +48,9 @@ func TestPreflightCommandReportsNativeFormats(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
if format == "json" && !strings.Contains(diagnostics.String(), "checking Audita readiness") {
|
||||
t.Fatalf("missing check progress on stderr: %s", diagnostics.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
provider.PreflightErr = errors.New("synthetic provider failure")
|
||||
|
||||
@@ -98,6 +98,11 @@ func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadiness
|
||||
report.Preparation = preparationAssessment{Outcome: item.Outcome, Reason: item.Reason}
|
||||
prepared = prepareErr == nil && (item.Outcome == "completed" || item.Outcome == "reused")
|
||||
}
|
||||
if !prepared && prepareErr == nil {
|
||||
prepareErr = fmt.Errorf("preparation did not produce reusable input evidence")
|
||||
report.Preparation.Outcome = "failed"
|
||||
report.Preparation.Reason = prepareErr.Error()
|
||||
}
|
||||
if prepareErr != nil {
|
||||
report.Findings = append(report.Findings, errorFinding("preparation", prepareErr.Error()))
|
||||
}
|
||||
@@ -112,9 +117,15 @@ func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadiness
|
||||
if prepared {
|
||||
report.Findings = append(report.Findings, okFinding("inputs", "prepared session inputs and audio are current"))
|
||||
if record := runtime.manifest.Stages["prepare"]; record != nil {
|
||||
if missing, ok := record.Metadata["previous_artifacts_missing_optional"]; ok {
|
||||
if hydrated := previousArtifactNames(record.Metadata["previous_artifacts_hydrated"]); len(hydrated) > 0 {
|
||||
report.Findings = append(report.Findings, okFinding("previous", fmt.Sprintf("prepared previous artifacts: %v", hydrated)))
|
||||
}
|
||||
if missing := previousArtifactNames(record.Metadata["previous_artifacts_missing_optional"]); len(missing) > 0 {
|
||||
report.Findings = append(report.Findings, infoFinding("previous", fmt.Sprintf("optional previous artifacts unavailable: %v", missing)))
|
||||
}
|
||||
if _, required := record.Metadata["previous_requirements_count"]; !required {
|
||||
report.Findings = append(report.Findings, infoFinding("previous", "no previous-session artifacts required"))
|
||||
}
|
||||
}
|
||||
}
|
||||
var failures []error
|
||||
@@ -195,3 +206,20 @@ func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadiness
|
||||
}
|
||||
return errors.Join(append(failures, runtime.ctx.Err())...)
|
||||
}
|
||||
|
||||
func previousArtifactNames(value any) []string {
|
||||
switch items := value.(type) {
|
||||
case []string:
|
||||
return items
|
||||
case []any:
|
||||
var names []string
|
||||
for _, item := range items {
|
||||
if name, ok := item.(string); ok {
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
return names
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"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/stage"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
@@ -197,3 +198,34 @@ func TestPreflightDoesNotProbeSupersededPreparationAfterFailure(t *testing.T) {
|
||||
t.Fatalf("failed=%+v calls=%d error=%v", failed, len(provider.PreflightRequests), err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreflightCannotSucceedWithoutPreparedEvidence(t *testing.T) {
|
||||
cfg := testConfig(t)
|
||||
deps := normalizeCommandDependencies(fakeCommandDependencies(&storage.FakeBackend{}, nil))
|
||||
report := &sessionReadinessReport{Preparation: preparationAssessment{Outcome: "not_attempted"}}
|
||||
plan := BoundedPlan{stages: []stage.Stage{resultStage{name: "prepare", result: &stage.StageResult{Disposition: stage.StageDispositionSkipped, SkipReason: "no inputs"}}}}
|
||||
summary, err := withLockedInvocation(context.Background(), cfg, plan, RunOptions{}, invocationDependencies{newAudita: deps.newAudita, newScriptorium: deps.newScriptorium}, func(runtime *invocationRuntime) error {
|
||||
return assessSessionReadiness(runtime, report, deps)
|
||||
})
|
||||
if err == nil || summary == nil || summary.Complete || report.Preparation.Outcome != "failed" {
|
||||
t.Fatalf("summary=%+v report=%+v error=%v", summary, report, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreflightReportsOptionalPreviousInputsAcrossReuse(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
artifact := cfg.ArtifactCatalog.Artifacts["player_handout"]
|
||||
artifact.Inputs["recap"] = config.ScriptoriumInputConfig{Source: "narratio.previous_session.artifact.session_recap", Required: false}
|
||||
cfg.ArtifactCatalog.Artifacts["player_handout"] = artifact
|
||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||
for _, want := range []string{"completed", "reused"} {
|
||||
report, err := inspectConfiguredForTest(context.Background(), cfg, deps)
|
||||
if err != nil || !report.Ready || report.Preparation.Outcome != want || !findingMatches(report.Findings, "INFO", "previous", "session_recap") {
|
||||
t.Fatalf("report=%+v error=%v", report, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,3 +173,96 @@ func TestSessionValidationCancellationWhileSessionIsLocked(t *testing.T) {
|
||||
t.Fatalf("waiting validation created probe paths: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type observedPreparationStore struct {
|
||||
manifest.Store
|
||||
saved chan struct{}
|
||||
proceed chan struct{}
|
||||
}
|
||||
|
||||
func (s *observedPreparationStore) Save(ctx context.Context, path string, m *manifest.Manifest) error {
|
||||
if err := s.Store.Save(ctx, path, m); err != nil {
|
||||
return err
|
||||
}
|
||||
if record := m.Stages["prepare"]; record != nil && record.Status == manifest.StatusSucceeded {
|
||||
select {
|
||||
case s.saved <- struct{}{}:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
select {
|
||||
case <-s.proceed:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestPreflightKeepsLockFromPreparationThroughProbe(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cfg, err := config.Load(pipeline, campaign, session)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
save := &observedPreparationStore{Store: &manifest.LocalStore{}, saved: make(chan struct{}, 1), proceed: make(chan struct{})}
|
||||
entered, release := make(chan struct{}), make(chan struct{})
|
||||
probe := &lockedAuditaProbe{check: func(ctx context.Context, _, _ string) error {
|
||||
close(entered)
|
||||
select {
|
||||
case <-release:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}}
|
||||
deps := normalizeCommandDependencies(fakeCommandDependencies(&storage.FakeBackend{}, nil))
|
||||
deps.newAudita = func(*config.Config) (audita.Runner, error) { return probe, nil }
|
||||
plan, err := BuildBoundedPlan("prepare", "prepare")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
report := &sessionReadinessReport{}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := withLockedInvocation(ctx, cfg, plan, RunOptions{Env: &Env{ManifestStore: save}}, invocationDependencies{newAudita: deps.newAudita, newScriptorium: deps.newScriptorium}, func(runtime *invocationRuntime) error { return assessSessionReadiness(runtime, report, deps) })
|
||||
done <- err
|
||||
}()
|
||||
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
assertLocked := func() {
|
||||
t.Helper()
|
||||
lock, err := store.AcquireSessionLockFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if lock != nil {
|
||||
_ = store.ReleaseSessionLock(lock)
|
||||
}
|
||||
if !errors.Is(err, artifacts.ErrLockConflict) {
|
||||
t.Fatalf("session lock is not held: %v", err)
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-save.saved:
|
||||
case err := <-done:
|
||||
t.Fatalf("preparation stopped: %v", err)
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
assertLocked()
|
||||
close(save.proceed)
|
||||
select {
|
||||
case <-entered:
|
||||
case err := <-done:
|
||||
t.Fatalf("probe did not start: %v", err)
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
assertLocked()
|
||||
close(release)
|
||||
if err := <-done; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if report.Preparation.Outcome != "completed" {
|
||||
t.Fatalf("preparation=%+v", report.Preparation)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user