Restore prepared inputs and flat session products

This commit is contained in:
2026-11-30 01:53:11 +00:00
parent e19ba81406
commit 3118bc35ba
12 changed files with 282 additions and 62 deletions

View File

@@ -43,6 +43,40 @@ func TestCommittedRestorePlanUsesOnlyDeclaredObjects(t *testing.T) {
}
}
func TestCommittedRestoreInstallsPreparedInputsAndFlatProducts(t *testing.T) {
cfg := restorePlanConfig(t)
fake := &storage.FakeBackend{}
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{
"artifacts/session_recap.md": []byte("recap"),
})
for _, name := range []string{"autocorrect.yml", "players.yml", "speakers.yml", "pipeline.resolved.yml", "glossaries/party.yml", "glossaries/campaign.yml", "glossaries/setting.yml", "glossaries/spells.yml", "glossaries/combined.yml"} {
rel := "prepare/inputs/" + name
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, current.RunID), rel)
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("prepared " + name)})
current.Commit.Artifacts = append(current.Commit.Artifacts, remoteRestoreArtifact(fake, artifacts.RemoteArtifactTypeRunFile, "run:"+rel, key))
}
for i := range current.Commit.Artifacts {
item := &current.Commit.Artifacts[i]
if item.Type == artifacts.RemoteArtifactTypePublishedOutput {
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, current.RunID), "published/custom/nested/recap.md")
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("recap")})
item.DestinationKey, item.Generation = key, fake.Objects[key].ETag
}
}
plan, err := buildRestorePlan(context.Background(), cfg, current, fake, RestorePlanOptions{})
if err != nil {
t.Fatal(err)
}
if _, err := executeRestorePlan(context.Background(), cfg, current, plan, nil, fake); err != nil {
t.Fatal(err)
}
root := artifacts.SessionWorkDirForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
mustReadEquals(t, filepath.Join(root, "artifacts", "session_recap.md"), "recap")
for _, name := range []string{"autocorrect.yml", "glossaries/combined.yml", "speakers.yml"} {
mustReadEquals(t, filepath.Join(root, "inputs", filepath.FromSlash(name)), "prepared "+name)
}
}
func TestCommittedRestoreDoesNotRequirePolishRunDiagnostics(t *testing.T) {
cfg := restorePlanConfig(t)
fake := &storage.FakeBackend{}
@@ -391,6 +425,19 @@ func seedCommittedRestoreSnapshot(t *testing.T, cfg *config.Config, fake *storag
remoteManifest := manifest.New(cfg.Session.SessionID, time.Now().UTC())
remoteManifest.Campaign = cfg.Session.Campaign
remoteManifest.RunID = runID
for relative := range outputs {
parts := strings.Split(relative, "/")
if len(parts) != 2 || (parts[0] != "transcripts" && parts[0] != "artifacts") {
continue
}
sourceKey := strings.NewReplacer("/", "_", ".", "_", "-", "_").Replace(relative)
record := remoteManifest.Stages["fixture"]
if record == nil {
record = &manifest.StageRecord{Name: "fixture", Status: manifest.StatusSucceeded}
remoteManifest.Stages["fixture"] = record
}
record.Outputs = append(record.Outputs, manifest.ArtifactRecord{SourceID: artifacts.ConfiguredArtifactSourceID(sourceKey), LocalPath: relative})
}
manifestData, err := json.Marshal(remoteManifest)
if err != nil {
t.Fatalf("marshal manifest: %v", err)