settle applies the changed wants in the order of design 47 H 771: the node's own composition, a reverted module, the holder of node-backup and the bus module (by the claims of the manifests the composer holds), each pipeline's wants by rank (older source first), the rest by name, the engine's own module last. A want of a higher rank waits on this machine alone for the lower ranks of its pipeline, held in its have as a wait of step placing and judged again at the next settle. The want's pipeline and rank are the mesh-delivery contract's stand-in until its commit. Builds: design 47 H §771; H-A-46, H-A-59, H-A-67, H-A-68 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
140 lines
6.7 KiB
Go
140 lines
6.7 KiB
Go
package selfcompose
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
)
|
|
|
|
// Design 47 G A-430, A-430a (the lead's answer A-430b): a want naming its version is resolved to its artifacts'
|
|
// digests through the verb versions of the registry seat of each artifact's kind, under `<module>/<artifact>`; an upstream copy
|
|
// by the digest its manifest pins. The build is made from those digests. A lookup that fails is said, naming the module, the
|
|
// version and the seat, and holds the module whole.
|
|
func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) {
|
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
|
d := func(c string) string { return "sha256:" + strings.Repeat(c, 64) }
|
|
manifest := map[string]any{"module": "mail", "version": "1", "build": map[string]any{"artifacts": []any{
|
|
map[string]any{"name": "server", "kind": "upstream", "from": "alpine@" + d("9")},
|
|
map[string]any{"name": "files", "kind": "archive", "from": "files"},
|
|
map[string]any{"name": "web", "kind": "image", "from": "Dockerfile"},
|
|
}}}
|
|
entry := meshcatalog.CatalogEntry{Module: "mail", Fp: fp, Manifest: manifest, Artifacts: []meshcatalog.Artifact{
|
|
{Ref: "mail:server", Kind: "upstream"}, {Ref: "mail:files", Kind: "archive"}, {Ref: "mail:web", Kind: "image"}}}
|
|
// The seats hold mail/files and mail/web; versions newest first.
|
|
held := map[string]string{
|
|
"oci-artifact-registry.mail/files": `{"name":"mail/files","versions":[{"name":"mail/files","kind":"archive","digest":"` + d("2") + `","version":"1.3.0"},{"name":"mail/files","kind":"archive","digest":"` + d("1") + `","version":"1.2.3"}]}`,
|
|
"container-image-registry.mail/web": `{"name":"mail/web","versions":[{"name":"mail/web","kind":"image","digest":"` + d("3") + `","version":"1.2.3"}]}`,
|
|
"container-image-registry.mail/other": `{"name":"mail/other","versions":[]}`,
|
|
}
|
|
for name, row := range map[string]struct {
|
|
want meshwants.WantsByWantNodeModuleValue
|
|
down string // a seat whose call fails
|
|
parts map[string]string
|
|
missing string // a word the reason holds
|
|
said []string
|
|
}{
|
|
"resolved": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true},
|
|
parts: map[string]string{"mail:server": d("9"), "mail:files": d("1"), "mail:web": d("3")}},
|
|
"a version a seat does not hold": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "2.0.0", Self: true},
|
|
missing: "2.0.0", said: []string{"mail at version 2.0.0", "oci-artifact-registry", "container-image-registry"}},
|
|
"a seat that does not answer": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}, down: "container-image-registry",
|
|
missing: "mail:web", said: []string{"mail at version 1.2.3: the seat container-image-registry"}},
|
|
} {
|
|
var mu sync.Mutex
|
|
var said []string
|
|
env := Env{Say: func(line string) { mu.Lock(); said = append(said, line); mu.Unlock() }}
|
|
calls := 0
|
|
env.Registry = EntryCall(func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) {
|
|
calls++
|
|
if verb != "versions" {
|
|
t.Errorf("%s: asked %s.%s", name, seat, verb)
|
|
}
|
|
if seat == row.down {
|
|
return nil, errors.New("no responders")
|
|
}
|
|
answer, ok := held[seat+"."+args.(map[string]string)["name"]]
|
|
if !ok {
|
|
return nil, errors.New("not held")
|
|
}
|
|
return json.RawMessage(answer), nil
|
|
})
|
|
env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
|
|
return nil, errors.New("not asked")
|
|
})
|
|
c := New(env)
|
|
c.wants["mail"] = row.want
|
|
c.keptEnt[fp] = keptEntry{entry: entry}
|
|
parts, missing := c.partsOf("mail", entry, row.want)
|
|
b := c.buildOf("mail", fp)
|
|
if row.missing != "" {
|
|
if parts != nil || b != nil || !strings.Contains(missing, row.missing) {
|
|
t.Errorf("%s: parts %v, build %v, missing %q: want the module held whole, naming %s", name, parts, b, missing, row.missing)
|
|
}
|
|
if c.entryHolds()["mail"] == "" {
|
|
t.Errorf("%s: the module is not held", name)
|
|
}
|
|
for _, w := range row.said {
|
|
if !strings.Contains(strings.Join(said, "\n"), w) {
|
|
t.Errorf("%s: said %q, want a line naming %q", name, said, w)
|
|
}
|
|
}
|
|
continue
|
|
}
|
|
if missing != "" || len(parts) != len(row.parts) {
|
|
t.Fatalf("%s: parts %v, missing %q", name, parts, missing)
|
|
}
|
|
for ref, digest := range row.parts {
|
|
if parts[ref] != digest {
|
|
t.Errorf("%s: %s at %s, want %s", name, ref, parts[ref], digest)
|
|
}
|
|
}
|
|
if b == nil || len(b.Artifacts) != 3 {
|
|
t.Fatalf("%s: build %+v", name, b)
|
|
}
|
|
for _, a := range b.Artifacts {
|
|
if a.Digest != row.parts["mail:"+a.Name] || a.Reference != referenceOf("mail", a.Name, a.Digest) {
|
|
t.Errorf("%s: artifact %+v", name, a)
|
|
}
|
|
}
|
|
// A resolution is asked once, and it names the node keeping the build its digests are of.
|
|
before := calls
|
|
c.partsOf("mail", entry, row.want)
|
|
if calls != before {
|
|
t.Errorf("%s: resolved again: %d calls, then %d", name, before, calls)
|
|
}
|
|
c.wants["mail"] = meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: row.want.Version, KeptOn: "g14", Self: true}
|
|
if node, _, kept, _ := c.KeptBuildOf(context.Background(), "mail", row.parts["mail:files"]); !kept || node != "g14" {
|
|
t.Errorf("%s: kept on %q %v, want g14", name, node, kept)
|
|
}
|
|
if _, _, kept, _ := c.KeptBuildOf(context.Background(), "mail", d("7")); kept {
|
|
t.Errorf("%s: a digest the want does not resolve to is said kept", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 H §771: the order applies the holder of a seat first, found by the claim of the manifest of the build the want names.
|
|
func TestAModulesClaimsAreReadFromTheEntryOfItsWantsBuild(t *testing.T) {
|
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
|
c := New(Env{})
|
|
c.keptEnt = map[string]keptEntry{}
|
|
c.wants["bus"] = meshwants.WantsByWantNodeModuleValue{Fp: fp}
|
|
c.keptEnt[fp] = keptEntry{entry: meshcatalog.CatalogEntry{Module: "bus", Fp: fp,
|
|
Manifest: map[string]any{"module": "bus", "version": "1", "claims": []any{map[string]any{"name": "mesh-broker"}}}}}
|
|
if claims, known := c.Claims(context.Background(), "bus", "mesh-broker"); !claims || !known {
|
|
t.Errorf("the bus claims mesh-broker: claims %v, known %v", claims, known)
|
|
}
|
|
if claims, known := c.Claims(context.Background(), "bus", "node-backup"); claims || !known {
|
|
t.Errorf("the bus claims no node-backup: claims %v, known %v", claims, known)
|
|
}
|
|
if claims, known := c.Claims(context.Background(), "ghost", "mesh-broker"); claims || known {
|
|
t.Errorf("a module with no want has no manifest read: claims %v, known %v", claims, known)
|
|
}
|
|
}
|