Read publication inventory without execution snapshots
This commit is contained in:
@@ -190,9 +190,8 @@ narratio session artifacts SESSION --remote
|
|||||||
|
|
||||||
Reports definitions, dependencies, local availability/evidence, and optional
|
Reports definitions, dependencies, local availability/evidence, and optional
|
||||||
remote publication state without reading artifact payload bodies. Without
|
remote publication state without reading artifact payload bodies. Without
|
||||||
`--remote`, this command avoids remote artifact inspection. Current publication
|
`--remote`, this command avoids remote artifact inspection. Remote entries use
|
||||||
outcomes include `published`, `carried_locked`, `locked_unpublished`,
|
the selected publication inventory and current lock state.
|
||||||
`optional_missing`, and `unselected`.
|
|
||||||
|
|
||||||
## Session init
|
## Session init
|
||||||
|
|
||||||
@@ -372,7 +371,7 @@ Plan analysis contains `targets`, `prerequisites`, `execute`, and `reuse`;
|
|||||||
artifact entries identify key, optional family/character, role, reason, and
|
artifact entries identify key, optional family/character, role, reason, and
|
||||||
force. Publication actions identify source, destination, required, and selected.
|
force. Publication actions identify source, destination, required, and selected.
|
||||||
Remote status outputs retain source, destination, required, state, lock state,
|
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.
|
actions carry kind, relative local path, remote key, status, optional reason/error.
|
||||||
Clean actions carry path, status (`would_delete`, `deleted`, `missing`, `empty`,
|
Clean actions carry path, status (`would_delete`, `deleted`, `missing`, `empty`,
|
||||||
`failed`), and optional error; cache records whether it was preserved, requested,
|
`failed`), and optional error; cache records whether it was preserved, requested,
|
||||||
|
|||||||
@@ -186,6 +186,10 @@ Validation by content type:
|
|||||||
|
|
||||||
Artifacts package owns shared remote current-state loading mechanics used by
|
Artifacts package owns shared remote current-state loading mechanics used by
|
||||||
restore, status and validation checks, and previous-cache planning.
|
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
|
The selected session manifest is accepted only with
|
||||||
`schema_version: narratio.session-manifest.v2` and complete stage identity.
|
`schema_version: narratio.session-manifest.v2` and complete stage identity.
|
||||||
@@ -218,7 +222,7 @@ identity before replacing a canonical local path.
|
|||||||
|
|
||||||
Core helpers:
|
Core helpers:
|
||||||
|
|
||||||
- `LoadCurrentState`
|
- `LoadCurrentInventory` and `LoadCurrentState`
|
||||||
- `ValidateCurrentStateIdentity`
|
- `ValidateCurrentStateIdentity`
|
||||||
- `RemoteCommitManifest` and `CurrentCommitPointer`
|
- `RemoteCommitManifest` and `CurrentCommitPointer`
|
||||||
|
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ Validation: `go test ./internal/app ./internal/stage ./internal/config`.
|
|||||||
|
|
||||||
## Stage 8: Separate publication inventory reads from execution snapshots
|
## Stage 8: Separate publication inventory reads from execution snapshots
|
||||||
|
|
||||||
Status: Pending
|
Status: Complete
|
||||||
|
|
||||||
Read `artifacts/current_state*.go`, `remote_commit.go`, application remote
|
Read `artifacts/current_state*.go`, `remote_commit.go`, application remote
|
||||||
discovery/status/configuration consumers, and their tests.
|
discovery/status/configuration consumers, and their tests.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type commandDependencies struct {
|
|||||||
newAudita func(*config.Config) (audita.Runner, error)
|
newAudita func(*config.Config) (audita.Runner, error)
|
||||||
newNotarius func() notarius.Runner
|
newNotarius func() notarius.Runner
|
||||||
discoverRemoteCurrentState func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error)
|
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)
|
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)
|
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 {
|
if deps.discoverRemoteCurrentState == nil {
|
||||||
deps.discoverRemoteCurrentState = discoverRemoteCurrentState
|
deps.discoverRemoteCurrentState = discoverRemoteCurrentState
|
||||||
}
|
}
|
||||||
|
if deps.discoverRemotePublication == nil {
|
||||||
|
deps.discoverRemotePublication = discoverRemotePublication
|
||||||
|
}
|
||||||
if deps.buildRestorePlan == nil {
|
if deps.buildRestorePlan == nil {
|
||||||
deps.buildRestorePlan = buildRestorePlan
|
deps.buildRestorePlan = buildRestorePlan
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func findRemoteSessionConfig(ctx context.Context, store storage.ObjectStore, ses
|
|||||||
}
|
}
|
||||||
var selected *artifacts.RemoteArtifact
|
var selected *artifacts.RemoteArtifact
|
||||||
if !authored {
|
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 {
|
if err == nil {
|
||||||
for _, item := range current.Commit.Artifacts {
|
for _, item := range current.Commit.Artifacts {
|
||||||
if item.Type == artifacts.RemoteArtifactTypeRunFile && item.Source == "run:prepare/inputs/session.yml" {
|
if item.Type == artifacts.RemoteArtifactTypeRunFile && item.Source == "run:prepare/inputs/session.yml" {
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ func inspectRemoteCurrentStateWithDependencies(ctx context.Context, cfg *config.
|
|||||||
return remoteCurrentStateCheck{}
|
return remoteCurrentStateCheck{}
|
||||||
}
|
}
|
||||||
deps = normalizeCommandDependencies(deps)
|
deps = normalizeCommandDependencies(deps)
|
||||||
current, err := deps.discoverRemoteCurrentState(ctx, cfg, store)
|
current, err := deps.discoverRemotePublication(ctx, cfg, store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return remoteCurrentStateCheck{Err: err}
|
return remoteCurrentStateCheck{Err: err}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -533,3 +534,71 @@ func addSecretsToPipelineConfig(t *testing.T, pipelinePath, secretsDir, accessKe
|
|||||||
}
|
}
|
||||||
configureTestSecrets(t, pipelinePath, secretsDir)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -225,19 +225,14 @@ func TestCommittedStatusReportsCarriedOutputOriginAndChecksExactKey(t *testing.T
|
|||||||
fake.SeedObject(storage.FakeObject{Key: oldKey, Data: []byte("carried\n")})
|
fake.SeedObject(storage.FakeObject{Key: oldKey, Data: []byte("carried\n")})
|
||||||
current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed"
|
current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed"
|
||||||
current.Commit.Artifacts[1].DestinationKey = oldKey
|
current.Commit.Artifacts[1].DestinationKey = oldKey
|
||||||
current.Manifest.Stages["publish"] = &manifest.StageRecord{
|
current.Manifest = nil
|
||||||
Name: "publish", Status: manifest.StatusSucceeded,
|
|
||||||
Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{
|
|
||||||
"source": "narratio.transcript.final_trimmed", "status": "carried_locked",
|
|
||||||
}}},
|
|
||||||
}
|
|
||||||
|
|
||||||
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, nil, true, "available")
|
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, nil, true, "available")
|
||||||
if err != nil || len(outputs) != 1 {
|
if err != nil || len(outputs) != 1 {
|
||||||
t.Fatalf("outputs=%#v err=%v", outputs, err)
|
t.Fatalf("outputs=%#v err=%v", outputs, err)
|
||||||
}
|
}
|
||||||
output := outputs[0]
|
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)
|
t.Fatalf("carried output=%#v", output)
|
||||||
}
|
}
|
||||||
if len(fake.ExistsKeys) == 0 || fake.ExistsKeys[len(fake.ExistsKeys)-1] != oldKey {
|
if len(fake.ExistsKeys) == 0 || fake.ExistsKeys[len(fake.ExistsKeys)-1] != oldKey {
|
||||||
|
|||||||
@@ -24,6 +24,25 @@ type RemoteCurrentState struct {
|
|||||||
Commit *artifacts.RemoteCommitManifest
|
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) {
|
func discoverRemoteCurrentState(ctx context.Context, cfg *config.Config, store storage.ObjectStore) (*RemoteCurrentState, error) {
|
||||||
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil {
|
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil {
|
||||||
return nil, fmt.Errorf("resolved config with pipeline/session is required")
|
return nil, fmt.Errorf("resolved config with pipeline/session is required")
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func TestSessionStateCommandReturnsPartialRemoteFailure(t *testing.T) {
|
|||||||
failure := errors.New("synthetic remote failure")
|
failure := errors.New("synthetic remote failure")
|
||||||
fake := &storage.FakeBackend{}
|
fake := &storage.FakeBackend{}
|
||||||
deps, _ := remoteSessionLoaderDependencies(fake)
|
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
|
return nil, failure
|
||||||
}
|
}
|
||||||
app, err := newApplication(deps, executePlan)
|
app, err := newApplication(deps, executePlan)
|
||||||
@@ -150,7 +150,7 @@ func TestPublishedOutputInspectionKeepsCarriedIdentityWithoutPayloadReads(t *tes
|
|||||||
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("carried\n")})
|
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("carried\n")})
|
||||||
current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed"
|
current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed"
|
||||||
current.Commit.Artifacts[1].DestinationKey = key
|
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)
|
reads := len(fake.Reads)
|
||||||
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: "narratio.transcript.final_trimmed"}}, true, "current")
|
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: "narratio.transcript.final_trimmed"}}, true, "current")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -160,7 +160,7 @@ func TestPublishedOutputInspectionKeepsCarriedIdentityWithoutPayloadReads(t *tes
|
|||||||
t.Fatalf("outputs=%#v", outputs)
|
t.Fatalf("outputs=%#v", outputs)
|
||||||
}
|
}
|
||||||
output := outputs[0]
|
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)
|
t.Fatalf("output=%#v", output)
|
||||||
}
|
}
|
||||||
if len(fake.Reads) != reads || fake.ExistsKeys[len(fake.ExistsKeys)-1] != key {
|
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")})
|
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"transcripts/full.json": []byte("published\n")})
|
||||||
declaration := ¤t.Commit.Artifacts[1]
|
declaration := ¤t.Commit.Artifacts[1]
|
||||||
declaration.Source = canonical
|
declaration.Source = canonical
|
||||||
current.Manifest.Stages["publish"] = &manifest.StageRecord{
|
current.Manifest = nil
|
||||||
Name: "publish", Status: manifest.StatusSucceeded,
|
|
||||||
Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{"source": canonical, "status": "carried_locked"}}},
|
|
||||||
}
|
|
||||||
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: canonical}}, true, "current")
|
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: canonical}}, true, "current")
|
||||||
if err != nil || len(outputs) != 1 {
|
if err != nil || len(outputs) != 1 {
|
||||||
t.Fatalf("outputs=%#v err=%v", outputs, err)
|
t.Fatalf("outputs=%#v err=%v", outputs, err)
|
||||||
}
|
}
|
||||||
output := outputs[0]
|
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)
|
t.Fatalf("accepted source lost publication evidence: %#v", output)
|
||||||
}
|
}
|
||||||
if cfg.PublicationOutputs()[0].Source != source {
|
if cfg.PublicationOutputs()[0].Source != source {
|
||||||
|
|||||||
@@ -176,7 +176,6 @@ func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote
|
|||||||
} else if current.State != nil {
|
} else if current.State != nil {
|
||||||
report.Remote.State = "current"
|
report.Remote.State = "current"
|
||||||
report.Remote.RunID = current.State.RunID
|
report.Remote.RunID = current.State.RunID
|
||||||
report.Remote.ManifestKey = current.State.CurrentManifestKey
|
|
||||||
}
|
}
|
||||||
locks := inspectRemoteLocks(ctx, cfg, store)
|
locks := inspectRemoteLocks(ctx, cfg, store)
|
||||||
fail("locks", locks.Err)
|
fail("locks", locks.Err)
|
||||||
@@ -265,9 +264,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor
|
|||||||
configuredOutputs := helperConfiguredOutputPathMap(catalog)
|
configuredOutputs := helperConfiguredOutputPathMap(catalog)
|
||||||
extractionOutputs := helperExtractionOutputSet(catalog)
|
extractionOutputs := helperExtractionOutputSet(catalog)
|
||||||
var declarations map[string]artifacts.RemoteArtifact
|
var declarations map[string]artifacts.RemoteArtifact
|
||||||
outcomes := map[string]string{}
|
|
||||||
if current != nil {
|
if current != nil {
|
||||||
outcomes = committedPublishOutputOutcomes(current.Manifest)
|
|
||||||
declarations = committedPublishedOutputs(current.Commit)
|
declarations = committedPublishedOutputs(current.Commit)
|
||||||
}
|
}
|
||||||
var resultErr error
|
var resultErr error
|
||||||
@@ -275,7 +272,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor
|
|||||||
source := strings.TrimSpace(rule.Source)
|
source := strings.TrimSpace(rule.Source)
|
||||||
destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(source, rule.Dest, configuredOutputs, extractionOutputs)
|
destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(source, rule.Dest, configuredOutputs, extractionOutputs)
|
||||||
_, isLocked := locked[source]
|
_, 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 {
|
if locksKnown {
|
||||||
output.LockState = "unlocked"
|
output.LockState = "unlocked"
|
||||||
if isLocked {
|
if isLocked {
|
||||||
|
|||||||
@@ -49,6 +49,21 @@ func LoadCurrentState(
|
|||||||
store storage.ObjectStore,
|
store storage.ObjectStore,
|
||||||
sessionPrefix string,
|
sessionPrefix string,
|
||||||
validation CurrentStateValidation,
|
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) {
|
) (*CurrentState, error) {
|
||||||
prefix := strings.TrimSpace(sessionPrefix)
|
prefix := strings.TrimSpace(sessionPrefix)
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
@@ -66,7 +81,7 @@ func LoadCurrentState(
|
|||||||
if !pointerExists {
|
if !pointerExists {
|
||||||
return nil, &CurrentCommitPointerMissingError{Key: pointerKey}
|
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 {
|
func ValidateCurrentStateIdentity(state *CurrentState, validation CurrentStateValidation) error {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
MaxRemoteSessionManifestBytes int64 = 8 << 20
|
MaxRemoteSessionManifestBytes int64 = 8 << 20
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadCommittedCurrentState(
|
func loadCommittedInventory(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
store storage.ObjectStore,
|
store storage.ObjectStore,
|
||||||
sessionPrefix string,
|
sessionPrefix string,
|
||||||
@@ -52,8 +52,20 @@ func loadCommittedCurrentState(
|
|||||||
if err := validatePointerCommitIdentity(pointer, commit); err != nil {
|
if err := validatePointerCommitIdentity(pointer, commit); err != nil {
|
||||||
return nil, err
|
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 {
|
if !ok {
|
||||||
return nil, fmt.Errorf("remote commit must declare exactly one session manifest artifact")
|
return nil, fmt.Errorf("remote commit must declare exactly one session manifest artifact")
|
||||||
}
|
}
|
||||||
@@ -65,20 +77,13 @@ func loadCommittedCurrentState(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := validateCommitManifestIdentity(commit, m); err != nil {
|
if err := validateCommitManifestIdentity(state.Commit, m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
state := &CurrentState{
|
state.CurrentManifestKey = sessionManifest.DestinationKey
|
||||||
SessionPrefix: sessionPrefix,
|
state.Manifest = m
|
||||||
CurrentPointerKey: pointerKey,
|
state.ManifestData = append([]byte(nil), manifestData...)
|
||||||
CurrentManifestKey: sessionManifest.DestinationKey,
|
|
||||||
RunID: commit.RunID,
|
|
||||||
Manifest: m,
|
|
||||||
ManifestData: append([]byte(nil), manifestData...),
|
|
||||||
Commit: commit,
|
|
||||||
Pointer: pointer,
|
|
||||||
}
|
|
||||||
if err := ValidateCurrentStateIdentity(state, validation); err != nil {
|
if err := ValidateCurrentStateIdentity(state, validation); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,3 +397,52 @@ func appendUnknownJSONField(t *testing.T, data []byte) []byte {
|
|||||||
}
|
}
|
||||||
return append(append([]byte(nil), trimmed[:len(trimmed)-1]...), []byte(`,"unexpected":true}`)...)
|
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