Share typed publication completion evidence
This commit is contained in:
@@ -93,32 +93,30 @@ func validateCleanupPublishEvidence(m *manifest.Manifest, campaign, sessionID st
|
||||
return "", fmt.Errorf("cleanup requires publish completion metadata")
|
||||
}
|
||||
|
||||
uploaded, ok := publishRecord.Metadata["uploaded"].(bool)
|
||||
if !ok || !uploaded {
|
||||
completion := artifacts.DecodePublicationCompletion(publishRecord.Metadata)
|
||||
if !completion.Uploaded.Valid || !completion.Uploaded.Value {
|
||||
return "", fmt.Errorf("cleanup requires publish metadata uploaded=true")
|
||||
}
|
||||
if skippedValue, exists := publishRecord.Metadata["skipped"]; exists {
|
||||
skipped, ok := skippedValue.(bool)
|
||||
if !ok {
|
||||
if completion.Skipped.Present {
|
||||
if !completion.Skipped.Valid {
|
||||
return "", fmt.Errorf("cleanup publish metadata skipped must be boolean")
|
||||
}
|
||||
if skipped {
|
||||
if completion.Skipped.Value {
|
||||
return "", fmt.Errorf("cleanup cannot use skipped publication evidence")
|
||||
}
|
||||
}
|
||||
|
||||
publishedRunID, err := canonicalCleanupMetadataString(publishRecord.Metadata, "published_run_id")
|
||||
publishedRunID, err := canonicalCleanupMetadataString(completion.RunID, artifacts.PublicationRunIDKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := artifacts.ValidateRunIdentity(publishedRunID); err != nil {
|
||||
return "", fmt.Errorf("cleanup publish metadata published_run_id: %w", err)
|
||||
}
|
||||
remoteCommitKey, err := canonicalCleanupMetadataString(publishRecord.Metadata, "remote_commit_key")
|
||||
remoteCommitKey, err := canonicalCleanupMetadataString(completion.CommitKey, artifacts.PublicationCommitKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
pointerKey, err := canonicalCleanupMetadataString(publishRecord.Metadata, "current_commit_pointer_key")
|
||||
pointerKey, err := canonicalCleanupMetadataString(completion.PointerKey, artifacts.PublicationPointerKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -138,9 +136,9 @@ func validateCleanupPublishEvidence(m *manifest.Manifest, campaign, sessionID st
|
||||
return publishedRunID, nil
|
||||
}
|
||||
|
||||
func canonicalCleanupMetadataString(metadata map[string]any, key string) (string, error) {
|
||||
value, ok := metadata[key].(string)
|
||||
if !ok || value == "" || strings.TrimSpace(value) != value {
|
||||
func canonicalCleanupMetadataString(field artifacts.PublicationStringField, key string) (string, error) {
|
||||
value := field.Value
|
||||
if !field.Valid || value == "" || strings.TrimSpace(value) != value {
|
||||
return "", fmt.Errorf("cleanup publish metadata %s must be a canonical nonempty string", key)
|
||||
}
|
||||
return value, nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -33,6 +34,28 @@ func TestBuildCleanupPlanSelectsCanonicalSessionRunsTarget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanupPublishEvidenceSurvivesJSONRoundTrip(t *testing.T) {
|
||||
env, m, runID := cleanupPlanningFixture(t)
|
||||
env.Config.Pipeline.Workspace.CleanupAfterPublish = true
|
||||
for _, roundTrip := range []bool{false, true} {
|
||||
if roundTrip {
|
||||
data, err := json.Marshal(m.Stages["publish"].Metadata)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(data, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Stages["publish"].Metadata = decoded
|
||||
}
|
||||
plan, err := buildCleanupPlan(env, m)
|
||||
if err != nil || !plan.enabled || plan.publishedRunID != runID {
|
||||
t.Fatalf("plan = %+v, error = %v", plan, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCleanupPlanRejectsInvalidPublishEvidenceWithoutExecutablePlan(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -311,21 +311,21 @@ func publishMetadata(
|
||||
commitKey string,
|
||||
pointerKey string,
|
||||
) map[string]any {
|
||||
return map[string]any{
|
||||
"stage": "publish",
|
||||
"uploaded": true,
|
||||
"s3_bucket": bucket,
|
||||
"s3_run_prefix": runPrefix,
|
||||
"published_run_id": runID,
|
||||
"run_files_uploaded": len(runUploaded),
|
||||
"run_uploaded_paths": append([]string(nil), runUploaded...),
|
||||
"published_files_uploaded": len(publishedUploaded),
|
||||
"published_paths": append([]string(nil), publishedUploaded...),
|
||||
"previous_files_uploaded": len(previousUploaded),
|
||||
"previous_uploaded_paths": append([]string(nil), previousUploaded...),
|
||||
"publish_output_outcomes": publishOutputOutcomeMetadata(outputPlan),
|
||||
"remote_commit_key": commitKey,
|
||||
"current_commit_pointer_key": pointerKey,
|
||||
"audio_upload_skipped": true,
|
||||
metadata := map[string]any{
|
||||
"stage": "publish",
|
||||
"s3_bucket": bucket,
|
||||
"s3_run_prefix": runPrefix,
|
||||
"run_files_uploaded": len(runUploaded),
|
||||
"run_uploaded_paths": append([]string(nil), runUploaded...),
|
||||
"published_files_uploaded": len(publishedUploaded),
|
||||
"published_paths": append([]string(nil), publishedUploaded...),
|
||||
"previous_files_uploaded": len(previousUploaded),
|
||||
"previous_uploaded_paths": append([]string(nil), previousUploaded...),
|
||||
artifacts.PublicationOutcomesKey: publishOutputOutcomeMetadata(outputPlan),
|
||||
"audio_upload_skipped": true,
|
||||
}
|
||||
for key, value := range artifacts.PublicationCompletionMetadata(artifacts.PublicationIdentity{RunID: runID, CommitKey: commitKey, PointerKey: pointerKey}) {
|
||||
metadata[key] = value
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||
)
|
||||
|
||||
type publishOutputStatus string
|
||||
type publishOutputStatus = artifacts.PublicationOutcomeStatus
|
||||
|
||||
const (
|
||||
publishOutputPublished publishOutputStatus = "published"
|
||||
publishOutputCarriedLocked publishOutputStatus = "carried_locked"
|
||||
publishOutputLockedUnpublished publishOutputStatus = "locked_unpublished"
|
||||
publishOutputOptionalMissing publishOutputStatus = "optional_missing"
|
||||
publishOutputUnselected publishOutputStatus = "unselected"
|
||||
publishOutputPublished = artifacts.PublicationPublished
|
||||
publishOutputCarriedLocked = artifacts.PublicationCarriedLocked
|
||||
publishOutputLockedUnpublished = artifacts.PublicationLockedUnpublished
|
||||
publishOutputOptionalMissing = artifacts.PublicationOptionalMissing
|
||||
publishOutputUnselected = artifacts.PublicationUnselected
|
||||
)
|
||||
|
||||
// PublicationAction describes a selected output mapping before remote publication.
|
||||
@@ -251,19 +251,10 @@ func publishOutputOutcomeMetadata(plan *publishOutputPlan) []map[string]any {
|
||||
}
|
||||
out := make([]map[string]any, 0, len(plan.Outcomes))
|
||||
for _, outcome := range plan.Outcomes {
|
||||
item := map[string]any{
|
||||
"source": outcome.Source,
|
||||
"status": string(outcome.Status),
|
||||
}
|
||||
if outcome.Destination != "" {
|
||||
item["destination"] = outcome.Destination
|
||||
}
|
||||
if outcome.DeclaredKey != "" {
|
||||
item["declared_key"] = outcome.DeclaredKey
|
||||
}
|
||||
if outcome.OriginRun != "" {
|
||||
item["origin_run"] = outcome.OriginRun
|
||||
}
|
||||
item := artifacts.PublicationOutcomeMetadata(artifacts.PublicationOutcome{
|
||||
Source: outcome.Source, Status: outcome.Status, Destination: outcome.Destination,
|
||||
DeclaredKey: outcome.DeclaredKey, OriginRun: outcome.OriginRun,
|
||||
})
|
||||
out = append(out, item)
|
||||
}
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user