CAT-BN3: mesh-build-node publishes through the registry seats and holds no registry credential
Bundles go through oci-artifact-registry and answer the seat's reference; a trunk package is packed under the builder's version and published through npm-package-registry, so the holder can check it with the builder. Reads are anonymous, so the write pair, the sealed secret and the store's address go. The one-part sender moves into buildstep for both build modules, so the move to the registry clients is made in one place. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -3,7 +3,9 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -11,54 +13,87 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
registry "git.novox.be/novox/mesh-contracts/go/seats/containerimageregistry"
|
||||
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
|
||||
"git.novox.be/novox/mesh-catalog/modules/mesh-build-go/buildstep"
|
||||
)
|
||||
|
||||
// pushed are the blobs the fake artifact store took, by digest, for the tests that read an archive back.
|
||||
// pushed are the blobs the fake holder took, by digest, for the tests that read an archive back.
|
||||
var pushed sync.Map
|
||||
|
||||
// fakeStore is a store of the test's own: its address in RegistryFile, each blob kept by repository and digest; fail,
|
||||
// when set, is the store's refusal.
|
||||
// fakeStore is the registry seats' holder as m's publish meets it (publish.go; CAT-BN3): publish opens a transfer and
|
||||
// answers the part it lacks, publish-part takes the chunks in sequence, and the last one keeps the whole part when it
|
||||
// hashes to its digest. Each file is kept by name and digest; fail, when set, is the holder's refusal at the last chunk.
|
||||
type fakeStore struct {
|
||||
mu sync.Mutex
|
||||
blobs map[string][]byte // "<repository>@<digest>"
|
||||
fail error
|
||||
mu sync.Mutex
|
||||
blobs map[string][]byte // "<name>@<digest>"
|
||||
fail error
|
||||
open map[string]registry.PublishInput
|
||||
chunks map[string][]byte
|
||||
published []registry.PublishInput
|
||||
seats []string
|
||||
}
|
||||
|
||||
func withStore(t *testing.T, m *Module) *fakeStore {
|
||||
t.Helper()
|
||||
s := &fakeStore{blobs: map[string][]byte{}}
|
||||
m.RegistryFile = filepath.Join(t.TempDir(), "registry")
|
||||
if err := os.WriteFile(m.RegistryFile, []byte("store.test:5000\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Push = func(ctx context.Context, registry, repository, digest string, body []byte) error {
|
||||
s := &fakeStore{blobs: map[string][]byte{}, open: map[string]registry.PublishInput{}, chunks: map[string][]byte{}}
|
||||
m.Call = func(key string, body any) (json.RawMessage, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.fail != nil {
|
||||
return s.fail
|
||||
raw, _ := json.Marshal(body)
|
||||
seat, verb, _ := strings.Cut(strings.TrimPrefix(key, "seat:"), ".")
|
||||
if seat != buildstep.ArtifactSeat && seat != buildstep.NpmSeat {
|
||||
return nil, errors.New("nats: no responders available for request")
|
||||
}
|
||||
if sum := sha256.Sum256(body); "sha256:"+hex.EncodeToString(sum[:]) != digest || registry != "store.test:5000" {
|
||||
t.Errorf("pushed %s to %s with bytes of another digest", digest, registry)
|
||||
switch verb {
|
||||
case "publish":
|
||||
var in registry.PublishInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
if (seat == buildstep.ArtifactSeat) != (in.Kind == "bundle") || in.Transfer == "" || strings.ContainsAny(in.Transfer, "/. *>") {
|
||||
t.Errorf("publish on %s of kind %q, transfer %q", seat, in.Kind, in.Transfer)
|
||||
}
|
||||
s.open[in.Transfer] = in
|
||||
s.seats = append(s.seats, seat)
|
||||
return json.Marshal(registry.PublishAnswer{Transfer: in.Transfer, Lacks: []string{in.Digest}})
|
||||
case "publish-part":
|
||||
var c registry.PublishPartInput
|
||||
_ = json.Unmarshal(raw, &c)
|
||||
data, _ := base64.StdEncoding.DecodeString(c.Data)
|
||||
s.chunks[c.Transfer] = append(s.chunks[c.Transfer], data...)
|
||||
if !c.Last {
|
||||
return json.Marshal(registry.PublishPartAnswer{Transfer: c.Transfer, Part: c.Part})
|
||||
}
|
||||
in, whole := s.open[c.Transfer], s.chunks[c.Transfer]
|
||||
delete(s.chunks, c.Transfer)
|
||||
if s.fail != nil {
|
||||
return nil, s.fail
|
||||
}
|
||||
if sum := sha256.Sum256(whole); "sha256:"+hex.EncodeToString(sum[:]) != in.Digest {
|
||||
t.Errorf("published %s with bytes of another digest", in.Digest)
|
||||
}
|
||||
s.blobs[in.Name+"@"+in.Digest] = whole
|
||||
s.published = append(s.published, in)
|
||||
pushed.Store(in.Digest, whole)
|
||||
return json.Marshal(registry.PublishPartAnswer{Transfer: c.Transfer, Part: c.Part, Complete: true})
|
||||
}
|
||||
s.blobs[repository+"@"+digest] = append([]byte(nil), body...)
|
||||
pushed.Store(digest, s.blobs[repository+"@"+digest])
|
||||
return nil
|
||||
return nil, errors.New("nats: no responders available for request")
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// archiveOf is the archive a build pushed, by its digest.
|
||||
// archiveOf is the archive a build published, by its digest.
|
||||
func archiveOf(t *testing.T, r BuildResult) []byte {
|
||||
t.Helper()
|
||||
raw, ok := pushed.Load(r.Digest)
|
||||
if !ok {
|
||||
t.Fatalf("nothing was pushed under %s", r.Digest)
|
||||
t.Fatalf("nothing was published under %s", r.Digest)
|
||||
}
|
||||
return raw.([]byte)
|
||||
}
|
||||
|
||||
// 1587-S6 (ADR 0498 §1): a done bundle answers the reference of the archive it pushed, under the manifest's module.
|
||||
// 1587-S6 (ADR 0498 §1; CAT-BN3): a done bundle is published through oci-artifact-registry and answers the seat's
|
||||
// reference of its archive, under the manifest's module.
|
||||
func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) {
|
||||
m, _, _ := builtMachine(t, ``)
|
||||
store := withStore(t, m)
|
||||
@@ -67,23 +102,33 @@ func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := out.(BuildResult)
|
||||
if want := "artifact-store://m/tools/blobs/" + r.Digest; r.Reference != want {
|
||||
if want := "oci-artifact-registry/m/tools@" + r.Digest; r.Reference != want {
|
||||
t.Errorf("reference %q, want %q", r.Reference, want)
|
||||
}
|
||||
if store.blobs["m/tools@"+r.Digest] == nil {
|
||||
t.Errorf("the store holds %d blobs, not m/tools@%s", len(store.blobs), r.Digest)
|
||||
if store.blobs["m/tools@"+r.Digest] == nil || len(store.seats) != 1 || store.seats[0] != buildstep.ArtifactSeat {
|
||||
t.Errorf("the holder holds %d files through %v, not m/tools@%s through %s", len(store.blobs), store.seats, r.Digest, buildstep.ArtifactSeat)
|
||||
}
|
||||
}
|
||||
|
||||
// 1587-S7 and S8 (ADR 0498 §2, the lead's decision L9): a push the store refuses fails the step `not stored:
|
||||
// <artifact>: <the store's words>`, and whatever the push answered, no packed file is left on the node.
|
||||
// 1587-S7 and S8 (ADR 0498 §2, the lead's decision L9): a publish the holder refuses fails the step `not stored:
|
||||
// <artifact>: <the holder's words>`, a seat nothing holds too, and whatever it answered, no packed file is left.
|
||||
func TestARefusedPushFailsNotStoredAndNoPackedFileStays(t *testing.T) {
|
||||
for _, fail := range []error{nil, errors.New("store.test:5000 refused the blob: 507 Insufficient Storage")} {
|
||||
for _, c := range []struct {
|
||||
fail error
|
||||
noSeat bool
|
||||
words string
|
||||
}{{nil, false, ""}, {errors.New("refused: the store did not take it: 507 Insufficient Storage"), false, "507"},
|
||||
{nil, true, "no responders"}} {
|
||||
m, _, work := builtMachine(t, ``)
|
||||
withStore(t, m).fail = fail
|
||||
withStore(t, m).fail = c.fail
|
||||
if c.noSeat {
|
||||
m.Call = func(string, any) (json.RawMessage, error) {
|
||||
return nil, errors.New("nats: no responders available for request")
|
||||
}
|
||||
}
|
||||
_, err := m.build(context.Background(), buildArgs())
|
||||
if fail != nil && (err == nil || !strings.HasPrefix(err.Error(), delivery.NotStored+"tools: ") || !strings.Contains(err.Error(), "507")) {
|
||||
t.Errorf("a refused push answered %v", err)
|
||||
if c.words != "" && (err == nil || !strings.HasPrefix(err.Error(), delivery.NotStored+"tools: ") || !strings.Contains(err.Error(), c.words)) {
|
||||
t.Errorf("a refused publish answered %v", err)
|
||||
}
|
||||
var archives []string
|
||||
filepath.WalkDir(work, func(p string, d os.DirEntry, err error) error {
|
||||
@@ -93,7 +138,7 @@ func TestARefusedPushFailsNotStoredAndNoPackedFileStays(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
if len(archives) != 0 {
|
||||
t.Errorf("push answered %v: packed files left on the node: %v", fail, archives)
|
||||
t.Errorf("publish answered %v: packed files left on the node: %v", c.fail, archives)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user