Verify S3 preparation through session preflight
This commit is contained in:
@@ -130,7 +130,7 @@ no-workspace/no-subprocess tests instead of duplicating their entire coverage.
|
|||||||
|
|
||||||
## Stage 3: Verify S3 checks through the existing preflight workflow
|
## Stage 3: Verify S3 checks through the existing preflight workflow
|
||||||
|
|
||||||
Status: Pending
|
Status: Complete
|
||||||
|
|
||||||
Read `internal/app/session_readiness.go`, `runner_composition.go`,
|
Read `internal/app/session_readiness.go`, `runner_composition.go`,
|
||||||
`runner_preflight.go`, and `session_readiness_test.go`. Standalone preflight
|
`runner_preflight.go`, and `session_readiness_test.go`. Standalone preflight
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func executeSelectedStage(runtime *invocationRuntime, selected stage.Stage) (out
|
|||||||
}
|
}
|
||||||
decision = decideStageExecution(recordedStageStatus(m, selected.Name()), runtime.opts.Force, validation)
|
decision = decideStageExecution(recordedStageStatus(m, selected.Name()), runtime.opts.Force, validation)
|
||||||
if decision.markSelectedStale {
|
if decision.markSelectedStale {
|
||||||
|
outcome.reason = decision.selectedStaleReason
|
||||||
staleAt := runtime.dependencies.now()
|
staleAt := runtime.dependencies.now()
|
||||||
if _, err := applyPreExecutionDecision(m, selected.Name(), decision, staleAt); err != nil {
|
if _, err := applyPreExecutionDecision(m, selected.Name(), decision, staleAt); err != nil {
|
||||||
return outcome, fmt.Errorf("invalidate dependents after resume validation for stage %q: %w", selected.Name(), err)
|
return outcome, fmt.Errorf("invalidate dependents after resume validation for stage %q: %w", selected.Name(), err)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -229,3 +230,91 @@ func TestPreflightReportsOptionalPreviousInputsAcrossReuse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type cancelAudioListingStore struct {
|
||||||
|
storage.ObjectStore
|
||||||
|
cancel context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s cancelAudioListingStore) List(ctx context.Context, prefix string) ([]storage.ObjectInfo, error) {
|
||||||
|
if strings.Contains(prefix, "/audio/") {
|
||||||
|
s.cancel()
|
||||||
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
|
return s.ObjectStore.List(ctx, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionReadinessChecksS3PreparationEvidence(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
replaceInFileOrFatal(t, session, "audio_dir: ./audio", "audio_s3:\n prefix: audio/")
|
||||||
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
key := artifacts.S3SessionPrefix(cfg.Pipeline.Storage.S3.RootPrefix, cfg.Session.Campaign, cfg.Session.SessionID) + "audio/alice.flac"
|
||||||
|
remote := &storage.FakeBackend{}
|
||||||
|
remote.SeedObject(storage.FakeObject{Key: key, Data: []byte("original")})
|
||||||
|
provider := &audita.FakeRunner{}
|
||||||
|
deps := fakeCommandDependencies(remote, nil)
|
||||||
|
deps.newAudita = func(*config.Config) (audita.Runner, error) { return provider, nil }
|
||||||
|
input := readinessInput(pipeline, campaign, session)
|
||||||
|
first, err := preflightSelectedSession(context.Background(), input, deps)
|
||||||
|
if err != nil || !first.Ready || first.Preparation.Outcome != "completed" {
|
||||||
|
t.Fatalf("first=%+v error=%v", first, err)
|
||||||
|
}
|
||||||
|
store := &manifest.LocalStore{}
|
||||||
|
m, err := store.Load(context.Background(), manifestPathFor(cfg))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m.MarkStageSucceeded("polish", time.Now().UTC(), nil)
|
||||||
|
if err := store.Save(context.Background(), manifestPathFor(cfg), m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
reads := len(remote.Reads)
|
||||||
|
reused, err := preflightSelectedSession(context.Background(), input, deps)
|
||||||
|
if err != nil || !reused.Ready || reused.Preparation.Outcome != "reused" || len(remote.Reads) != reads {
|
||||||
|
t.Fatalf("reuse=%+v error=%v", reused, err)
|
||||||
|
}
|
||||||
|
providerErr := errors.New("provider unavailable after reuse")
|
||||||
|
provider.PreflightErr = providerErr
|
||||||
|
failedProvider, err := preflightSelectedSession(context.Background(), input, deps)
|
||||||
|
if !errors.Is(err, providerErr) || failedProvider.Ready || failedProvider.Preparation.Outcome != "reused" {
|
||||||
|
t.Fatalf("provider=%+v error=%v", failedProvider, err)
|
||||||
|
}
|
||||||
|
provider.PreflightErr = nil
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancelDeps := deps
|
||||||
|
cancelDeps.newObjectStore = func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
|
return cancelAudioListingStore{ObjectStore: remote, cancel: cancel}, nil
|
||||||
|
}
|
||||||
|
cancelled, err := preflightSelectedSession(ctx, input, cancelDeps)
|
||||||
|
cancel()
|
||||||
|
if !errors.Is(err, context.Canceled) || cancelled.Ready {
|
||||||
|
t.Fatalf("cancelled=%+v error=%v", cancelled, err)
|
||||||
|
}
|
||||||
|
remote.SeedObject(storage.FakeObject{Key: key, Data: []byte("changed audio")})
|
||||||
|
changed, err := preflightSelectedSession(context.Background(), input, deps)
|
||||||
|
if err != nil || !changed.Ready || changed.Preparation.Outcome != "completed" {
|
||||||
|
t.Fatalf("changed=%+v error=%v", changed, err)
|
||||||
|
}
|
||||||
|
m, err = store.Load(context.Background(), manifestPathFor(cfg))
|
||||||
|
if err != nil || m.Stages["polish"].Status != manifest.StatusStale {
|
||||||
|
t.Fatalf("state=%+v error=%v", m, err)
|
||||||
|
}
|
||||||
|
found := false
|
||||||
|
for _, record := range m.Inputs {
|
||||||
|
if record.Kind == "audio" && record.S3Key == key && record.S3ETag == remote.Objects[key].ETag && record.S3Size == int64(len("changed audio")) {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Fatalf("new S3 evidence missing: %+v", m.Inputs)
|
||||||
|
}
|
||||||
|
outage := errors.New("synthetic S3 access failure")
|
||||||
|
remote.ListErr = outage
|
||||||
|
failed, err := preflightSelectedSession(context.Background(), input, deps)
|
||||||
|
if !errors.Is(err, outage) || failed.Ready || failed.Preparation.Outcome != "failed" || !strings.Contains(failed.Preparation.Reason, "could not be verified") || !strings.Contains(err.Error(), "synthetic S3 access failure") {
|
||||||
|
t.Fatalf("access failure=%+v error=%v", failed, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user