Each machine placing the module on the step's branch is asked compose-candidate for its input; one composer.Request per machine (depth compose, the one machine, one case change) carries it with the manifests, verdicts and seat definitions of the step's catalog revision read through mesh-catalog's revision; the request is kept under its run ask (refused at the inputs state's 64 MiB cap, naming the store); one run ask per machine on node-build-go's check queue under the assigner's name, naming no head, its program the node-engine build's catalog entry (the build each machine runs as its running says, read through entry, or the revision's where it differs from the trunk's) with the composer's package. The run's end is heard on the build seat's step-ended and its verdict read through buildstep.StepEnded.ReadOutput; a machine the watchman said away passes with a warning. The step is served from main. Builds: design 47 G §354, §22, §63, §64, §389, A-226, A-238, A-240, A-243, A-252, A-254, A-261 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
177 lines
9.1 KiB
Go
177 lines
9.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
|
)
|
|
|
|
const (
|
|
commitE1 = "1111111111111111111111111111111111111111"
|
|
commitE2 = "2222222222222222222222222222222222222222"
|
|
commitE3 = "3333333333333333333333333333333333333333"
|
|
)
|
|
|
|
// runStand is a composition run over stand-ins of the mesh-catalog seat, the machines' engines, the build seat and its step-ended.
|
|
type runStand struct {
|
|
mu sync.Mutex
|
|
asks map[string]buildstep.StepAsk // by node
|
|
requests map[string]composer.Request // by node
|
|
entries []string // the fingerprints `entry` was asked
|
|
r *compositionRun
|
|
}
|
|
|
|
func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand {
|
|
s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}}
|
|
engine := func(fp, commit string) meshcatalog.CatalogEntry {
|
|
return meshcatalog.CatalogEntry{Module: "engine", Fp: fp, Repository: "novox/mesh-host", Commit: commit, Path: ".", Serves: []string{ne.Seat + ".composition"},
|
|
Manifest: map[string]any{"module": "engine"}}
|
|
}
|
|
revisionCommit := commitE1
|
|
if revisionEngine != "src2:e1" {
|
|
revisionCommit = commitE3
|
|
}
|
|
pages := map[string]meshcatalog.RevisionAnswer{
|
|
"": {Revision: &meshcatalog.CatalogRevision{Revision: 7, Branch: "main", Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: "d1"}}},
|
|
Entries: []meshcatalog.CatalogEntry{engine(revisionEngine, revisionCommit), {Module: "bad", Verdict: mcc.VerdictRefused, Inputs: &meshcatalog.EntryInputs{Problems: []string{"no seat x"}},
|
|
Manifest: map[string]any{"module": "bad"}}}, Next: "bad"},
|
|
"bad": {Revision: &meshcatalog.CatalogRevision{Revision: 7}, Entries: []meshcatalog.CatalogEntry{{Module: "m", Verdict: mcc.VerdictAccepted, Manifest: map[string]any{"module": "m"}}}},
|
|
}
|
|
call := func(key string, body any) (json.RawMessage, error) {
|
|
raw, _ := json.Marshal(body)
|
|
switch key {
|
|
case mcc.RevisionVerb:
|
|
var in meshcatalog.RevisionInput
|
|
_ = json.Unmarshal(raw, &in)
|
|
if in.Revision != 7 || in.Branch != "main" {
|
|
return nil, errors.New("asked another revision")
|
|
}
|
|
return json.Marshal(pages[in.After])
|
|
case seatDefinitionsKey:
|
|
return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Found: true, Entry: &meshcatalog.SeatDefinitionsAnswerEntry{Seat: "s1", Digest: seatDigest, Definition: map[string]any{"seat": "s1"}}})
|
|
case entryVerbKey:
|
|
var in meshcatalog.EntryInput
|
|
_ = json.Unmarshal(raw, &in)
|
|
s.mu.Lock()
|
|
s.entries = append(s.entries, in.Fingerprint)
|
|
s.mu.Unlock()
|
|
commit := map[string]string{"src2:e1": commitE1, "src2:e2": commitE2}[in.Fingerprint]
|
|
return json.Marshal(meshcatalog.EntryAnswer{Entry: engine(in.Fingerprint, commit)})
|
|
}
|
|
return nil, errors.New("no such verb " + key)
|
|
}
|
|
engines := func(node, _ string, _ any) (json.RawMessage, error) {
|
|
return json.RawMessage(`{"candidate":"main.7","node":"` + node + `","verdict":"composed","input":{"node":"` + node + `"},"modules":[],"own":{},"took":1,"v":1}`), nil
|
|
}
|
|
running := map[string]string{"ace": "src2:e1", "g14": "src2:e2"}
|
|
away := &awayNodes{}
|
|
away.set("shanks", true)
|
|
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
|
ends := &runEnds{}
|
|
s.r = &compositionRun{
|
|
inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, call: engines, bound: time.Second},
|
|
keeper: keeper, call: call, ends: ends, away: away, now: time.Now, logf: t.Logf,
|
|
trunk: func() (mcc.Half, bool) {
|
|
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true
|
|
},
|
|
running: func(node, module string) (ne.Running, bool) {
|
|
fp, ok := running[node]
|
|
return ne.Running{Node: node, Module: module, Fingerprint: fp}, ok && module == "engine"
|
|
},
|
|
put: func(_ context.Context, a buildstep.StepAsk) error {
|
|
body, err := keeper.body(a.Run.Input.Digest)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
req, err := composer.Decode(body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
node := req.Machines[0]
|
|
s.mu.Lock()
|
|
s.asks[node], s.requests[node] = a, req
|
|
s.mu.Unlock()
|
|
m := composer.Machine{Composes: true}
|
|
if node == "g14" {
|
|
m = composer.Machine{Reason: "two modules own one path", Problems: []string{"/etc/x is m's and bad's"}}
|
|
}
|
|
v, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: changeCase, Machines: map[string]composer.Machine{node: m}}}})
|
|
go ends.heard(buildstep.StepEnded{Ask: a.ID, Asker: runAsker, Node: "builder1", Outcome: buildstep.OutcomePassed, Output: string(v)})
|
|
return nil
|
|
},
|
|
}
|
|
return s
|
|
}
|
|
|
|
// Design 47 G §354, §63, §64, A-226, A-238, A-240, A-243, A-252, A-254, A-261: one request and one run ask per machine, the request
|
|
// depth compose with the one machine and one case `change`, its manifests, verdicts and seats from the step's revision; the
|
|
// composer is the node-engine build each machine runs, its entry read through `entry`, or the revision's where it differs from the
|
|
// trunk's; the run's verdict is read from its step-ended; a machine away passes with a warning, one not composing fails the step.
|
|
func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
|
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
|
out := s.r.run(context.Background(), "ask-step", step)
|
|
if out.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(out.Said, "g14 does not compose") || !strings.Contains(out.Said, "/etc/x") ||
|
|
strings.Contains(out.Said, "ace") || len(out.Warnings) != 1 || !strings.Contains(out.Warnings[0], "shanks is away") {
|
|
t.Fatalf("the step came to %+v", out)
|
|
}
|
|
if len(s.asks) != 2 {
|
|
t.Fatalf("asked %d runs, want one per machine not away", len(s.asks))
|
|
}
|
|
a, req := s.asks["ace"], s.requests["ace"]
|
|
if a.Kind != buildstep.AskCheck || a.Language != buildstep.AskGo || a.Asker != runAsker || a.Run == nil || len(a.Run.Heads) != 0 ||
|
|
a.Run.Input.Verb != "seat:mesh-wants.input" || a.Run.Program != (buildstep.RunProgram{Repository: "novox/mesh-host", Commit: commitE1, Dir: ".", Package: composer.Package}) {
|
|
t.Errorf("the run ask of ace %+v %+v", a, a.Run)
|
|
}
|
|
if s.asks["g14"].Run.Program.Commit != commitE2 {
|
|
t.Errorf("g14's composer is built at %s, want the build its node-engine runs", s.asks["g14"].Run.Program.Commit)
|
|
}
|
|
if req.Depth != composer.DepthCompose || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase ||
|
|
string(req.Input) != `{"node":"ace"}` || len(req.Seats) != 1 || string(req.Seats[0]) != `{"seat":"s1"}` {
|
|
t.Errorf("the request of ace %+v", req)
|
|
}
|
|
c := req.Cases[0]
|
|
if string(c.Manifests["m"].Raw) != `{"module":"m"}` || len(c.Manifests) != 3 || len(c.Verdicts) != 1 || !strings.Contains(string(c.Verdicts["bad"]), `"refused"`) ||
|
|
!strings.Contains(string(c.Verdicts["bad"]), "no seat x") {
|
|
t.Errorf("the case %+v %s", c.Manifests, c.Verdicts)
|
|
}
|
|
if strings.Join(s.entries, " ") == "" {
|
|
t.Error("no node-engine entry is read through entry")
|
|
}
|
|
|
|
// The revision's node-engine differs from the trunk's: that build composes every machine, and no entry is asked.
|
|
changed := newRunStand(t, "src2:e3", "src2:e1", "d1")
|
|
if out := changed.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed {
|
|
t.Fatalf("the step came to %+v", out)
|
|
}
|
|
if changed.asks["ace"].Run.Program.Commit != commitE3 || changed.asks["g14"].Run.Program.Commit != commitE3 || len(changed.entries) != 0 {
|
|
t.Errorf("the change's node-engine does not compose every machine: %+v %+v %v", changed.asks["ace"].Run.Program, changed.asks["g14"].Run.Program, changed.entries)
|
|
}
|
|
|
|
// A seat digest neither the revision nor the trunk holds: could not run, naming the seat and the digest (A-261).
|
|
other := newRunStand(t, "src2:e1", "src2:e1", "d2")
|
|
if out := other.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
|
!strings.Contains(out.Said, "s1") || !strings.Contains(out.Said, "d1") || len(other.asks) != 0 {
|
|
t.Errorf("a seat digest not held came to %+v, %d asks", out, len(other.asks))
|
|
}
|
|
|
|
// At the inputs state's cap the ask is refused, naming the store (§354).
|
|
full := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
|
full.r.keeper.used = func() (int64, error) { return inputsCap, nil }
|
|
if out := full.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
|
!strings.Contains(out.Said, "the state inputs is at its cap") || len(full.asks) != 0 {
|
|
t.Errorf("an ask at the cap came to %+v, %d asks", out, len(full.asks))
|
|
}
|
|
}
|