Publish products without execution ledgers
This commit is contained in:
@@ -16,9 +16,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
InputKindManifest = "previous_manifest"
|
||||
InputKindArtifact = "previous_artifact"
|
||||
InputSource = "previous_session_publish.current"
|
||||
)
|
||||
|
||||
type Plan struct {
|
||||
@@ -38,7 +36,6 @@ type Record struct {
|
||||
Size int64
|
||||
Generation string
|
||||
S3Bucket string
|
||||
VerifiedContent []byte
|
||||
}
|
||||
|
||||
// Resolve evaluates previous-session requirements against the one selected
|
||||
@@ -99,7 +96,7 @@ func Resolve(
|
||||
)
|
||||
|
||||
result := &Plan{}
|
||||
current, err := artifacts.LoadCurrentState(ctx, store, previousSessionPrefix, artifacts.CurrentStateValidation{
|
||||
current, err := artifacts.LoadCurrentInventory(ctx, store, previousSessionPrefix, artifacts.CurrentStateValidation{
|
||||
ExpectedSessionID: previousSessionID,
|
||||
ExpectedCampaign: campaign,
|
||||
ValidateRunID: true,
|
||||
@@ -116,32 +113,10 @@ func Resolve(
|
||||
return nil, fmt.Errorf("load previous-session current state: %w", err)
|
||||
}
|
||||
result.PreviousRunID = strings.TrimSpace(current.RunID)
|
||||
currentManifestKey := current.CurrentManifestKey
|
||||
if current.Commit == nil {
|
||||
return nil, fmt.Errorf("previous-session current state does not include a committed remote declaration")
|
||||
}
|
||||
|
||||
manifestRel, err := relativeToSession(paths, paths.PreviousManifestPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifestRecord := Record{
|
||||
Kind: InputKindManifest,
|
||||
LocalRelativePath: manifestRel,
|
||||
LocalPath: paths.PreviousManifestPath,
|
||||
RemoteKey: currentManifestKey,
|
||||
S3Bucket: bucket,
|
||||
}
|
||||
committedManifest, ok := current.Commit.Artifact(artifacts.RemoteArtifactTypeSessionManifest)
|
||||
if !ok || committedManifest.DestinationKey != currentManifestKey {
|
||||
return nil, fmt.Errorf("previous-session remote commit does not declare its session manifest")
|
||||
}
|
||||
manifestRecord.SHA256 = committedManifest.SHA256
|
||||
manifestRecord.Size = committedManifest.Size
|
||||
manifestRecord.Generation = committedManifest.Generation
|
||||
manifestRecord.VerifiedContent = append([]byte(nil), current.ManifestData...)
|
||||
result.Records = append(result.Records, manifestRecord)
|
||||
|
||||
for _, requirement := range orderedRequirements {
|
||||
sourceID := previousArtifactSourceID(requirement.Name)
|
||||
selectedArtifact, ok := committedPublishedArtifactBySource(current.Commit, sourceID)
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestResolveUsesExactCommittedDeclaration(t *testing.T) {
|
||||
t.Fatalf("PreviousRunID = %q, want previous-run", plan.PreviousRunID)
|
||||
}
|
||||
got := recordRelPaths(plan.Records)
|
||||
want := []string{"inputs/previous/artifacts/session_recap.md", "inputs/previous/manifest.json"}
|
||||
want := []string{"inputs/previous/artifacts/session_recap.md"}
|
||||
if strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Fatalf("record rel paths = %#v, want %#v", got, want)
|
||||
}
|
||||
@@ -70,8 +70,8 @@ func TestResolveDerivesLocalPathFromCommittedDestination(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Resolve() error = %v", err)
|
||||
}
|
||||
if len(plan.Records) != 2 {
|
||||
t.Fatalf("records len = %d, want 2", len(plan.Records))
|
||||
if len(plan.Records) != 1 {
|
||||
t.Fatalf("records len = %d, want 1", len(plan.Records))
|
||||
}
|
||||
if plan.Records[0].LocalRelativePath != "inputs/previous/artifacts/session_recap.md" {
|
||||
t.Fatalf("artifact local relative path = %q", plan.Records[0].LocalRelativePath)
|
||||
@@ -103,11 +103,8 @@ func TestResolveUsesCommittedSourceMappingForCustomDestination(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Resolve() error = %v", err)
|
||||
}
|
||||
if len(plan.Records) != 2 {
|
||||
t.Fatalf("records = %#v, want manifest and artifact", plan.Records)
|
||||
}
|
||||
if manifestRecord := findRecord(plan.Records, InputKindManifest); manifestRecord == nil || len(manifestRecord.VerifiedContent) == 0 {
|
||||
t.Fatalf("manifest record = %#v, want retained verified content", manifestRecord)
|
||||
if len(plan.Records) != 1 {
|
||||
t.Fatalf("records = %#v, want artifact only", plan.Records)
|
||||
}
|
||||
artifact := findRecord(plan.Records, InputKindArtifact)
|
||||
if artifact == nil {
|
||||
@@ -174,8 +171,8 @@ func TestResolveSkipsMissingOptionalPreviousArtifact(t *testing.T) {
|
||||
if strings.Join(plan.SkippedMissing, ",") != "session_recap" {
|
||||
t.Fatalf("SkippedMissing = %#v, want session_recap", plan.SkippedMissing)
|
||||
}
|
||||
if len(plan.Records) != 1 || plan.Records[0].Kind != InputKindManifest {
|
||||
t.Fatalf("records = %#v, want manifest only", plan.Records)
|
||||
if len(plan.Records) != 0 {
|
||||
t.Fatalf("records = %#v, want none", plan.Records)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,21 +189,6 @@ func TestResolveMissingRequiredPreviousArtifactFails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveValidatesPreviousManifestIdentity(t *testing.T) {
|
||||
cfg, paths := previousCacheTestConfig(t)
|
||||
store := &storage.FakeBackend{}
|
||||
manifest := previousManifestWithOutput(t, cfg, "artifacts/session_recap.md", nil)
|
||||
manifest.SessionID = "wrong-session"
|
||||
seedPreviousCurrent(t, store, cfg, manifest)
|
||||
|
||||
_, err := Resolve(context.Background(), cfg, paths, []artifacts.PreviousArtifactRequirement{
|
||||
{Name: "session_recap", Required: true},
|
||||
}, store)
|
||||
if err == nil || !strings.Contains(err.Error(), "identity does not match") {
|
||||
t.Fatalf("Resolve() error = %v, want identity validation error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveMissingCurrentRunPointerSkipsOptionalRequirements(t *testing.T) {
|
||||
cfg, paths := previousCacheTestConfig(t)
|
||||
store := &storage.FakeBackend{}
|
||||
@@ -434,3 +416,26 @@ func sha256ForPreviousCacheTest(data []byte) string {
|
||||
sum := sha256.Sum256(data)
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func TestResolvePreviousProductWithoutExecutionSnapshot(t *testing.T) {
|
||||
cfg, paths := previousCacheTestConfig(t)
|
||||
store := &storage.FakeBackend{}
|
||||
previous := previousManifestWithOutput(t, cfg, "artifacts/session_recap.md", nil)
|
||||
expectedKey := seedCommittedPreviousState(t, store, cfg, previous, []artifacts.RemoteArtifact{committedPublishedArtifactForTest("narratio.artifact.session_recap", "artifacts/session_recap.md", []byte("recap"), "product-generation")})
|
||||
prefix := artifacts.S3SessionPrefix("dnd", cfg.Session.Campaign, cfg.Session.PreviousSessionID)
|
||||
manifestKey := artifacts.S3RunSessionManifestKey(prefix, "previous-run")
|
||||
delete(store.Objects, manifestKey)
|
||||
store.Reads = nil
|
||||
plan, err := Resolve(context.Background(), cfg, paths, []artifacts.PreviousArtifactRequirement{{Name: "session_recap", Required: true}}, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(plan.Records) != 1 || plan.Records[0].RemoteKey != expectedKey {
|
||||
t.Fatalf("plan %+v", plan)
|
||||
}
|
||||
for _, read := range store.Reads {
|
||||
if read.Key == manifestKey {
|
||||
t.Fatal("execution snapshot was read")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user