Verify publishing and restore after cleanup
This commit is contained in:
@@ -271,7 +271,7 @@ evidence after historical run files are gone.
|
|||||||
|
|
||||||
## Stage 6: Verify Publication And Restore With Disposable Run History
|
## Stage 6: Verify Publication And Restore With Disposable Run History
|
||||||
|
|
||||||
Status: Pending.
|
Status: Complete.
|
||||||
|
|
||||||
Read `internal/stage/publish_sources.go`, `publish_commit.go`,
|
Read `internal/stage/publish_sources.go`, `publish_commit.go`,
|
||||||
`internal/app/restore_manifest_paths.go`, `restore_workflow_test.go`,
|
`internal/app/restore_manifest_paths.go`, `restore_workflow_test.go`,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/whisperx"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||||
"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"
|
||||||
@@ -101,4 +102,46 @@ func TestCleanedSessionReusesProductsAndSupportsForcedAnalysis(t *testing.T) {
|
|||||||
if _, err := os.Stat(filepath.Join(paths.ArtifactsDir, "recap.md")); err != nil {
|
if _, err := os.Stat(filepath.Join(paths.ArtifactsDir, "recap.md")); err != nil {
|
||||||
t.Fatalf("canonical output missing: %v", err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ func TestRestoreThenForcedAnalyzeUsesRestoredDurableState(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("load restored session manifest: %v", err)
|
t.Fatalf("load restored session manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
producerRun := filepath.Join(sessionRoot, "runs", "20260519T010203Z-a1b2c3d4")
|
||||||
|
if _, err := os.Stat(producerRun); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("restore unexpectedly required producer run: %v", err)
|
||||||
|
}
|
||||||
upstreamCompletedAt := map[string]time.Time{}
|
upstreamCompletedAt := map[string]time.Time{}
|
||||||
for _, stageName := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "extract"} {
|
for _, stageName := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "extract"} {
|
||||||
rec := beforeAnalyze.Stages[stageName]
|
rec := beforeAnalyze.Stages[stageName]
|
||||||
@@ -262,6 +266,8 @@ func restoreWorkflowManifestJSON(t *testing.T, sessionID, campaign string) []byt
|
|||||||
for i, stageName := range stages {
|
for i, stageName := range stages {
|
||||||
m.MarkStageSucceeded(stageName, now.Add(time.Duration(i+1)*time.Minute), nil)
|
m.MarkStageSucceeded(stageName, now.Add(time.Duration(i+1)*time.Minute), nil)
|
||||||
}
|
}
|
||||||
|
m.Stages["trim"].Logs = []string{"/prior/session/runs/old/trim/logs/report.json"}
|
||||||
|
m.Stages["trim"].GeneratedConfigs = []string{"/prior/session/runs/old/trim/config.yml"}
|
||||||
transcript := filepath.Join(t.TempDir(), "final.trimmed.json")
|
transcript := filepath.Join(t.TempDir(), "final.trimmed.json")
|
||||||
mustWriteTestFile(t, transcript, `{"segments":[]}`+"\n")
|
mustWriteTestFile(t, transcript, `{"segments":[]}`+"\n")
|
||||||
setCurrentBuiltInEvidence(t, m, "trim", artifacts.TranscriptOutputKindFinalTrimmed, artifacts.ArtifactTranscriptFinalTrimmed, transcript)
|
setCurrentBuiltInEvidence(t, m, "trim", artifacts.TranscriptOutputKindFinalTrimmed, artifacts.ArtifactTranscriptFinalTrimmed, transcript)
|
||||||
|
|||||||
@@ -1411,3 +1411,50 @@ func writeStageTestFile(t *testing.T, path, contents string) {
|
|||||||
t.Fatalf("WriteFile(%q): %v", path, err)
|
t.Fatalf("WriteFile(%q): %v", path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPublishAfterCleanupUsesDurableProducts(t *testing.T) {
|
||||||
|
env, m, oldRun := publishFixture(t)
|
||||||
|
env.Config.Pipeline.Workspace.CleanupAfterPublish = true
|
||||||
|
fake := env.ObjectStore.(*storage.FakeBackend)
|
||||||
|
first, err := (publishStage{}).Run(context.Background(), env, m)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m.MarkStageSucceeded("publish", time.Now().UTC(), nil)
|
||||||
|
m.Stages["publish"].Metadata = first.Metadata
|
||||||
|
if _, err := (cleanupStage{}).Run(context.Background(), env, m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Lstat(oldRun); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("old run remains: %v", err)
|
||||||
|
}
|
||||||
|
m.RunID = "20260517T010203Z-1a2b3c4d"
|
||||||
|
m.S3RunPrefix = artifacts.S3RunPrefix(m.S3SessionPrefix, m.RunID)
|
||||||
|
m.LocalWorkDir = artifacts.SessionRunRootForCampaign(env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID)
|
||||||
|
writeStageTestFile(t, filepath.Join(m.LocalWorkDir, "publish", "logs", "current.log"), "current")
|
||||||
|
m.Stages["polish"].Logs = []string{filepath.Join(m.LocalWorkDir, "publish", "logs", "current.log")}
|
||||||
|
second, err := (publishStage{}).Run(context.Background(), env, m)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("publish after cleanup: %v", err)
|
||||||
|
}
|
||||||
|
for _, rel := range []string{"transcripts/final.trimmed.json", "artifacts/session_recap.md"} {
|
||||||
|
if _, ok := fake.Objects[publishOutputRemoteKey(m.S3RunPrefix, rel)]; !ok {
|
||||||
|
t.Fatalf("missing published product %s", rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if got := second.Metadata["run_uploaded_paths"]; !reflect.DeepEqual(got, []string{"publish/logs/current.log"}) {
|
||||||
|
t.Fatalf("current run uploads = %#v", got)
|
||||||
|
}
|
||||||
|
pointer := artifacts.S3CurrentCommitPointerKey(m.S3SessionPrefix)
|
||||||
|
if len(fake.Uploads) == 0 || fake.Uploads[len(fake.Uploads)-1].Key != pointer {
|
||||||
|
t.Fatal("pointer was not written last")
|
||||||
|
}
|
||||||
|
m.MarkStageSucceeded("publish", time.Now().UTC(), nil)
|
||||||
|
m.Stages["publish"].Metadata = second.Metadata
|
||||||
|
if _, err := (cleanupStage{}).Run(context.Background(), env, m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Lstat(filepath.Dir(m.LocalWorkDir)); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("new runs remain: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user