Verify publishing and restore after cleanup
This commit is contained in:
@@ -1411,3 +1411,50 @@ func writeStageTestFile(t *testing.T, path, contents string) {
|
||||
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