distribution: test versions' digest per seat; say why a version has none

Review round 1: versionsAnswer's choice of digest per seat had no test.
TestTheVerbsSpeakTheSeatsContract now holds it, with a store whose blob
and manifest digests differ. OCI.Blob refuses a manifest that keeps no
single blob, naming its layers, and versions says that in the journal:
the contract's answer has no field for why.

Notes for H2: OCI.Held (oci.go) compares the tag's manifest digest with
a bundle's or an archive's blob digest, the same kind as this fault;
versions answers kind "" since the tool reads a kind its input does not
take.

Builds: design 47 G A-430a (G-22-lead-answers-2), design 51 *One contract*
This commit is contained in:
2026-11-20 16:20:00 +01:00
parent 6f4e85c656
commit b68de8f186
5 changed files with 27 additions and 4 deletions
@@ -44,7 +44,11 @@ func partAnswer(in reg.PublishPartInput, a holder.PublishAnswer) reg.PublishPart
func versionsAnswer(v *holder.Verbs, kind string, a holder.VersionsAnswer) reg.VersionsAnswer {
out := reg.VersionsAnswer{Name: a.Name, Versions: []reg.Artifact{}}
for _, ver := range a.Versions {
d, _ := v.VersionDigest(a.Seat, a.Name, ver)
d, err := v.VersionDigest(a.Seat, a.Name, ver)
if err != nil {
// The contract's answer has no field for why; the version is answered with no digest and the reason said here.
logf("versions: %s %s on %s answers no digest: %v", a.Name, ver, a.Seat, err)
}
out.Versions = append(out.Versions, reg.Artifact{Name: a.Name, Version: ver, Digest: d, Kind: kind})
}
return out
@@ -12,6 +12,12 @@ import (
"distribution/internal/holder"
)
// twoDigests is a store whose every version's manifest digest and blob differ.
type twoDigests struct{ holder.Catalog }
func (twoDigests) Digest(string, string) (string, error) { return "sha256:manifest", nil }
func (twoDigests) Blob(string, string) (string, error) { return "sha256:blob", nil }
func jsonFields(v any) map[string]bool {
out := map[string]bool{}
t := reflect.TypeOf(v)
@@ -59,6 +65,14 @@ func TestTheVerbsSpeakTheSeatsContract(t *testing.T) {
if a := publishAnswer(holder.PublishAnswer{Transfer: "t", Missing: []string{"sha256:bb"}}); !reflect.DeepEqual(a.Lacks, []string{"sha256:bb"}) || a.Held {
t.Errorf("publish answers %+v", a)
}
// versions answers the digest a reference names (design 47 G A-430a): the blob on the artifact seat, the manifest on the image seat.
cat := twoDigests{}
for _, c := range []struct{ seat, want string }{{holder.ArtifactSeat, "sha256:blob"}, {holder.ImageSeat, "sha256:manifest"}} {
got := versionsAnswer(&holder.Verbs{Catalog: cat}, "", holder.VersionsAnswer{Seat: c.seat, Name: "m/files", Versions: []string{"0.1.7"}})
if len(got.Versions) != 1 || got.Versions[0].Digest != c.want || got.Versions[0].Version != "0.1.7" {
t.Errorf("versions on %s answers %+v, want digest %s", c.seat, got.Versions, c.want)
}
}
if r, err := partOf(reg.PublishPartInput{Transfer: "t", Part: "sha256:bb", Data: "aGk=", Last: true}); err != nil || string(r.Data) != "hi" || r.Digest != "sha256:bb" {
t.Errorf("publish-part read %+v, %v", r, err)
}
@@ -724,6 +724,11 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
t.Errorf("VersionDigest(%s, m/tools, %s) = %q, %v, want %q", c.seat, c.version, got, err, c.want)
}
}
// A manifest that keeps no single blob answers no digest and says why.
store.manifests["m/tools:0.2.0"] = []byte(`{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:c"},"layers":[{"digest":"sha256:a"},{"digest":"sha256:b"}]}`)
if got, err := v.VersionDigest(ArtifactSeat, "m/tools", "0.2.0"); got != "" || err == nil || !strings.Contains(err.Error(), "2 layers") {
t.Errorf("VersionDigest of a manifest of two layers = %q, %v, want no digest and why", got, err)
}
gone := "sha256:" + strings.Repeat("e", 64)
_, err = b.h.Publish(ArtifactSeat, "x.mesh-delivery-builder", PublishRequest{Name: "m/tools", Version: "0.1.5", Kind: KindBundle, Digest: gone, Transfer: "republish-m-0-1-5-tools"})
if err == nil || !strings.Contains(err.Error(), "not stored: ") || !strings.Contains(err.Error(), gone) || store.manifests["m/tools:0.1.5"] != nil ||
+2 -2
View File
@@ -274,7 +274,7 @@ func (o *OCI) Digest(name, version string) (string, error) {
}
// Blob is the one blob the manifest name holds at version keeps (Manifest.Holder's shape): a bundle's or an archive's,
// what its reference names. Empty when none is held at version, or the manifest keeps no single blob.
// what its reference names. Empty when none is held at version; an error naming why when the manifest keeps no single blob.
func (o *OCI) Blob(name, version string) (string, error) {
resp, b, err := o.do(http.MethodGet, "/v2/"+name+"/manifests/"+version, "", nil, mediaManifest)
if err != nil {
@@ -291,7 +291,7 @@ func (o *OCI) Blob(name, version string) (string, error) {
return "", fmt.Errorf("the manifest of %s:%s cannot be read: %w", name, version, err)
}
if !m.Holder() {
return "", nil
return "", fmt.Errorf("the manifest of %s:%s keeps %d layers under a %q configuration, not one blob", name, version, len(m.Layers), m.ConfigMedia)
}
return m.Layers[0], nil
}
@@ -20,7 +20,7 @@ type Catalog interface {
// Digest is the digest name holds at version, empty when none.
Digest(name, version string) (string, error)
// Blob is the one blob the manifest name holds at version keeps, for a bundle or an archive: the digest its reference
// names and its published event carries. Empty when none is held, or the manifest is not of that shape.
// names and its published event carries. Empty when none is held; an error when the manifest keeps no single blob.
Blob(name, version string) (string, error)
// Remove deletes name at version by its manifest's digest, every tag naming that digest with it; the store's
// collector frees its blobs.