From ebdf8b522f7f8ab379d7cbae6824ba181ed596ca Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 2 Dec 2026 15:44:52 +0000 Subject: [PATCH] Read publication inventory without execution snapshots --- docs/cli.md | 7 +- docs/internal/artifacts.md | 6 +- docs/roadmap/implementation.md | 2 +- internal/app/command_dependencies.go | 4 ++ internal/app/config_loader.go | 2 +- internal/app/operator_inspection.go | 2 +- internal/app/remote_session_test.go | 69 +++++++++++++++++++ internal/app/restore_commit_test.go | 9 +-- internal/app/restore_discovery.go | 19 +++++ .../app/session_inspection_command_test.go | 13 ++-- internal/app/session_state_command.go | 5 +- internal/artifacts/current_state.go | 17 ++++- internal/artifacts/current_state_commit.go | 31 +++++---- internal/artifacts/remote_commit_test.go | 49 +++++++++++++ 14 files changed, 194 insertions(+), 41 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 87fad77..e9080cd 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -190,9 +190,8 @@ narratio session artifacts SESSION --remote Reports definitions, dependencies, local availability/evidence, and optional remote publication state without reading artifact payload bodies. Without -`--remote`, this command avoids remote artifact inspection. Current publication -outcomes include `published`, `carried_locked`, `locked_unpublished`, -`optional_missing`, and `unselected`. +`--remote`, this command avoids remote artifact inspection. Remote entries use +the selected publication inventory and current lock state. ## Session init @@ -372,7 +371,7 @@ Plan analysis contains `targets`, `prerequisites`, `execute`, and `reuse`; artifact entries identify key, optional family/character, role, reason, and force. Publication actions identify source, destination, required, and selected. Remote status outputs retain source, destination, required, state, lock state, -optional outcome, declared destination/key, origin run, and error. Restore +declared destination/key, origin run, and error. Restore actions carry kind, relative local path, remote key, status, optional reason/error. Clean actions carry path, status (`would_delete`, `deleted`, `missing`, `empty`, `failed`), and optional error; cache records whether it was preserved, requested, diff --git a/docs/internal/artifacts.md b/docs/internal/artifacts.md index cc30d0b..1ec8e29 100644 --- a/docs/internal/artifacts.md +++ b/docs/internal/artifacts.md @@ -186,6 +186,10 @@ Validation by content type: Artifacts package owns shared remote current-state loading mechanics used by restore, status and validation checks, and previous-cache planning. +`LoadCurrentInventory` reads and verifies the pointer-selected commit without +fetching an execution snapshot. Status, publication inspection, and session +configuration acquisition use that inventory. The existing restore and +previous-cache paths still use the snapshot reader until their cutover. The selected session manifest is accepted only with `schema_version: narratio.session-manifest.v2` and complete stage identity. @@ -218,7 +222,7 @@ identity before replacing a canonical local path. Core helpers: -- `LoadCurrentState` +- `LoadCurrentInventory` and `LoadCurrentState` - `ValidateCurrentStateIdentity` - `RemoteCommitManifest` and `CurrentCommitPointer` diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 06cf8ca..558349a 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -286,7 +286,7 @@ Validation: `go test ./internal/app ./internal/stage ./internal/config`. ## Stage 8: Separate publication inventory reads from execution snapshots -Status: Pending +Status: Complete Read `artifacts/current_state*.go`, `remote_commit.go`, application remote discovery/status/configuration consumers, and their tests. diff --git a/internal/app/command_dependencies.go b/internal/app/command_dependencies.go index 4ab2006..50e74f5 100644 --- a/internal/app/command_dependencies.go +++ b/internal/app/command_dependencies.go @@ -24,6 +24,7 @@ type commandDependencies struct { newAudita func(*config.Config) (audita.Runner, error) newNotarius func() notarius.Runner discoverRemoteCurrentState func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) + discoverRemotePublication func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) buildRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, storage.ObjectStore, RestorePlanOptions) (*RestorePlan, error) executeRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, *RestorePlan, *RestoreReport, storage.ObjectStore) (*RestoreExecutionResult, error) } @@ -55,6 +56,9 @@ func normalizeCommandDependencies(deps commandDependencies) commandDependencies if deps.discoverRemoteCurrentState == nil { deps.discoverRemoteCurrentState = discoverRemoteCurrentState } + if deps.discoverRemotePublication == nil { + deps.discoverRemotePublication = discoverRemotePublication + } if deps.buildRestorePlan == nil { deps.buildRestorePlan = buildRestorePlan } diff --git a/internal/app/config_loader.go b/internal/app/config_loader.go index 74acf9c..c118ca2 100644 --- a/internal/app/config_loader.go +++ b/internal/app/config_loader.go @@ -108,7 +108,7 @@ func findRemoteSessionConfig(ctx context.Context, store storage.ObjectStore, ses } var selected *artifacts.RemoteArtifact if !authored { - current, err := artifacts.LoadCurrentState(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{ExpectedCampaign: campaign, ExpectedSessionID: sessionID, ValidateRunID: true}) + current, err := artifacts.LoadCurrentInventory(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{ExpectedCampaign: campaign, ExpectedSessionID: sessionID, ValidateRunID: true}) if err == nil { for _, item := range current.Commit.Artifacts { if item.Type == artifacts.RemoteArtifactTypeRunFile && item.Source == "run:prepare/inputs/session.yml" { diff --git a/internal/app/operator_inspection.go b/internal/app/operator_inspection.go index 3d38255..8b4eb57 100644 --- a/internal/app/operator_inspection.go +++ b/internal/app/operator_inspection.go @@ -162,7 +162,7 @@ func inspectRemoteCurrentStateWithDependencies(ctx context.Context, cfg *config. return remoteCurrentStateCheck{} } deps = normalizeCommandDependencies(deps) - current, err := deps.discoverRemoteCurrentState(ctx, cfg, store) + current, err := deps.discoverRemotePublication(ctx, cfg, store) if err != nil { return remoteCurrentStateCheck{Err: err} } diff --git a/internal/app/remote_session_test.go b/internal/app/remote_session_test.go index f00b0a4..e30746e 100644 --- a/internal/app/remote_session_test.go +++ b/internal/app/remote_session_test.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "io" "os" "path/filepath" "strings" @@ -533,3 +534,71 @@ func addSecretsToPipelineConfig(t *testing.T, pipelinePath, secretsDir, accessKe } configureTestSecrets(t, pipelinePath, secretsDir) } + +func TestPublicationInspectionAndSessionConfigIgnoreExecutionSnapshot(t *testing.T) { + for _, tc := range []struct { + name string + omit bool + body []byte + }{ + {"no snapshot", true, nil}, {"missing snapshot", false, nil}, {"malformed snapshot", false, []byte("not json")}, {"unsupported snapshot", false, []byte(`{"schema_version":"unsupported"}`)}, + } { + t.Run(tc.name, func(t *testing.T) { + cfg := restorePlanConfig(t) + fake := &storage.FakeBackend{} + current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"transcripts/final.trimmed.json": []byte(`{"segments":[]}`)}) + sessionKey := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, current.RunID), "prepare/inputs/session.yml") + fake.SeedObject(storage.FakeObject{Key: sessionKey, Data: []byte("session_id: 2026-05-03\ntitle: Inventory\n")}) + current.Commit.Artifacts = append(current.Commit.Artifacts, remoteRestoreArtifact(fake, artifacts.RemoteArtifactTypeRunFile, "run:prepare/inputs/session.yml", sessionKey)) + if tc.omit { + filtered := current.Commit.Artifacts[:0] + for _, item := range current.Commit.Artifacts { + if item.Type != artifacts.RemoteArtifactTypeSessionManifest { + filtered = append(filtered, item) + } + } + current.Commit.Artifacts = filtered + } + if tc.body == nil { + delete(fake.Objects, current.CurrentManifestKey) + } else { + fake.SeedObject(storage.FakeObject{Key: current.CurrentManifestKey, Data: tc.body}) + } + commitData, err := artifacts.EncodeRemoteCommitManifest(*current.Commit) + if err != nil { + t.Fatal(err) + } + commitKey := artifacts.S3RunCommitKey(current.SessionPrefix, current.RunID) + fake.SeedObject(storage.FakeObject{Key: commitKey, Data: commitData}) + pointer, err := artifacts.EncodeCurrentCommitPointer(artifacts.CurrentCommitPointer{FormatVersion: artifacts.RemoteCommitFormatVersion, Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, RunID: current.RunID, CommitKey: commitKey, CommitSHA256: restoreCommitSHA256(commitData), CommitSize: int64(len(commitData)), CommitGeneration: fake.Objects[commitKey].ETag}) + if err != nil { + t.Fatal(err) + } + fake.SeedObject(storage.FakeObject{Key: artifacts.S3CurrentCommitPointerKey(current.SessionPrefix), Data: pointer}) + fake.Reads = nil + publication, err := discoverRemotePublication(context.Background(), cfg, fake) + if err != nil || publication.RunID != current.RunID { + t.Fatalf("publication %+v %v", publication, err) + } + _, _, body, err := findRemoteSessionConfig(context.Background(), fake, current.SessionPrefix, current.SessionPrefix+"session.yml", cfg.Session.Campaign, cfg.Session.SessionID) + if err != nil { + t.Fatal(err) + } + data, err := io.ReadAll(body) + if err != nil { + t.Fatal(err) + } + if err := body.Close(); err != nil { + t.Fatal(err) + } + if !strings.Contains(string(data), "title: Inventory") { + t.Fatalf("session %s", data) + } + for _, read := range fake.Reads { + if read.Key == current.CurrentManifestKey { + t.Fatal("execution snapshot was read") + } + } + }) + } +} diff --git a/internal/app/restore_commit_test.go b/internal/app/restore_commit_test.go index 3c79a68..a2c738f 100644 --- a/internal/app/restore_commit_test.go +++ b/internal/app/restore_commit_test.go @@ -225,19 +225,14 @@ func TestCommittedStatusReportsCarriedOutputOriginAndChecksExactKey(t *testing.T fake.SeedObject(storage.FakeObject{Key: oldKey, Data: []byte("carried\n")}) current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed" current.Commit.Artifacts[1].DestinationKey = oldKey - current.Manifest.Stages["publish"] = &manifest.StageRecord{ - Name: "publish", Status: manifest.StatusSucceeded, - Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{ - "source": "narratio.transcript.final_trimmed", "status": "carried_locked", - }}}, - } + current.Manifest = nil outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, nil, true, "available") if err != nil || len(outputs) != 1 { t.Fatalf("outputs=%#v err=%v", outputs, err) } output := outputs[0] - if output.Outcome != "carried_locked" || output.State != "published" || output.Destination != "transcripts/full.json" || output.DeclaredDestination != "transcripts/original.json" || output.DeclaredKey != oldKey || output.OriginRun != originRun { + if output.State != "published" || output.Destination != "transcripts/full.json" || output.DeclaredDestination != "transcripts/original.json" || output.DeclaredKey != oldKey || output.OriginRun != originRun { t.Fatalf("carried output=%#v", output) } if len(fake.ExistsKeys) == 0 || fake.ExistsKeys[len(fake.ExistsKeys)-1] != oldKey { diff --git a/internal/app/restore_discovery.go b/internal/app/restore_discovery.go index 1bf4f33..2cc5a70 100644 --- a/internal/app/restore_discovery.go +++ b/internal/app/restore_discovery.go @@ -24,6 +24,25 @@ type RemoteCurrentState struct { Commit *artifacts.RemoteCommitManifest } +func discoverRemotePublication(ctx context.Context, cfg *config.Config, store storage.ObjectStore) (*RemoteCurrentState, error) { + if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil || store == nil { + return nil, fmt.Errorf("resolved config and remote object store are required") + } + bucket := artifacts.ResolvePublishBucket(cfg, nil) + if strings.TrimSpace(bucket) == "" { + return nil, fmt.Errorf("publish bucket is required") + } + prefix, err := artifacts.ResolvePublishSessionPrefix(cfg, nil) + if err != nil { + return nil, fmt.Errorf("resolve publish session prefix: %w", err) + } + current, err := artifacts.LoadCurrentInventory(ctx, store, prefix, artifacts.CurrentStateValidation{ExpectedSessionID: cfg.Session.SessionID, ExpectedCampaign: cfg.Session.Campaign}) + if err != nil { + return nil, fmt.Errorf("remote %w", err) + } + return &RemoteCurrentState{Bucket: bucket, SessionPrefix: prefix, RunID: current.Commit.RunID, SessionID: current.Commit.SessionID, Campaign: current.Commit.Campaign, Commit: current.Commit}, nil +} + func discoverRemoteCurrentState(ctx context.Context, cfg *config.Config, store storage.ObjectStore) (*RemoteCurrentState, error) { if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil { return nil, fmt.Errorf("resolved config with pipeline/session is required") diff --git a/internal/app/session_inspection_command_test.go b/internal/app/session_inspection_command_test.go index aa6e266..6e45976 100644 --- a/internal/app/session_inspection_command_test.go +++ b/internal/app/session_inspection_command_test.go @@ -110,7 +110,7 @@ func TestSessionStateCommandReturnsPartialRemoteFailure(t *testing.T) { failure := errors.New("synthetic remote failure") fake := &storage.FakeBackend{} deps, _ := remoteSessionLoaderDependencies(fake) - deps.discoverRemoteCurrentState = func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) { + deps.discoverRemotePublication = func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) { return nil, failure } app, err := newApplication(deps, executePlan) @@ -150,7 +150,7 @@ func TestPublishedOutputInspectionKeepsCarriedIdentityWithoutPayloadReads(t *tes fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("carried\n")}) current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed" current.Commit.Artifacts[1].DestinationKey = key - current.Manifest.Stages["publish"] = &manifest.StageRecord{Name: "publish", Status: manifest.StatusSucceeded, Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{"source": "narratio.transcript.final_trimmed", "status": "carried_locked"}}}} + current.Manifest = nil reads := len(fake.Reads) outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: "narratio.transcript.final_trimmed"}}, true, "current") if err != nil { @@ -160,7 +160,7 @@ func TestPublishedOutputInspectionKeepsCarriedIdentityWithoutPayloadReads(t *tes t.Fatalf("outputs=%#v", outputs) } output := outputs[0] - if output.State != "published" || output.Outcome != "carried_locked" || output.LockState != "locked" || output.DeclaredKey != key || output.DeclaredDestination != "transcripts/original.json" || output.OriginRun != originRun { + if output.State != "published" || output.LockState != "locked" || output.DeclaredKey != key || output.DeclaredDestination != "transcripts/original.json" || output.OriginRun != originRun { t.Fatalf("output=%#v", output) } if len(fake.Reads) != reads || fake.ExistsKeys[len(fake.ExistsKeys)-1] != key { @@ -247,16 +247,13 @@ func TestPublishedOutputInspectionNormalizesAcceptedSources(t *testing.T) { current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"transcripts/full.json": []byte("published\n")}) declaration := ¤t.Commit.Artifacts[1] declaration.Source = canonical - current.Manifest.Stages["publish"] = &manifest.StageRecord{ - Name: "publish", Status: manifest.StatusSucceeded, - Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{"source": canonical, "status": "carried_locked"}}}, - } + current.Manifest = nil outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: canonical}}, true, "current") if err != nil || len(outputs) != 1 { t.Fatalf("outputs=%#v err=%v", outputs, err) } output := outputs[0] - if output.Source != canonical || output.State != "published" || output.LockState != "locked" || output.Outcome != "carried_locked" || output.DeclaredKey != declaration.DestinationKey || output.OriginRun != current.RunID { + if output.Source != canonical || output.State != "published" || output.LockState != "locked" || output.DeclaredKey != declaration.DestinationKey || output.OriginRun != current.RunID { t.Fatalf("accepted source lost publication evidence: %#v", output) } if cfg.PublicationOutputs()[0].Source != source { diff --git a/internal/app/session_state_command.go b/internal/app/session_state_command.go index 9c3eb34..74e915f 100644 --- a/internal/app/session_state_command.go +++ b/internal/app/session_state_command.go @@ -176,7 +176,6 @@ func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote } else if current.State != nil { report.Remote.State = "current" report.Remote.RunID = current.State.RunID - report.Remote.ManifestKey = current.State.CurrentManifestKey } locks := inspectRemoteLocks(ctx, cfg, store) fail("locks", locks.Err) @@ -265,9 +264,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor configuredOutputs := helperConfiguredOutputPathMap(catalog) extractionOutputs := helperExtractionOutputSet(catalog) var declarations map[string]artifacts.RemoteArtifact - outcomes := map[string]string{} if current != nil { - outcomes = committedPublishOutputOutcomes(current.Manifest) declarations = committedPublishedOutputs(current.Commit) } var resultErr error @@ -275,7 +272,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor source := strings.TrimSpace(rule.Source) destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(source, rule.Dest, configuredOutputs, extractionOutputs) _, isLocked := locked[source] - output := sessionPublishedOutput{Source: source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[source]} + output := sessionPublishedOutput{Source: source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing"} if locksKnown { output.LockState = "unlocked" if isLocked { diff --git a/internal/artifacts/current_state.go b/internal/artifacts/current_state.go index 2a5ff4f..46d0217 100644 --- a/internal/artifacts/current_state.go +++ b/internal/artifacts/current_state.go @@ -49,6 +49,21 @@ func LoadCurrentState( store storage.ObjectStore, sessionPrefix string, validation CurrentStateValidation, +) (*CurrentState, error) { + state, err := LoadCurrentInventory(ctx, store, sessionPrefix, validation) + if err != nil { + return nil, err + } + return loadCommittedCurrentState(ctx, store, state, validation) +} + +// LoadCurrentInventory reads the selected publication identity and declarations +// without fetching an execution snapshot. +func LoadCurrentInventory( + ctx context.Context, + store storage.ObjectStore, + sessionPrefix string, + validation CurrentStateValidation, ) (*CurrentState, error) { prefix := strings.TrimSpace(sessionPrefix) if prefix == "" { @@ -66,7 +81,7 @@ func LoadCurrentState( if !pointerExists { return nil, &CurrentCommitPointerMissingError{Key: pointerKey} } - return loadCommittedCurrentState(ctx, store, prefix, pointerKey, validation) + return loadCommittedInventory(ctx, store, prefix, pointerKey, validation) } func ValidateCurrentStateIdentity(state *CurrentState, validation CurrentStateValidation) error { diff --git a/internal/artifacts/current_state_commit.go b/internal/artifacts/current_state_commit.go index 2378575..586eed7 100644 --- a/internal/artifacts/current_state_commit.go +++ b/internal/artifacts/current_state_commit.go @@ -19,7 +19,7 @@ const ( MaxRemoteSessionManifestBytes int64 = 8 << 20 ) -func loadCommittedCurrentState( +func loadCommittedInventory( ctx context.Context, store storage.ObjectStore, sessionPrefix string, @@ -52,8 +52,20 @@ func loadCommittedCurrentState( if err := validatePointerCommitIdentity(pointer, commit); err != nil { return nil, err } + if strings.TrimSpace(validation.ExpectedCampaign) != "" && commit.Campaign != strings.TrimSpace(validation.ExpectedCampaign) { + return nil, fmt.Errorf("remote commit campaign %q does not match expected campaign %q", commit.Campaign, validation.ExpectedCampaign) + } + if strings.TrimSpace(validation.ExpectedSessionID) != "" && commit.SessionID != strings.TrimSpace(validation.ExpectedSessionID) { + return nil, fmt.Errorf("remote commit session_id %q does not match expected session_id %q", commit.SessionID, validation.ExpectedSessionID) + } + if strings.TrimSpace(validation.ExpectedRunID) != "" && commit.RunID != strings.TrimSpace(validation.ExpectedRunID) { + return nil, fmt.Errorf("remote commit run_id %q does not match expected run_id %q", commit.RunID, validation.ExpectedRunID) + } + return &CurrentState{SessionPrefix: sessionPrefix, CurrentPointerKey: pointerKey, RunID: commit.RunID, Commit: commit, Pointer: pointer}, nil +} - sessionManifest, ok := commit.Artifact(RemoteArtifactTypeSessionManifest) +func loadCommittedCurrentState(ctx context.Context, store storage.ObjectStore, state *CurrentState, validation CurrentStateValidation) (*CurrentState, error) { + sessionManifest, ok := state.Commit.Artifact(RemoteArtifactTypeSessionManifest) if !ok { return nil, fmt.Errorf("remote commit must declare exactly one session manifest artifact") } @@ -65,20 +77,13 @@ func loadCommittedCurrentState( if err != nil { return nil, err } - if err := validateCommitManifestIdentity(commit, m); err != nil { + if err := validateCommitManifestIdentity(state.Commit, m); err != nil { return nil, err } - state := &CurrentState{ - SessionPrefix: sessionPrefix, - CurrentPointerKey: pointerKey, - CurrentManifestKey: sessionManifest.DestinationKey, - RunID: commit.RunID, - Manifest: m, - ManifestData: append([]byte(nil), manifestData...), - Commit: commit, - Pointer: pointer, - } + state.CurrentManifestKey = sessionManifest.DestinationKey + state.Manifest = m + state.ManifestData = append([]byte(nil), manifestData...) if err := ValidateCurrentStateIdentity(state, validation); err != nil { return nil, err } diff --git a/internal/artifacts/remote_commit_test.go b/internal/artifacts/remote_commit_test.go index 9a5be87..d962a42 100644 --- a/internal/artifacts/remote_commit_test.go +++ b/internal/artifacts/remote_commit_test.go @@ -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") + } + } + }) + } +}