publishconformance: the cases every publish holder is held to for a publish with a digest and no parts

Builds: design 47 G A-73, A-417, A-490

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-19 16:51:10 +01:00
parent 6f8ba0bf69
commit 2bc9ea9377
@@ -0,0 +1,59 @@
// Package publishconformance holds the cases every holder of a registry seat's `publish` is held to, so that two holders of
// one contract cannot each read it their own way (novox/hq design 47 G A-73, A-417, A-490): a publish with a version, a
// digest and no parts moves nothing. A holder holding what the digest names under the name says it published; a holder that
// holds none of it refuses it as not stored, naming the digest, and says it refused. A holder's own test runs Run over its
// own test bed.
package publishconformance
import (
"strings"
"testing"
)
// Name, Version and Digest are what the cases publish.
const (
Name = "novox/example"
Version = "0.1.0"
Digest = "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
)
// Outcome is what a holder did with a publish: whether the transfer ended with it, how many parts it asked for, the event
// it said on its seat (published or refused) with its reason, and the error it answered.
type Outcome struct {
Ended bool
Lacks int
Event string
Reason string
Err error
}
// Bed is one holder under test, fresh for a case.
type Bed struct {
// Hold makes the holder hold Digest under Name, as the builder's reservation of Version would find it.
Hold func()
// Publish sends the publish of name at version with the digest and no parts, and reports what the holder did.
Publish func(name, version, digest string) Outcome
}
// Run runs the cases over beds made by fresh.
func Run(t *testing.T, fresh func(t *testing.T) Bed) {
t.Helper()
t.Run("a publish with a digest and no parts is published when the holder holds it", func(t *testing.T) {
b := fresh(t)
b.Hold()
o := b.Publish(Name, Version, Digest)
if o.Err != nil || !o.Ended || o.Lacks != 0 || o.Event != "published" {
t.Fatalf("a held digest answered %+v; want ended, no part lacked, published said", o)
}
})
t.Run("a publish with a digest and no parts is refused as not stored, naming the digest, when the holder holds none", func(t *testing.T) {
b := fresh(t)
o := b.Publish(Name, Version, Digest)
if o.Err == nil || !strings.Contains(o.Err.Error(), "not stored") || !strings.Contains(o.Err.Error(), Digest) {
t.Fatalf("a digest not held answered %+v; want the error to say not stored and name %s", o, Digest)
}
if o.Event != "refused" || !strings.Contains(o.Reason, Digest) || o.Lacks != 0 || !o.Ended {
t.Errorf("a digest not held answered %+v; want refused said with the digest in its reason, ended, no part lacked", o)
}
})
}