Replace session validation with standalone preflight
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user