Document and verify published product imports
This commit is contained in:
@@ -108,7 +108,7 @@ func findRemoteSessionConfig(ctx context.Context, store storage.ObjectStore, ses
|
||||
}
|
||||
var selected *artifacts.RemoteArtifact
|
||||
if !authored {
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{ExpectedCampaign: campaign, ExpectedSessionID: sessionID, ValidateRunID: true})
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{ExpectedCampaign: campaign, ExpectedSessionID: sessionID})
|
||||
if err == nil {
|
||||
for _, item := range current.Commit.Artifacts {
|
||||
if item.Type == artifacts.RemoteArtifactTypeRunFile && item.Source == "run:prepare/inputs/session.yml" {
|
||||
|
||||
@@ -156,16 +156,24 @@ func TestLockedProductsRemainUsableAfterImportAndRepublish(t *testing.T) {
|
||||
if _, err := artifacts.ResolveSessionArtifactWithCatalog(importedPaths, imported, artifacts.ConfiguredArtifactSourceID("session_recap"), catalog); err != nil {
|
||||
t.Fatalf("carried configured product unavailable: %v", err)
|
||||
}
|
||||
downstream := &scriptorium.FakeRunner{}
|
||||
result, err := executePlan(ctx, cfg, mustBoundedPlan(t, "analyze", "analyze"), RunOptions{Force: true, SelectedArtifacts: []string{"player_handout"}, Env: &Env{Scriptorium: downstream}})
|
||||
if err != nil {
|
||||
t.Fatalf("consume carried product in downstream work: %v", err)
|
||||
}
|
||||
if len(downstream.RunRequests) != 1 || downstream.RunRequests[0].InputPaths["recap"] != filepath.Join(importedPaths.ArtifactsDir, "session_recap.md") {
|
||||
t.Fatalf("downstream work did not reuse the carried recap: %#v", downstream.RunRequests)
|
||||
}
|
||||
imported, err = (&manifest.LocalStore{}).Load(ctx, result.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, rule := range rules {
|
||||
if err := artifacts.RemoveRemoteLock(ctx, fake, prefix, rule.Source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
imported.RunID = "20260521T010203Z-a1b2c3d4"
|
||||
imported.LocalWorkDir = artifacts.SessionRunRootForCampaign(cfg.Pipeline.Workspace.Root, imported.Campaign, imported.SessionID, imported.RunID)
|
||||
if err := os.MkdirAll(imported.LocalWorkDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
publishedRun := imported.RunID
|
||||
env.ArtifactStore = artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
if _, err := publish.Run(ctx, env, imported); err != nil {
|
||||
t.Fatalf("republish imported products: %v", err)
|
||||
@@ -174,6 +182,7 @@ func TestLockedProductsRemainUsableAfterImportAndRepublish(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
imported.RunID = "20260522T010203Z-a1b2c3d4"
|
||||
imported.S3RunPrefix = artifacts.S3RunPrefix(prefix, imported.RunID)
|
||||
imported.LocalWorkDir = artifacts.SessionRunRootForCampaign(cfg.Pipeline.Workspace.Root, imported.Campaign, imported.SessionID, imported.RunID)
|
||||
if err := os.MkdirAll(imported.LocalWorkDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -182,7 +191,7 @@ func TestLockedProductsRemainUsableAfterImportAndRepublish(t *testing.T) {
|
||||
t.Fatal("republish accepted a tampered required product")
|
||||
}
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, fake, prefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil || current.RunID != "20260521T010203Z-a1b2c3d4" {
|
||||
if err != nil || current.RunID != publishedRun {
|
||||
t.Fatalf("failed republish changed current publication: %#v, %v", current, err)
|
||||
}
|
||||
}
|
||||
@@ -222,6 +231,18 @@ func TestImportedPartialExtractionRegeneratesCompleteBundle(t *testing.T) {
|
||||
if artifacts.SuppliedExtractionComplete(paths, before, artifacts.ExtractionDefinitionsFromConfig(cfg.Pipeline.Notarius)) {
|
||||
t.Fatal("partial extraction was treated as complete")
|
||||
}
|
||||
definitions := artifacts.ExtractionDefinitionsFromConfig(cfg.Pipeline.Notarius)
|
||||
catalog := artifacts.NewArtifactCatalog()
|
||||
if err := catalog.RegisterExtractionArtifacts(definitions); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.HydrateExtractionArtifacts(paths, before, definitions)
|
||||
if _, err := artifacts.ResolveSessionArtifactWithCatalog(paths, before, artifacts.ExtractionArtifactSourceID("npc_registry"), catalog); err != nil {
|
||||
t.Fatalf("imported extraction product unavailable: %v", err)
|
||||
}
|
||||
if _, err := artifacts.ResolveSessionArtifactWithCatalog(paths, before, artifacts.ExtractionArtifactSourceID("encounters"), catalog); err == nil {
|
||||
t.Fatal("missing extraction product became available")
|
||||
}
|
||||
runner := &materializingNotariusRunner{cfg: cfg.Pipeline.Notarius}
|
||||
result, err := executePlan(ctx, cfg, mustBoundedPlan(t, "extract", "extract"), RunOptions{Env: &Env{Notarius: runner}})
|
||||
if err != nil {
|
||||
|
||||
@@ -1169,7 +1169,7 @@ func TestExecutePublishIgnoresRetiredSharedLockObject(t *testing.T) {
|
||||
if storeInitCalls != 1 {
|
||||
t.Fatalf("object store initialization calls = %d, want 1", storeInitCalls)
|
||||
}
|
||||
current, err := artifacts.LoadCurrentInventory(context.Background(), fake, sessionPrefix, artifacts.CurrentStateValidation{ValidateRunID: true})
|
||||
current, err := artifacts.LoadCurrentInventory(context.Background(), fake, sessionPrefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadCurrentState() error = %v", err)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -99,7 +100,14 @@ func TestFullRunWithSuppliedTranscriptPreparesAndRendersSelectedVariant(t *testi
|
||||
if _, err := restoreSessionState(context.Background(), cfg, RestorePlanOptions{}, normalizeCommandDependencies(restoreCommandDependencies(fake))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plan := mustBoundedPlan(t, "", "analyze")
|
||||
baseline, err := (&manifest.LocalStore{}).Load(context.Background(), manifestPathFor(cfg))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if baseline.Stages["publish"] != nil || baseline.Stages["cleanup"] != nil {
|
||||
t.Fatalf("import fabricated publication or cleanup: %#v", baseline.Stages)
|
||||
}
|
||||
plan := mustBoundedPlan(t, "", "")
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -131,6 +139,17 @@ func TestFullRunWithSuppliedTranscriptPreparesAndRendersSelectedVariant(t *testi
|
||||
}
|
||||
}
|
||||
}
|
||||
current, err := discoverRemotePublication(context.Background(), cfg, fake)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
restorePreview, err := buildInventoryRestorePlan(context.Background(), cfg, current, fake, RestorePlanOptions{DryRun: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Contains(restorePreview.Satisfied, "render") || slices.Contains(restorePreview.Remaining, "render") {
|
||||
t.Fatalf("restore preview did not preserve reusable local render: %#v", restorePreview)
|
||||
}
|
||||
forced := mustBoundedPlan(t, "transcribe", "transcribe")
|
||||
input := &executionInput{plan: forced}
|
||||
input.Force.Value = true
|
||||
|
||||
@@ -24,12 +24,22 @@ func TestInventoryImportInstallsValidatedBaselineAndRetriesSave(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if err := os.MkdirAll(paths.Root, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := writeRestoreMarker(paths); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := executeRestorePlan(ctx, cfg, current, plan, nil, fake); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := installInventoryBaseline(ctx, cfg, plan, &failingRestoreManifestStore{}); err == nil {
|
||||
t.Fatal("expected final manifest save to fail")
|
||||
}
|
||||
if err := requireCompleteRestore(paths); err == nil {
|
||||
t.Fatal("failed save did not retain the incomplete-restore marker")
|
||||
}
|
||||
path := artifacts.SessionManifestPathForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
t.Fatalf("failed save installed manifest: %v", err)
|
||||
@@ -41,11 +51,13 @@ func TestInventoryImportInstallsValidatedBaselineAndRetriesSave(t *testing.T) {
|
||||
if err := installInventoryBaseline(ctx, cfg, retry, &manifest.LocalStore{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := clearRestoreMarker(paths); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := (&manifest.LocalStore{}).Load(ctx, path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if !artifacts.SuppliedTranscriptCoverage(paths, loaded.SuppliedProducts)["trim"] {
|
||||
t.Fatalf("trimmed transcript unavailable after retry: %#v", loaded.SuppliedProducts)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,16 @@ func installInventoryBaseline(ctx context.Context, cfg *config.Config, plan *Res
|
||||
if err := artifacts.ValidateSuppliedProduct(paths, action.SourceID, action.LocalRelativePath, record); err != nil {
|
||||
return fmt.Errorf("validate imported product %q: %w", action.SourceID, err)
|
||||
}
|
||||
if priorSourceChecksum(plan.baseline, action.SourceID) == action.SHA256 {
|
||||
}
|
||||
if err := invalidateImportedDependencies(plan.candidate, plan.baseline, plan.Actions); err != nil {
|
||||
return err
|
||||
}
|
||||
return store.Save(ctx, paths.ManifestPath, plan.candidate)
|
||||
}
|
||||
|
||||
func invalidateImportedDependencies(candidate, baseline *manifest.Manifest, actions []RestoreAction) error {
|
||||
for _, action := range actions {
|
||||
if action.SourceID == "" || action.Kind == RestoreActionConflict || priorSourceChecksum(baseline, action.SourceID) == action.SHA256 {
|
||||
continue
|
||||
}
|
||||
producer := importedProductProducer(action.SourceID)
|
||||
@@ -38,14 +47,14 @@ func installInventoryBaseline(ctx context.Context, cfg *config.Config, plan *Res
|
||||
return fmt.Errorf("unknown imported product source %q", action.SourceID)
|
||||
}
|
||||
at := time.Now().UTC()
|
||||
if existing := plan.candidate.Stages[producer]; existing != nil && existing.Status == manifest.StatusSucceeded {
|
||||
plan.candidate.MarkStageStale(producer, at, staleReasonChangedResult)
|
||||
if existing := candidate.Stages[producer]; existing != nil && existing.Status == manifest.StatusSucceeded {
|
||||
candidate.MarkStageStale(producer, at, staleReasonChangedResult)
|
||||
}
|
||||
if _, err := invalidateDependentSucceededStagesWithReason(plan.candidate, producer, at, staleReasonChangedResult); err != nil {
|
||||
if _, err := invalidateDependentSucceededStagesWithReason(candidate, producer, at, staleReasonChangedResult); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return store.Save(ctx, paths.ManifestPath, plan.candidate)
|
||||
return nil
|
||||
}
|
||||
|
||||
func importedProductProducer(source string) string {
|
||||
|
||||
@@ -137,7 +137,7 @@ func buildInventoryRestorePlan(ctx context.Context, cfg *config.Config, current
|
||||
})
|
||||
|
||||
plan := &RestorePlan{Actions: actions}
|
||||
if err := projectInventoryCoverage(ctx, cfg, plan); err != nil {
|
||||
if err := projectInventoryCoverage(ctx, cfg, plan, store); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, action := range actions {
|
||||
@@ -157,7 +157,7 @@ func buildInventoryRestorePlan(ctx context.Context, cfg *config.Config, current
|
||||
|
||||
// projectInventoryCoverage describes completion if all accepted transfers
|
||||
// validate successfully. It never treats a declaration as verified content.
|
||||
func projectInventoryCoverage(ctx context.Context, cfg *config.Config, plan *RestorePlan) error {
|
||||
func projectInventoryCoverage(ctx context.Context, cfg *config.Config, plan *RestorePlan, store storage.ObjectStore) error {
|
||||
manifestPath := artifacts.SessionManifestPathForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
local, _, err := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, manifestPath)
|
||||
if err != nil {
|
||||
@@ -261,12 +261,34 @@ func projectInventoryCoverage(ctx context.Context, cfg *config.Config, plan *Res
|
||||
}
|
||||
covered["extract"] = covered["extract"] || complete
|
||||
}
|
||||
if cfg.Pipeline.Render == nil || cfg.Pipeline.Render.Enabled == nil || *cfg.Pipeline.Render.Enabled {
|
||||
names = append(names, "render")
|
||||
}
|
||||
if cfg.Pipeline.Notarius != nil && cfg.Pipeline.Notarius.Enabled {
|
||||
names = append(names, "extract")
|
||||
// Reuse the normal read-only stage projection for preserved local work.
|
||||
// Proposed downloads have not been installed, so the supplied coverage above
|
||||
// remains conditional and local validation may conservatively schedule work.
|
||||
if local != nil {
|
||||
model, cloneErr := cloneManifestForPlan(plan.candidate, cfg)
|
||||
if cloneErr != nil {
|
||||
return cloneErr
|
||||
}
|
||||
if err := invalidateImportedDependencies(model, plan.baseline, plan.Actions); err != nil {
|
||||
return err
|
||||
}
|
||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
||||
selection, selectionErr := BuildBoundedPlan("", "")
|
||||
if effectiveErr == nil && selectionErr == nil {
|
||||
projection, _ := projectSelectedWork(ctx, cfg, selection, false, nil, effective, artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root), store, model)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if projection != nil {
|
||||
for _, item := range projection.Stages {
|
||||
if item.Decision.action == stageActionSkip && recordedStageStatus(local, item.Name) == manifest.StatusSucceeded {
|
||||
covered[item.Name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
names = []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "extract", "analyze", "publish", "notify", "cleanup"}
|
||||
for _, name := range names {
|
||||
if covered[name] {
|
||||
plan.Satisfied = append(plan.Satisfied, name)
|
||||
|
||||
@@ -77,6 +77,17 @@ func TestRestoreThenForcedAnalyzeUsesRestoredDurableState(t *testing.T) {
|
||||
if beforeAnalyze.Stages["trim"] != nil {
|
||||
t.Fatal("import invented a trim execution")
|
||||
}
|
||||
selected := []string{"player_handout"}
|
||||
effective, err := resolveEffectiveArtifacts(cfg, selected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := &executionInput{plan: mustBoundedPlan(t, "analyze", "analyze")}
|
||||
input.Force.Value = true
|
||||
preview, err := buildSessionPlan(context.Background(), cfg, input, selected, effective, commandDependencies{})
|
||||
if err != nil || len(preview.Stages) != 1 || preview.Stages[0].Action != "run" || preview.Stages[0].Analysis == nil || len(preview.Stages[0].Analysis.Reuse) != 1 {
|
||||
t.Fatalf("bounded analysis preview = %#v, %v", preview, err)
|
||||
}
|
||||
|
||||
stdout.Reset()
|
||||
stderr.Reset()
|
||||
|
||||
@@ -37,7 +37,6 @@ type CurrentStateValidation struct {
|
||||
ExpectedCampaign string
|
||||
ExpectedSessionID string
|
||||
ExpectedRunID string
|
||||
ValidateRunID bool
|
||||
}
|
||||
|
||||
// LoadCurrentInventory reads the selected publication identity and declarations
|
||||
|
||||
@@ -166,7 +166,6 @@ func TestLoadCurrentStateReadsVerifiedRemoteCommit(t *testing.T) {
|
||||
state, err := LoadCurrentInventory(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{
|
||||
ExpectedCampaign: commit.Campaign,
|
||||
ExpectedSessionID: commit.SessionID,
|
||||
ValidateRunID: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadCurrentInventory() error = %v", err)
|
||||
|
||||
@@ -320,6 +320,7 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
sessionFile string
|
||||
}{
|
||||
{name: "catalog pipeline with local audio session", pipelineFile: "pipeline.catalog.yml", sessionFile: "session.local-audio.yml"},
|
||||
{name: "minimal pipeline with published products", pipelineFile: "pipeline.minimal.yml", sessionFile: "session.published-products.yml"},
|
||||
{
|
||||
name: "minimal pipeline with local audio session",
|
||||
pipelineFile: "pipeline.minimal.yml",
|
||||
|
||||
@@ -99,7 +99,6 @@ func Resolve(
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, store, previousSessionPrefix, artifacts.CurrentStateValidation{
|
||||
ExpectedSessionID: previousSessionID,
|
||||
ExpectedCampaign: campaign,
|
||||
ValidateRunID: true,
|
||||
})
|
||||
if err != nil {
|
||||
var pointerMissing *artifacts.CurrentCommitPointerMissingError
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func loadPriorPublishCommit(ctx context.Context, store storage.ObjectStore, sessionPrefix, campaign, sessionID string) (*artifacts.RemoteCommitManifest, error) {
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{
|
||||
ExpectedCampaign: campaign, ExpectedSessionID: sessionID, ValidateRunID: true,
|
||||
ExpectedCampaign: campaign, ExpectedSessionID: sessionID,
|
||||
})
|
||||
if errors.Is(err, artifacts.ErrCurrentCommitPointerMissing) {
|
||||
return nil, nil
|
||||
|
||||
@@ -795,7 +795,7 @@ func TestPublishCarriesLockedRequiredOutputAndCommits(t *testing.T) {
|
||||
t.Fatalf("carried published output metadata = %#v", outcome)
|
||||
}
|
||||
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{ValidateRunID: true})
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -971,7 +971,7 @@ func TestPublishFailurePreservesPreviousCommittedSnapshotAndRetryIsDeterministic
|
||||
if got := fake.Objects[pointerKey].Data; !reflect.DeepEqual(got, priorPointer) {
|
||||
t.Fatalf("current pointer changed after failed publication: %q", got)
|
||||
}
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{ValidateRunID: true})
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadCurrentState() error = %v", err)
|
||||
}
|
||||
@@ -992,7 +992,7 @@ func TestPublishFailurePreservesPreviousCommittedSnapshotAndRetryIsDeterministic
|
||||
if len(fake.Uploads) == 0 || fake.Uploads[len(fake.Uploads)-1].Key != pointerKey {
|
||||
t.Fatalf("retry uploads = %#v, want pointer as final mutation", fake.Uploads)
|
||||
}
|
||||
state, err = artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{ValidateRunID: true})
|
||||
state, err = artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadCurrentState() after retry error = %v", err)
|
||||
}
|
||||
@@ -1051,7 +1051,7 @@ func TestPublishDoesNotSelectCommitWhenLockAppearsAtCommitPoint(t *testing.T) {
|
||||
if _, exists := fake.Objects[commitKey]; !exists {
|
||||
t.Fatalf("immutable attempt commit %q missing after final lock appeared", commitKey)
|
||||
}
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{ValidateRunID: true})
|
||||
state, err := artifacts.LoadCurrentInventory(context.Background(), fake, m.S3SessionPrefix, artifacts.CurrentStateValidation{})
|
||||
if err != nil || state.RunID != oldRunID {
|
||||
t.Fatalf("current state after lock loss = %#v, %v; want old run %q", state, err, oldRunID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user