gitea: the package seats take a publish with a digest and no parts as tag-or-refuse (A-490, A-490a) #707

Merged
mesh-tools merged 5 commits from fix/gitea-publish-by-digest into main 2026-11-19 21:40:03 +00:00
6 changed files with 80 additions and 4 deletions
Showing only changes of commit 4bdcedd0f0 - Show all commits
@@ -683,6 +683,39 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
}}
})
})
// Design 47 G A-490j: the one-part publish a build module makes while it builds, as every publish holder is held to it,
// checked through the real Reserved against the builder's answer.
t.Run("the publish while the build runs", func(t *testing.T) {
publishconformance.RunReserved(t, func(t *testing.T) publishconformance.ReservedBed {
b := newBed(true)
answer := ""
b.h.Builder = Reserved{Ask: func(string, any) (json.RawMessage, error) {
if answer == "" {
return nil, errors.New("no reserved version of m/tools")
}
return json.RawMessage(answer), nil
}}
return publishconformance.ReservedBed{
Reserve: func(r publishconformance.Reservation) {
d := map[publishconformance.Reservation]string{publishconformance.NoDigestYet: "", publishconformance.SameDigest: part.Digest,
publishconformance.OtherDigest: digestOf([]byte("another"))}[r]
answer = `{"module":"m","version":"0.1.0","artifacts":[{"artifact":"m:tools","digest":"` + d + `"}]}`
},
PublishWhole: func() publishconformance.Outcome {
r := req("t-whole")
r.Version = "0.1.0"
a, err := b.h.Publish(ArtifactSeat, builder, r)
if err == nil && !a.Ended {
_, err = b.h.PublishPart(ArtifactSeat, builder, PartRequest{Transfer: "t-whole", Digest: part.Digest, Last: true, Data: blob})
}
o := publishconformance.Outcome{Err: err}
if len(b.said) > 0 {
o.Event, o.Reason = b.said[len(b.said)-1].event, b.said[len(b.said)-1].body.Reason
}
return o
}}
})
})
t.Run("a publish with a version and no parts tags the held digest at the store's size; one not held is not stored", func(t *testing.T) {
// Design 47 G A-417, A-73, A-50: the build stored the bundle untagged; the builder's publish of its version with that
// digest and no parts tags it and says published, nothing sent; a digest the store holds none of is refused as not
@@ -9,7 +9,7 @@ import (
// Reserved is the holder's check of a publish against the builder's reservation (novox/hq design 47 §381, §478, §504): it asks the
// seat mesh-builds' verb reserved with the publish's name and version, a package's name in its ecosystem, and accepts the publish
// only when that version is the one reserved and an artifact of it has the publish's digest. It reads no catalog and a publish gains
// only when that version is the one reserved and an artifact of it has the publish's digest or none yet (A-490j). It reads no catalog and a publish gains
// no field. It is the Builder the holder's Check asks.
type Reserved struct {
// Ask is the runtime's request and reply over the bus (mesh-sdk stdio.Ask).
@@ -34,7 +34,10 @@ func (r Reserved) Recorded(name, version, digest string) (bool, string, error) {
return false, fmt.Sprintf("%s reserved %s for %s, not %s", a.Module, a.Version, name, version), nil
}
for _, art := range a.Artifacts {
if art.Digest == digest {
// An artifact whose build has not recorded its digest yet takes the publish: the builder records a build's digests only when
// the build ends, while the build module publishes during it (design 47 G §369, A-415, A-490j). Its record then meets what
// the holder holds: the published kept on the reservation marks the artifact, and a digest that differs fails the build.
if art.Digest == digest || art.Digest == "" {
return true, "", nil
}
}
@@ -19,6 +19,7 @@ func reservedChecksAPublishAgainstTheReservation(t *testing.T) {
}{
{name: "the reserved version and digest", answer: `{"module":"mesh-image","version":"0.1.7","artifacts":[{"artifact":"mesh-image:image","digest":"sha256:aa"}]}`, ok: true},
{name: "another artifact of it carries the digest", answer: `{"module":"mesh-image","version":"0.1.7","artifacts":[{"artifact":"mesh-image:aux"},{"artifact":"mesh-image:image","digest":"sha256:aa"}]}`, ok: true},
{name: "the artifact is not built yet", answer: `{"module":"mesh-image","version":"0.1.7","artifacts":[{"artifact":"mesh-image:image"}]}`, ok: true},
{name: "another digest", answer: `{"module":"mesh-image","version":"0.1.7","artifacts":[{"artifact":"mesh-image:image","digest":"sha256:bb"}]}`, why: "another digest than sha256:aa"},
{name: "another version reserved", answer: `{"module":"mesh-image","version":"0.1.8","artifacts":[]}`, why: "reserved 0.1.8 for registry/mesh-image, not 0.1.7"},
{name: "the builder refused the name", err: errors.New("no entry carries registry/mesh-image"), why: "no entry carries registry/mesh-image"},
@@ -3,6 +3,7 @@ package packageseats
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"strings"
"testing"
@@ -182,6 +183,40 @@ func TestTheForgeHoldsBothPackageSeats(t *testing.T) {
})
})
}
// Design 47 G A-490j: the one-part publish a build module makes while it builds, as every publish holder is held to it, per
// seat, checked through the real Reserved against the builder's answer.
for _, seat := range []string{GoSeat, NpmSeat} {
t.Run("the publish while the build runs on "+seat, func(t *testing.T) {
publishconformance.RunReserved(t, func(t *testing.T) publishconformance.ReservedBed {
b := newBed(true)
whole := []byte("a package built now")
answer := ""
b.h.Builder = Reserved{Ask: func(string, any) (json.RawMessage, error) {
if answer == "" {
return nil, errors.New("no reserved version of mesh-sdk")
}
return json.RawMessage(answer), nil
}}
return publishconformance.ReservedBed{
Reserve: func(r publishconformance.Reservation) {
d := map[publishconformance.Reservation]string{publishconformance.NoDigestYet: "", publishconformance.SameDigest: digest(whole),
publishconformance.OtherDigest: digest([]byte("another"))}[r]
answer = `{"module":"mesh-sdk","version":"0.1.19","artifacts":[{"artifact":"mesh-sdk:` + seat + `","digest":"` + d + `"}]}`
},
PublishWhole: func() publishconformance.Outcome {
a, err := b.h.Publish(seat, goBuild, pub("mesh-sdk", "0.1.19", whole))
if err == nil && !a.Ended {
_, err = b.h.PublishPart(seat, goBuild, "t-mesh-sdk", digest(whole), 0, true, whole)
}
o := publishconformance.Outcome{Err: err}
if len(b.said) > 0 {
o.Event, o.Reason = b.said[len(b.said)-1].event, b.said[len(b.said)-1].o.Reason
}
return o
}}
})
})
}
// Design 47 G A-73, A-417: the builder's publish again names the version and the digest and no parts.
t.Run("a publish with a digest and no parts is published when held, refused as not stored when not", func(t *testing.T) {
for _, seat := range []string{NpmSeat, GoSeat} {
@@ -9,7 +9,7 @@ import (
// Reserved is the holder's check of a publish against the builder's reservation (novox/hq design 47 §381, §478, §504): it asks the
// seat mesh-builds' verb reserved with the publish's name and version, a package's name in its ecosystem, and accepts the publish
// only when that version is the one reserved and an artifact of it has the publish's digest. It reads no catalog and a publish gains
// only when that version is the one reserved and an artifact of it has the publish's digest or none yet (A-490j). It reads no catalog and a publish gains
// no field. It is the Builder the holder's Check asks.
type Reserved struct {
// Ask is the runtime's request and reply over the bus (mesh-sdk stdio.Ask).
@@ -34,7 +34,10 @@ func (r Reserved) Recorded(name, version, digest string) (bool, string, error) {
return false, fmt.Sprintf("%s reserved %s for %s, not %s", a.Module, a.Version, name, version), nil
}
for _, art := range a.Artifacts {
if art.Digest == digest {
// An artifact whose build has not recorded its digest yet takes the publish: the builder records a build's digests only when
// the build ends, while the build module publishes during it (design 47 G §369, A-415, A-490j). Its record then meets what
// the holder holds: the published kept on the reservation marks the artifact, and a digest that differs fails the build.
if art.Digest == digest || art.Digest == "" {
return true, "", nil
}
}
@@ -19,6 +19,7 @@ func reservedChecksAPublishAgainstTheReservation(t *testing.T) {
}{
{name: "the reserved version and digest", answer: `{"module":"mesh-sdk","version":"0.1.19","artifacts":[{"artifact":"mesh-sdk:ts","digest":"sha256:aa"}]}`, ok: true},
{name: "another artifact of it carries the digest", answer: `{"module":"mesh-sdk","version":"0.1.19","artifacts":[{"artifact":"mesh-sdk:go"},{"artifact":"mesh-sdk:ts","digest":"sha256:aa"}]}`, ok: true},
{name: "the artifact is not built yet", answer: `{"module":"mesh-sdk","version":"0.1.19","artifacts":[{"artifact":"mesh-sdk:ts"}]}`, ok: true},
{name: "another digest", answer: `{"module":"mesh-sdk","version":"0.1.19","artifacts":[{"artifact":"mesh-sdk:ts","digest":"sha256:bb"}]}`, why: "another digest than sha256:aa"},
{name: "another version reserved", answer: `{"module":"mesh-sdk","version":"0.1.20","artifacts":[]}`, why: "reserved 0.1.20 for @novox/mesh-sdk, not 0.1.19"},
{name: "the builder refused the name", err: errors.New("no entry carries @novox/mesh-sdk"), why: "no entry carries @novox/mesh-sdk"},