gitea: a no-parts publish of a version held under another digest is refused as not stored, named by its digest; conformance runs on both package seats

The builder's republish recognises a refusal by the words not stored.
Builds: design 47 G A-490, A-490a

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-19 17:04:55 +01:00
parent 5dfb357333
commit 13d43a7de0
3 changed files with 25 additions and 21 deletions
@@ -672,7 +672,7 @@ func TestTheHolderOfTheTwoImageSeats(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 },
Hold: func(d string) { b.store.has[d] = 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}
@@ -226,8 +226,10 @@ func (h *Holder) Publish(seat, caller string, p Publish) (Answer, error) {
return Answer{}, fmt.Errorf("publish: the forge cannot say whether it holds %s@%s: %w", p.Name, p.Version, err)
} else if ok {
if d != p.Digest {
reason := fmt.Sprintf("%s@%s is published with %s, not %s", p.Name, p.Version, d, p.Digest)
return Answer{Transfer: p.Transfer, Ended: true}, h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason)
// A no-parts publish names nothing the forge holds: it is refused as not stored (A-490), which the builder's
// republish recognises by those words.
reason := fmt.Sprintf("not stored: %s@%s is published with %s, not %s", p.Name, p.Version, d, p.Digest)
return Answer{Transfer: p.Transfer, Ended: true}, errors.Join(errors.New("publish: "+reason), h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason))
}
o := outcomeOf(p, "")
o.Reference = Reference(p.Name, p.Version)
@@ -162,24 +162,26 @@ 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-490, A-490a: the publish contract's no-parts form, as every publish holder is held to it, per seat.
for _, seat := range []string{GoSeat, NpmSeat} {
t.Run("the publish conformance cases on "+seat, func(t *testing.T) {
publishconformance.Run(t, func(t *testing.T) publishconformance.Bed {
b := newBed(true)
return publishconformance.Bed{
Hold: func(d string) {
b.forge.holdDigest(seat, publishconformance.Name, publishconformance.Version, d)
},
Publish: func(name, version, digest string) publishconformance.Outcome {
a, err := b.h.Publish(seat, 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} {
@@ -332,7 +334,7 @@ func TestTheForgeHoldsBothPackageSeats(t *testing.T) {
// The same version published with other content is refused, never uploaded over.
b = newBed(true)
b.forge.files[NpmSeat] = map[string][]byte{"x@0.1.0": []byte("first")}
if _, err := b.h.Publish(NpmSeat, nodeBuild, pub("x", "0.1.0", file)); err != nil || len(b.said) != 1 || b.said[0].event != EventRefused {
if _, err := b.h.Publish(NpmSeat, nodeBuild, pub("x", "0.1.0", file)); err == nil || !strings.Contains(err.Error(), "not stored") || len(b.said) != 1 || b.said[0].event != EventRefused {
t.Errorf("a published version with other content: %v, said %+v", err, b.said)
}
})