diff --git a/modules/distribution/internal/holder/holder_test.go b/modules/distribution/internal/holder/holder_test.go index 08d6aee84..e4628991b 100644 --- a/modules/distribution/internal/holder/holder_test.go +++ b/modules/distribution/internal/holder/holder_test.go @@ -18,6 +18,7 @@ import ( "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" artifactref "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/publishconformance" ) type memObjects map[string][]byte @@ -666,6 +667,22 @@ func TestTheHolderOfTheTwoImageSeats(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.store.has[publishconformance.Digest] = true }, + Publish: func(name, version, digest string) publishconformance.Outcome { + got, err := b.h.Publish(ArtifactSeat, builder, PublishRequest{Name: name, Version: version, Kind: KindBundle, Digest: digest, Transfer: "t"}) + o := publishconformance.Outcome{Ended: got.Ended, Lacks: len(got.Missing), 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 diff --git a/modules/gitea/cmd/package-registry/seats.go b/modules/gitea/cmd/package-registry/seats.go index 246da7580..63ddb1f49 100644 --- a/modules/gitea/cmd/package-registry/seats.go +++ b/modules/gitea/cmd/package-registry/seats.go @@ -291,7 +291,7 @@ func verbTools[PI, PA, PPI, PPA, VI, VA, RI, RA any](seat string, holder func() } return []stdio.Tool{ {Name: seat + "." + packageseats.VerbPublish, Input: obj, - Description: "Open a transfer of a package's one file (ADR 0611): its name, the builder's version, kind package, its sha256 digest and the file as its one part; answers the part the forge lacks. A version held with that digest answers held and says published.", + Description: "Open a transfer of a package's one file (ADR 0611): its name, the builder's version, kind package, its sha256 digest and the file as its one part; answers the part the forge lacks. A version held with that digest answers held and says published; with no part at all (the builder's publish again) nothing moves: held says published, else refused as not stored, naming the digest (design 47 G A-490).", Run: run(func(h *packageseats.Holder, args map[string]any) (any, error) { in, err := as[PI](args) if err != nil { diff --git a/modules/gitea/internal/packageseats/holder.go b/modules/gitea/internal/packageseats/holder.go index f16b8a8f3..dff199e88 100644 --- a/modules/gitea/internal/packageseats/holder.go +++ b/modules/gitea/internal/packageseats/holder.go @@ -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 } diff --git a/modules/gitea/internal/packageseats/holder_test.go b/modules/gitea/internal/packageseats/holder_test.go index 9fd27c9b2..9e41d5560 100644 --- a/modules/gitea/internal/packageseats/holder_test.go +++ b/modules/gitea/internal/packageseats/holder_test.go @@ -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.