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

@@ -41,6 +41,42 @@ func TestRestorePlanDefaultScope(t *testing.T) {
}
}
func TestRestorePlanMapsNestedPublishedDestinationToFlatProduct(t *testing.T) {
cfg := restorePlanConfig(t)
store := &storage.FakeBackend{}
current := seedCommittedRestoreSnapshot(t, cfg, store, "20260519T010203Z-a1b2c3d4", map[string][]byte{
"artifacts/session_recap.md": []byte("recap"),
})
for i := range current.Commit.Artifacts {
item := &current.Commit.Artifacts[i]
if item.Type != artifacts.RemoteArtifactTypePublishedOutput {
continue
}
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, current.RunID), "published/custom/nested/recap.md")
store.SeedObject(storage.FakeObject{Key: key, Data: []byte("recap")})
item.DestinationKey, item.Generation = key, store.Objects[key].ETag
}
plan, err := buildRestorePlan(context.Background(), cfg, current, store, RestorePlanOptions{})
if err != nil {
t.Fatal(err)
}
action := restoreActionForPath(t, plan, "artifacts/session_recap.md")
if !strings.HasSuffix(action.RemoteKey, "/published/custom/nested/recap.md") {
t.Fatalf("remote key = %q", action.RemoteKey)
}
}
func TestRestorePreparedInputMappingIncludesGeneratedInputs(t *testing.T) {
for _, name := range []string{"autocorrect.yml", "speakers.yml", "players.yml", "pipeline.resolved.yml", "glossaries/combined.yml"} {
sessionPrefix := "dnd/campaigns/c/sessions/s/"
artifact := artifacts.RemoteArtifact{Type: artifacts.RemoteArtifactTypeRunFile, Source: "run:prepare/inputs/" + name, DestinationKey: artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(sessionPrefix, "run-1"), "prepare/inputs/"+name)}
got, included, err := restoreLocalRelativePathForCommittedArtifact(sessionPrefix, artifact, false)
if err != nil || !included || got != "inputs/"+name {
t.Fatalf("%s: path=%q included=%v error=%v", name, got, included, err)
}
}
}
func TestRestorePlanIncludeAudio(t *testing.T) {
cfg := restorePlanConfig(t)
current := restorePlanCurrentState(t, cfg)
@@ -112,7 +148,7 @@ func TestRestorePlanIncludesPreviousCacheByDefault(t *testing.T) {
}
got := actionRelPaths(plan.Actions)
want := []string{"manifest.json", "previous/artifacts/session_recap.md", "previous/manifest.json"}
want := []string{"inputs/previous/artifacts/session_recap.md", "inputs/previous/manifest.json", "manifest.json"}
if !slices.Equal(got, want) {
t.Fatalf("action local paths = %#v, want %#v", got, want)
}
@@ -154,7 +190,7 @@ func TestRestorePlanMissingOptionalPreviousCacheSkipsArtifact(t *testing.T) {
}
got := actionRelPaths(plan.Actions)
want := []string{"manifest.json", "previous/manifest.json"}
want := []string{"inputs/previous/manifest.json", "manifest.json"}
if !slices.Equal(got, want) {
t.Fatalf("action local paths = %#v, want %#v", got, want)
}
@@ -184,7 +220,7 @@ func TestRestorePlanPreviousCacheConflictRequiresForce(t *testing.T) {
seedCurrentRestoreObject(t, store, current, current.CurrentManifestKey, []byte(`{"session_id":"2026-05-03"}`))
seedRestorePreviousCurrent(t, store, cfg, "# remote previous recap\n")
sessionRoot := artifacts.SessionWorkDirForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
mustWriteTestFile(t, filepath.Join(sessionRoot, "previous", "artifacts", "session_recap.md"), "# local previous recap\n")
mustWriteTestFile(t, filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md"), "# local previous recap\n")
plan, err := buildRestorePlan(context.Background(), cfg, current, store, RestorePlanOptions{})
if err != nil {
@@ -410,6 +446,9 @@ func seedRestoreObject(store *storage.FakeBackend, key string, data []byte) {
name := strings.TrimPrefix(relative, "published/")
name = strings.TrimSuffix(strings.TrimPrefix(name, "artifacts/"), filepath.Ext(name))
source = artifacts.ConfiguredArtifactSourceID(name)
if name == "encounters" {
source = artifacts.ExtractionArtifactSourceID(name)
}
}
artifact := remoteRestoreArtifact(store, typeID, source, destination)
replaced := false