Merge imported products into local session state
This commit is contained in:
@@ -163,13 +163,13 @@ func TestLoadCurrentStateReadsVerifiedRemoteCommit(t *testing.T) {
|
||||
commit := testRemoteCommit(t, "20260519T010203Z-a1b2c3d4")
|
||||
seedRemoteCommit(t, store, testCurrentSessionPrefix(), commit, "commit-generation", "manifest-generation")
|
||||
|
||||
state, err := LoadCurrentState(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{
|
||||
state, err := LoadCurrentInventory(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{
|
||||
ExpectedCampaign: commit.Campaign,
|
||||
ExpectedSessionID: commit.SessionID,
|
||||
ValidateRunID: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadCurrentState() error = %v", err)
|
||||
t.Fatalf("LoadCurrentInventory() error = %v", err)
|
||||
}
|
||||
if state.Commit == nil || state.Pointer == nil {
|
||||
t.Fatalf("state does not expose selected immutable commit: %#v", state)
|
||||
@@ -177,11 +177,11 @@ func TestLoadCurrentStateReadsVerifiedRemoteCommit(t *testing.T) {
|
||||
if state.CurrentPointerKey != S3CurrentCommitPointerKey(testCurrentSessionPrefix()) {
|
||||
t.Fatalf("CurrentPointerKey = %q", state.CurrentPointerKey)
|
||||
}
|
||||
if state.Manifest.RunID != commit.RunID {
|
||||
t.Fatalf("manifest run ID = %q, want %q", state.Manifest.RunID, commit.RunID)
|
||||
if state.RunID != commit.RunID {
|
||||
t.Fatalf("inventory run ID = %q, want %q", state.RunID, commit.RunID)
|
||||
}
|
||||
|
||||
wantReads := []string{state.CurrentPointerKey, state.Pointer.CommitKey, state.CurrentManifestKey}
|
||||
wantReads := []string{state.CurrentPointerKey, state.Pointer.CommitKey}
|
||||
if len(store.Reads) != len(wantReads) {
|
||||
t.Fatalf("committed current-state reads = %#v, want %q", store.Reads, wantReads)
|
||||
}
|
||||
@@ -197,21 +197,8 @@ func TestLoadCurrentStateUsesMetadataFromOpenedObjectVersion(t *testing.T) {
|
||||
commit := testRemoteCommit(t, "20260519T010203Z-a1b2c3d4")
|
||||
seedRemoteCommit(t, store, testCurrentSessionPrefix(), commit, "commit-generation", "manifest-generation")
|
||||
|
||||
if _, err := LoadCurrentState(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{}); err != nil {
|
||||
t.Fatalf("LoadCurrentState() error = %v, want verification from Read metadata", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeCommittedManifestGuidesRemoteRecovery(t *testing.T) {
|
||||
_, err := decodeCommittedManifest(context.Background(), []byte(`{"session_id":"2026-05-03"}`))
|
||||
if err == nil {
|
||||
t.Fatal("decodeCommittedManifest() error = nil, want unsupported schema failure")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "schema_version is required") || !strings.Contains(err.Error(), "republish this session") {
|
||||
t.Fatalf("decodeCommittedManifest() error = %v, want schema and republish guidance", err)
|
||||
}
|
||||
if strings.Contains(err.Error(), "local state") {
|
||||
t.Fatalf("decodeCommittedManifest() error = %v, must not describe remote state as local", err)
|
||||
if _, err := LoadCurrentInventory(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{}); err != nil {
|
||||
t.Fatalf("LoadCurrentInventory() error = %v, want verification from Read metadata", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,44 +228,12 @@ func TestLoadCurrentStateRejectsPointerCommitIdentityMismatch(t *testing.T) {
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: S3CurrentCommitPointerKey(prefix), Data: pointerData})
|
||||
|
||||
_, err = LoadCurrentState(context.Background(), store, prefix, CurrentStateValidation{})
|
||||
_, err = LoadCurrentInventory(context.Background(), store, prefix, CurrentStateValidation{})
|
||||
if err == nil || !strings.Contains(err.Error(), "does not match selected remote commit") {
|
||||
t.Fatalf("error = %v, want pointer/commit identity mismatch", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadCurrentStateRejectsCommitManifestIdentityMismatch(t *testing.T) {
|
||||
store := &storage.FakeBackend{}
|
||||
commit := testRemoteCommit(t, "20260519T010203Z-a1b2c3d4")
|
||||
pointer := seedRemoteCommit(t, store, testCurrentSessionPrefix(), commit, "commit-generation", "manifest-generation")
|
||||
|
||||
wrongManifest := testManifestJSON(t, "2026-05-03", "wrong-campaign", commit.RunID)
|
||||
store.SeedObject(storage.FakeObject{
|
||||
Key: commit.Artifacts[0].DestinationKey,
|
||||
Data: wrongManifest,
|
||||
ETag: "manifest-generation",
|
||||
})
|
||||
commit.Artifacts[0].SHA256 = remoteObjectSHA256(wrongManifest)
|
||||
commit.Artifacts[0].Size = int64(len(wrongManifest))
|
||||
commitData, err := EncodeRemoteCommitManifest(commit)
|
||||
if err != nil {
|
||||
t.Fatalf("EncodeRemoteCommitManifest() error = %v", err)
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: pointer.CommitKey, Data: commitData, ETag: "commit-generation"})
|
||||
pointer.CommitSHA256 = remoteObjectSHA256(commitData)
|
||||
pointer.CommitSize = int64(len(commitData))
|
||||
pointerData, err := EncodeCurrentCommitPointer(*pointer)
|
||||
if err != nil {
|
||||
t.Fatalf("EncodeCurrentCommitPointer() error = %v", err)
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: S3CurrentCommitPointerKey(testCurrentSessionPrefix()), Data: pointerData})
|
||||
|
||||
_, err = LoadCurrentState(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{})
|
||||
if err == nil || !strings.Contains(err.Error(), "does not match committed session manifest") {
|
||||
t.Fatalf("error = %v, want commit/manifest identity mismatch", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadCurrentStateRejectsCommitChecksumOrGenerationMismatch(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -313,7 +268,7 @@ func TestLoadCurrentStateRejectsCommitChecksumOrGenerationMismatch(t *testing.T)
|
||||
}
|
||||
store.SeedObject(storage.FakeObject{Key: S3CurrentCommitPointerKey(testCurrentSessionPrefix()), Data: pointerData})
|
||||
|
||||
_, err = LoadCurrentState(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{})
|
||||
_, err = LoadCurrentInventory(context.Background(), store, testCurrentSessionPrefix(), CurrentStateValidation{})
|
||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("error = %v, want %q", err, test.want)
|
||||
}
|
||||
@@ -435,7 +390,7 @@ func TestCurrentInventoryDoesNotReadExecutionSnapshot(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if current.Manifest != nil || current.Commit.RunID != runID {
|
||||
if current.Commit.RunID != runID {
|
||||
t.Fatalf("inventory %+v", current)
|
||||
}
|
||||
for _, read := range store.Reads {
|
||||
|
||||
Reference in New Issue
Block a user