gitea: the package seats take a publish with a digest and no parts (held says published, else refused not stored)
The builder's publish again sends version and digest and no parts; the package seats refused it as not one part. Both registry holders now run the publish conformance cases. Builds: design 47 G A-73, A-417, A-490 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -213,7 +213,9 @@ func (h *Holder) answer(transfer string, r parts.Received) Answer {
|
||||
return Answer{Transfer: transfer, Lacks: r.Lacks, Ended: r.Ended}
|
||||
}
|
||||
|
||||
// Publish is `publish` on seat for the proved caller: a package is one file, its digest the file's sha256.
|
||||
// Publish is `publish` on seat for the proved caller: a package is one file, its digest the file's sha256. With its one
|
||||
// part the file travels (design 51 *Publishing*); with none (the builder's publish again, design 47 G A-73, A-417) the
|
||||
// version is said published when the forge holds it under the digest, and refused as not stored otherwise.
|
||||
func (h *Holder) Publish(seat, caller string, p Publish) (Answer, error) {
|
||||
if err := checkPublish(seat, p); err != nil {
|
||||
return Answer{}, err
|
||||
@@ -231,6 +233,12 @@ func (h *Holder) Publish(seat, caller string, p Publish) (Answer, error) {
|
||||
o.Reference = Reference(p.Name, p.Version)
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, h.Say(seat, EventPublished, o)
|
||||
}
|
||||
// A publish with a version, a digest and no parts (design 47 G A-73, A-417): what the forge holds under the version has
|
||||
// been said published above; nothing else travels, so the publish is refused as not stored, naming the digest.
|
||||
if len(p.Parts) == 0 {
|
||||
reason := fmt.Sprintf("not stored: the forge holds no %s of %s, so version %s names nothing", p.Digest, p.Name, p.Version)
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, errors.Join(errors.New("publish: "+reason), h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason))
|
||||
}
|
||||
// The transfer's name is the caller's own (the seat's contract): none would open the seat's one nameless transfer,
|
||||
// which key() still makes a valid id.
|
||||
if strings.TrimSpace(p.Transfer) == "" {
|
||||
@@ -377,8 +385,8 @@ func checkPublish(seat string, p Publish) error {
|
||||
return fmt.Errorf("publish: %s holds packages, not a %s", seat, p.Kind)
|
||||
case !strings.HasPrefix(p.Digest, "sha256:"):
|
||||
return fmt.Errorf("publish: digest %q is no sha256 digest", p.Digest)
|
||||
case len(p.Parts) != 1 || p.Parts[0].Digest != p.Digest:
|
||||
return errors.New("publish: a package is one file, its one part the package's digest")
|
||||
case len(p.Parts) > 1 || (len(p.Parts) == 1 && p.Parts[0].Digest != p.Digest):
|
||||
return errors.New("publish: a package is one file, its one part the package's digest, or no part at all")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/parts"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/publishconformance"
|
||||
)
|
||||
|
||||
type memObjects map[string][]byte
|
||||
@@ -50,10 +51,21 @@ func (b builder) Recorded(_, _, _ string) (bool, string, error) { return b.ok, "
|
||||
// forge is the forge's package registry: seat -> name@version -> file.
|
||||
type forge struct {
|
||||
files map[string]map[string][]byte
|
||||
digests map[string]string // seat+name@version -> a digest held with no bytes kept
|
||||
removed []string
|
||||
}
|
||||
|
||||
func (f *forge) holdDigest(seat, name, version, d string) {
|
||||
if f.digests == nil {
|
||||
f.digests = map[string]string{}
|
||||
}
|
||||
f.digests[seat+" "+name+"@"+version] = d
|
||||
}
|
||||
|
||||
func (f *forge) Held(seat, name, version string) (string, bool, error) {
|
||||
if d, ok := f.digests[seat+" "+name+"@"+version]; ok {
|
||||
return d, true, nil
|
||||
}
|
||||
b, ok := f.files[seat][name+"@"+version]
|
||||
if !ok {
|
||||
return "", false, nil
|
||||
@@ -150,6 +162,48 @@ func TestTheForgeHoldsBothPackageSeats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 G A-490: the publish contract's no-parts form, as every publish holder is held to it.
|
||||
t.Run("the publish conformance cases", func(t *testing.T) {
|
||||
publishconformance.Run(t, func(t *testing.T) publishconformance.Bed {
|
||||
b := newBed(true)
|
||||
return publishconformance.Bed{
|
||||
Hold: func() {
|
||||
b.forge.holdDigest(GoSeat, publishconformance.Name, publishconformance.Version, publishconformance.Digest)
|
||||
},
|
||||
Publish: func(name, version, digest string) publishconformance.Outcome {
|
||||
a, err := b.h.Publish(GoSeat, goBuild, Publish{Transfer: "t", Name: name, Version: version, Kind: KindPackage, Digest: digest})
|
||||
o := publishconformance.Outcome{Ended: a.Ended, Lacks: len(a.Lacks), 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} {
|
||||
b := newBed(true)
|
||||
none := pub("mesh-sdk", "0.1.0", file)
|
||||
none.Parts = nil
|
||||
a, err := b.h.Publish(seat, goBuild, none)
|
||||
if err == nil || !strings.Contains(err.Error(), "not stored") || !strings.Contains(err.Error(), digest(file)) || !a.Ended {
|
||||
t.Fatalf("%s: a publish of a digest the forge lacks answered %+v, %v; want refused as not stored, naming the digest", seat, a, err)
|
||||
}
|
||||
if len(b.said) != 1 || b.said[0].event != EventRefused || !strings.Contains(b.said[0].o.Reason, digest(file)) || !b.findings["publish-refused mesh-sdk@0.1.0"] {
|
||||
t.Errorf("%s: said %+v, findings %v; want refused with the digest and the finding raised", seat, b.said, b.findings)
|
||||
}
|
||||
b = newBed(true)
|
||||
if _, ok := b.forge.files[seat]; !ok {
|
||||
b.forge.files[seat] = map[string][]byte{}
|
||||
}
|
||||
b.forge.files[seat]["mesh-sdk@0.1.0"] = file
|
||||
a, err = b.h.Publish(seat, goBuild, none)
|
||||
if err != nil || !a.Ended || len(a.Lacks) != 0 || len(b.said) != 1 || b.said[0].event != EventPublished || b.said[0].o.Reference != "mesh-sdk@0.1.0" {
|
||||
t.Errorf("%s: a held digest answered %+v, %v, said %+v; want published", seat, a, err, b.said)
|
||||
}
|
||||
}
|
||||
})
|
||||
// Tools review F4 and running review F2's kind: a seat's incoming is read per seat with the cap its binding
|
||||
// carries; an open transfer is armed with its idle key, re-armed for the rest when it took a chunk since, and
|
||||
// dropped with its chunks when it had none for 24 hours; a cap from the binding refuses a transfer past it.
|
||||
|
||||
Reference in New Issue
Block a user