Validate sessions with prepared downstream inputs
This commit is contained in:
@@ -538,7 +538,13 @@ subprocess-free; neither preflight nor fixture storage advances latest views.
|
|||||||
|
|
||||||
## Stage 15. Use the shared downstream checks in session validation
|
## Stage 15. Use the shared downstream checks in session validation
|
||||||
|
|
||||||
Status: Pending
|
Status: Complete
|
||||||
|
|
||||||
|
Validation checks existing prepared glossary evidence using the shared
|
||||||
|
request builder and downstream checker, with a dedicated `.validation` probe
|
||||||
|
namespace and explicit synthetic/provider-side-effect findings. Focused tests
|
||||||
|
cover missing evidence, valid reuse, unchanged manifest and source independence,
|
||||||
|
provider and destination failures, cancellation, and Scriptorium findings.
|
||||||
|
|
||||||
Read `app/session_inspection_command.go`, `operator_inspection.go`, invocation
|
Read `app/session_inspection_command.go`, `operator_inspection.go`, invocation
|
||||||
acquisition, and their validation tests. Retain basic configuration findings.
|
acquisition, and their validation tests. Retain basic configuration findings.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
@@ -17,6 +18,7 @@ type commandDependencies struct {
|
|||||||
loadPipelineSource func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error)
|
loadPipelineSource func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error)
|
||||||
newObjectStore func(context.Context, *config.Config) (storage.ObjectStore, error)
|
newObjectStore func(context.Context, *config.Config) (storage.ObjectStore, error)
|
||||||
newScriptorium func() scriptorium.Runner
|
newScriptorium func() scriptorium.Runner
|
||||||
|
newAudita func(*config.Config) (audita.Runner, error)
|
||||||
discoverRemoteCurrentState func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error)
|
discoverRemoteCurrentState func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error)
|
||||||
buildRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, storage.ObjectStore, RestorePlanOptions) (*RestorePlan, error)
|
buildRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, storage.ObjectStore, RestorePlanOptions) (*RestorePlan, error)
|
||||||
executeRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, *RestorePlan, *RestoreReport, storage.ObjectStore) (*RestoreExecutionResult, error)
|
executeRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, *RestorePlan, *RestoreReport, storage.ObjectStore) (*RestoreExecutionResult, error)
|
||||||
@@ -34,6 +36,9 @@ func normalizeCommandDependencies(deps commandDependencies) commandDependencies
|
|||||||
if deps.newObjectStore == nil {
|
if deps.newObjectStore == nil {
|
||||||
deps.newObjectStore = storage.NewObjectStoreFromConfig
|
deps.newObjectStore = storage.NewObjectStoreFromConfig
|
||||||
}
|
}
|
||||||
|
if deps.newAudita == nil {
|
||||||
|
deps.newAudita = buildDefaultAuditaRunner
|
||||||
|
}
|
||||||
if deps.newScriptorium == nil {
|
if deps.newScriptorium == nil {
|
||||||
deps.newScriptorium = defaultScriptoriumRunner
|
deps.newScriptorium = defaultScriptoriumRunner
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ func inspectStableInputs(cfg *config.Config) []stableInputCheck {
|
|||||||
}{
|
}{
|
||||||
{name: "speakers", in: cfg.StableInputs.SpeakersFile},
|
{name: "speakers", in: cfg.StableInputs.SpeakersFile},
|
||||||
{name: "autocorrect", in: cfg.StableInputs.AutocorrectFile},
|
{name: "autocorrect", in: cfg.StableInputs.AutocorrectFile},
|
||||||
{name: "glossary", in: cfg.StableInputs.GlossaryFile},
|
|
||||||
{name: "players", derived: true},
|
{name: "players", derived: true},
|
||||||
{name: "party", in: cfg.StableInputs.PartyFile},
|
{name: "party", in: cfg.StableInputs.PartyFile},
|
||||||
{name: "spell_catalog", in: cfg.StableInputs.SpellCatalogFile, optional: true},
|
{name: "spell_catalog", in: cfg.StableInputs.SpellCatalogFile, optional: true},
|
||||||
|
|||||||
@@ -4,11 +4,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"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/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"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/preflight"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,29 +121,75 @@ func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps comm
|
|||||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
||||||
fail("config", effectiveErr)
|
fail("config", effectiveErr)
|
||||||
if configErr == nil && effectiveErr == nil {
|
if configErr == nil && effectiveErr == nil {
|
||||||
targets, targetErr := validationInspectionTargets(cfg, cfg.Session.SessionID)
|
targets, targetErr := validationDownstreamTargets(cfg, cfg.Session.SessionID)
|
||||||
if targetErr != nil {
|
if targetErr != nil {
|
||||||
fail("scriptorium", targetErr)
|
fail("preflight", targetErr)
|
||||||
} else if len(targets) > 0 {
|
} else {
|
||||||
runner := deps.newScriptorium()
|
var inspector scriptorium.Runner
|
||||||
checked, checkErr := preflight.Check(ctx, runner, targets)
|
if len(targets.Scriptorium) > 0 {
|
||||||
hasInspectionError := false
|
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 {
|
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 {
|
switch item.Severity {
|
||||||
case preflight.SeverityError:
|
case preflight.SeverityError:
|
||||||
hasInspectionError = true
|
hasError = true
|
||||||
report.Findings = append(report.Findings, errorFinding("scriptorium", message))
|
report.Findings = append(report.Findings, errorFinding(category, message))
|
||||||
case preflight.SeverityWarning:
|
case preflight.SeverityWarning:
|
||||||
report.Findings = append(report.Findings, warnFinding("scriptorium", message))
|
report.Findings = append(report.Findings, warnFinding(category, message))
|
||||||
default:
|
default:
|
||||||
report.Findings = append(report.Findings, infoFinding("scriptorium", message))
|
report.Findings = append(report.Findings, infoFinding(category, message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if checkErr != nil {
|
if checkErr != nil {
|
||||||
resultErr = errors.Join(resultErr, checkErr)
|
resultErr = errors.Join(resultErr, checkErr)
|
||||||
if !hasInspectionError {
|
if !hasError {
|
||||||
report.Findings = append(report.Findings, errorFinding("scriptorium", checkErr.Error()))
|
report.Findings = append(report.Findings, errorFinding("preflight", checkErr.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"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/preflight"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
@@ -33,7 +38,9 @@ func TestSessionValidationSharesPromptFindingsAndLeavesNoWorkspace(t *testing.T)
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
fake := &scriptorium.FakeRunner{RequirementsResult: &scriptorium.RequirementsReport{Complete: false, Inputs: []scriptorium.RequirementInput{{Name: "conditional", Kind: "conditional", Explanation: "unknown"}}}}
|
fake := &scriptorium.FakeRunner{RequirementsResult: &scriptorium.RequirementsReport{Complete: false, Inputs: []scriptorium.RequirementInput{{Name: "conditional", Kind: "conditional", Explanation: "unknown"}}}}
|
||||||
|
seedValidationPrepared(t, cfg)
|
||||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||||
|
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||||
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
||||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||||
if err != nil || !report.Valid || len(fake.RequirementsRequests) == 0 {
|
if err != nil || !report.Valid || len(fake.RequirementsRequests) == 0 {
|
||||||
@@ -53,8 +60,8 @@ func TestSessionValidationSharesPromptFindingsAndLeavesNoWorkspace(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
if _, err := os.Stat(paths.Root); !errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(filepath.Join(paths.RunsDir, ".validation", "polish")); err != nil {
|
||||||
t.Fatalf("validation created workspace: %v", err)
|
t.Fatalf("probe namespace: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +111,9 @@ func TestSessionValidationReportsOptionalSourceAndDisabledPrerequisite(t *testin
|
|||||||
child.Inputs["recap"] = config.ScriptoriumInputConfig{Source: "narratio.artifact.session_recap", Required: false}
|
child.Inputs["recap"] = config.ScriptoriumInputConfig{Source: "narratio.artifact.session_recap", Required: false}
|
||||||
cfg.ArtifactCatalog.Artifacts["player_handout"] = child
|
cfg.ArtifactCatalog.Artifacts["player_handout"] = child
|
||||||
fake := &validationReportRunner{}
|
fake := &validationReportRunner{}
|
||||||
|
seedValidationPrepared(t, cfg)
|
||||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||||
|
deps.newAudita = func(*config.Config) (audita.Runner, error) { return &audita.FakeRunner{}, nil }
|
||||||
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
deps.newScriptorium = func() scriptorium.Runner { return fake }
|
||||||
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
report, err := inspectSessionValidation(context.Background(), cfg, deps)
|
||||||
if err != nil || !report.Valid {
|
if err != nil || !report.Valid {
|
||||||
@@ -134,9 +143,128 @@ func TestSessionValidationSkipsInspectorWithoutTargets(t *testing.T) {
|
|||||||
cfg.Pipeline.Trim.Enabled = &disabled
|
cfg.Pipeline.Trim.Enabled = &disabled
|
||||||
cfg.Pipeline.Scriptorium = nil
|
cfg.Pipeline.Scriptorium = nil
|
||||||
cfg.ArtifactCatalog = nil
|
cfg.ArtifactCatalog = nil
|
||||||
|
seedValidationPrepared(t, cfg)
|
||||||
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
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 }
|
deps.newScriptorium = func() scriptorium.Runner { t.Fatal("unexpected inspector"); return nil }
|
||||||
if _, err := inspectSessionValidation(context.Background(), cfg, deps); err != nil {
|
if _, err := inspectSessionValidation(context.Background(), cfg, deps); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func seedValidationPrepared(t *testing.T, cfg *config.Config) artifacts.SessionPaths {
|
||||||
|
t.Helper()
|
||||||
|
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||||
|
paths, err := store.EnsureLayoutFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m := manifest.New(cfg.Session.SessionID, time.Now().UTC())
|
||||||
|
m.Campaign = cfg.Session.Campaign
|
||||||
|
for _, d := range artifactpolicy.GlossaryInputSources() {
|
||||||
|
path := filepath.Join(paths.InputsDir, d.Filename)
|
||||||
|
mustWriteTestFile(t, path, "synthetic: {entries: []}\n")
|
||||||
|
checksum, err := store.Checksum(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m.Inputs = append(m.Inputs, manifest.InputRecord{Kind: d.ManifestKind, Path: path, Checksum: checksum})
|
||||||
|
}
|
||||||
|
m.MarkStageSucceeded("prepare", time.Now().UTC(), nil)
|
||||||
|
if err := (&manifest.LocalStore{}).Save(context.Background(), paths.ManifestPath, m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
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{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
seedValidationPrepared(t, cfg)
|
||||||
|
fake := &audita.FakeRunner{}
|
||||||
|
deps := fakeCommandDependencies(&storage.FakeBackend{}, nil)
|
||||||
|
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 {
|
||||||
|
t.Fatalf("cancelled: %+v %v", report, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ type SessionPaths struct {
|
|||||||
RestoreMarkerPath string
|
RestoreMarkerPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SessionValidationPolishDir identifies the temporary destination-probe namespace.
|
||||||
|
func SessionValidationPolishDir(paths SessionPaths) string {
|
||||||
|
return filepath.Join(paths.RunsDir, ".validation", "polish")
|
||||||
|
}
|
||||||
|
|
||||||
// SessionWorkDirForCampaign returns the canonical campaign-aware work directory for one session.
|
// SessionWorkDirForCampaign returns the canonical campaign-aware work directory for one session.
|
||||||
func SessionWorkDirForCampaign(rootDir, campaign, sessionID string) string {
|
func SessionWorkDirForCampaign(rootDir, campaign, sessionID string) string {
|
||||||
return filepath.Join(rootDir, config.PathWorkDirSegment, campaign, sessionID)
|
return filepath.Join(rootDir, config.PathWorkDirSegment, campaign, sessionID)
|
||||||
|
|||||||
Reference in New Issue
Block a user