Read publication inventory without execution snapshots
This commit is contained in:
@@ -397,3 +397,52 @@ func appendUnknownJSONField(t *testing.T, data []byte) []byte {
|
||||
}
|
||||
return append(append([]byte(nil), trimmed[:len(trimmed)-1]...), []byte(`,"unexpected":true}`)...)
|
||||
}
|
||||
|
||||
func TestCurrentInventoryDoesNotReadExecutionSnapshot(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
snapshot bool
|
||||
body []byte
|
||||
}{
|
||||
{"no snapshot", false, nil}, {"missing snapshot", true, nil}, {"malformed snapshot", true, []byte("not json")}, {"unsupported snapshot", true, []byte(`{"schema_version":"unsupported"}`)},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
prefix := testCurrentSessionPrefix()
|
||||
runID := "20260519T010203Z-a1b2c3d4"
|
||||
commit := testRemoteCommit(t, runID)
|
||||
old := commit.Artifacts[0]
|
||||
commit.Artifacts = []RemoteArtifact{{Type: RemoteArtifactTypePublishedOutput, Source: ArtifactTranscriptFinalTrimmed, DestinationKey: S3RunRelativeDestinationKey(S3RunPrefix(prefix, runID), "published/transcripts/final.trimmed.json"), SHA256: strings.Repeat("a", 64), Size: 1, Generation: "output-generation"}}
|
||||
if tc.snapshot {
|
||||
commit.Artifacts = append(commit.Artifacts, old)
|
||||
}
|
||||
store := &storage.FakeBackend{}
|
||||
if tc.body != nil {
|
||||
store.SeedObject(storage.FakeObject{Key: old.DestinationKey, Data: tc.body, ETag: "irrelevant"})
|
||||
}
|
||||
data, err := EncodeRemoteCommitManifest(commit)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := S3RunCommitKey(prefix, runID)
|
||||
store.SeedObject(storage.FakeObject{Key: key, Data: data, ETag: "commit-generation"})
|
||||
pointer := testCommitPointer(t, prefix, commit)
|
||||
encoded, err := EncodeCurrentCommitPointer(pointer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: S3CurrentCommitPointerKey(prefix), Data: encoded})
|
||||
current, err := LoadCurrentInventory(context.Background(), store, prefix, CurrentStateValidation{ExpectedCampaign: commit.Campaign, ExpectedSessionID: commit.SessionID, ExpectedRunID: runID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if current.Manifest != nil || current.Commit.RunID != runID {
|
||||
t.Fatalf("inventory %+v", current)
|
||||
}
|
||||
for _, read := range store.Reads {
|
||||
if read.Key == old.DestinationKey {
|
||||
t.Fatal("execution snapshot was read")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user