Require committed remote current state
This commit is contained in:
@@ -351,7 +351,71 @@ func TestRestorePlanTraversalUnsafeKeyFails(t *testing.T) {
|
||||
}
|
||||
|
||||
func seedRestoreObject(store *storage.FakeBackend, key string, data []byte) {
|
||||
if strings.HasSuffix(key, "/current/commit-pointer.json") {
|
||||
if _, exists := store.Objects[key]; exists {
|
||||
return
|
||||
}
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: key, Data: data})
|
||||
for pointerKey, pointerObject := range store.Objects {
|
||||
if !strings.HasSuffix(pointerKey, "/current/commit-pointer.json") || key == pointerKey {
|
||||
continue
|
||||
}
|
||||
pointer, err := artifacts.DecodeCurrentCommitPointer(pointerObject.Data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
commitObject, ok := store.Objects[pointer.CommitKey]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
commit, err := artifacts.DecodeRemoteCommitManifest(commitObject.Data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
runPrefix := strings.TrimSuffix(pointer.CommitKey, "commit.json")
|
||||
sessionPrefix := strings.TrimSuffix(runPrefix, "runs/"+pointer.RunID+"/")
|
||||
if !strings.HasPrefix(key, sessionPrefix) {
|
||||
continue
|
||||
}
|
||||
destination := key
|
||||
if strings.HasPrefix(key, sessionPrefix) && !strings.HasPrefix(key, runPrefix) {
|
||||
destination = runPrefix + strings.TrimPrefix(key, sessionPrefix)
|
||||
store.SeedObject(storage.FakeObject{Key: destination, Data: data})
|
||||
}
|
||||
typeID := artifacts.RemoteArtifactTypePublishedOutput
|
||||
source := "narratio.test"
|
||||
if destination == artifacts.S3RunSessionManifestKey(sessionPrefix, pointer.RunID) {
|
||||
typeID, source = artifacts.RemoteArtifactTypeSessionManifest, "session.manifest"
|
||||
} else if relative := strings.TrimPrefix(destination, runPrefix); strings.HasPrefix(relative, "artifacts/") {
|
||||
name := strings.TrimSuffix(strings.TrimPrefix(relative, "artifacts/"), filepath.Ext(relative))
|
||||
source = artifacts.ConfiguredArtifactSourceID(name)
|
||||
}
|
||||
artifact := remoteRestoreArtifact(store, typeID, source, destination)
|
||||
replaced := false
|
||||
for index := range commit.Artifacts {
|
||||
if commit.Artifacts[index].DestinationKey == destination {
|
||||
commit.Artifacts[index] = artifact
|
||||
replaced = true
|
||||
}
|
||||
}
|
||||
if !replaced {
|
||||
commit.Artifacts = append(commit.Artifacts, artifact)
|
||||
}
|
||||
commitData, err := artifacts.EncodeRemoteCommitManifest(*commit)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: pointer.CommitKey, Data: commitData})
|
||||
commitObject = store.Objects[pointer.CommitKey]
|
||||
pointer.CommitSHA256 = restoreCommitSHA256(commitData)
|
||||
pointer.CommitSize = int64(len(commitData))
|
||||
pointer.CommitGeneration = commitObject.ETag
|
||||
pointerData, err := artifacts.EncodeCurrentCommitPointer(*pointer)
|
||||
if err == nil {
|
||||
store.SeedObject(storage.FakeObject{Key: pointerKey, Data: pointerData})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func actionRelPaths(actions []RestoreAction) []string {
|
||||
@@ -402,12 +466,10 @@ func configureRestorePlanPreviousRequirement(cfg *config.Config, required bool)
|
||||
func restorePlanCurrentState(t *testing.T, cfg *config.Config) *RemoteCurrentState {
|
||||
t.Helper()
|
||||
sessionPrefix := artifacts.S3SessionPrefix("dnd", cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
manifestKey, runIDKey := artifacts.ResolveCurrentStateKeys(sessionPrefix)
|
||||
return &RemoteCurrentState{
|
||||
Bucket: "test-bucket",
|
||||
SessionPrefix: sessionPrefix,
|
||||
CurrentManifestKey: manifestKey,
|
||||
CurrentRunIDKey: runIDKey,
|
||||
CurrentManifestKey: artifacts.S3RunSessionManifestKey(sessionPrefix, "20260519T010203Z-a1b2c3d4"),
|
||||
RunID: "20260519T010203Z-a1b2c3d4",
|
||||
SessionID: cfg.Session.SessionID,
|
||||
Campaign: cfg.Session.Campaign,
|
||||
|
||||
Reference in New Issue
Block a user