K3 answered-digest, K4 kits: a publish answered other-bytes with the publish's own fingerprint is the held digest in the step result and both in the log, else refused; the publish kit's rows follow H-A-738, the reproducible kit
The shared publish names the ask's own fingerprint on a publish that names none. The kit's Bed gains HoldWith, PublishWith and Held. Builds: design 47 H2 H-A-589 (4), H-A-589 (5), H-A-591, H-A-593 (2) (3), H-A-738 (1)
This commit is contained in:
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -31,6 +31,15 @@ type Part struct {
|
||||
type Opened struct {
|
||||
Held bool
|
||||
Lacks []string
|
||||
// Other is the receiver's answer that it holds the name and version with another digest: nothing is sent (design 47 H2
|
||||
// H-A-729, H-A-738).
|
||||
Other *Other
|
||||
}
|
||||
|
||||
// Other is the digest a receiver holds for a name and version it was offered other bytes for, and the fingerprint it keeps
|
||||
// for them, empty where it keeps none.
|
||||
type Other struct {
|
||||
Digest, Fingerprint string
|
||||
}
|
||||
|
||||
// Open opens (or opens again) the transfer on the receiver, naming every part: the caller's own call.
|
||||
@@ -45,6 +54,8 @@ type Sent struct {
|
||||
Held bool
|
||||
Parts []string
|
||||
Chunks int
|
||||
// Other is what the receiver held the name and version as, when it answered other bytes: nothing was sent.
|
||||
Other *Other
|
||||
}
|
||||
|
||||
// Send opens the transfer and sends the parts the receiver answers it lacks, each in chunks of at most MaxChunk, in
|
||||
@@ -59,7 +70,10 @@ func Send(ctx context.Context, open Open, chunk Chunk, parts []Part) (Sent, erro
|
||||
if err != nil {
|
||||
return Sent{}, err
|
||||
}
|
||||
sent := Sent{Held: opened.Held}
|
||||
sent := Sent{Held: opened.Held, Other: opened.Other}
|
||||
if opened.Other != nil {
|
||||
return sent, nil
|
||||
}
|
||||
for _, d := range opened.Lacks {
|
||||
p, ok := byDigest[d]
|
||||
if !ok {
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
// 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 is the builder's publish again. A holder holding what the digest names under the name says it published
|
||||
// (it moves nothing, or, where the bytes sit in the artifact store, as distribution's A-417 takes them, tags them); a holder
|
||||
// that holds none of it, or holds the version under another digest, refuses it as not stored, naming the digest, and says it
|
||||
// refused (A-490, A-490a). The cases live here beside the build modules' conformance kit (design 47 G §680, A-490a). A
|
||||
// that holds none of it refuses it as not stored, naming the digest, and says it refused (A-490, A-490a); one that holds the
|
||||
// version under another digest answers other-bytes with that digest and the fingerprint it keeps, no error and nothing
|
||||
// stored (design 47 H2 H-A-589 (1), H-A-593 (2), H-A-729, H-A-738 (1)). The cases live here beside the build modules' conformance kit (design 47 G §680, A-490a). A
|
||||
// holder's own test runs Run over its own test bed, for every seat it fills.
|
||||
package publishconformance
|
||||
|
||||
@@ -21,22 +22,38 @@ const (
|
||||
Other = "sha256:fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"
|
||||
)
|
||||
|
||||
// OtherBytes is the answer other-bytes: the digest the holder holds for the name and version and the fingerprint it keeps for
|
||||
// them, empty where it keeps none.
|
||||
type OtherBytes struct {
|
||||
Digest, Fingerprint string
|
||||
}
|
||||
|
||||
// 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.
|
||||
// it said on its seat (published or refused) with its reason, the error it answered and the other-bytes it answered, nil
|
||||
// when it did not.
|
||||
type Outcome struct {
|
||||
Ended bool
|
||||
Lacks int
|
||||
Event string
|
||||
Reason string
|
||||
Err error
|
||||
Other *OtherBytes
|
||||
}
|
||||
|
||||
// Bed is one holder under test, fresh for a case.
|
||||
type Bed struct {
|
||||
// Hold makes the holder hold the digest under Name at Version, as the builder's reservation of Version would find it.
|
||||
Hold func(digest string)
|
||||
// Publish sends the publish of name at version with the digest and no parts, and reports what the holder did.
|
||||
// Publish sends the publish of name at version with the digest and no parts, and no fingerprint, and reports what the
|
||||
// holder did.
|
||||
Publish func(name, version, digest string) Outcome
|
||||
// HoldWith is Hold, the holder keeping the fingerprint for the version beside the digest.
|
||||
HoldWith func(digest, fingerprint string)
|
||||
// PublishWith is Publish naming a fingerprint.
|
||||
PublishWith func(name, version, digest, fingerprint string) Outcome
|
||||
// Held is what the holder holds for name at version now, as its verb versions answers it: the digest and the
|
||||
// fingerprint kept, each empty where none is held.
|
||||
Held func(name, version string) (digest, fingerprint string)
|
||||
}
|
||||
|
||||
// Run runs the cases over beds made by fresh.
|
||||
@@ -60,15 +77,37 @@ func Run(t *testing.T, fresh func(t *testing.T) Bed) {
|
||||
t.Errorf("a digest not held answered %+v; want refused said with the digest in its reason, ended, no part lacked", o)
|
||||
}
|
||||
})
|
||||
t.Run("a publish with a digest and no parts is refused as not stored, naming the digest, when the holder holds the version under another digest", func(t *testing.T) {
|
||||
// H-A-593 (2), H-A-738 (1): a version held under another digest is answered other-bytes, never a refusal and never stored.
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
kept, offers string
|
||||
}{
|
||||
{"with the publish's fingerprint", "src2:aa", "src2:aa"},
|
||||
{"with another fingerprint", "src2:bb", "src2:aa"},
|
||||
{"with no fingerprint kept", "", "src2:aa"},
|
||||
{"with no fingerprint named", "src2:aa", ""},
|
||||
} {
|
||||
t.Run("a publish naming the digest of a version the holder holds under another digest "+c.name+" is answered other-bytes, nothing stored", func(t *testing.T) {
|
||||
b := fresh(t)
|
||||
b.HoldWith(Other, c.kept)
|
||||
o := b.PublishWith(Name, Version, Digest, c.offers)
|
||||
if o.Err != nil || o.Other == nil || o.Other.Digest != Other || o.Other.Fingerprint != c.kept || o.Lacks != 0 {
|
||||
t.Fatalf("another digest held answered %+v; want no error and other-bytes with %s and the kept fingerprint %q, no part lacked", o, Other, c.kept)
|
||||
}
|
||||
if d, f := b.Held(Name, Version); d != Other || f != c.kept {
|
||||
t.Errorf("the holder holds %s with the fingerprint %q after it, want %s with %q: nothing stored", d, f, Other, c.kept)
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("a publish of the digest the holder holds is answered as held, with the fingerprint it keeps", func(t *testing.T) {
|
||||
b := fresh(t)
|
||||
b.Hold(Other)
|
||||
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("another digest held answered %+v; want the error to say not stored and name %s", o, Digest)
|
||||
b.HoldWith(Digest, "src2:aa")
|
||||
o := b.PublishWith(Name, Version, Digest, "src2:bb")
|
||||
if o.Err != nil || o.Other != nil || o.Event != "published" {
|
||||
t.Fatalf("the held digest answered %+v; want no error, no other-bytes and published", o)
|
||||
}
|
||||
if o.Event != "refused" || !strings.Contains(o.Reason, "not stored") || !strings.Contains(o.Reason, Digest) || o.Lacks != 0 || !o.Ended {
|
||||
t.Errorf("another digest held answered %+v; want refused said as not stored with the digest, ended, no part lacked", o)
|
||||
if d, f := b.Held(Name, Version); d != Digest || f != "src2:aa" {
|
||||
t.Errorf("versions answers %s with the fingerprint %q, want %s with src2:aa", d, f, Digest)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package publishconformance
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// holder is a correct holder of a registry seat in memory: what the kit's cases hold it to (design 47 H2 H-A-593 (2),
|
||||
// H-A-738 (1)).
|
||||
type holder struct{ digest, fingerprint string }
|
||||
|
||||
func (h *holder) publish(digest, fingerprint string) Outcome {
|
||||
switch {
|
||||
case h.digest == digest:
|
||||
return Outcome{Ended: true, Event: "published"}
|
||||
case h.digest != "":
|
||||
return Outcome{Other: &OtherBytes{Digest: h.digest, Fingerprint: h.fingerprint}}
|
||||
}
|
||||
reason := "the digest " + digest + " is not stored"
|
||||
return Outcome{Ended: true, Event: "refused", Reason: reason, Err: errors.New(reason)}
|
||||
}
|
||||
|
||||
func TestTheKitHoldsACorrectHolder(t *testing.T) {
|
||||
Run(t, func(t *testing.T) Bed {
|
||||
h := &holder{}
|
||||
return Bed{
|
||||
Hold: func(d string) { h.digest, h.fingerprint = d, "" },
|
||||
Publish: func(_, _, d string) Outcome { return h.publish(d, "") },
|
||||
HoldWith: func(d, f string) { h.digest, h.fingerprint = d, f },
|
||||
PublishWith: func(_, _, d, f string) Outcome { return h.publish(d, f) },
|
||||
Held: func(_, _ string) (string, string) { return h.digest, h.fingerprint },
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package steprun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// **A publish answered with the held digest** (design 47 H2 H-A-589 (4), H-A-738 (1)): a registry holds a name and version
|
||||
// with another digest than the build made and answers `other-bytes` with that digest and the fingerprint it keeps. The
|
||||
// shared publish compares that fingerprint with the publish's own (the ask's); equal, the publish is answered as published
|
||||
// with the held digest, nothing stored, and the ask's publish records the digest the seat answered, which the ask's step
|
||||
// result names for the artifact (ADR 0605 §9: a done key names what its seat answered) while the step log names both
|
||||
// digests; other or absent, the publish is refused naming both.
|
||||
|
||||
type publishKey struct{}
|
||||
|
||||
// heldPublish is one artifact's publish of an ask: the fingerprint it publishes under, and the digest its seat answered when that
|
||||
// is not the digest built.
|
||||
type heldPublish struct {
|
||||
mu sync.Mutex
|
||||
fingerprint string
|
||||
answered string
|
||||
}
|
||||
|
||||
// withPublish is ctx for the publish of one artifact of an ask whose fingerprint is fingerprint, and the record the ask
|
||||
// reads the answered digest from.
|
||||
func withPublish(ctx context.Context, fingerprint string) (context.Context, *heldPublish) {
|
||||
a := &heldPublish{fingerprint: fingerprint}
|
||||
return context.WithValue(ctx, publishKey{}, a), a
|
||||
}
|
||||
|
||||
func publishOf(ctx context.Context) *heldPublish {
|
||||
a, _ := ctx.Value(publishKey{}).(*heldPublish)
|
||||
return a
|
||||
}
|
||||
|
||||
// Answered is the digest the seat answered for the artifact when it held the version as another digest, empty when it
|
||||
// answered the digest built.
|
||||
func (a *heldPublish) Answered() string {
|
||||
if a == nil {
|
||||
return ""
|
||||
}
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
return a.answered
|
||||
}
|
||||
|
||||
// heldAnswer reads a publish answered `other-bytes` of the digest built: the held digest it is published as, or the refusal.
|
||||
func heldAnswer(ctx context.Context, seat, name, version, built, heldDigest, heldFingerprint, fingerprint string) error {
|
||||
if fingerprint == "" || heldFingerprint != fingerprint {
|
||||
return fmt.Errorf("%s holds %s %s as %s with the fingerprint %q, and the publish names %s with the fingerprint %q: a held version offered with other bytes (ADR 0605 §4)",
|
||||
seat, name, version, heldDigest, heldFingerprint, built, fingerprint)
|
||||
}
|
||||
if a := publishOf(ctx); a != nil {
|
||||
a.mu.Lock()
|
||||
a.answered = heldDigest
|
||||
a.mu.Unlock()
|
||||
}
|
||||
Phase(ctx, fmt.Sprintf("%s answered %s %s as published with the held digest %s, built %s: the same fingerprint, nothing stored", seat, name, version, heldDigest, built))
|
||||
return nil
|
||||
}
|
||||
@@ -254,8 +254,9 @@ func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version strin
|
||||
}
|
||||
}
|
||||
var (
|
||||
out any
|
||||
err error
|
||||
out any
|
||||
err error
|
||||
published *heldPublish
|
||||
)
|
||||
if a.From != "" {
|
||||
if s.Copy == nil {
|
||||
@@ -285,7 +286,9 @@ func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version strin
|
||||
args["version"] = version
|
||||
}
|
||||
Phase(ctx, "build "+a.Artifact)
|
||||
out, err = s.Build(ctx, args)
|
||||
var buildCtx context.Context
|
||||
buildCtx, published = withPublish(ctx, job.Fp)
|
||||
out, err = s.Build(buildCtx, args)
|
||||
}
|
||||
if err != nil {
|
||||
// The compare's out-of-step is answered with the failure, so the build's end still names it.
|
||||
@@ -306,6 +309,12 @@ func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version strin
|
||||
if err := json.Unmarshal(r, &built); err != nil || built.Digest == "" {
|
||||
return nil, fmt.Errorf("the build of %s answered no digest: %s", a.Artifact, r)
|
||||
}
|
||||
// A version its seat held as another digest with the same fingerprint is the held digest, which the done key names
|
||||
// (H-A-589 (4), H-A-738 (1)).
|
||||
if held := published.Answered(); held != "" {
|
||||
Phase(ctx, fmt.Sprintf("%s: built %s, answered %s: the step result names %s", a.Artifact, built.Digest, held, held))
|
||||
built.Digest = held
|
||||
}
|
||||
answer.Artifacts = append(answer.Artifacts, sdkstep.AskBuilt{Artifact: a.Artifact, Digest: built.Digest, Reference: built.Reference})
|
||||
if built.Kept != "" {
|
||||
answer.Kept = strings.TrimPrefix(built.Kept, "sha256:")
|
||||
|
||||
@@ -15,9 +15,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
)
|
||||
@@ -324,3 +328,43 @@ func runsCounted(puller func(read func(key string) (json.RawMessage, error)) *st
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reproducible holds a build module to giving one digest per artifact from two folders (design 47 H2 H-A-591, H-A-593 (3)):
|
||||
// fill writes the module's files into a folder, build builds its artifacts there and answers each one's digest by name. The
|
||||
// two folders have different names and the second one's files other times, so a digest that moved with a path or a time
|
||||
// fails. A catalogue check (failurekit) refuses a build module whose tests do not call it.
|
||||
func Reproducible(t *testing.T, fill func(dir string) error, build func(dir string) (map[string]string, error)) {
|
||||
t.Helper()
|
||||
var digests [2]map[string]string
|
||||
for i, name := range []string{"first-folder", "a-second-folder-elsewhere"} {
|
||||
dir := filepath.Join(t.TempDir(), name)
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := fill(dir); err != nil {
|
||||
t.Fatalf("the module's files are not written into %s: %v", dir, err)
|
||||
}
|
||||
if i == 1 {
|
||||
later := time.Now().Add(-24 * time.Hour)
|
||||
_ = filepath.WalkDir(dir, func(p string, _ fs.DirEntry, err error) error {
|
||||
if err == nil {
|
||||
_ = os.Chtimes(p, later, later)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
out, err := build(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("the build in %s: %v", dir, err)
|
||||
}
|
||||
digests[i] = out
|
||||
}
|
||||
if len(digests[0]) == 0 {
|
||||
t.Error("the build gave no artifact, so none is held to one digest")
|
||||
}
|
||||
for artifact, first := range digests[0] {
|
||||
if second, ok := digests[1][artifact]; !ok || second != first {
|
||||
t.Errorf("the artifact %s has the digest %s built in one folder and %q in another: its bytes depend on where or when it was built", artifact, first, second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -301,3 +303,22 @@ func TestRunsCountedRefusesAPullerThatDoesNotReadTheStepsState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-593 (3): the shared pack gives one digest from two folders; one that writes a folder's name into its bytes does not.
|
||||
func TestTheSharedPackIsReproducible(t *testing.T) {
|
||||
fill := func(dir string) error {
|
||||
if err := os.MkdirAll(filepath.Join(dir, "src"), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
for name, body := range map[string]string{"b.txt": "b", "src/a.txt": "a", "a.txt": "a"} {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reproducible(t, fill, func(dir string) (map[string]string, error) {
|
||||
_, digest, err := steprun.Pack(dir)
|
||||
return map[string]string{"archive": digest}, err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,7 +78,13 @@ func SentHow(n int) func(parts.Sent) string {
|
||||
// PublishParts publishes in with ps as its parts on seat, through that seat's client: in's fields are the seat's own
|
||||
// (the four registry seats share the publish verb's input, design 51), the parts are written by the client.
|
||||
func PublishParts(ctx context.Context, call SeatCall, seat string, in reg.PublishInput, ps []parts.Part) (parts.Sent, error) {
|
||||
if a := publishOf(ctx); a != nil && in.Fingerprint == "" {
|
||||
in.Fingerprint = a.fingerprint // the ask's own: the holder keeps it for the version (H-A-589 (2))
|
||||
}
|
||||
sent, err := publishParts(ctx, call, seat, in, ps)
|
||||
if err == nil && sent.Other != nil {
|
||||
err = heldAnswer(ctx, seat, in.Name, in.Version, in.Digest, sent.Other.Digest, sent.Other.Fingerprint, in.Fingerprint)
|
||||
}
|
||||
return sent, PublishFault(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package steprun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
reg "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/parts"
|
||||
)
|
||||
|
||||
// Design 47 H2 H-A-589 (4), H-A-738 (1): a publish answered other-bytes carrying the publish's own fingerprint is answered
|
||||
// as published with the held digest: the ask's record names it, the step log names both digests, and nothing is sent; with
|
||||
// another or no fingerprint it is refused naming both.
|
||||
func TestAPublishOfAHeldVersionIsAnsweredWithTheHeldDigest(t *testing.T) {
|
||||
const built, held = "sha256:aaaa", "sha256:bbbb"
|
||||
for _, c := range []struct {
|
||||
name, kept, ask string
|
||||
answered string
|
||||
refused bool
|
||||
}{
|
||||
{"the same fingerprint", "src2:f1", "src2:f1", held, false},
|
||||
{"another fingerprint", "src2:f2", "src2:f1", "", true},
|
||||
{"no kept fingerprint", "", "src2:f1", "", true},
|
||||
{"no fingerprint of its own", "src2:f1", "", "", true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
var log []string
|
||||
ctx := context.WithValue(context.Background(), phaseKey{}, &phases{logf: func(f string, a ...any) { log = append(log, fmt.Sprintf(f, a...)) }})
|
||||
ctx, record := withPublish(ctx, c.ask)
|
||||
calls := 0
|
||||
call := func(key string, in any) (json.RawMessage, error) {
|
||||
calls++
|
||||
raw, _ := json.Marshal(in)
|
||||
if want := c.ask; want != "" && !strings.Contains(string(raw), want) && strings.HasSuffix(key, ".publish") {
|
||||
t.Errorf("the publish %s names no fingerprint %s of the ask", raw, want)
|
||||
}
|
||||
other := map[string]any{"digest": held}
|
||||
if c.kept != "" {
|
||||
other["fingerprint"] = c.kept
|
||||
}
|
||||
return json.Marshal(map[string]any{"other-bytes": other})
|
||||
}
|
||||
in := reg.PublishInput{Name: "x/y", Kind: reg.PublishInputKindArchive, Version: "0.1.0", Digest: built, Transfer: "t"}
|
||||
sent, err := PublishParts(ctx, call, GoSeat, in, []parts.Part{{Digest: built, Size: 1, Open: nil}})
|
||||
if (err != nil) != c.refused || record.Answered() != c.answered || calls != 1 || sent.Other == nil {
|
||||
t.Fatalf("answered %q, err %v after %d calls (other %+v), want answered %q and refused %v with the one publish call", record.Answered(), err, calls, sent.Other, c.answered, c.refused)
|
||||
}
|
||||
if c.refused && !(strings.Contains(err.Error(), built) && strings.Contains(err.Error(), held)) {
|
||||
t.Errorf("the refusal %v does not name both digests", err)
|
||||
}
|
||||
if !c.refused && !(strings.Contains(strings.Join(log, "\n"), built) && strings.Contains(strings.Join(log, "\n"), held)) {
|
||||
t.Errorf("the step log %q does not name both digests", log)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user