Share typed publication completion evidence

This commit is contained in:
2026-12-02 21:28:37 +00:00
parent 134513e3b9
commit e824e133d7
10 changed files with 235 additions and 77 deletions

View File

@@ -0,0 +1,39 @@
package artifacts
import (
"encoding/json"
"reflect"
"testing"
)
func TestPublicationMetadataRoundTrip(t *testing.T) {
metadata := PublicationCompletionMetadata(PublicationIdentity{RunID: "run", CommitKey: "commit", PointerKey: "pointer"})
metadata[PublicationOutcomesKey] = []map[string]any{
PublicationOutcomeMetadata(PublicationOutcome{Source: "one", Status: PublicationPublished, Destination: "a", DeclaredKey: "key", OriginRun: "run"}),
{"source": "bad", "status": "invalid"},
PublicationOutcomeMetadata(PublicationOutcome{Source: "two", Status: PublicationOptionalMissing}),
}
before := DecodePublicationCompletion(metadata)
outcomes := DecodePublicationOutcomes(metadata)
if !before.Uploaded.Valid || !before.Uploaded.Value || before.Skipped.Present || !before.RunID.Valid || len(outcomes) != 2 {
t.Fatalf("completion = %+v, outcomes = %+v", before, outcomes)
}
body, err := json.Marshal(metadata)
if err != nil {
t.Fatal(err)
}
var decoded map[string]any
if err := json.Unmarshal(body, &decoded); err != nil {
t.Fatal(err)
}
if got := DecodePublicationCompletion(decoded); !reflect.DeepEqual(got, before) {
t.Fatalf("completion = %+v, want %+v", got, before)
}
if got := DecodePublicationOutcomes(decoded); !reflect.DeepEqual(got, outcomes) {
t.Fatalf("outcomes = %+v, want %+v", got, outcomes)
}
decoded[PublicationSkippedKey] = "false"
if field := DecodePublicationCompletion(decoded).Skipped; !field.Present || field.Valid {
t.Fatalf("malformed skipped = %+v", field)
}
}