Design 47 lines 1888-1906 at b229f5c4 (test 60): the verb sits in every build seat's definition. Its judgement (what may be kept, the kept builds a node holds, the three refusals) is shared code of one domain's modules, so it is the domain SDK's (sdk/buildstep KeptArtifact, ADR 0634 §2): mesh-build-go keeps its store, sweep and tools and drops its own copy of the judgement and its table; mesh-build-node and mesh-build-image keep no build and answer over none, so a module claiming no oci-artifact-registry is refused and the holder is answered not kept. Their manifests serve the verb and invoke seat:mesh-catalog.module, which the judgement asks. Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ (Joined from 42d364fe.) Builds: design 47 G §271, §464 (BLD9) Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
112 lines
4.6 KiB
Go
112 lines
4.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/contracts/go/seats/nodebuildgo"
|
|
sdkstep "git.novox.be/novox/mesh-delivery/sdk/buildstep"
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
)
|
|
|
|
// memObjects is an object store in memory, as the tool runner keeps one for the module.
|
|
type memObjects struct {
|
|
objects map[string]buscalls.ObjectInfo
|
|
}
|
|
|
|
func (o *memObjects) Put(name string, data []byte, description string) (buscalls.ObjectInfo, error) {
|
|
i := buscalls.ObjectInfo{Name: name, Size: uint64(len(data)), Description: description, Modified: time.Now()}
|
|
o.objects[name] = i
|
|
return i, nil
|
|
}
|
|
func (o *memObjects) List() ([]buscalls.ObjectInfo, error) {
|
|
out := []buscalls.ObjectInfo{}
|
|
for _, i := range o.objects {
|
|
out = append(out, i)
|
|
}
|
|
return out, nil
|
|
}
|
|
func (o *memObjects) Delete(name string) error { delete(o.objects, name); return nil }
|
|
|
|
// Design 47 *The artifact store's holder takes its own new build even when its seat is the one broken* (test 60, W12.5):
|
|
// a trunk build of a module claiming oci-artifact-registry that the seat refuses is kept on this node and answered kept;
|
|
// any other build the seat refuses fails not stored; kept-artifact answers the store and object of a kept build, refuses
|
|
// a module that claims no oci-artifact-registry, one not kept here and one kept under another digest, and a drop or the
|
|
// sweep removes it.
|
|
func TestTheStoreHoldersRefusedBuildIsKeptAndServedByKeptArtifact(t *testing.T) {
|
|
holder := `{"module":"demo","version":"1","claims":[{"name":"oci-artifact-registry","scope":"mesh"}],"build":{"artifacts":[` + goBundle + `]}}`
|
|
refuse := func(key string, _ any) (json.RawMessage, error) {
|
|
return nil, errors.New("refused: the store did not take it")
|
|
}
|
|
for _, c := range []struct {
|
|
name, manifest string
|
|
publish bool
|
|
kept bool
|
|
}{
|
|
{"the store holder's trunk build", holder, true, true},
|
|
{"another module's trunk build", manifestWith(goBundle), true, false},
|
|
{"the store holder's candidate build", holder, false, false},
|
|
} {
|
|
m, states, _ := buildModule(t, c.manifest, "the program")
|
|
objects := &memObjects{objects: map[string]buscalls.ObjectInfo{}}
|
|
m.KeptBuilds, m.Self, m.Node = objects, "mesh-build-go", "ace"
|
|
m.Call = refuse
|
|
args := map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "tools", "fp": "src2:" + strings.Repeat("a", 64)}
|
|
if c.publish {
|
|
args["publish"] = true
|
|
}
|
|
for _, tool := range m.Tools(m.StepTools()) {
|
|
if tool.Name == "build_go_build" {
|
|
if _, err := tool.Run(args); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
st := states.waitEnd(t)
|
|
var res BuildResult
|
|
_ = json.Unmarshal(st.Result, &res)
|
|
if got := st.State == sdkstep.StepPassed && res.Kept != "" && len(objects.objects) == 1; got != c.kept {
|
|
t.Fatalf("%s: kept %v (step %s %q, kept %q, %d objects), want %v", c.name, got, st.State, st.Reason, res.Kept, len(objects.objects), c.kept)
|
|
}
|
|
if !c.kept {
|
|
continue
|
|
}
|
|
hex := strings.TrimPrefix(res.Kept, "sha256:")
|
|
// The answer's judgement is the domain SDK's (sdk/buildstep KeptArtifact, its own table); here only that the verb
|
|
// answers this node's kept build from this module's store, asking the seat mesh-catalog nothing for it.
|
|
m.AskInput = func(key string, _ any) (json.RawMessage, error) { return nil, errors.New("asked " + key) }
|
|
fp := args["fp"].(string)
|
|
var verb func(map[string]any) (any, error)
|
|
for _, tool := range m.SeatTools(nil) {
|
|
if tool.Name == Seat+"."+seat.VerbKeptArtifact {
|
|
verb = tool.Run
|
|
}
|
|
}
|
|
out, _ := verb(map[string]any{"module": "demo", "fp": fp, "digest": hex})
|
|
raw, _ := json.Marshal(out)
|
|
var got seat.KeptArtifactAnswer
|
|
if err := json.Unmarshal(raw, &got); err != nil || got.Refused != "" || got.Error != "" || got.Store != "mesh-build-go_kept-builds" || got.Object != hex || got.Size == 0 {
|
|
t.Errorf("kept-artifact of the kept build: %s", raw)
|
|
}
|
|
// Another node's build in the shared store is not this node's to answer.
|
|
m.AskInput = func(string, any) (json.RawMessage, error) {
|
|
return json.RawMessage(`{"module":{"module":"demo","manifest":` + holder + `}}`), nil
|
|
}
|
|
m.Node = "g14"
|
|
if got := m.keptArtifact(seat.KeptArtifactInput{Module: "demo", Fp: fp, Digest: hex}); got.Refused != seat.KeptArtifactAnswerRefusedNotKept {
|
|
t.Errorf("another node's kept build answered %+v", got)
|
|
}
|
|
m.Node = "ace"
|
|
m.sweepKeptBuilds(time.Now(), time.Hour)
|
|
if len(objects.objects) != 1 {
|
|
t.Errorf("a build kept within the bound was swept")
|
|
}
|
|
if err := m.dropKeptBuild(hex); err != nil || len(objects.objects) != 0 {
|
|
t.Errorf("drop: %v, %d objects left", err, len(objects.objects))
|
|
}
|
|
}
|
|
}
|