Verify publishing and restore after cleanup

This commit is contained in:
2026-11-30 14:04:10 +00:00
parent e9a81509b0
commit e9d74a7de0
4 changed files with 97 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import (
"time"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/config"
@@ -101,4 +102,46 @@ func TestCleanedSessionReusesProductsAndSupportsForcedAnalysis(t *testing.T) {
if _, err := os.Stat(filepath.Join(paths.ArtifactsDir, "recap.md")); err != nil {
t.Fatalf("canonical output missing: %v", err)
}
// Publish the retained products in another invocation after the old run is gone.
cfg.Pipeline.Storage.Backend = config.StorageBackendS3
cfg.Pipeline.Publish = &config.PublishConfig{Enabled: boolPtr(true), UploadRun: boolPtr(true), Outputs: []config.PublishOutputRule{
{Source: artifacts.ExtractionArtifactSourceID("npc_registry"), Dest: "artifacts/npc_registry.json", Required: boolPtr(true)},
{Source: artifacts.ConfiguredArtifactSourceID("recap"), Dest: "artifacts/recap.md", Required: boolPtr(true)},
}}
cfg.ArtifactCatalog, err = config.DeriveArtifactCatalog(cfg.Pipeline, cfg.Party)
if err != nil {
t.Fatal(err)
}
seed = loadLifecycleManifest(t, cfg)
for _, name := range []string{"merge", "polish", "normalize", "render"} {
seed.MarkStageSucceeded(name, time.Now().UTC(), nil)
}
if err := (&manifest.LocalStore{}).Save(context.Background(), paths.ManifestPath, seed); err != nil {
t.Fatal(err)
}
remote := &storage.FakeBackend{}
env.ObjectStore = remote
invoke("publish-again", BoundedPlan{stages: []stage.Stage{mustSelectStage(t, "publish"), selectedCleanupStage(t)}}, false)
if _, err := os.Lstat(paths.RunsDir); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("second cleanup left runs: %v", err)
}
prefix := artifacts.S3SessionPrefix("dnd", cfg.Session.Campaign, cfg.Session.SessionID)
pointerKey := artifacts.S3CurrentCommitPointerKey(prefix)
if len(remote.Uploads) == 0 || remote.Uploads[len(remote.Uploads)-1].Key != pointerKey {
t.Fatalf("publication pointer not last: %#v", remote.Uploads)
}
commit, err := artifacts.DecodeRemoteCommitManifest(remote.Objects[artifacts.S3RunCommitKey(prefix, "publish-again")].Data)
if err != nil {
t.Fatal(err)
}
var found int
for _, item := range commit.Artifacts {
if item.Type == artifacts.RemoteArtifactTypePublishedOutput {
found++
}
}
if found != 2 {
t.Fatalf("published product count = %d, commit = %#v", found, commit)
}
}