Compare commits
34
Commits
go/v0.1.21
...
go/v0.1.75
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
277c53067e | ||
|
|
227f6e68ce | ||
|
|
744204c5ab | ||
|
|
0f41b405ba | ||
|
|
20f0e9baaf | ||
|
|
75c636a5ec | ||
|
|
0cbabe9860 | ||
|
|
d2c9dc7de6 | ||
|
|
53199f16ce | ||
|
|
256eb34a0d | ||
|
|
a47c8e7922 | ||
|
|
16f9ad2950 | ||
|
|
b1f25f91d5 | ||
|
|
d281faeeb7 | ||
|
|
e312999843 | ||
|
|
5dba7fe68b | ||
|
|
f0f28c56a4 | ||
|
|
20a7bd0f3c | ||
|
|
0b1ce08985 | ||
|
|
f053e3b041 | ||
|
|
d428650ce4 | ||
|
|
351eda0867 | ||
|
|
5e3d92ae33 | ||
|
|
e5e5c50e67 | ||
|
|
8167d825ed | ||
|
|
ac95e5628c | ||
|
|
bed9b61d5a | ||
|
|
67ef449230 | ||
|
|
8a52b6f801 | ||
|
|
380d4781e6 | ||
|
|
7534bf5c07 | ||
|
|
08fe40f233 | ||
|
|
27e96a2a1b | ||
|
|
f98d5ec748 |
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -12,6 +13,8 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
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"
|
||||
@@ -19,6 +22,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
// The run of a composition step (design 47 G §354, §63, §64, §718; A-226, A-238, A-240, A-252, A-254, A-261): the step reads one
|
||||
@@ -53,6 +57,18 @@ type compositionRun struct {
|
||||
call func(key string, body any) (json.RawMessage, error)
|
||||
// trunk is the trunk's catalog half as the assigner holds it.
|
||||
trunk func() (mcc.Half, bool)
|
||||
// newest is the newest catalog half the assigner's views hold of each watched branch (halves.views), and watched a module's
|
||||
// watched branches in its registration's order (halves.watchedOf): a machine's composition takes each module's manifest across
|
||||
// them (design 47 H-A-143, G §532). Nil: the step's revision alone.
|
||||
newest func() map[string]mcc.Half
|
||||
watched func(module string) []string
|
||||
// assigned is the modules the assignments place on a machine (world.assignments), for the modules no watched branch lists;
|
||||
// assignment is the machine's assignments whole, which the case composes with those modules left out (H-A-148).
|
||||
assigned func(node string) []string
|
||||
assignment func(node string) (mma.Assignments, bool)
|
||||
// findings is where the step raises the finding assignment-unlisted of each assignment it leaves out (H-A-149); the pass over
|
||||
// the assignments clears it.
|
||||
findings assign.Findings
|
||||
// running is the last `running` heard of a module on a node (world.runningOf), never the node-engine's bucket.
|
||||
running func(node, module string) (ne.Running, bool)
|
||||
// away says the watchman holds machine away (machine-away, not back since): the one presence the assigner keeps (world.awayNow),
|
||||
@@ -209,6 +225,9 @@ func (p *runPrep) get(ctx context.Context) error {
|
||||
p.err = errors.New("the step's catalog revision is not read: " + err.Error())
|
||||
return
|
||||
}
|
||||
if p.r.newest != nil && p.r.watched != nil {
|
||||
half = acrossBranches(p.step, half, p.r.newest(), p.r.watched)
|
||||
}
|
||||
if p.seats, p.err = p.r.seats(ctx, half.Revision.Definitions); p.err != nil {
|
||||
return
|
||||
}
|
||||
@@ -229,6 +248,21 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co
|
||||
r.logf("the composition run %s is not ended: %v", key, err)
|
||||
}
|
||||
}
|
||||
// The one set of unlisted assignments, read once at the run's start and carried on the run to the leaving-out, the finding and
|
||||
// every step's judgement, the resume's too (design 47 H-A-152, H-A-153).
|
||||
unlisted := r.unlistedOn(node)
|
||||
if len(unlisted) > 0 {
|
||||
if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool {
|
||||
if c.Ask != ask || c.Ended != nil {
|
||||
return false
|
||||
}
|
||||
c.Unlisted = unlisted
|
||||
return true
|
||||
}); err != nil {
|
||||
end(node + ": the run's unlisted assignments are not written: " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := prep.get(ctx); err != nil {
|
||||
end(node + ": " + err.Error())
|
||||
return
|
||||
@@ -243,8 +277,15 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co
|
||||
end(node + ": " + err.Error())
|
||||
return
|
||||
}
|
||||
cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none}
|
||||
if left, err := r.leftOut(node, unlisted); err != nil {
|
||||
end(node + ": " + err.Error())
|
||||
return
|
||||
} else if left != nil {
|
||||
cs.Assignments = left
|
||||
}
|
||||
req := composer.Request{V: composer.Version, Input: in.Body, Depth: composer.DepthCompose, Machines: []string{node},
|
||||
Cases: []composer.Case{{Name: changeCase, Manifests: prep.manifests, None: prep.none}}, Seats: prep.seats,
|
||||
Cases: []composer.Case{cs}, Seats: prep.seats,
|
||||
BlameTries: r.runs.set.blameTries} // the composer's bound of its search for culprits (§721, A-466r)
|
||||
raw, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -289,7 +330,29 @@ const notTried = "not tried: the search reached its bound"
|
||||
// could not run where the module was not tried (A-470b); a machine that does not compose and blames no module fails every step on
|
||||
// it, on the node's own account; a verdict with no `blamed` (a composer before §721) is judged as before, with the warning "the
|
||||
// composer names no culprits"; otherwise the machine passes, with a warning for each other module blamed there.
|
||||
//
|
||||
// The run's unlisted are the modules the machine is assigned that no watched branch's newest revision lists, left out of its
|
||||
// composition, as the run's start read them (H-A-152, H-A-153): each is said on every path, in the machine's failed or
|
||||
// could-not-run words where one is set, else as a warning, never the machine's failure and never dropped in silence (H-A-143,
|
||||
// H-A-144, H-A-148).
|
||||
func judgeRun(module string, run meshwants.CompositionRun) machineEnd {
|
||||
end := judgeVerdict(module, run)
|
||||
for _, u := range run.Unlisted {
|
||||
said := run.Machine + " is assigned " + u + ", which no watched branch lists (H-A-143)"
|
||||
switch {
|
||||
case end.failed != "":
|
||||
end.failed += "; " + said
|
||||
case end.couldNot != "":
|
||||
end.couldNot += "; " + said
|
||||
default:
|
||||
end.warnings = append(end.warnings, said)
|
||||
}
|
||||
}
|
||||
return end
|
||||
}
|
||||
|
||||
// judgeVerdict is judgeRun before the unlisted modules are said.
|
||||
func judgeVerdict(module string, run meshwants.CompositionRun) machineEnd {
|
||||
node := run.Machine
|
||||
if run.Ended == nil {
|
||||
return machineEnd{couldNot: node + ": the step stopped before its composition run " + runKeyOf(run.Candidate, node) + " ended"}
|
||||
@@ -503,6 +566,135 @@ func caseOf(half mcc.Half) (map[string]composer.Manifest, map[string]string, err
|
||||
return manifests, none, nil
|
||||
}
|
||||
|
||||
// acrossBranches is the catalog half a machine's composition reads (design 47 H-A-143, H-A-144, G §532): each module's entry from
|
||||
// the newest revision of the first of its watched branches, in its registration's order, that lists it, none for a module with no
|
||||
// watched branches; the candidate's revision replaces its
|
||||
// branch's newest for the modules it moves (its movers and the step's module), and the whole of it where it is that branch's newest
|
||||
// or the branch's is not held. The half keeps the candidate's revision, its definitions with it.
|
||||
func acrossBranches(step meshwants.StepRun, candidate mcc.Half, newest map[string]mcc.Half, watched func(module string) []string) mcc.Half {
|
||||
halves := make(map[string]mcc.Half, len(newest)+1)
|
||||
for b, h := range newest {
|
||||
halves[b] = h
|
||||
}
|
||||
if own, held := newest[step.Branch]; !held || candidate.Revision.Revision >= own.Revision.Revision {
|
||||
halves[step.Branch] = candidate
|
||||
} else {
|
||||
mix := mcc.Half{Revision: own.Revision, Entries: maps.Clone(own.Entries)}
|
||||
moved := []string{step.Module}
|
||||
for _, m := range candidate.Revision.Movers {
|
||||
moved = append(moved, m.Module)
|
||||
}
|
||||
for _, m := range moved {
|
||||
if e, ok := candidate.Entries[m]; ok {
|
||||
mix.Entries[m] = e
|
||||
} else {
|
||||
delete(mix.Entries, m)
|
||||
}
|
||||
}
|
||||
halves[step.Branch] = mix
|
||||
}
|
||||
out := mcc.Half{Revision: candidate.Revision, Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||
for _, h := range halves {
|
||||
for name := range h.Entries {
|
||||
if _, done := out.Entries[name]; done {
|
||||
continue
|
||||
}
|
||||
for _, b := range watched(name) { // none: no watched branch lists it, it is unlisted (H-A-144)
|
||||
if e, ok := halves[b].Entries[name]; ok {
|
||||
out.Entries[name] = e
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// unlistedOn is the one set of unlisted assignments of node (H-A-152): the modules the assignments place there that the newest
|
||||
// revision of none of their watched branches lists, a module with no watched branches among them (H-A-143, H-A-144), by name.
|
||||
// The candidate never enters it, so a module the change drops while still assigned stays in the composition and fails it as the
|
||||
// change's own fault (ADR 0578 §2). Where the newest revisions are not followed yet nothing is unlisted: none while no branch's
|
||||
// newest is held, and not a module one of whose watched branches' newest is not held yet.
|
||||
func (r *compositionRun) unlistedOn(node string) []string {
|
||||
if r.assigned == nil || r.newest == nil || r.watched == nil {
|
||||
return nil
|
||||
}
|
||||
newest := r.newest()
|
||||
if len(newest) == 0 {
|
||||
return nil
|
||||
}
|
||||
var out []string
|
||||
for _, m := range r.assigned(node) {
|
||||
watched := r.watched(m)
|
||||
if !listedOn(newest, watched, m) && !slices.ContainsFunc(watched, func(b string) bool { _, held := newest[b]; return !held }) {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
slices.Sort(out)
|
||||
return slices.Compact(out)
|
||||
}
|
||||
|
||||
// leftOut is the case's assignments of node with each module of the run's unlisted set left out, or nil where none is (the case
|
||||
// then composes the input's): a stale assignment is a fault of the assignments, not of the change judged, so it is left out of the
|
||||
// composition, said in the journal, raised as assignment-unlisted and, at the judgement, said as unlisted from the same set
|
||||
// (design 47 H-A-148, H-A-149, H-A-152, H-A-143; ADR 0578 §2).
|
||||
func (r *compositionRun) leftOut(node string, set []string) (map[string]json.RawMessage, error) {
|
||||
if r.assignment == nil || len(set) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
a, ok := r.assignment(node)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
var unlisted []string
|
||||
for _, m := range a.Modules {
|
||||
if slices.Contains(set, m.Module) {
|
||||
unlisted = append(unlisted, m.Module)
|
||||
}
|
||||
}
|
||||
if len(unlisted) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
a.Modules = slices.DeleteFunc(slices.Clone(a.Modules), func(m mma.PlacedModule) bool { return slices.Contains(unlisted, m.Module) })
|
||||
raw, err := mmac.EncodeAssignments(a)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("its assignments with %s left out cannot be encoded: %w", strings.Join(unlisted, ", "), err)
|
||||
}
|
||||
r.logf("%s: the composition leaves out %s, assigned there and listed on no watched branch (H-A-148)", node, strings.Join(unlisted, ", "))
|
||||
for _, m := range unlisted {
|
||||
r.raiseUnlisted(node, m)
|
||||
}
|
||||
return map[string]json.RawMessage{node: raw}, nil
|
||||
}
|
||||
|
||||
// raiseUnlisted writes the finding assignment-unlisted of module on node (H-A-149); one not written is said in the journal.
|
||||
func (r *compositionRun) raiseUnlisted(node, module string) {
|
||||
if r.findings.Put == nil {
|
||||
return
|
||||
}
|
||||
now := r.now
|
||||
if now == nil {
|
||||
now = time.Now
|
||||
}
|
||||
f, err := assign.UnlistedFinding(node, module, now())
|
||||
if err == nil {
|
||||
err = r.findings.Put(f)
|
||||
}
|
||||
if err != nil {
|
||||
r.logf("the finding %s is not written: %v", assign.UnlistedKey(node, module), err)
|
||||
}
|
||||
}
|
||||
|
||||
// listedOn says whether the newest revision of one of module's watched branches lists it (H-A-143, H-A-144).
|
||||
func listedOn(newest map[string]mcc.Half, watched []string, module string) bool {
|
||||
for _, b := range watched {
|
||||
if _, ok := newest[b].Entries[module]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// nodeEngineEntry is the entry of the module that claims the seat node-engine, or false.
|
||||
func nodeEngineEntry(entries map[string]meshcatalog.CatalogEntry) (meshcatalog.CatalogEntry, bool) {
|
||||
for _, name := range slices.Sorted(mapsKeys(entries)) {
|
||||
@@ -616,3 +808,32 @@ func runAskPublisher(js jetstream.JetStream) func(ctx context.Context, a buildst
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// newestOf is the newest catalog half the views hold of each watched branch, or nil while the catalog half is not followed.
|
||||
func (iv *catalogViews) newestOf() func() map[string]mcc.Half {
|
||||
if iv == nil {
|
||||
return nil
|
||||
}
|
||||
return func() map[string]mcc.Half {
|
||||
if iv.h == nil {
|
||||
return map[string]mcc.Half{}
|
||||
}
|
||||
return iv.h.views()
|
||||
}
|
||||
}
|
||||
|
||||
// listed says whether one of module's watched branches lists it in the newest revision the views hold (H-A-149's clear).
|
||||
func (iv *catalogViews) listed(module string) bool {
|
||||
if iv == nil || iv.h == nil {
|
||||
return false
|
||||
}
|
||||
return listedOn(iv.h.views(), iv.h.watchedOf(module), module)
|
||||
}
|
||||
|
||||
// watchedOf is a module's watched branches in its registration's order (halves.watchedOf); none while the half is not followed.
|
||||
func (iv *catalogViews) watchedOf(module string) []string {
|
||||
if iv == nil || iv.h == nil {
|
||||
return nil
|
||||
}
|
||||
return iv.h.watchedOf(module)
|
||||
}
|
||||
|
||||
@@ -4,18 +4,24 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
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"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -259,6 +265,104 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Another watched branch's app is in every machine's case, and a module assigned there that no watched branch lists is said in
|
||||
// the machine's reason (H-A-143, §532).
|
||||
across := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||
across.r.newest = func() map[string]mcc.Half {
|
||||
return map[string]mcc.Half{"master": {Revision: meshcatalog.CatalogRevision{Branch: "master", Revision: 2},
|
||||
Entries: map[string]meshcatalog.CatalogEntry{"f1-circuits": {Module: "f1-circuits", Fp: "f1", Manifest: map[string]any{"module": "f1-circuits"}}}}}
|
||||
}
|
||||
across.r.watched = func(module string) []string {
|
||||
if module == "checker" || module == "lidarr" { // no registration names them; lidarr is on main's revision all the same (H-A-144)
|
||||
return nil
|
||||
}
|
||||
return []string{"main", "master"}
|
||||
}
|
||||
across.r.assigned = func(node string) []string { return []string{"m", "f1-circuits", "checker", "lidarr"} }
|
||||
if out := across.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed ||
|
||||
!strings.Contains(out.Said, "g14 is assigned checker, which no watched branch lists (H-A-143)") ||
|
||||
!strings.Contains(out.Said, "g14 is assigned lidarr, which no watched branch lists (H-A-143)") {
|
||||
t.Errorf("the step across the watched branches came to %+v", out)
|
||||
}
|
||||
if c := across.requests["ace"].Cases[0]; string(c.Manifests["f1-circuits"].Raw) != `{"module":"f1-circuits"}` || len(c.Manifests) != 4 ||
|
||||
c.Manifests["lidarr"].Raw != nil {
|
||||
t.Errorf("the case across the watched branches holds %v", slices.Sorted(maps.Keys(c.Manifests)))
|
||||
}
|
||||
if c := across.requests["ace"].Cases[0]; c.Assignments != nil {
|
||||
t.Errorf("with no assignments held the case composes the input's, it carries %v", c.Assignments)
|
||||
}
|
||||
|
||||
// A stale assignment is left out of the case's assignments as well, said, and the machine composes; a listed module stays in
|
||||
// (H-A-148, ADR 0578 §2). The one set is the watched branches' newest revisions', carried on the run (H-A-152, H-A-153): a module
|
||||
// the candidate drops while the newest still lists it stays in, the change's own fault, and while no newest revision is followed
|
||||
// nothing is left out.
|
||||
dropsWeb := func() map[string]mcc.Half {
|
||||
h := across.r.newest()
|
||||
h["main"] = mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: "main", Revision: 6},
|
||||
Entries: map[string]meshcatalog.CatalogEntry{"m": {Module: "m", Manifest: map[string]any{"module": "m"}},
|
||||
"web": {Module: "web", Fp: "w1", Manifest: map[string]any{"module": "web"}}}}
|
||||
return h
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
assigned []string
|
||||
newest func() map[string]mcc.Half // nil: across's
|
||||
want []string // the case's modules of ace; nil: the input's assignments
|
||||
}{
|
||||
{"a stale assignment left out and said, the machine composes", []string{"m", "f1-circuits", "checker"}, nil, []string{"m", "f1-circuits"}},
|
||||
{"listed modules alone: the input's assignments", []string{"m", "f1-circuits"}, nil, nil},
|
||||
{"a module the candidate drops, the newest lists: kept", []string{"m", "f1-circuits", "web"}, dropsWeb, nil},
|
||||
{"no newest revision followed: nothing left out", []string{"m", "checker"}, func() map[string]mcc.Half { return map[string]mcc.Half{} }, nil},
|
||||
} {
|
||||
left := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||
left.r.newest, left.r.watched = across.r.newest, across.r.watched
|
||||
if tc.newest != nil {
|
||||
left.r.newest = tc.newest
|
||||
}
|
||||
left.r.assigned = func(string) []string { return tc.assigned }
|
||||
left.r.assignment = func(node string) (mma.Assignments, bool) {
|
||||
a := mma.Assignments{Node: node}
|
||||
for _, m := range tc.assigned {
|
||||
a.Modules = append(a.Modules, mma.PlacedModule{Module: m})
|
||||
}
|
||||
return a, true
|
||||
}
|
||||
left.verdict = func(string) (composer.Machine, bool) { return composer.Machine{Composes: true}, true }
|
||||
raised := map[string][]byte{}
|
||||
left.r.findings = assign.Findings{Put: putInto(raised)}
|
||||
out := left.r.run(context.Background(), "ask-step", step)
|
||||
// H-A-149: the step that leaves an assignment out raises assignment-unlisted, scope delivery, id <node>.<module>, a warning.
|
||||
var f mcseat.Finding
|
||||
_ = json.Unmarshal(raised[assign.UnlistedKey("ace", "checker")], &f)
|
||||
if want := tc.want != nil; want != (f.Kind == assign.KindAssignmentUnlisted && f.Scope == "delivery" && f.ID == "ace.checker" &&
|
||||
f.Severity == mcseat.FindingSeverityWarning) || (!want && len(raised) != 0) {
|
||||
t.Errorf("%s: raised %v", tc.name, raised)
|
||||
}
|
||||
said := "ace is assigned checker, which no watched branch lists (H-A-143)"
|
||||
if out.Outcome != meshwants.StepEndedOutcomePassed || (tc.want != nil) != slices.Contains(out.Warnings, said) {
|
||||
t.Errorf("%s: the step came to %+v", tc.name, out)
|
||||
}
|
||||
if run, _, _, _ := left.runs.read(runKeyOf("main.7", "ace")); (tc.want != nil) != slices.Equal(run.Unlisted, []string{"checker"}) ||
|
||||
(tc.want == nil && run.Unlisted != nil) {
|
||||
t.Errorf("%s: the run carries the unlisted %v", tc.name, run.Unlisted)
|
||||
}
|
||||
raw, ok := left.requests["ace"].Cases[0].Assignments["ace"]
|
||||
if tc.want == nil {
|
||||
if ok {
|
||||
t.Errorf("%s: the case carries assignments %s", tc.name, raw)
|
||||
}
|
||||
continue
|
||||
}
|
||||
a, err := mmac.DecodeAssignments(raw)
|
||||
var got []string
|
||||
for _, m := range a.Modules {
|
||||
got = append(got, m.Module)
|
||||
}
|
||||
if err != nil || !slices.Equal(got, tc.want) {
|
||||
t.Errorf("%s: the case composes ace with %v (%v), want %v", tc.name, got, err, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
// 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 }
|
||||
@@ -438,21 +542,35 @@ func TestAMachineIsJudgedByTheModulesItBlames(t *testing.T) {
|
||||
run meshwants.CompositionRun
|
||||
failed, couldNo string
|
||||
warnings []string
|
||||
unlisted []string
|
||||
}{
|
||||
{"blamed module fails", "a", runOf(blamesA), "ace holds a: /etc/x is a's and c's", "", nil},
|
||||
{"another module passes with a warning", "b", runOf(blamesA), "", "", []string{"ace holds a: /etc/x is a's and c's"}},
|
||||
{"blames no module fails both", "b", runOf(`{"composes":false,"reason":"the node's own composition","blamed":[]}`), "ace does not compose and blames no module: the node's own composition", "", nil},
|
||||
{"an old composer", "b", runOf(`{"composes":false,"reason":"x"}`), "ace does not compose: x", "", []string{"ace: the composer names no culprits"}},
|
||||
{"composes", "b", runOf(`{"composes":true,"blamed":[]}`), "", "", nil},
|
||||
{"blamed module fails", "a", runOf(blamesA), "ace holds a: /etc/x is a's and c's", "", nil, nil},
|
||||
{"another module passes with a warning", "b", runOf(blamesA), "", "", []string{"ace holds a: /etc/x is a's and c's"}, nil},
|
||||
{"blames no module fails both", "b", runOf(`{"composes":false,"reason":"the node's own composition","blamed":[]}`), "ace does not compose and blames no module: the node's own composition", "", nil, nil},
|
||||
{"an old composer", "b", runOf(`{"composes":false,"reason":"x"}`), "ace does not compose: x", "", []string{"ace: the composer names no culprits"}, nil},
|
||||
{"composes", "b", runOf(`{"composes":true,"blamed":[]}`), "", "", nil, nil},
|
||||
{"own module not tried", "a", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"not tried: the search reached its bound"}]}`), "",
|
||||
"ace holds a untried: the composer's search for culprits reached its bound of blame_tries (A-470b)", nil},
|
||||
"ace holds a untried: the composer's search for culprits reached its bound of blame_tries (A-470b)", nil, nil},
|
||||
{"another not tried", "b", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"not tried: the search reached its bound"}]}`), "", "",
|
||||
[]string{"ace holds a: not tried: the search reached its bound"}},
|
||||
{"not judged", "a", runOf(`{"composes":false,"not_judged":"no seat list","blamed":[]}`), "", "ace was not judged: no seat list", nil},
|
||||
{"could not run", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"}, "", "ace: gone", nil},
|
||||
[]string{"ace holds a: not tried: the search reached its bound"}, nil},
|
||||
{"not judged", "a", runOf(`{"composes":false,"not_judged":"no seat list","blamed":[]}`), "", "ace was not judged: no seat list", nil, nil},
|
||||
{"could not run", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"}, "", "ace: gone", nil, nil},
|
||||
// H-A-143: a module assigned there that no watched branch lists is said in the reason, or as a warning where it composes.
|
||||
{"an unlisted module in the reason", "b", runOf(`{"composes":false,"reason":"nothing provides \"photos\"","blamed":[]}`),
|
||||
"ace does not compose and blames no module: nothing provides \"photos\"; ace is assigned photos, which no watched branch lists (H-A-143)", "", nil, []string{"photos"}},
|
||||
{"does not compose, blames a module, an unlisted module", "a", runOf(`{"composes":false,"reason":"nothing provides \"photos\"","blamed":[{"module":"a","problem":"nothing provides \"photos\""}]}`),
|
||||
"ace holds a: nothing provides \"photos\"; ace is assigned photos, which no watched branch lists (H-A-143)", "", nil, []string{"photos"}},
|
||||
{"another module blamed, an unlisted module", "b", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"x"}]}`), "", "",
|
||||
[]string{"ace holds a: x", "ace is assigned photos, which no watched branch lists (H-A-143)"}, []string{"photos"}},
|
||||
{"could not run, an unlisted module", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"},
|
||||
"", "ace: gone; ace is assigned photos, which no watched branch lists (H-A-143)", nil, []string{"photos"}},
|
||||
{"an unlisted module where it composes", "b", runOf(`{"composes":true,"blamed":[]}`), "", "",
|
||||
[]string{"ace is assigned photos, which no watched branch lists (H-A-143)"}, []string{"photos"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
e := judgeRun(tc.module, tc.run)
|
||||
run := tc.run
|
||||
run.Unlisted = tc.unlisted // the set the run's start wrote (H-A-153)
|
||||
e := judgeRun(tc.module, run)
|
||||
if e.failed != tc.failed || e.couldNot != tc.couldNo || !slices.Equal(e.warnings, tc.warnings) {
|
||||
t.Errorf("judged %+v, want failed %q, could not run %q, warnings %q", e, tc.failed, tc.couldNo, tc.warnings)
|
||||
}
|
||||
@@ -572,3 +690,106 @@ func TestARerunMovesEveryReaderThatDidNotPass(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H-A-143, G §532: a machine's composition takes each module's entry from the newest revision of the first of its
|
||||
// watched branches, in its registration's order, that lists it; the candidate's revision replaces its branch's newest for the
|
||||
// modules it moves, and whole where it is that branch's newest; the half keeps the candidate's revision.
|
||||
func TestACompositionTakesEachModuleAcrossTheWatchedBranches(t *testing.T) {
|
||||
entry := func(module, fp string) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: module, Fp: fp, Manifest: map[string]any{"module": module}}
|
||||
}
|
||||
half := func(branch string, revision int64, movers []string, entries ...meshcatalog.CatalogEntry) mcc.Half {
|
||||
h := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: branch, Revision: revision, Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: branch}}},
|
||||
Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||
for _, m := range movers {
|
||||
h.Revision.Movers = append(h.Revision.Movers, meshcatalog.TakeInEntry{Module: m})
|
||||
}
|
||||
for _, e := range entries {
|
||||
h.Entries[e.Module] = e
|
||||
}
|
||||
return h
|
||||
}
|
||||
newest := map[string]mcc.Half{
|
||||
"main": half("main", 4, nil, entry("engine", "e1"), entry("a", "a1"), entry("both", "main")),
|
||||
"master": half("master", 9, nil, entry("f1-circuits", "f1")),
|
||||
"nox-mesh": half("nox-mesh", 3, nil, entry("link2pay", "l1"), entry("photos", "p1"), entry("both", "nox")),
|
||||
}
|
||||
registrations := map[string][]string{"both": {"nox-mesh", "main"}, "f1-circuits": {"master"}, "link2pay": {"nox-mesh"}, "photos": {"nox-mesh"}}
|
||||
registrations["engine"], registrations["a"] = []string{"main"}, []string{"main"}
|
||||
watched := func(module string) []string { return registrations[module] } // a module no registration names has none (H-A-144)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
step meshwants.StepRun
|
||||
candidate mcc.Half
|
||||
newest map[string]mcc.Half
|
||||
want map[string]string // module -> fingerprint
|
||||
}{
|
||||
{"the newest of main, the others' apps beside it", meshwants.StepRun{Branch: "main", Module: "a", Revision: 5},
|
||||
half("main", 5, []string{"a"}, entry("engine", "e1"), entry("a", "a2"), entry("both", "main")), newest,
|
||||
map[string]string{"engine": "e1", "a": "a2", "both": "nox", "f1-circuits": "f1", "link2pay": "l1", "photos": "p1"}},
|
||||
{"an older candidate moves only its movers", meshwants.StepRun{Branch: "nox-mesh", Module: "link2pay", Revision: 2},
|
||||
half("nox-mesh", 2, []string{"photos"}, entry("link2pay", "l0"), entry("both", "nox0")), newest,
|
||||
map[string]string{"engine": "e1", "a": "a1", "both": "nox", "f1-circuits": "f1", "link2pay": "l0"}},
|
||||
{"a branch not yet held is the candidate's", meshwants.StepRun{Branch: "master", Module: "f1-circuits", Revision: 1},
|
||||
half("master", 1, nil, entry("f1-circuits", "f0")), map[string]mcc.Half{"main": newest["main"]},
|
||||
map[string]string{"engine": "e1", "a": "a1", "both": "main", "f1-circuits": "f0"}},
|
||||
{"no view held yet: the candidate alone", meshwants.StepRun{Branch: "main", Module: "a", Revision: 5},
|
||||
half("main", 5, nil, entry("a", "a2")), nil, map[string]string{"a": "a2"}},
|
||||
{"a module no registration names is not composed", meshwants.StepRun{Branch: "main", Module: "a", Revision: 5},
|
||||
half("main", 5, nil, entry("a", "a2"), entry("checker", "c1")), nil, map[string]string{"a": "a2"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := acrossBranches(tc.step, tc.candidate, tc.newest, watched)
|
||||
fps := map[string]string{}
|
||||
for name, e := range got.Entries {
|
||||
fps[name] = e.Fp
|
||||
}
|
||||
if !maps.Equal(fps, tc.want) {
|
||||
t.Errorf("composed from %v, want %v", fps, tc.want)
|
||||
}
|
||||
if got.Revision.Revision != tc.candidate.Revision.Revision || len(got.Revision.Definitions) != 1 || got.Revision.Definitions[0].Digest != tc.step.Branch {
|
||||
t.Errorf("the half keeps revision %d with definitions %v, want the candidate's %d with its own", got.Revision.Revision, got.Revision.Definitions,
|
||||
tc.candidate.Revision.Revision)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H-A-149: the pass over the assignments clears assignment-unlisted when the assignment is gone or one of the module's
|
||||
// watched branches lists it again, and keeps it while it stands; another finding is left alone.
|
||||
func TestThePassClearsAnUnlistedAssignmentsFinding(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
assigned []string // novox's modules
|
||||
listed bool
|
||||
kept bool
|
||||
}{
|
||||
{"still assigned and listed nowhere: kept", []string{"checker"}, false, true},
|
||||
{"the assignment gone: cleared", []string{"web"}, false, false},
|
||||
{"listed again: cleared", []string{"checker"}, true, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w := newWorld()
|
||||
a := mma.Assignments{V: keys.Version, Node: "novox"}
|
||||
for _, m := range tc.assigned {
|
||||
a.Modules = append(a.Modules, mma.PlacedModule{Module: m})
|
||||
}
|
||||
putAssignments(w, a)
|
||||
findings := map[string][]byte{}
|
||||
f, _ := assign.UnlistedFinding("novox", "checker", time.Now())
|
||||
_ = putInto(findings)(f)
|
||||
other, _ := assign.UnplacedFinding("g14", time.Now())
|
||||
_ = putInto(findings)(other)
|
||||
p := &passer{w: w, logf: t.Logf, listed: func(string) bool { return tc.listed }, findings: assign.Findings{Put: putInto(findings),
|
||||
Delete: func(k string) error { delete(findings, k); return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil }}}
|
||||
p.clearUnlisted()
|
||||
if _, ok := findings[assign.UnlistedKey("novox", "checker")]; ok != tc.kept {
|
||||
t.Errorf("the finding kept %v, want %v", ok, tc.kept)
|
||||
}
|
||||
if _, ok := findings[assign.UnplacedKey("g14")]; !ok {
|
||||
t.Error("another finding is cleared")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ func (r *compositionRuns) leave(pipeline string, stop func(ids []string)) ([]str
|
||||
|
||||
// passedOn is whether the step of module passed on the machine of an ended run (§722): neither failed nor could not run there.
|
||||
func passedOn(module string, run meshwants.CompositionRun) bool {
|
||||
e := judgeRun(module, run)
|
||||
e := judgeVerdict(module, run) // the unlisted modules change only the words, never whether it passed
|
||||
return e.failed == "" && e.couldNot == ""
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
@@ -191,3 +193,25 @@ func (h *halves) views() map[string]mcc.Half {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// watchedOf is module's watched branches in its registration's order (the branch `register` named first, then each branch in the
|
||||
// order `watch` added it). Once registrations are held, a module none names has none: it is unlisted (H-A-144). Only before the
|
||||
// first registrations are held do the gate's source's branches stand in (the branches followed then), in the order the source
|
||||
// gives them, by their names escaped as its keys are (design 47 G §532, H-A-143, H-A-144).
|
||||
func (h *halves) watchedOf(module string) []string {
|
||||
h.mu.Lock()
|
||||
b := h.branches
|
||||
h.mu.Unlock()
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
if b.Registrations != nil && len(b.Registrations.All()) > 0 {
|
||||
if reg, ok := b.Registrations.Registration(module); ok {
|
||||
return slices.Clone(reg.Branches)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
out := b.Followed()
|
||||
slices.SortStableFunc(out, func(x, y string) int { return strings.Compare(keys.EscapeName(x), keys.EscapeName(y)) })
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -48,3 +50,45 @@ func TestAMeshThatNamesNoBranchSettlesTheAssignersFirstPass(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H-A-143, H-A-144, G §532: a module's watched branches are its registration's, in its order; once registrations are held a
|
||||
// module none names has none; before the first registrations the gate's source's branches stand in, in the source's order.
|
||||
func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
regs []seat.Registration
|
||||
module string
|
||||
want []string
|
||||
}{
|
||||
{"its registration's order", []seat.Registration{{Module: "link2pay", Branches: []string{"nox-mesh", "main"}}}, "link2pay", []string{"nox-mesh", "main"}},
|
||||
{"no registration names it", []seat.Registration{{Module: "link2pay", Branches: []string{"nox-mesh", "main"}}}, "checker", nil},
|
||||
{"before the first registrations, the source's", []seat.Registration{}, "checker", []string{"main", "master"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
call := func(key string, _ any) (json.RawMessage, error) {
|
||||
switch key {
|
||||
case mcc.RegistrationsVerb:
|
||||
return json.Marshal(seat.RegistrationsAnswer{Registrations: tc.regs})
|
||||
case mcc.SourceVerb:
|
||||
return json.Marshal(map[string][]string{"branches": {"master", "main"}})
|
||||
}
|
||||
return nil, errors.New("not answered here")
|
||||
}
|
||||
reader := &views.ProcessReader{Module: "mesh-delivery-assigner", Call: call, Logf: t.Logf}
|
||||
h := &halves{w: newWorld(), call: call, reader: reader, wake: func() {}, logf: t.Logf, ctx: ctx}
|
||||
if err := h.follow(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, f := range reader.Followers()[:2] { // the registrations and the gate's source
|
||||
if err := f.Start(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if got := h.watchedOf(tc.module); !slices.Equal(got, tc.want) {
|
||||
t.Errorf("the watched branches of %s are %v, want %v", tc.module, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1769,6 +1769,11 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) {
|
||||
}
|
||||
if kept, ok := b.cat.at[branch][in.Revision]; ok {
|
||||
rev := meshcatalog.CatalogRevision{Kind: "trunk", Branch: in.Branch, Revision: in.Revision}
|
||||
for k := range b.cat.at[branch] { // its base, the newest kept below it, as the take-in names it (H-A-154)
|
||||
if k < in.Revision && k > rev.Base {
|
||||
rev.Base = k
|
||||
}
|
||||
}
|
||||
for _, e := range kept {
|
||||
rev.Entries = append(rev.Entries, meshcatalog.EntryRef{Module: e.Module, Digest: e.ManifestDigest})
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
}
|
||||
}
|
||||
p := &passer{kvs: kvs, w: w, logf: logger.Printf, say: say, findings: findings, said: map[string]bool{}, answeredAt: map[string]uint64{},
|
||||
reads: reads, seats: gate, askForFile: getenv("MESH_ASSIGNER_ASK_OPERATOR_FOR_FILE")}
|
||||
reads: reads, seats: gate, askForFile: getenv("MESH_ASSIGNER_ASK_OPERATOR_FOR_FILE"), listed: iv.listed}
|
||||
p.askOperatorFor() // the setting ask-operator-for said once at the start (design 47 G A-425a)
|
||||
// The setting tier-bound (design 47 H §751) and the one timer that wakes the pass at a tier's deadline (H-A-56).
|
||||
tierBound, err := tierBoundSetting(getenv)
|
||||
@@ -665,7 +665,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
// The composition step (design 47 G §22, §354): the seat mesh-wants' accepted kind step, run by one run ask per machine.
|
||||
if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil {
|
||||
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept,
|
||||
trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume,
|
||||
validate: run.validate, resumeValidate: run.resumeValidate, ended: runs.stepEnded, now: time.Now, logf: logger.Printf}
|
||||
move := steps.move(ctx) // the readers a rerun carried (§727, A-470d)
|
||||
|
||||
@@ -56,6 +56,8 @@ type passer struct {
|
||||
findings assign.Findings
|
||||
// unplaced are the nodes whose unplaced finding this process wrote.
|
||||
unplaced map[string]bool
|
||||
// listed says whether a module's watched branches list it (catalogViews.listed), for the clear of assignment-unlisted.
|
||||
listed func(module string) bool
|
||||
// answeredAt is, by the id of a backup ask, how many values the have had when its answer was written into the want.
|
||||
answeredAt map[string]uint64
|
||||
// now is the clock; nil is time.Now.
|
||||
@@ -208,6 +210,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
}))
|
||||
chosen, _ := assign.DecodePolicies(p.w.read(assign.PoliciesBucket()))
|
||||
defer p.unplacedFindings()
|
||||
defer p.clearUnlisted()
|
||||
defer func() { p.seatHolders(ctx, viewOf(p.w.trunkName()).manifests) }()
|
||||
p.clearStaleCalls()
|
||||
placed := p.w.placedNodes()
|
||||
@@ -655,6 +658,33 @@ func (p *passer) unplacedFindings() {
|
||||
}
|
||||
}
|
||||
|
||||
// clearUnlisted clears, in the pass over the assignments, each finding assignment-unlisted whose assignment is gone or whose module
|
||||
// one of its watched branches lists again, so the clear never waits for the next composition step on that machine (H-A-149).
|
||||
func (p *passer) clearUnlisted() {
|
||||
if p.findings.Keys == nil || p.findings.Delete == nil || p.listed == nil {
|
||||
return
|
||||
}
|
||||
keys, err := p.findings.Keys()
|
||||
if err != nil {
|
||||
p.logf("the findings assignment-unlisted are not read, so none is cleared in this pass: %v", err)
|
||||
return
|
||||
}
|
||||
assignments := p.w.assignments()
|
||||
for _, key := range keys {
|
||||
node, module, ok := assign.UnlistedOfKey(key)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
assigned := slices.ContainsFunc(assignments[node].Modules, func(m mma.PlacedModule) bool { return m.Module == module })
|
||||
if assigned && !p.listed(module) {
|
||||
continue
|
||||
}
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// seatHolders writes the seat mesh-module-assigner's state seat-holders from every node's assignments (ADR 0571 §4): one key per
|
||||
// seat held once, `<seat>`, and one per node of a node seat, `<seat>.<node>`, written only where it differs, and a key no
|
||||
// assignments holds any more deleted. A pass follows each assignments change and each manifest the indexer takes in, so no
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
// `<pipeline>.validate` of the state composition-runs in the CompositionRun form with no machine, which every mover's step
|
||||
// reads: the cycle the revision's entries make (graph.RefusedCycle) ends it at once; else the manifest validator built from
|
||||
// the revision's own entry of the module holding the seat mesh-catalog, on the Go build seat as the composer is, runs in the
|
||||
// sandbox over the revision's manifests and the branch's previous revision's, its input kept and served on mesh-wants' input.
|
||||
// sandbox over the revision's manifests and its base's (H-A-154), its input kept and served on mesh-wants' input.
|
||||
// Every mover's step ends the same: failed `cycle` naming the cycle, failed `manifest-refused` naming every problem of a
|
||||
// manifest the revision alters or between manifests one it alters takes part in, or passed.
|
||||
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
validatorPackage = "mesh-delivery-indexer/cmd/mesh-judge"
|
||||
// validateKeySuffix ends the key of a revision's validate run, `<pipeline>.validate` (H-A-108).
|
||||
validateKeySuffix = "." + meshwants.StepRunStepValidate
|
||||
// beforeCase is the validator's case of the branch's previous revision, beside changeCase (H-A-108 (3)).
|
||||
// beforeCase is the validator's case of the revision's base, beside changeCase (H-A-108 (3), H-A-151, H-A-154).
|
||||
beforeCase = "before"
|
||||
// The reasons a validate step fails with, the first word of its said (§745).
|
||||
reasonManifestRefused = "manifest-refused"
|
||||
@@ -112,16 +112,29 @@ func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepR
|
||||
if err != nil {
|
||||
return couldNotRun("the step's catalog revision is not read: " + err.Error())
|
||||
}
|
||||
before, err := r.before(ctx, step)
|
||||
before, err := r.before(ctx, step, half)
|
||||
if err != nil {
|
||||
return couldNotRun("the branch's previous catalog revision is not read: " + err.Error())
|
||||
return couldNotRun("the base of the case before is not read: " + err.Error())
|
||||
}
|
||||
// A revision that names no base (the branch's first take-in) is judged against an empty case before, and says so (H-A-151).
|
||||
empty := ""
|
||||
if half.Revision.Base <= 0 {
|
||||
empty = emptyBeforeWords
|
||||
}
|
||||
if problems := causedProblems(v.Change, v.Before, altered(half, before)); len(problems) > 0 {
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomeFailed, Said: reasonManifestRefused + ": " + strings.Join(problems, "; ")}
|
||||
said := reasonManifestRefused + ": " + strings.Join(problems, "; ")
|
||||
if empty != "" {
|
||||
said += " (" + empty + ")"
|
||||
}
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomeFailed, Said: said}
|
||||
}
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed, Said: empty}
|
||||
}
|
||||
|
||||
// emptyBeforeWords say, in a validate step's end, that its revision names no base: the branch's first take-in, judged against
|
||||
// an empty case before (H-A-151, H-A-154).
|
||||
const emptyBeforeWords = "the case before is empty: the revision names no base, the branch's first take-in"
|
||||
|
||||
// validateVerdict is a validate run's verdict as the run keeps it: the cycle the revision makes, or the validator's two cases.
|
||||
type validateVerdict struct {
|
||||
Cycle []meshcatalog.ArtifactRef `json:"cycle,omitempty"`
|
||||
@@ -148,15 +161,16 @@ func cycleWords(cycle []meshcatalog.ArtifactRef) string {
|
||||
return strings.Join(words, " → ")
|
||||
}
|
||||
|
||||
// before is the branch's catalog revision before the step's, read through the seat mesh-catalog's verb revision (H-A-108 (3));
|
||||
// none before the first.
|
||||
func (r *compositionRun) before(ctx context.Context, step meshwants.StepRun) (mcc.Half, error) {
|
||||
if step.Revision <= 1 {
|
||||
// before is the case before of the step's revision half: the revision its base names, the newest kept revision below it that
|
||||
// its take-in pinned, read through the seat mesh-catalog's verb revision (H-A-108 (3), H-A-151, H-A-154); empty where the
|
||||
// revision names no base, the branch's first take-in.
|
||||
func (r *compositionRun) before(ctx context.Context, step meshwants.StepRun, half mcc.Half) (mcc.Half, error) {
|
||||
if half.Revision.Base <= 0 {
|
||||
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{}}, nil
|
||||
}
|
||||
prev := step
|
||||
prev.Revision--
|
||||
return r.revision(ctx, prev)
|
||||
base := step
|
||||
base.Revision = half.Revision.Base
|
||||
return r.revision(ctx, base)
|
||||
}
|
||||
|
||||
// altered are the modules whose manifest the revision adds or changes against the one before it.
|
||||
@@ -270,9 +284,9 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh
|
||||
end(meshwants.CompositionRunOutcomePassed, "", verdict)
|
||||
return
|
||||
}
|
||||
before, err := r.before(ctx, step)
|
||||
before, err := r.before(ctx, step, half)
|
||||
if err != nil {
|
||||
couldNot("the branch's previous catalog revision is not read: " + err.Error())
|
||||
couldNot("the base of the case before is not read: " + err.Error())
|
||||
return
|
||||
}
|
||||
entry, ok := catalogEntry(half.Entries)
|
||||
|
||||
@@ -20,7 +20,9 @@ import (
|
||||
// run, `<pipeline>.validate` of the state composition-runs; a manifest the revision alters that names an unknown field fails
|
||||
// it `manifest-refused` naming the problem, a problem of a manifest it leaves as it was does not, and the validator is the
|
||||
// revision's own entry of the module holding the seat mesh-catalog, on the Go build seat; a revision whose entries make a cycle
|
||||
// fails it `cycle` naming the cycle, with no validator asked.
|
||||
// fails it `cycle` naming the cycle, with no validator asked. The case before is the revision its base names (H-A-151, H-A-154:
|
||||
// the newest kept below it, which the stand-in names as the indexer does); a revision naming no base, the branch's first take-in,
|
||||
// is judged against an empty case before, said in its end, and no revision below it is asked.
|
||||
func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
indexer := meshcatalog.CatalogEntry{Module: "indexer", Repository: "novox/mesh-delivery", Commit: commitE3, Path: "modules/mesh-delivery-indexer",
|
||||
Fp: "src2:ix", Serves: []string{"seat:" + meshcatalog.Seat + ".revision"}, Manifest: map[string]any{"module": "indexer"}, ManifestDigest: "d-ix"}
|
||||
@@ -28,9 +30,24 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
return meshcatalog.CatalogEntry{Module: module, Manifest: map[string]any{"module": module, "d": digest}, ManifestDigest: digest, Edges: edges}
|
||||
}
|
||||
revisions := map[int64][]meshcatalog.CatalogEntry{
|
||||
6: {indexer, entry("web", "d-web-1"), entry("db", "d-db")},
|
||||
7: {indexer, entry("web", "d-web-2"), entry("db", "d-db")},
|
||||
9: {indexer, entry("a", "d-a", meshcatalog.Edge{From: "a:x", To: "b:y", Kind: 3}, meshcatalog.Edge{From: "b:y", To: "a:x", Kind: 3}), entry("b", "d-b")},
|
||||
6: {indexer, entry("web", "d-web-1"), entry("db", "d-db")},
|
||||
7: {indexer, entry("web", "d-web-2"), entry("db", "d-db")},
|
||||
9: {indexer, entry("a", "d-a", meshcatalog.Edge{From: "a:x", To: "b:y", Kind: 3}, meshcatalog.Edge{From: "b:y", To: "a:x", Kind: 3}), entry("b", "d-b")},
|
||||
3: {indexer},
|
||||
12: {indexer, entry("web", "d-web-2"), entry("db", "d-db")},
|
||||
}
|
||||
// base is the newest kept revision below n, as the take-in names it; none below the first. Revision 12 names 7 with 8 to 11
|
||||
// never kept, so a case before read as the number minus one could not run (H-A-154).
|
||||
base := func(n int64) (b int64) {
|
||||
if n == 12 {
|
||||
return 7
|
||||
}
|
||||
for k := range revisions {
|
||||
if k < n && k > b {
|
||||
b = k
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
call := func(key string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
@@ -42,7 +59,7 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
if !ok || in.Branch != "main" {
|
||||
return nil, errors.New("asked another revision")
|
||||
}
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: in.Revision,
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: in.Revision, Base: base(in.Revision),
|
||||
Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: "sd"}}}, Entries: entries})
|
||||
case seatDefinitionsKey:
|
||||
return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Found: true, Entry: &meshcatalog.SeatDefinitionsAnswerEntry{Seat: "s1", Digest: "sd", Definition: map[string]any{"seat": "s1"}}})
|
||||
@@ -117,4 +134,17 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
if o.Outcome != meshwants.StepEndedOutcomeFailed || o.Said != reasonCycle+": a:x → b:y → a:x" || len(asks) != 1 {
|
||||
t.Errorf("a revision making a cycle ended %+v (%d validator asks)", o, len(asks))
|
||||
}
|
||||
// The stand-in validator answers its one verdict: judged against the empty case before, web's problem is the revision's.
|
||||
if o := r.validate(ctx, "ask-first", step("indexer", 3)); o.Outcome != meshwants.StepEndedOutcomeFailed ||
|
||||
o.Said != reasonManifestRefused+`: web: unknown field "colour" (`+emptyBeforeWords+")" || len(asks) != 2 || len(requests[1].Cases[1].Manifests) != 0 {
|
||||
t.Errorf("a revision naming no base ended %+v (%d validator asks), want it judged against an empty case before, said", o, len(asks))
|
||||
}
|
||||
// Revision 12 holds revision 7's manifests and names base 7: judged against it, web's problem is the revision's, db's old one
|
||||
// is not, and the case before holds base 7's manifests.
|
||||
if o := r.validate(ctx, "ask-base", step("web", 12)); o.Outcome != meshwants.StepEndedOutcomeFailed ||
|
||||
o.Said != reasonManifestRefused+`: web: unknown field "colour"` || len(asks) != 3 {
|
||||
t.Errorf("a revision naming base 7 below its number ended %+v (%d validator asks), want it judged against base 7", o, len(asks))
|
||||
} else if web := requests[2].Cases[1].Manifests["web"]; len(requests[2].Cases[1].Manifests) != 3 || !strings.Contains(string(web.Raw), "d-web-2") {
|
||||
t.Errorf("the case before of revision 12 is %+v, want base 7's manifests", requests[2].Cases[1].Manifests)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,3 +553,18 @@ func (w *world) placedBranches() map[string]map[string]string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// assignedOn is the modules the assignments place on node.
|
||||
func (w *world) assignedOn(node string) []string {
|
||||
var out []string
|
||||
for _, m := range w.assignments()[node].Modules {
|
||||
out = append(out, m.Module)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// assignmentOf is node's assignments, or false where none is held.
|
||||
func (w *world) assignmentOf(node string) (mma.Assignments, bool) {
|
||||
a, ok := w.assignments()[node]
|
||||
return a, ok
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// KindAssignmentUnlisted is a module assigned to a node that no watched branch lists, left out of that node's composition
|
||||
// (design 47 H-A-148, H-A-149): scope delivery, id `<node>.<module>`, severity warning.
|
||||
const (
|
||||
KindAssignmentUnlisted = "assignment-unlisted"
|
||||
ScopeAssignmentUnlisted = "delivery"
|
||||
)
|
||||
|
||||
// UnlistedKey is its finding's key, `delivery.<node>.<module>.assignment-unlisted`.
|
||||
func UnlistedKey(node, module string) string {
|
||||
return views.FindingKey(ScopeAssignmentUnlisted, KeyID(node+"."+module), KindAssignmentUnlisted)
|
||||
}
|
||||
|
||||
// UnlistedOfKey is the node and module of an assignment-unlisted finding's key, or false for another finding's.
|
||||
func UnlistedOfKey(key string) (node, module string, ok bool) {
|
||||
rest, ok := strings.CutPrefix(key, ScopeAssignmentUnlisted+".")
|
||||
if !ok {
|
||||
return "", "", false
|
||||
}
|
||||
if rest, ok = strings.CutSuffix(rest, "."+KindAssignmentUnlisted); !ok {
|
||||
return "", "", false
|
||||
}
|
||||
node, module, ok = strings.Cut(rest, ".")
|
||||
return node, module, ok && node != "" && module != "" && !strings.Contains(module, ".")
|
||||
}
|
||||
|
||||
// UnlistedFinding is the finding of module assigned to node and listed on none of its watched branches, raised by the composition
|
||||
// step that leaves the assignment out (H-A-149).
|
||||
func UnlistedFinding(node, module string, at time.Time) (mcseat.Finding, error) {
|
||||
summary := fmt.Sprintf("%s is assigned %s, which no watched branch lists, so its composition leaves the assignment out", node, module)
|
||||
return encode(Observed{Scope: ScopeAssignmentUnlisted, ID: node + "." + module, Kind: KindAssignmentUnlisted, Machine: node,
|
||||
Severity: mcseat.FindingSeverityWarning, Summary: summary, Headline: clipHeadline(module + " on " + node + " is listed nowhere"),
|
||||
Explanation: summary + ": a stale assignment is a fault of the assignments, not of the change judged (ADR 0578 §2). " +
|
||||
"Take it off, or register the module on a watched branch.",
|
||||
Source: "assigner." + KindAssignmentUnlisted}, at)
|
||||
}
|
||||
@@ -132,6 +132,20 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e
|
||||
}
|
||||
}
|
||||
|
||||
// picture is build.Builder.Picture: the source revision the view of branch holds (design 47 H H-A-155), false while the branch
|
||||
// is not followed or its view holds none.
|
||||
func (c *catalogHalf) picture(branch string) (int64, bool) {
|
||||
cat, ok := c.branches.Catalog(branch)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
half, ok := cat.View()
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return half.Revision.Source, true
|
||||
}
|
||||
|
||||
// namesOf are the package names an entry's artifacts carry, in one line.
|
||||
func namesOf(e meshcatalog.CatalogEntry) string {
|
||||
var names []string
|
||||
|
||||
+7
-2
@@ -33,8 +33,13 @@ type catalogHolder struct {
|
||||
mu sync.Mutex
|
||||
entries map[string]meshcatalog.CatalogEntry
|
||||
revision int64
|
||||
// source is the source revision each trunk revision is taken in from; 0 is 1.
|
||||
source int64
|
||||
}
|
||||
|
||||
// sourceLocked is the source revision of the revisions put now. The caller holds mu.
|
||||
func (h *catalogHolder) sourceLocked() int64 { return max(h.source, 1) }
|
||||
|
||||
func newCatalogHolder(t *testing.T, ctx context.Context, js jetstream.JetStream, nc *nats.Conn) *catalogHolder {
|
||||
t.Helper()
|
||||
h := &catalogHolder{ctx: ctx, js: js, entries: map[string]meshcatalog.CatalogEntry{}}
|
||||
@@ -84,7 +89,7 @@ func (h *catalogHolder) whole() meshcatalog.RevisionAnswer {
|
||||
all = append(all, e)
|
||||
}
|
||||
at := time.Now()
|
||||
return meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: h.revision, Kind: "trunk", Branch: "main", Entries: refs, Source: 1, At: &at}, Entries: all}
|
||||
return meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: h.revision, Kind: "trunk", Branch: "main", Entries: refs, Source: h.sourceLocked(), At: &at}, Entries: all}
|
||||
}
|
||||
|
||||
// put sets one module's entry in a new trunk revision of main and says catalog-revision.
|
||||
@@ -100,7 +105,7 @@ func (h *catalogHolder) putAll(t *testing.T, es ...meshcatalog.CatalogEntry) {
|
||||
h.entries[e.Module] = e
|
||||
changed = append(changed, e.Module)
|
||||
}
|
||||
ev, _ := json.Marshal(meshcatalog.CatalogRevisionEvent{Branch: "main", Kind: "trunk", Revision: h.revision, Source: 1, Entries: int64(len(h.entries)), Changed: changed, V: 1})
|
||||
ev, _ := json.Marshal(meshcatalog.CatalogRevisionEvent{Branch: "main", Kind: "trunk", Revision: h.revision, Source: h.sourceLocked(), Entries: int64(len(h.entries)), Changed: changed, V: 1})
|
||||
h.mu.Unlock()
|
||||
if _, err := h.js.Publish(h.ctx, meshcatalog.SubjectCatalogRevision("main"), ev); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -522,9 +522,9 @@ func isState(state string) func(builds.BuilderBuild) bool {
|
||||
// the digests of both bundles, both build modules' toolchains, after a fetch and a build on one node (ADR 0478 clause 4).
|
||||
func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
b := startBed(t)
|
||||
// DLV-B10 (design 51, round 2): the builder's versions, findings and the floor's three sources are on the bus; the seat
|
||||
// answers 0.1.4, so netcheck's bundles are numbered from 0.1.5. Two merges close together, the first replaced before
|
||||
// its claim: the second is numbered at once, and the first never.
|
||||
// The builder's versions, findings and the floor's three sources are on the bus, the seat answering 0.1.4; two merges close
|
||||
// together, the first replaced before its claim. The builder numbers neither in its state versions (design 47 H H-A-159,
|
||||
// G §348, §369): the reservation is the one place a version is numbered.
|
||||
reg := b.registry(t, "n1", "0.1.4")
|
||||
const netcheck = "catalogue-a67f0196-netcheck.module.json"
|
||||
first := "src2:" + strings.Repeat("1", 64)
|
||||
@@ -534,8 +534,8 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
v := b.await(t, "netcheck", isState(builds.BuildDone))
|
||||
for _, a := range []string{"tools-go", "tools-typescript"} {
|
||||
es := reg.of(t, "netcheck/"+a)
|
||||
if len(es) != 1 || es[0].Version != "0.1.5" || es[0].Fingerprint != fp || es[0].State != versions.Numbered || es[0].Digest != digestOf(a) {
|
||||
t.Errorf("versions of netcheck/%s = %+v, want the second merge numbered 0.1.5 at once with its digest, the first never", a, es)
|
||||
if len(es) != 0 {
|
||||
t.Errorf("versions of netcheck/%s = %+v, want none: the builder numbers nothing of its own (H-A-159)", a, es)
|
||||
}
|
||||
}
|
||||
if v.By != "n1.mesh-delivery-builder" || v.Manifest != digest || len(v.Artifacts) != 2 {
|
||||
@@ -565,13 +565,13 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
}
|
||||
// 1955/L7 (ADR 0571 §1): the build's start and end are in the module log build-log under the module's key, read as a
|
||||
// reader with the log's read reads them, the end naming the manifest and what was made.
|
||||
// DLV-B10: between them the build log holds the build's narrations (build.said), each version numbered, and why.
|
||||
// H-A-159: no version is numbered of the builder's own, so the build log holds no narration of one (build.said).
|
||||
var ended []builds.BuildLogEntry
|
||||
for _, e := range b.logged(t, "netcheck") {
|
||||
if e.Event != builds.BuildSaidEvent {
|
||||
ended = append(ended, e)
|
||||
} else if e.Why != versions.SaidNumbered || !strings.Contains(e.Line, "numbered 0.1.5") || e.FP != fp {
|
||||
t.Errorf("said = %+v, want netcheck's versions numbered", e)
|
||||
} else if e.Why == versions.SaidNumbered || e.Why == versions.SaidKept {
|
||||
t.Errorf("said = %+v, want no version of the builder's own numbered (H-A-159)", e)
|
||||
}
|
||||
}
|
||||
if len(ended) != 2 || ended[0].Event != builds.BuildStartedEvent || ended[1].Event != builds.BuildEndedEvent ||
|
||||
@@ -596,7 +596,7 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
}
|
||||
}
|
||||
// Design 32, design 47 G §348: a package's name the catalog half's entry of the module gives later reaches the builder by the
|
||||
// branch follower's view (never the indexer's state), and looks at the module again; the done bundles are kept, not numbered twice.
|
||||
// branch follower's view (never the indexer's state), and looks at the module again.
|
||||
named := b.entry("netcheck", "modules/netcheck", commit, fp, digest, nil, bothToolchains, 0)
|
||||
named.Manifest = b.manifestOf(t, "catalogue-a67f0196-netcheck.module.json")
|
||||
named.Artifacts = []meshcatalog.Artifact{{Ref: "netcheck:lib", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "netcheck"}}}
|
||||
@@ -606,11 +606,12 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
if got := reg.numberedOf("netcheck/tools-go"); len(got) != 0 {
|
||||
t.Errorf("version.numbered of netcheck/tools-go said %v, want none", got)
|
||||
}
|
||||
for _, a := range []string{"tools-go", "tools-typescript"} {
|
||||
reg.published(t, "netcheck/"+a, "0.1.5", digestOf(a))
|
||||
// Versions numbered before G, which the state keeps until G §372 removes it: one a holder removes below, one it refuses.
|
||||
kept, _ := json.Marshal(versions.Entry{Name: "netcheck/tools-typescript", Kind: versions.KindBundle, Series: "0.1", Version: "0.1.5", Module: "netcheck",
|
||||
Fingerprint: fp, Digest: digestOf("tools-typescript"), Seat: ociartifactregistry.Seat, State: versions.Published, At: time.Now().UTC()})
|
||||
if _, err := reg.versions.Put(b.ctx, versions.Key("netcheck/tools-typescript", "0.1.5"), kept); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.awaitOf(t, "netcheck/tools-go", func(es []versions.Entry) bool { return len(es) == 1 && es[0].State == versions.Published })
|
||||
// A numbered version a holder will refuse below, written to the state as the builder numbers one.
|
||||
refusable, _ := json.Marshal(versions.Entry{Name: "netcheck/tools-go", Kind: versions.KindBundle, Series: "0.1", Version: "0.1.6", Module: "netcheck",
|
||||
Fingerprint: "src2:" + strings.Repeat("6", 64), Seat: ociartifactregistry.Seat, State: versions.Numbered, At: time.Now().UTC()})
|
||||
if _, err := reg.versions.Put(b.ctx, versions.Key("netcheck/tools-go", "0.1.6"), refusable); err != nil {
|
||||
@@ -643,7 +644,7 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
t.Errorf("version.numbered of netcheck/tools-go said %v, want none", got)
|
||||
}
|
||||
// DLV-B10: a build module's bound running out fails the trunk build, which is the builder's finding build-failed; the
|
||||
// fingerprint built again keeps its number, said with why, and its done build clears the finding.
|
||||
// fingerprint built again clears it with its done build, numbering nothing of the builder's own (H-A-159).
|
||||
release := make(chan struct{})
|
||||
b.fake.hang.Store(&release)
|
||||
third := "src2:" + strings.Repeat("4", 64)
|
||||
@@ -666,12 +667,6 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
close(release)
|
||||
b.moduleFP(t, "netcheck", netcheck, "modules/netcheck", bothToolchains, "89abcdef0123456789abcdef0123456789abcdef", third, 3) // the entry moves to a later commit, same fingerprint
|
||||
b.awaitFP(t, "netcheck", third, isState(builds.BuildDone))
|
||||
b.awaitSaid(t, "kept: fingerprint "+third+" is numbered under it")
|
||||
if !slices.ContainsFunc(b.logged(t, "netcheck"), func(e builds.BuildLogEntry) bool {
|
||||
return e.Event == builds.BuildSaidEvent && e.Why == versions.SaidKept && e.FP == third && strings.Contains(e.Line, "kept: fingerprint "+third)
|
||||
}) {
|
||||
t.Errorf("the build log of netcheck says no version kept at %s", third)
|
||||
}
|
||||
reg.awaitFinding(t, failed, false)
|
||||
// DLV-B4: the seats' refused and removed, heard on the builder's durable consumer, move a numbered version: a retention
|
||||
// removal turns the entry removed with its reason, a refusal refused with the holder's reason and the bytes it refused.
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
sweep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshartifactsweep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-sdk/go/operatorask"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
@@ -156,9 +157,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
conn.SetReconnectHandler(func(*nats.Conn) { hearing.Again(); heard.Nudge("") })
|
||||
// The builder asks the controller, as its own account, whether the artifact store still holds a done key's blobs
|
||||
// (the seat verb held, novox/hq issue 1937) before it leaves the key done, on its calls connection.
|
||||
// The builder numbers each trunk build at its claim (novox/hq design 51 *The versions*): its state versions, bound once
|
||||
// the bus holds it; the floor's three sources asked as its own account.
|
||||
versionsKV := process.AwaitBucket(ctx, js, conn, own.versions, "no trunk build is numbered: each is built unnumbered and published by its digest", logger.Printf)
|
||||
// The state versions, kept from before G (design 51 *The versions*) and read through builder_versions until G §372 removes
|
||||
// it, bound once the bus holds it; the builder numbers nothing in it (design 47 H H-A-159).
|
||||
versionsKV := process.AwaitBucket(ctx, js, conn, own.versions, "builder_versions answers nothing of the versions numbered before G", logger.Printf)
|
||||
found := &findings{module: cred.Module, w: fw, logf: logger.Printf, now: time.Now}
|
||||
floorWaits := &versions.FloorWaits{Holder: versions.HolderOf(branches), Logf: logger.Printf, Said: found.floorSaid(context.WithoutCancel(ctx))}
|
||||
// The names waiting on their floor are kept in the state floor-waits (DLV-B4): a restarted builder takes them in, so
|
||||
@@ -205,13 +206,28 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
unput := &unputs{bounds: pubBoundsKV.KV, store: b.Claimer.Store, looking: b.Looking, findings: found,
|
||||
bound: meshconditionsclient.CallUnansweredAfter, now: time.Now, logf: logger.Printf}
|
||||
b.Left, b.Ended = unput.left, unput.ended
|
||||
b.Numbers = build.VersionNumbers{N: numberer}
|
||||
// The builder numbers nothing of its own (design 47 H H-A-159, G §348, §349, §369): b.Numbers stays nil, so no trunk build
|
||||
// is numbered in the state versions, waits on a floor or arms a publish-unanswered bound of it; the reservation is the one
|
||||
// place a version is numbered. The state, kept from before G, is still read (builder_versions) until G §372 removes it.
|
||||
// The builder's toolchain waits (design 47 G §672): its state waits, and wait-held and wait-ended on its stream waits; its
|
||||
// bound is its setting toolchain-wait-minutes.
|
||||
waitBound, err := toolchainWaitOf(getenv("MESH_BUILDER_TOOLCHAIN_WAIT_FILE"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A build step ask waits for the builder's picture of its branch to hold its source revision (design 47 H H-A-155); its
|
||||
// bound is its setting revision-wait-minutes (H-A-156).
|
||||
revisionWait, err := numberFile(getenv("MESH_BUILDER_REVISION_WAIT_FILE"), int(build.DefaultRevisionWait/time.Minute))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.RevisionWait = time.Duration(revisionWait) * time.Minute
|
||||
// A step ask naming a package with no pin waits for its release (H-A-165); its bound is package-wait-minutes.
|
||||
packageWait, err := numberFile(getenv("MESH_BUILDER_PACKAGE_WAIT_FILE"), int(build.DefaultPackageWait/time.Minute))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.PackageWait = time.Duration(packageWait) * time.Minute
|
||||
waitsBucket := process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, build.WaitsState), "the toolchain waits are kept in memory only, and builder_waits shows none", logger.Printf)
|
||||
b.Waits = newWaitsKept(waitsBucket, func(ctx context.Context, event, id string, body any) error {
|
||||
return emitEvent(context.WithoutCancel(ctx), js, cred, event, id, body)
|
||||
@@ -226,6 +242,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return emitSeatEvent(context.WithoutCancel(ctx), js, cred, meshbuilds.SubjectPackagePublished, "package-published-"+p.Module+"-"+p.Version+"-"+p.Artifact, p)
|
||||
}
|
||||
b.Reserved = reserved
|
||||
// A release heard, or the newest the builder's record keeps, pins a package an entry names with none (H-A-165).
|
||||
reserved.heardReleased = b.VersionReleased
|
||||
b.NewestReleased = reserved.r.NewestReleased
|
||||
// The last versions-filled the stream keeps is read at the start (design 47 G §369, §372): a restart does not lose it.
|
||||
reserved.readFilled(ctx, lastKeptOf(js, cred, logger.Printf), sleeps)
|
||||
// A state bound later numbers the builds looked at without it.
|
||||
@@ -450,6 +469,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// fingerprint no branch carries is closed (issue 1660) once the first view of every followed branch is in (never at the start:
|
||||
// a holder of the seat that is down holds no other part of it).
|
||||
half.b = b
|
||||
b.Picture = half.picture
|
||||
branches.Held = func(string, meshcatalog.CatalogRevision) { b.PictureHeld() } // a revision held wakes a step ask's wait (H-A-162)
|
||||
half.ready = func() {
|
||||
if err := b.Sweep(ctx, half.pictured()...); err != nil {
|
||||
errs <- err
|
||||
|
||||
@@ -44,12 +44,15 @@ type reservations struct {
|
||||
// built asks a done build's publish (design 47 G A-457a), released ends its item; nil are none.
|
||||
built func(ctx context.Context, module, version string) error
|
||||
released func(ctx context.Context, module, version string)
|
||||
filled atomic.Bool
|
||||
bounds func() jetstream.KeyValue
|
||||
found *findings
|
||||
bound time.Duration
|
||||
wake func(context.Context)
|
||||
logf func(string, ...any)
|
||||
// heardReleased is told each version-released taken in (design 47 H H-A-165): a step ask waiting for a package of the
|
||||
// module wakes. Nil tells nobody.
|
||||
heardReleased func(module, version string)
|
||||
filled atomic.Bool
|
||||
bounds func() jetstream.KeyValue
|
||||
found *findings
|
||||
bound time.Duration
|
||||
wake func(context.Context)
|
||||
logf func(string, ...any)
|
||||
// call asks a seat's verb: the git seat's tag (design 47 G §370).
|
||||
call toolCaller
|
||||
// say says package-published on the seat mesh-builds; nil says none.
|
||||
@@ -252,6 +255,9 @@ func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
if rv.released != nil {
|
||||
rv.released(ctx, ev.Module, ev.Version)
|
||||
}
|
||||
if rv.heardReleased != nil {
|
||||
rv.heardReleased(ev.Module, ev.Version)
|
||||
}
|
||||
rv.found.clear(ctx, versions.VersionUnreleased, meshconditionsclient.ScopeModule, ev.Module)
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -134,10 +134,15 @@ func TestTheCatalogsWordsMoveTheReservations(t *testing.T) {
|
||||
if err != nil || !strings.Contains(got.Summary, "m:b unpublished") || strings.Contains(got.Summary, "m:a unpublished") || !strings.Contains(got.Summary, "1.4.3") {
|
||||
t.Fatalf("finding = %+v (%v), want version-unreleased naming m:b of 1.4.3", got, err)
|
||||
}
|
||||
var heardReleases []string // H-A-165: a release heard wakes a step ask waiting for a package of the module
|
||||
rv.heardReleased = func(m, v string) { heardReleases = append(heardReleases, m+" "+v) }
|
||||
released := &wakeMsg{subject: meshcatalog.SubjectVersionReleased, data: []byte(`{"v":1,"module":"m","version":"1.4.3","source":1,"artifacts":[]}`)}
|
||||
if !rv.heard(ctx, released) || !released.acked {
|
||||
t.Fatalf("version-released was not taken in (acked %v)", released.acked)
|
||||
}
|
||||
if strings.Join(heardReleases, ", ") != "m 1.4.3" {
|
||||
t.Errorf("the release heard was told %v, want m 1.4.3 (H-A-165)", heardReleases)
|
||||
}
|
||||
if strings.Join(items, ", ") != "asked m 1.4.3, ended m 1.4.3" {
|
||||
t.Errorf("publish items %v, want the build's end to ask the publish and the release to end it", items)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -49,4 +50,29 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended within 20 s")
|
||||
}
|
||||
// H-A-155: an ask naming a source revision the builder's picture of main does not hold yet waits for it, said in the
|
||||
// journal, and is answered once a revision taken in from it arrives.
|
||||
run.Pipeline, run.Revision, run.Source = "main.2.netcheck", 2, 2
|
||||
data, _ = json.Marshal(run)
|
||||
msg = nats.NewMsg(meshbuilds.AcceptSubjectStep)
|
||||
msg.Data = data
|
||||
msg.Header.Set("x-event-id", "ask-2")
|
||||
if err := sub.PublishMsg(msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.awaitSaid(t, "main.2.netcheck: revision 2 of main not in the builder's picture yet")
|
||||
b.catalog.mu.Lock()
|
||||
b.catalog.source = 2
|
||||
b.catalog.mu.Unlock()
|
||||
// Revision 2, taken in from source 2, moves another module: netcheck's entry is the one the picture holds already.
|
||||
b.moduleFP(t, "ca-trust", "catalogue-a67f0196-ca-trust.module.json", "modules/ca-trust", nil, commit, "src2:"+strings.Repeat("4", 64), 0)
|
||||
select {
|
||||
case m := <-ended:
|
||||
var end meshbuilds.StepEnded
|
||||
if err := json.Unmarshal(m.Data, &end); err != nil || end.ID != "ask-2" || end.Outcome != meshbuilds.StepEndedOutcomePassed {
|
||||
t.Fatalf("step-ended = %+v, %v; want the ask ask-2 passed once the picture held source revision 2", end, err)
|
||||
}
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended for ask-2 within 20 s")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// **A build waits for its revision; a build with no version is never made** (design 47 H H-A-155, H-A-156; H-A-141): a step
|
||||
// ask names its branch and source revision, and the builder reserves the version before it builds. When the builder's picture
|
||||
// of that branch does not hold that source revision yet, or holds it but has not taken in the entry of the asked fingerprint
|
||||
// from it, the ask waits for the picture to take it in, woken by each entry the picture takes in (take, EntryGone) and each
|
||||
// revision its view holds (PictureHeld, H-A-162), never a
|
||||
// timer or a poll, up to RevisionWait (the setting revision-wait-minutes); past it the ask fails, naming the revision and the
|
||||
// branch, and nothing is built. A step ask with no source (a run on request) does not wait.
|
||||
|
||||
// DefaultRevisionWait is the bound of a step ask's wait for its revision, its setting revision-wait-minutes' default (H-A-156).
|
||||
const DefaultRevisionWait = 2 * time.Minute
|
||||
|
||||
func (b *Builder) revisionWait() time.Duration {
|
||||
if b.RevisionWait > 0 {
|
||||
return b.RevisionWait
|
||||
}
|
||||
return DefaultRevisionWait
|
||||
}
|
||||
|
||||
// PictureHeld is told each revision a branch's view takes in whole, whether or not an entry changed (H-A-162): every step
|
||||
// ask waiting for its revision looks again.
|
||||
func (b *Builder) PictureHeld() {
|
||||
b.init()
|
||||
b.pictureMoved()
|
||||
}
|
||||
|
||||
// pictureMoved wakes every step ask waiting for the picture: an entry was taken in or went, or a revision was held.
|
||||
func (b *Builder) pictureMoved() {
|
||||
b.mu.Lock()
|
||||
moved := b.moved
|
||||
b.moved = make(chan struct{})
|
||||
b.mu.Unlock()
|
||||
close(moved)
|
||||
}
|
||||
|
||||
// holdsRevision says whether the builder's picture of branch holds the source revision and has taken in every entry of the
|
||||
// ask from that branch.
|
||||
func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuilds.BuildEntry) bool {
|
||||
held, ok := b.Picture(branch)
|
||||
if !ok || held < source {
|
||||
return false
|
||||
}
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
for _, e := range entries {
|
||||
key, err := builds.BuilderBuildKey(e.Module, e.Fingerprint)
|
||||
if err != nil {
|
||||
return true // the build key is refused where the entry is built, with why
|
||||
}
|
||||
if b.origin[key].Branch != branch && b.heard[branch+"\x00"+e.Module].Fp2 != e.Fingerprint {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// awaitRevision returns no outcome once the builder's picture of the ask's branch holds its source revision; past the bound the
|
||||
// step's outcome failed, at the builder's stop could not run, each with its words.
|
||||
func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (outcome, said string) {
|
||||
if b.Picture == nil || run.Source <= 0 || run.Branch == "" {
|
||||
return "", ""
|
||||
}
|
||||
bound := b.revisionWait()
|
||||
notHeld := fmt.Sprintf("revision %d of %s not in the builder's picture", run.Source, run.Branch)
|
||||
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
|
||||
defer stop()
|
||||
told := false
|
||||
for {
|
||||
b.mu.Lock()
|
||||
moved := b.moved
|
||||
b.mu.Unlock()
|
||||
if b.holdsRevision(run.Branch, run.Source, run.Entries) {
|
||||
if told {
|
||||
b.logf("%s: revision %d of %s is in the builder's picture: the build goes on", run.Pipeline, run.Source, run.Branch)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
if !told {
|
||||
b.logf("%s: %s yet: the ask waits for it, at most %s", run.Pipeline, notHeld, bound)
|
||||
told = true
|
||||
}
|
||||
select {
|
||||
case <-moved:
|
||||
case <-wait.Done():
|
||||
if ctx.Err() != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, notHeld + ": the builder stopped before it was"
|
||||
}
|
||||
b.logf("%s: %s within %s: the step fails, nothing is built", run.Pipeline, notHeld, bound)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s within %s", notHeld, bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// **A package with no pin waits for its release** (design 47 H H-A-165, H-A-161): an entry keeps a mesh package none of
|
||||
// whose versions is released with an empty version. Its step ask waits, as for its revision, for the release of the module
|
||||
// that holds the package (the catalog's version-released, VersionReleased), up to PackageWait (the setting
|
||||
// package-wait-minutes), then builds with that release as the package's pin (v<version>); past the bound the step fails,
|
||||
// naming the package, and nothing is built.
|
||||
|
||||
// DefaultPackageWait is the bound of a step ask's wait for a package's release, its setting package-wait-minutes' default.
|
||||
const DefaultPackageWait = 10 * time.Minute
|
||||
|
||||
func (b *Builder) packageWait() time.Duration {
|
||||
if b.PackageWait > 0 {
|
||||
return b.PackageWait
|
||||
}
|
||||
return DefaultPackageWait
|
||||
}
|
||||
|
||||
// VersionReleased takes the catalog's version-released of module in: a step ask waiting for a package of it wakes.
|
||||
func (b *Builder) VersionReleased(module, version string) {
|
||||
b.init()
|
||||
b.mu.Lock()
|
||||
b.releases[module] = version
|
||||
b.mu.Unlock()
|
||||
b.pictureMoved()
|
||||
}
|
||||
|
||||
// releaseOf is the pin a package is built against: the release of the module holding it, as Go names it; "" for none yet.
|
||||
func (b *Builder) releaseOf(ctx context.Context, pkg string) string {
|
||||
if b.Members == nil {
|
||||
return ""
|
||||
}
|
||||
module, _, found, err := b.Members(ctx, pkg)
|
||||
if err != nil || !found {
|
||||
return ""
|
||||
}
|
||||
b.mu.Lock()
|
||||
v := b.releases[module]
|
||||
b.mu.Unlock()
|
||||
if v == "" && b.NewestReleased != nil {
|
||||
if kept, ok, err := b.NewestReleased(ctx, module); err == nil && ok {
|
||||
v = kept
|
||||
}
|
||||
}
|
||||
if v == "" {
|
||||
return ""
|
||||
}
|
||||
return "v" + v
|
||||
}
|
||||
|
||||
// awaitPins fills each package entry names with no pin from its release, waiting for one; no outcome once every package has
|
||||
// a pin, failed past the bound, could not run at the builder's stop.
|
||||
func (b *Builder) awaitPins(ctx context.Context, entry *meshcatalog.CatalogEntry) (outcome, said string) {
|
||||
var unpinned []string
|
||||
for p, v := range entry.Packages {
|
||||
if v == "" {
|
||||
unpinned = append(unpinned, p)
|
||||
}
|
||||
}
|
||||
if len(unpinned) == 0 {
|
||||
return "", ""
|
||||
}
|
||||
slices.Sort(unpinned)
|
||||
bound := b.packageWait()
|
||||
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
|
||||
defer stop()
|
||||
pins := map[string]string{}
|
||||
told := false
|
||||
for {
|
||||
b.mu.Lock()
|
||||
moved := b.moved
|
||||
b.mu.Unlock()
|
||||
missing := ""
|
||||
for _, p := range unpinned {
|
||||
if pins[p] == "" {
|
||||
pins[p] = b.releaseOf(ctx, p)
|
||||
}
|
||||
if pins[p] == "" && missing == "" {
|
||||
missing = p
|
||||
}
|
||||
}
|
||||
if missing == "" {
|
||||
packages := maps.Clone(entry.Packages)
|
||||
maps.Copy(packages, pins)
|
||||
entry.Packages = packages
|
||||
if told {
|
||||
b.logf("%s at %s: every package it names has a released version: built with %v", entry.Module, entry.Fp, pins)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
notReleased := fmt.Sprintf("package %s has no released version", missing)
|
||||
if !told {
|
||||
b.logf("%s at %s: %s yet: the ask waits for its release, at most %s", entry.Module, entry.Fp, notReleased, bound)
|
||||
told = true
|
||||
}
|
||||
select {
|
||||
case <-moved:
|
||||
case <-wait.Done():
|
||||
if ctx.Err() != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, notReleased + ": the builder stopped before it was"
|
||||
}
|
||||
b.logf("%s at %s: %s within %s: the step fails, nothing is built", entry.Module, entry.Fp, notReleased, bound)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s within %s", notReleased, bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,10 +103,21 @@ type Builder struct {
|
||||
Now func() time.Time
|
||||
Node string
|
||||
// Numbers numbers each trunk build at its claim and records what it was built with (design 51 *The versions*); nil
|
||||
// numbers nothing.
|
||||
// numbers nothing, as the builder's program leaves it (design 47 H H-A-159: the reservation numbers, G §369).
|
||||
Numbers Numbers
|
||||
// Reserved reserves the version of a trunk build at its start (design 47 G §369); nil reserves nothing.
|
||||
Reserved Reservations
|
||||
// Picture answers the source revision the builder's picture of a watched branch holds, false while it holds none (design 47
|
||||
// H H-A-155, H-A-141): a step ask naming a newer one waits for it. Nil waits for nothing.
|
||||
Picture func(branch string) (source int64, held bool)
|
||||
// RevisionWait bounds a step ask's wait for its revision, its setting revision-wait-minutes (H-A-156); DefaultRevisionWait
|
||||
// when 0.
|
||||
RevisionWait time.Duration
|
||||
// PackageWait bounds a step ask's wait for the release of a package its entry names with no pin, its setting
|
||||
// package-wait-minutes (H-A-165); DefaultPackageWait when 0. NewestReleased reads the newest version the builder's
|
||||
// record of releases keeps for a module; nil reads none, and only a release heard (VersionReleased) gives a pin.
|
||||
PackageWait time.Duration
|
||||
NewestReleased func(ctx context.Context, module string) (version string, found bool, err error)
|
||||
// Forms answers what each node's engine states it reads (ADR 0618 §2, ADR 0624 §1): present, the nodes whose engine
|
||||
// answered when last asked, and counted, every node the assignments names, present or away, a node with no statement
|
||||
// stating nothing (the baseline's first forms). A done key names each artifact in the forms these keep, the oldest in
|
||||
@@ -149,6 +160,10 @@ type Builder struct {
|
||||
// builds are the ends that withdraw the asks of a key's build in flight, by build key (ADR 0664 §4): a newer fingerprint of
|
||||
// the module takes its older one's build out, and the asker drops that build's asks.
|
||||
builds map[string]context.CancelCauseFunc
|
||||
// moved is closed and made again at each entry the picture takes in or drops: the step asks waiting for a revision wake.
|
||||
moved chan struct{}
|
||||
// releases are the versions heard released, by module (VersionReleased): a package with no pin waits for one.
|
||||
releases map[string]string
|
||||
}
|
||||
|
||||
type planned struct {
|
||||
@@ -178,6 +193,8 @@ func (b *Builder) init() {
|
||||
b.published, b.held, b.waiting = map[string]bool{}, map[string]bool{}, map[string]map[string]chan string{}
|
||||
b.hands, b.events = map[string]*handWatch{}, map[string]bool{}
|
||||
b.builds = map[string]context.CancelCauseFunc{}
|
||||
b.moved = make(chan struct{})
|
||||
b.releases = map[string]string{}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -230,6 +247,7 @@ func (b *Builder) EntryGone(branch string, first bool, module string) {
|
||||
b.mu.Lock()
|
||||
delete(b.heard, branch+"\x00"+module)
|
||||
b.mu.Unlock()
|
||||
b.pictureMoved()
|
||||
if first {
|
||||
b.Forget(module)
|
||||
}
|
||||
@@ -256,6 +274,7 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog.
|
||||
b.edges[bk] = e
|
||||
}
|
||||
b.mu.Unlock()
|
||||
b.pictureMoved()
|
||||
if superseded != nil {
|
||||
// A newer fingerprint of the module: the build of the older one in flight is taken out, and its asks are withdrawn
|
||||
// from the build seats (ADR 0664 §4).
|
||||
|
||||
@@ -34,6 +34,10 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui
|
||||
if b.StepEntry == nil {
|
||||
return finish(meshbuilds.StepEndedOutcomeCouldNotRun, "the builder reads no entry of the seat mesh-catalog")
|
||||
}
|
||||
// The version is reserved before the build (H-A-155): the ask waits for the builder's picture to hold its revision.
|
||||
if outcome, said := b.awaitRevision(ctx, run); outcome != "" {
|
||||
return finish(outcome, said)
|
||||
}
|
||||
var failed []string
|
||||
for _, e := range run.Entries {
|
||||
outcome, said := b.buildEntry(ctx, e)
|
||||
@@ -59,6 +63,10 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
if entry.Module != e.Module || (e.Commit != "" && entry.Commit != e.Commit) {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("the entry of %s at %s is of %s at %s", e.Module, e.Fingerprint, entry.Module, entry.Commit)
|
||||
}
|
||||
// A package the entry names with no pin is built against its release, waited for (H-A-165).
|
||||
if outcome, said := b.awaitPins(ctx, &entry); outcome != "" {
|
||||
return outcome, said
|
||||
}
|
||||
key, err := builds.BuilderBuildKey(entry.Module, entry.Fp)
|
||||
if err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, err.Error()
|
||||
|
||||
@@ -3,13 +3,17 @@ package build
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
@@ -112,6 +116,184 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision)
|
||||
t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails)
|
||||
t.Run("H-A-162: a revision held that changes no entry wakes the ask", aRevisionHeldWakesTheAsk)
|
||||
t.Run("H-A-165: a package with no pin waits for its release and is built with it", aPackageWithNoPinWaitsForItsRelease)
|
||||
t.Run("H-A-165: past its bound a package with no release fails the step", aPackageWithNoReleaseFailsPastItsBound)
|
||||
}
|
||||
|
||||
// unpinnedRig is a rig whose step entry m names the package x with no version, built by the module contracts.
|
||||
func unpinnedRig(t *testing.T) (*rig, *fakeReservations) {
|
||||
var held atomic.Int64
|
||||
r, res, entry := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r.b.Picture = nil // no revision to wait for here
|
||||
entry.Packages = map[string]string{"git.novox.be/novox/mesh-contracts/go/seats/x": "", "git.novox.be/novox/mesh-sdk/go": "v0.1.20"}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) { return entry, nil }
|
||||
r.b.Members = func(_ context.Context, pkg string) (string, string, bool, error) {
|
||||
return "contracts", "contracts:x", pkg == "git.novox.be/novox/mesh-contracts/go/seats/x", nil
|
||||
}
|
||||
return r, res
|
||||
}
|
||||
|
||||
func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
r, _ := unpinnedRig(t)
|
||||
var once sync.Once
|
||||
looked := make(chan struct{})
|
||||
r.b.NewestReleased = func(context.Context, string) (string, bool, error) { // the record holds none yet
|
||||
once.Do(func() { close(looked) })
|
||||
return "", false, nil
|
||||
}
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
select {
|
||||
case <-looked:
|
||||
case end := <-ended:
|
||||
t.Fatalf("the ask ended before the package was released: %+v, asks %+v", end, r.asks.Asks())
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the ask never looked for the package's release")
|
||||
}
|
||||
if _, ok := r.st.vals[r.key]; ok {
|
||||
t.Fatal("the build was made before the package had a release")
|
||||
}
|
||||
r.b.VersionReleased("contracts", "0.1.3")
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the release did not wake the ask")
|
||||
}
|
||||
r.b.Wait()
|
||||
asks := r.asks.Asks()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(asks) == 0 ||
|
||||
!reflect.DeepEqual(asks[0].Packages, buildstep.PackageVersions{"git.novox.be/novox/mesh-contracts/go/seats/x": "v0.1.3", "git.novox.be/novox/mesh-sdk/go": "v0.1.20"}) {
|
||||
t.Errorf("end = %+v, asks %+v; want passed, built with x at v0.1.3", end, asks)
|
||||
}
|
||||
}
|
||||
|
||||
func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) {
|
||||
r, _ := unpinnedRig(t)
|
||||
r.b.PackageWait = time.Nanosecond
|
||||
end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
r.b.Wait()
|
||||
if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || built ||
|
||||
!strings.Contains(end.Said, "package git.novox.be/novox/mesh-contracts/go/seats/x has no released version") {
|
||||
t.Errorf("end = %+v, built %v; want failed naming the package, nothing built", end, built)
|
||||
}
|
||||
// A release the builder's own record keeps gives the pin at once.
|
||||
r.b.NewestReleased = func(_ context.Context, module string) (string, bool, error) {
|
||||
return "0.1.2", module == "contracts", nil
|
||||
}
|
||||
if end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); strings.Contains(end.Said, "no released version") {
|
||||
t.Errorf("a release the record keeps did not pin the package: %+v", end)
|
||||
}
|
||||
}
|
||||
|
||||
func aRevisionHeldWakesTheAsk(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
held.Store(40)
|
||||
asked := make(chan struct{}, 1)
|
||||
r, res, entry := revisionRig(t, &held, asked)
|
||||
r.b.Entry(context.Background(), Origin{Branch: "main", Source: 40, First: true}, entry) // the entry, unchanged since 40
|
||||
r.b.Wait()
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.8.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 8, Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
select {
|
||||
case <-asked:
|
||||
case end := <-ended:
|
||||
t.Fatalf("the ask ended before the picture held its revision: %+v", end)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the ask never read the builder's picture")
|
||||
}
|
||||
held.Store(41)
|
||||
r.b.PictureHeld() // revision 8, from source 41, changes no entry
|
||||
select {
|
||||
case end := <-ended:
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 {
|
||||
t.Errorf("end = %+v, reserved from %+v; want passed with its version reserved", end, res.sources)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("a revision held did not wake the ask")
|
||||
}
|
||||
}
|
||||
|
||||
// revisionRig is a rig whose builder reserves, its step entry m at fp1, its picture of main holding the source revision held.
|
||||
func revisionRig(t *testing.T, held *atomic.Int64, asked chan struct{}) (*rig, *fakeReservations, meshcatalog.CatalogEntry) {
|
||||
r := newRig(t, goBundle)
|
||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||
res := &fakeReservations{filled: true}
|
||||
r.b.Reserved = res
|
||||
entry := meshcatalog.CatalogEntry{Module: "m", Repository: "novox/mesh-catalog", Path: "modules/m", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20", Fp: fp1,
|
||||
ManifestDigest: mdigest('a'), Inputs: &meshcatalog.EntryInputs{Toolchains: CatalogToolchains(agreedToolchains)}}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) { return entry, nil }
|
||||
r.b.Picture = func(branch string) (int64, bool) {
|
||||
select {
|
||||
case asked <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return held.Load(), branch == "main" && held.Load() > 0
|
||||
}
|
||||
return r, res, entry
|
||||
}
|
||||
|
||||
func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
held.Store(40)
|
||||
asked := make(chan struct{}, 1)
|
||||
r, res, entry := revisionRig(t, &held, asked)
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
select {
|
||||
case <-asked: // the ask read the picture, which holds source revision 40
|
||||
case end := <-ended:
|
||||
t.Fatalf("the ask ended before the picture held its revision: %+v, reserved from %+v", end, res.sources)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the ask never read the builder's picture")
|
||||
}
|
||||
if _, ok := r.st.vals[r.key]; ok {
|
||||
t.Fatal("the ask built before the picture held its revision")
|
||||
}
|
||||
held.Store(41)
|
||||
r.b.Entry(context.Background(), Origin{Branch: "main", Source: 41, First: true}, entry) // the picture takes revision 41 in
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the ask was not woken by the entry the picture took in")
|
||||
}
|
||||
r.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 {
|
||||
t.Errorf("end = %+v, reserved from %+v; want passed with one version reserved from revision 41", end, res.sources)
|
||||
}
|
||||
}
|
||||
|
||||
func aStepAskPastItsRevisionBoundFails(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
held.Store(40)
|
||||
r, res, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r.b.RevisionWait = time.Nanosecond
|
||||
end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
r.b.Wait()
|
||||
if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "revision 41 of main not in the builder's picture") || built || len(res.sources) != 0 {
|
||||
t.Errorf("end = %+v, built %v, reserved %+v; want failed naming revision 41 of main, nothing built", end, built, res.sources)
|
||||
}
|
||||
// A step ask with no source (a run on request) does not wait (H-A-156).
|
||||
end = r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "run.1.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if strings.Contains(end.Said, "not in the builder's picture") {
|
||||
t.Errorf("an ask with no source waited: %+v", end)
|
||||
}
|
||||
}
|
||||
|
||||
// digestOf is the manifest digest a step's entry names: the rig's manifest, or one no store holds, whose plan cannot be read.
|
||||
|
||||
@@ -3,16 +3,14 @@ package versions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The tools' descriptions.
|
||||
const (
|
||||
FloorAgainDescription = "Ask the floor of one name again now, by hand (design 51 *The floor*): the seat's versions, the seat git's " +
|
||||
"git.tags and the indexer's indexer_requirements, as the builder asks them by itself when a silent source says something. " +
|
||||
"Answers which sources were silent and whether the floor is now known. A name the builder's versions already hold needs no floor: " +
|
||||
"refused, saying so. A hand act."
|
||||
FloorAgainDescription = "Refused for every name: the builder numbers nothing of its own and asks no floor (design 47 H H-A-159); " +
|
||||
"a version is numbered by the reservation (design 47 G §369, builder_reserved). Kept until design 47 G §372 removes it with " +
|
||||
"the state versions."
|
||||
)
|
||||
|
||||
// Acts are the builder's hand acts on its versions, answered by its program (the tools bundle writes them to reasks).
|
||||
@@ -31,24 +29,9 @@ type Acts struct {
|
||||
DropReserved func(ctx context.Context, module, series, by, why string, at time.Time) (string, error)
|
||||
}
|
||||
|
||||
// FloorAgain is builder_floor_again of name: the floor counts only for a name the versions hold nothing of.
|
||||
func (a Acts) FloorAgain(ctx context.Context, name string) (string, error) {
|
||||
entries, err := a.Numberer.Versions.Of(ctx, name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(entries) > 0 {
|
||||
return "", fmt.Errorf("%s holds %d versions: its floor counts only for its first number, so nothing is asked", name, len(entries))
|
||||
}
|
||||
answer := name + " waits on no floor in this builder: the floor is asked at its next claim"
|
||||
if a.Numberer.Waits != nil {
|
||||
for _, w := range a.Numberer.Waits.Waiting() {
|
||||
if w.Name == name {
|
||||
answer = fmt.Sprintf("the floor of %s is asked again (%s were silent)", name, strings.Join(w.Silent, ", "))
|
||||
}
|
||||
}
|
||||
a.Numberer.Waits.Wake(WakeByHand, "", "", name)
|
||||
}
|
||||
a.Reconsider(ctx)
|
||||
return answer + "; builder_versions shows its version once numbered", nil
|
||||
// FloorAgain is builder_floor_again of name: refused, since the builder numbers nothing of its own and no claim asks a floor
|
||||
// (design 47 H H-A-159; the reservation numbers, G §369). The tool stays until G §372 removes it with the state versions.
|
||||
func (a Acts) FloorAgain(_ context.Context, name string) (string, error) {
|
||||
return "", fmt.Errorf("the floor of %s is not asked: the builder numbers nothing of its own and asks no floor (design 47 H H-A-159); "+
|
||||
"a version is numbered by the reservation (G §369, builder_reserved)", name)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome)
|
||||
var change func(*Entry)
|
||||
switch event {
|
||||
case HeardPublished:
|
||||
// A published of other bytes than an entry records under its number is no publish of that entry: the reservation
|
||||
// numbered it and takes it in (design 47 H H-A-159, G §369, A-415; ADR 0605 §4), and the entry stays as it is.
|
||||
if e, ok, _, err := n.Versions.Recorded(ctx, o.Name, o.Version, o.Digest); err == nil && !ok && e.Digest != "" && o.Digest != "" && e.Digest != o.Digest {
|
||||
return wake, fmt.Errorf("%s@%s is recorded with digest %s, so %s's published of %s is %w", o.Name, o.Version, e.Digest, seat, o.Digest, ErrNotNumbered)
|
||||
}
|
||||
change = func(e *Entry) {
|
||||
e.State, e.Reason = Published, ""
|
||||
if e.Digest == "" {
|
||||
|
||||
@@ -295,6 +295,23 @@ func (r *Reserver) ReleasedFor(ctx context.Context, module, fingerprint string)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// NewestReleased is the newest version the builder's own record of releases keeps for module (design 47 H H-A-165): a
|
||||
// package with no pin is built against it; false when the record holds none.
|
||||
func (r *Reserver) NewestReleased(ctx context.Context, module string) (string, bool, error) {
|
||||
if r.Releases == nil {
|
||||
return "", false, nil
|
||||
}
|
||||
raw, _, found, err := r.Releases.Get(ctx, ReleasedKey(module))
|
||||
if err != nil || !found {
|
||||
return "", false, err
|
||||
}
|
||||
var rec ReleasedRecord
|
||||
if json.Unmarshal(raw, &rec) != nil || len(rec.Kept) == 0 {
|
||||
return "", false, nil
|
||||
}
|
||||
return rec.Kept[len(rec.Kept)-1].Version, true, nil
|
||||
}
|
||||
|
||||
// keepRelease adds a release to the module's record, dropping the oldest past ReleasedKept.
|
||||
func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string) error {
|
||||
n := r.ReleasedKept
|
||||
|
||||
@@ -201,11 +201,13 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
||||
t.Errorf("reservations left: %v", all)
|
||||
}
|
||||
// One key per module holds the last releases, the oldest dropped (A-456b).
|
||||
newest := ""
|
||||
for _, fp := range []string{"src2:b1", "src2:b2"} {
|
||||
n, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newest = n.Version
|
||||
if _, err := r.Released(ctx, "m", n.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -219,6 +221,13 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
||||
if ok, _ := r.ReleasedFor(ctx, "m", "src2:b2"); !ok {
|
||||
t.Error("the newest release is not kept")
|
||||
}
|
||||
// H-A-165: the newest version the record keeps is the pin of a package with none.
|
||||
if v, ok, err := r.NewestReleased(ctx, "m"); !ok || err != nil || v != newest {
|
||||
t.Errorf("newest released of m = %q, %v (%v), want %s", v, ok, err, newest)
|
||||
}
|
||||
if _, ok, _ := r.NewestReleased(ctx, "other"); ok {
|
||||
t.Error("a module never released has a newest release")
|
||||
}
|
||||
}
|
||||
|
||||
// TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas: design 47 G A-490b — a build again of a done key replaces
|
||||
|
||||
@@ -440,6 +440,13 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
if wake, _ := n.Heard(ctx, SeatGoPackages, HeardPublished, "e2", Outcome{Name: "m/x", Digest: "sha256:dd"}); !reflect.DeepEqual(wake, []string{"m/lib"}) {
|
||||
t.Fatalf("a published on the Go seat woke %v, want m/lib, whose seat was silent", wake)
|
||||
}
|
||||
// Design 47 G §369, A-415; ADR 0605 §4: a published of other bytes under the number is the reservation's, never this entry's.
|
||||
if _, err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e5", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:new"}); !errors.Is(err, ErrNotNumbered) {
|
||||
t.Fatalf("a published of other bytes under 0.1.14: %v, want ErrNotNumbered", err)
|
||||
}
|
||||
if all, _ := n.Versions.Of(ctx, "m/program"); all[0].State != Numbered || all[0].Digest != "sha256:aa" {
|
||||
t.Fatalf("after a published of other bytes: %+v, want it numbered with sha256:aa", all[0])
|
||||
}
|
||||
for _, h := range []struct{ event, state, reason string }{{HeardRefused, Refused, "bytes differ"}, {HeardPublished, Published, ""}, {HeardRefused, Published, ""}, {HeardRemoved, Removed, "retention"}} {
|
||||
if _, err := n.Heard(ctx, SeatArtifacts, h.event, "e3", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:aa", Reason: h.reason}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -581,11 +588,13 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
}
|
||||
_, _ = v.Mark(ctx, "m/p", "0.1.4", func(e *Entry) { e.State = Published })
|
||||
acts := Acts{Numberer: &Numberer{Versions: v, Waits: &FloorWaits{}}, Reconsider: func(context.Context) {}}
|
||||
if _, err := acts.FloorAgain(ctx, "m/p"); err == nil {
|
||||
t.Error("a name with versions asks its floor again")
|
||||
}
|
||||
if ans, err := acts.FloorAgain(ctx, "m/new"); err != nil || ans == "" {
|
||||
t.Errorf("floor again of a new name: %q %v", ans, err)
|
||||
reconsidered := false
|
||||
acts.Reconsider = func(context.Context) { reconsidered = true }
|
||||
// H-A-159: the builder numbers nothing of its own, so no claim asks a floor: the tool refuses, saying so, and does nothing.
|
||||
for _, name := range []string{"m/p", "m/new"} {
|
||||
if ans, err := acts.FloorAgain(ctx, name); err == nil || !strings.Contains(err.Error(), "numbers nothing of its own") || reconsidered {
|
||||
t.Errorf("floor again of %s: %q %v, looked again %v; want refused naming H-A-159, nothing looked at", name, ans, err, reconsidered)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -186,9 +186,9 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
m.Streams[2].Name != "mesh-delivery-builder-findings" || !reflect.DeepEqual(m.Streams[2].Events, []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"}) {
|
||||
t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB, the builds' stream (build.ended.**, 7 days, kept last per subject: design 47 G A-181) and the findings' stream", m.Streams)
|
||||
}
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 5 ||
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 7 || m.Config["revision-wait-minutes"].Default != float64(2) || m.Config["package-wait-minutes"].Default != float64(10) ||
|
||||
m.Config["publish-pause"].Default != float64(30) || m.Config["publish-pause-max"].Default != float64(30) || m.Config["publish-tries"].Default != float64(8) {
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, the publish settings 30 s, 30 min and 8 tries (design 47 G §588, §633, A-457a)", m.Config)
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, revision-wait-minutes of 2 (H-A-156), package-wait-minutes of 10 (H-A-165), the publish settings 30 s, 30 min and 8 tries (design 47 G §588, §633, A-457a)", m.Config)
|
||||
}
|
||||
// Design 47 G §349: version.numbered is no longer said; old-form-closed on the family version, apart from the builds' ends.
|
||||
if want := []string{"build.asked-again", "version.old-form-closed"}; !reflect.DeepEqual(m.Emits, want) {
|
||||
@@ -241,7 +241,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
|
||||
t.Errorf("process = %v", p)
|
||||
}
|
||||
env, _ := p["env"].(map[string]any)
|
||||
if len(env) != 6 || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
if len(env) != 8 || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PACKAGE_WAIT_FILE"] != "${dir:state}/package-wait-minutes" || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
t.Errorf("env = %v, want the broker file and the path of the toolchain wait's file, never the setting itself (design 47 G §672, A-71)", p["env"])
|
||||
}
|
||||
for k, v := range env {
|
||||
|
||||
@@ -147,6 +147,22 @@
|
||||
"trusted": false,
|
||||
"default": 60
|
||||
},
|
||||
"revision-wait-minutes": {
|
||||
"type": "number",
|
||||
"description": "minutes a build step ask waits for the builder's picture of its branch to hold its source revision before it fails, building nothing (design 47 H H-A-155, H-A-156).",
|
||||
"minimum": 1,
|
||||
"maximum": 60,
|
||||
"trusted": false,
|
||||
"default": 2
|
||||
},
|
||||
"package-wait-minutes": {
|
||||
"type": "number",
|
||||
"description": "minutes a build step ask waits for the release of a mesh package its entry names with no pin before it fails, building nothing (design 47 H H-A-165).",
|
||||
"minimum": 1,
|
||||
"maximum": 120,
|
||||
"trusted": false,
|
||||
"default": 10
|
||||
},
|
||||
"publish-pause": {
|
||||
"type": "number",
|
||||
"description": "seconds before a version's second publish try, doubled per try up to publish-pause-max (design 47 G A-457a).",
|
||||
@@ -223,6 +239,22 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:toolchain-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "revision-wait",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/revision-wait-minutes",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:revision-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "package-wait",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/package-wait-minutes",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:package-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "publish-pause",
|
||||
"type": "file",
|
||||
@@ -269,6 +301,8 @@
|
||||
"env": {
|
||||
"MESH_BROKER_FILE": "${dir:state}/broker",
|
||||
"MESH_BUILDER_TOOLCHAIN_WAIT_FILE": "${dir:state}/toolchain-wait-minutes",
|
||||
"MESH_BUILDER_REVISION_WAIT_FILE": "${dir:state}/revision-wait-minutes",
|
||||
"MESH_BUILDER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_FILE": "${dir:state}/publish-pause",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE": "${dir:state}/publish-pause-max",
|
||||
"MESH_BUILDER_PUBLISH_TRIES_FILE": "${dir:state}/publish-tries",
|
||||
|
||||
@@ -74,6 +74,8 @@ type Branches struct {
|
||||
holders atomic.Pointer[seatHolders]
|
||||
// Changed, when not nil, is told of each change to a branch's view (module, its entry, deleted), set before Wire.
|
||||
Changed func(branch, module string, entry json.RawMessage, deleted bool, at time.Time)
|
||||
// Held, when not nil, is told of each revision a branch's view takes in whole (Catalog.Held; H-A-162), set before Wire.
|
||||
Held func(branch string, revision seat.CatalogRevision)
|
||||
// Adopted, when not nil, is told on a goroutine of its own of each branch whose view was adopted, with that view (a part that waits for
|
||||
// its first branch's first view, design 47 G §507), set before Wire.
|
||||
Adopted func(branch string, c *Catalog)
|
||||
@@ -253,6 +255,11 @@ func (b *Branches) reconcile() {
|
||||
b.Changed(branch, module, entry, deleted, at)
|
||||
}
|
||||
}
|
||||
c.Held = func(r seat.CatalogRevision) {
|
||||
if b.Held != nil {
|
||||
b.Held(branch, r)
|
||||
}
|
||||
}
|
||||
// A catalog-revision also asks again each entry whose ask failed in transport (design 47 H, H-A-60).
|
||||
hear := func(ctx context.Context, data []byte) error {
|
||||
err := c.Hear(ctx, data)
|
||||
|
||||
@@ -59,6 +59,9 @@ type Catalog struct {
|
||||
waits int64
|
||||
// made is when the view's numbering last started again (H-A-141), the follower's Created; zero is catalogCreated.
|
||||
made time.Time
|
||||
// Held, when not nil, is told each revision the view takes in whole, once it holds it, whether or not an entry
|
||||
// changed (design 47 H H-A-162): a part waiting for a revision wakes on it. Set before Start.
|
||||
Held func(seat.CatalogRevision)
|
||||
}
|
||||
|
||||
// created is madeLocked, taking mu.
|
||||
@@ -232,7 +235,9 @@ func (c *Catalog) ask(_ context.Context, after string) (views.Answer, error) {
|
||||
}
|
||||
rev := a.Revision.Revision
|
||||
holds := false
|
||||
if a.Next == "" {
|
||||
whole := a.Next == ""
|
||||
held := *a.Revision
|
||||
if whole {
|
||||
c.held, c.paging = c.paging, nil
|
||||
if c.waits <= rev {
|
||||
c.waits, holds = 0, true
|
||||
@@ -242,6 +247,9 @@ func (c *Catalog) ask(_ context.Context, after string) (views.Answer, error) {
|
||||
if holds {
|
||||
c.Follower.Holds(ViewName(rev))
|
||||
}
|
||||
if whole && c.Held != nil {
|
||||
c.Held(held)
|
||||
}
|
||||
return views.Answer{V: 1, Owner: seat.Seat, State: c.Follower.State, Revision: uint64(rev), Created: c.created(), Values: values, Next: a.Next, At: time.Now()}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -83,6 +84,14 @@ func TestCatalogIsAViewPerWatchedBranch(t *testing.T) {
|
||||
c.Follower.Wait = time.Nanosecond
|
||||
c.Follower.Logf = logf
|
||||
}
|
||||
// H-A-162: each revision the view takes in whole is told to Held.
|
||||
var heldMu sync.Mutex
|
||||
var held []int64
|
||||
main.Held = func(r seat.CatalogRevision) {
|
||||
heldMu.Lock()
|
||||
defer heldMu.Unlock()
|
||||
held = append(held, r.Revision)
|
||||
}
|
||||
if main.Follower.State == rel.Follower.State || main.Follower.State != "catalog-revisions.main" || rel.Follower.State != views.BranchState(seat.StateCatalogRevisions, "release/1") {
|
||||
t.Fatalf("views are named %q and %q", main.Follower.State, rel.Follower.State)
|
||||
}
|
||||
@@ -116,17 +125,25 @@ func TestCatalogIsAViewPerWatchedBranch(t *testing.T) {
|
||||
}
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
for {
|
||||
if h, _ := main.View(); h.Revision.Revision == 4 {
|
||||
heldMu.Lock()
|
||||
told := len(held)
|
||||
heldMu.Unlock()
|
||||
if h, _ := main.View(); h.Revision.Revision == 4 && told == 2 {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("main never held revision 4")
|
||||
t.Fatal("main never held revision 4, told to Held")
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
if n := f.asked("release/1"); n != 1 {
|
||||
t.Errorf("release/1 asked %d times after main's revision", n)
|
||||
}
|
||||
heldMu.Lock()
|
||||
if !slices.Equal(held, []int64{3, 4}) {
|
||||
t.Errorf("Held was told %v, want 3 then 4", held)
|
||||
}
|
||||
heldMu.Unlock()
|
||||
logMu.Lock()
|
||||
said := false
|
||||
for _, l := range logged {
|
||||
|
||||
@@ -711,6 +711,8 @@ type CatalogRevisionDefinitionsItem struct {
|
||||
type CatalogRevision struct {
|
||||
// when (RFC 3339 time)
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
// the newest kept revision of its branch below it, which the take-in that wrote it pinned for its pipeline: the base of the validate step's case before (design 47 H-A-147, H-A-151, H-A-154); absent on the branch's first take-in
|
||||
Base int64 `json:"base,omitempty"`
|
||||
// the watched branch the revision is of
|
||||
Branch string `json:"branch,omitempty"`
|
||||
// the seat definitions it was judged with, each by its digest, read whole through seat-definitions
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v ModulesAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "the module verb (captured: xclip)", subject: "", given: "{\"module\":{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"manifest\":{\"build\":{\"artifacts\":[{\"binary\":\"xclip-tools\",\"from\":\"cmd/xclip-tools\",\"kind\":\"bundle\",\"language\":\"go\",\"loads\":[\"xclip-tools\"],\"name\":\"tools\",\"system\":\"arch\"}]},\"capabilities\":[\"package-manager\"],\"module\":\"xclip\",\"resources\":[{\"id\":\"package\",\"package\":\"xclip\",\"type\":\"package\"}],\"tools\":[\"xclip_copy\",\"xclip_paste\",\"xclip_targets\",\"xclip_session\"],\"version\":\"1\"},\"module\":\"xclip\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\"}}", wire: "{\"module\":{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"manifest\":{\"build\":{\"artifacts\":[{\"binary\":\"xclip-tools\",\"from\":\"cmd/xclip-tools\",\"kind\":\"bundle\",\"language\":\"go\",\"loads\":[\"xclip-tools\"],\"name\":\"tools\",\"system\":\"arch\"}]},\"capabilities\":[\"package-manager\"],\"module\":\"xclip\",\"resources\":[{\"id\":\"package\",\"package\":\"xclip\",\"type\":\"package\"}],\"tools\":[\"xclip_copy\",\"xclip_paste\",\"xclip_targets\",\"xclip_session\"],\"version\":\"1\"},\"module\":\"xclip\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\"}}",
|
||||
decode: func(b []byte) (any, error) { var v ModuleAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "a watched branch's catalog graph revision", subject: "", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}",
|
||||
{name: "a watched branch's catalog graph revision", subject: "", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v CatalogRevisionsByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
|
||||
@@ -899,6 +899,8 @@ type CompositionRun struct {
|
||||
// the outcome's words
|
||||
Said string `json:"said,omitempty"`
|
||||
Started *time.Time `json:"started,omitempty"`
|
||||
// the module names of the assignments left out of the machine's composition, those no watched branch's newest revision lists, written when the run starts and read by every step's judgement and by the resume (design 47 H-A-152, H-A-153)
|
||||
Unlisted []string `json:"unlisted,omitempty"`
|
||||
// that machine's composer verdict (design 47 G §721)
|
||||
Verdict map[string]any `json:"verdict,omitempty"`
|
||||
}
|
||||
|
||||
@@ -208,7 +208,8 @@
|
||||
"fingerprint": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
"repository": "novox/mesh-catalog"
|
||||
}
|
||||
]
|
||||
],
|
||||
"base": 9
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1927,6 +1927,10 @@
|
||||
"$ref": "#/defs/TakeInEntry"
|
||||
},
|
||||
"description": "the movers of the take-in that wrote it, so a redelivered source-moved whose revision is kept says take-in.taken again from them, recomputing nothing (design 47 H §743, H-A-92); absent for one with no mover"
|
||||
},
|
||||
"base": {
|
||||
"type": "integer",
|
||||
"description": "the newest kept revision of its branch below it, which the take-in that wrote it pinned for its pipeline: the base of the validate step's case before (design 47 H-A-147, H-A-151, H-A-154); absent on the branch's first take-in"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1701,6 +1701,13 @@
|
||||
"verdict": {
|
||||
"type": "object",
|
||||
"description": "that machine's composer verdict (design 47 G §721)"
|
||||
},
|
||||
"unlisted": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "the module names of the assignments left out of the machine's composition, those no watched branch's newest revision lists, written when the run starts and read by every step's judgement and by the resume (design 47 H-A-152, H-A-153)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -273,6 +273,8 @@ export interface CatalogRevisionDefinitionsItem {
|
||||
export interface CatalogRevision {
|
||||
/** when (RFC 3339 time) */
|
||||
"at"?: string;
|
||||
/** the newest kept revision of its branch below it, which the take-in that wrote it pinned for its pipeline: the base of the validate step's case before (design 47 H-A-147, H-A-151, H-A-154); absent on the branch's first take-in */
|
||||
"base"?: number;
|
||||
/** the watched branch the revision is of */
|
||||
"branch"?: string;
|
||||
/** the seat definitions it was judged with, each by its digest, read whole through seat-definitions */
|
||||
|
||||
@@ -319,6 +319,8 @@ export interface CompositionRun {
|
||||
/** the outcome's words */
|
||||
"said"?: string;
|
||||
"started"?: string;
|
||||
/** the module names of the assignments left out of the machine's composition, those no watched branch's newest revision lists, written when the run starts and read by every step's judgement and by the resume (design 47 H-A-152, H-A-153) */
|
||||
"unlisted"?: string[];
|
||||
/** that machine's composer verdict (design 47 G §721) */
|
||||
"verdict"?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
+87
-11
@@ -162,6 +162,8 @@ type bed struct {
|
||||
answer func(verb string, answer string)
|
||||
// calls are the verbs the stand-in was called with, in order, as `<seat>.<verb> <input>`.
|
||||
calls func() []string
|
||||
// called is signalled after each call the stand-in answered, its answer chosen.
|
||||
called <-chan struct{}
|
||||
// restart stops the bridge, runs between, and starts it again on the same bus.
|
||||
restart func(between func())
|
||||
}
|
||||
@@ -237,6 +239,7 @@ func startBed(t *testing.T, head string) *bed {
|
||||
answers["git."+verb] = string(gitfixture.Given(t, verb+" answers", "verb:"+verb+".answer"))
|
||||
}
|
||||
var called []string
|
||||
signal := make(chan struct{}, 1)
|
||||
for _, subject := range []string{"mesh.seat.*.call.*.*", "mesh.seat.*.tool.*"} {
|
||||
sub, err := ctl.Subscribe(subject, func(m *nats.Msg) {
|
||||
parts := strings.Split(m.Subject, ".")
|
||||
@@ -249,6 +252,10 @@ func startBed(t *testing.T, head string) *bed {
|
||||
answer = answers[verb+" "+in.Repository]
|
||||
}
|
||||
mu.Unlock()
|
||||
select {
|
||||
case signal <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
if answer == "" {
|
||||
answer = `{"error":"the stand-in holds no answer"}`
|
||||
}
|
||||
@@ -279,7 +286,7 @@ func startBed(t *testing.T, head string) *bed {
|
||||
start()
|
||||
t.Cleanup(func() { stop() })
|
||||
set := func(verb, answer string) { mu.Lock(); answers[verb] = answer; mu.Unlock() }
|
||||
return &bed{srv: srv, ctl: ctl, js: js, ctx: ctx, done: done, answer: set,
|
||||
return &bed{srv: srv, ctl: ctl, js: js, ctx: ctx, done: done, answer: set, called: signal,
|
||||
calls: func() []string { mu.Lock(); defer mu.Unlock(); return append([]string(nil), called...) },
|
||||
restart: func(between func()) {
|
||||
stop()
|
||||
@@ -289,6 +296,30 @@ func startBed(t *testing.T, head string) *bed {
|
||||
}}
|
||||
}
|
||||
|
||||
// callsOf is how many calls of the stand-in start with prefix.
|
||||
func callsOf(b *bed, prefix string) int {
|
||||
n := 0
|
||||
for _, c := range b.calls() {
|
||||
if strings.HasPrefix(c, prefix) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// calledTimes waits until the stand-in answered n calls starting with prefix: a call's answer is chosen when it is counted.
|
||||
func calledTimes(t *testing.T, b *bed, prefix string, n int) {
|
||||
t.Helper()
|
||||
bound := time.After(20 * time.Second)
|
||||
for callsOf(b, prefix) < n {
|
||||
select {
|
||||
case <-b.called:
|
||||
case <-bound:
|
||||
t.Fatalf("%d calls %s within 20 s, want %d", callsOf(b, prefix), prefix, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// headAt sets the stand-in seat git so main of the catalog is at head, protected or not.
|
||||
func headAt(b *bed, head string, protected bool) {
|
||||
p := "true"
|
||||
@@ -363,7 +394,10 @@ func TestBridgeSaysOneHeadMovedPerMove(t *testing.T) {
|
||||
b.restart(func() { headAt(b, h4, true) })
|
||||
said("a restart after a move", forgemsg.HeadMoved{Head: h4, Before: h3, Start: true})
|
||||
held(t, b, h4)
|
||||
branchReads := callsOf(b, "git.branch ")
|
||||
b.restart(func() {}) // at the head held: nothing
|
||||
// The head moves only once the start has read the head held, so that read is not the move's (§739: start true).
|
||||
calledTimes(t, b, "git.branch ", branchReads+1)
|
||||
headAt(b, h5, true)
|
||||
move(t, b, "main")
|
||||
said("the next move, the first message after the restart at the head held", forgemsg.HeadMoved{Head: h5, Before: h4})
|
||||
@@ -372,13 +406,11 @@ func TestBridgeSaysOneHeadMovedPerMove(t *testing.T) {
|
||||
t.Errorf("the bridge asked %s; it asks the seat git nothing but branch", c)
|
||||
}
|
||||
}
|
||||
heads, err := b.js.KeyValue(b.ctx, headsBucket(forgeBridgeModule()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e, err := heads.Get(b.ctx, "branch.novox.mesh-catalog.main"); err != nil || string(e.Value()) != h5 {
|
||||
t.Errorf("the state heads holds %v (%v), want %s", e, err, h5)
|
||||
// One read per start and per move of main: the first view's registrations, said after a start, adopt no branch (§532).
|
||||
if n := callsOf(b, "git.branch "); n != 3+4 {
|
||||
t.Errorf("the bridge read the head %d times, want 7: once at each of 3 starts and once per move of main (4)", n)
|
||||
}
|
||||
held(t, b, h5) // kept after the message is written, so watched for, not read at once
|
||||
}
|
||||
|
||||
func heard(t *testing.T, b *bed) <-chan *nats.Msg {
|
||||
@@ -395,10 +427,16 @@ func heard(t *testing.T, b *bed) <-chan *nats.Msg {
|
||||
return ch
|
||||
}
|
||||
|
||||
// next is the next message heard on subject within a bound; the others are passed by.
|
||||
// next is the next message heard on subject within 20 s; the others are passed by.
|
||||
func next(t *testing.T, ch <-chan *nats.Msg, subject string) []byte {
|
||||
t.Helper()
|
||||
bound := time.After(20 * time.Second)
|
||||
return nextWithin(t, ch, subject, 20*time.Second)
|
||||
}
|
||||
|
||||
// nextWithin is next within bound.
|
||||
func nextWithin(t *testing.T, ch <-chan *nats.Msg, subject string, within time.Duration) []byte {
|
||||
t.Helper()
|
||||
bound := time.After(within)
|
||||
for {
|
||||
select {
|
||||
case m := <-ch:
|
||||
@@ -406,7 +444,7 @@ func next(t *testing.T, ch <-chan *nats.Msg, subject string) []byte {
|
||||
return m.Data
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("nothing on %s within 20 s", subject)
|
||||
t.Fatalf("nothing on %s within %s", subject, within)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -455,6 +493,30 @@ func TestBridgePerformsWhatIsOwedOnce(t *testing.T) {
|
||||
}
|
||||
return n
|
||||
}
|
||||
// The bridge's acknowledgements on its durable of the stream owed, heard as the bus hears them.
|
||||
acks := make(chan *nats.Msg, 16)
|
||||
ackSub, err := b.ctl.ChanSubscribe("$JS.ACK."+seat.StreamOwed+".n1_mesh-delivery-forge-bridge.>", acks)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = ackSub.Unsubscribe() })
|
||||
if err := b.ctl.Flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
acked := func(n int) {
|
||||
t.Helper()
|
||||
bound := time.After(20 * time.Second)
|
||||
for n > 0 {
|
||||
select {
|
||||
case m := <-acks:
|
||||
if string(m.Data) == "+ACK" {
|
||||
n--
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("the bridge did not acknowledge what it heard on %s within 20 s", seat.StreamOwed)
|
||||
}
|
||||
}
|
||||
}
|
||||
gateOwed := gitfixture.Seat(t, seat.Seat, "events", "owed is said, a status", "event:owed")[0]
|
||||
subject := seat.SubjectOwed("novox~mesh-sdk", "178")
|
||||
for range 2 {
|
||||
@@ -479,12 +541,26 @@ func TestBridgePerformsWhatIsOwedOnce(t *testing.T) {
|
||||
_ = json.Unmarshal(gateOwed, &other)
|
||||
other["id"] = "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/other"
|
||||
otherOwed, _ := json.Marshal(other)
|
||||
// The three acts heard are acknowledged before the stop: one stopped while its outcome is on its way is heard again
|
||||
// after the start, by design, which is not what this part of the test is about.
|
||||
acked(3)
|
||||
// An act said while the bridge stops may be handed to the stopped bridge's pull before the bus has seen it go: the bus
|
||||
// hands it again after its consumer's acknowledgement wait, its redelivery the only clock (H-A-48).
|
||||
owedConsumer, err := b.js.Consumer(b.ctx, seat.StreamOwed, "n1_mesh-delivery-forge-bridge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ackWait := owedConsumer.CachedInfo().Config.AckWait
|
||||
b.restart(func() {
|
||||
if _, err := b.js.Publish(b.ctx, subject, otherOwed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
if e := ended(); e.Of != seat.Seat || e.Outcome != forgemsg.OwedPerformed {
|
||||
afterRestart, err := forgemsg.DecodeOwedEnded(nextWithin(t, ch, forgeSubject(forgemsg.OwedEndedEvent), ackWait+20*time.Second))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e := afterRestart; e.Of != seat.Seat || e.Outcome != forgemsg.OwedPerformed {
|
||||
t.Errorf("the gate's status after the restart: %+v, want performed", e)
|
||||
}
|
||||
if n := count("git.status"); n != 2 {
|
||||
|
||||
@@ -115,24 +115,31 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
var regs *meshcatalogclient.Registrations
|
||||
turn := &sync.Mutex{}
|
||||
mv := &mover{call: call, pub: js, heads: heads, watched: watched, turn: turn, logger: logger}
|
||||
recompute := func() {
|
||||
// begun says the start's read of the heads covers the watched branches from now on; it and what is watched are set
|
||||
// under setting, so a branch added before begun is read by the start and one added after it is adopted.
|
||||
var setting sync.Mutex
|
||||
begun := false
|
||||
recompute := func() (added bool) {
|
||||
if regs != nil {
|
||||
watched.Set(registeredOf(regs.All()), unescaped(src.Branches()))
|
||||
added = watched.Set(registeredOf(regs.All()), unescaped(src.Branches()))
|
||||
}
|
||||
return added
|
||||
}
|
||||
started := make(chan struct{}) // closed once the watched branches are read
|
||||
regs, _, err = meshcatalogclient.WireRegistrationsProcess(reader, keptCall, func(mcseat.Registration, bool) {
|
||||
recompute()
|
||||
select {
|
||||
case <-started: // a branch registered while the bridge runs is adopted: its head read (§532)
|
||||
setting.Lock()
|
||||
adopt := recompute() && begun
|
||||
setting.Unlock()
|
||||
// Only a registration adding a watched branch while the bridge runs is adopted, its head read (§532); the first
|
||||
// view's registrations, said after the start, add none, so the start reads their heads once, with start true (§739).
|
||||
if adopt {
|
||||
go mv.readHeads(ctx)
|
||||
default:
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
src.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { recompute() }
|
||||
src.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { setting.Lock(); recompute(); setting.Unlock() }
|
||||
if _, err := reader.Adopt(src.Follower, sourcebranches.Seat, sourcebranches.EventSourceMoved, src.Hear); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -167,7 +174,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return nil
|
||||
}
|
||||
}
|
||||
setting.Lock()
|
||||
recompute()
|
||||
begun = true
|
||||
setting.Unlock()
|
||||
close(started)
|
||||
// What the gate says it owes, on its seat's stream owed through this module's durable there (made from its consumes).
|
||||
// A stream not there yet is said, and the bridge goes on: its other work does not wait on the gate.
|
||||
|
||||
@@ -27,6 +27,23 @@ func TestAMoveOfAWatchedBranchIsOneHeadMoved(t *testing.T) {
|
||||
if !watchedOf("main").Watches("novox/other", "main") || watchedOf("main").Watches("novox/other", "beta") {
|
||||
t.Errorf("before the first registration the gate's source's branches are watched, of every repository")
|
||||
}
|
||||
// §532: only a registration adding a watched branch is adopted; the same registrations read again (a first view's
|
||||
// values said after the start) add none.
|
||||
regs := []Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main", "beta"}}}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
regs []Registered
|
||||
want bool
|
||||
}{
|
||||
{"the same registrations again", regs, false},
|
||||
{"a branch fewer", []Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main"}}}, false},
|
||||
{"a branch registered", regs, true},
|
||||
{"a repository registered", append(regs, Registered{Origin: "novox/other", Branches: []string{"main"}}), true},
|
||||
} {
|
||||
if got := w.Set(c.regs, []string{"main"}); got != c.want {
|
||||
t.Errorf("%s: added %v, want %v", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
|
||||
const head, before = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc"
|
||||
moved := Moved{Owner: "novox", Repo: "mesh-sdk", Branch: "feat/47-H"}
|
||||
|
||||
@@ -21,8 +21,10 @@ type Registered struct {
|
||||
Branches []string
|
||||
}
|
||||
|
||||
// Set takes what the bridge read: the registrations (none before the first) and the gate's source's branches by name.
|
||||
func (w *Watched) Set(regs []Registered, source []string) {
|
||||
// Set takes what the bridge read: the registrations (none before the first) and the gate's source's branches by name. It
|
||||
// says whether a branch is watched now that was not (§532: a registration adding a watched branch is adopted); the same
|
||||
// registrations read again add none.
|
||||
func (w *Watched) Set(regs []Registered, source []string) (added bool) {
|
||||
by := map[string][]string{}
|
||||
for _, r := range regs {
|
||||
for _, b := range r.Branches {
|
||||
@@ -33,8 +35,33 @@ func (w *Watched) Set(regs []Registered, source []string) {
|
||||
}
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
before := w.pairsLocked()
|
||||
w.byRepo, w.registered = by, len(regs) > 0
|
||||
w.source = slices.Clone(source)
|
||||
for p := range w.pairsLocked() {
|
||||
if !before[p] {
|
||||
added = true
|
||||
}
|
||||
}
|
||||
return added
|
||||
}
|
||||
|
||||
// pairsLocked is every watched branch as `<repository> <branch>`, the repository empty before the first registration
|
||||
// (the gate's source's branch, of every repository). The caller holds mu.
|
||||
func (w *Watched) pairsLocked() map[string]bool {
|
||||
out := map[string]bool{}
|
||||
if !w.registered {
|
||||
for _, b := range w.source {
|
||||
out[" "+b] = true
|
||||
}
|
||||
return out
|
||||
}
|
||||
for repo, branches := range w.byRepo {
|
||||
for _, b := range branches {
|
||||
out[repo+" "+b] = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Watches says whether a move of branch in repository is one the bridge writes.
|
||||
|
||||
@@ -49,10 +49,12 @@ import (
|
||||
)
|
||||
|
||||
// busConf is the shape of the composed accounts file (mesh-controller internal/broker): one account with JetStream, the
|
||||
// controller's user and the indexer's own principal <node>.<module>.
|
||||
// controller's user and the indexer's own principal <node>.<module>; and the bus's system account, whose disconnect events
|
||||
// tell a restart when the stopped indexer's connections are gone (restartWaits).
|
||||
const busConf = `
|
||||
listen: 127.0.0.1:-1
|
||||
jetstream { store_dir: %q }
|
||||
system_account: SYS
|
||||
accounts {
|
||||
MESH {
|
||||
jetstream: enabled
|
||||
@@ -61,6 +63,11 @@ accounts {
|
||||
{ user: "n1.mesh-delivery-indexer", password: "pw" }
|
||||
]
|
||||
}
|
||||
SYS {
|
||||
users = [
|
||||
{ user: "sys", password: "pw" }
|
||||
]
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@@ -420,12 +427,54 @@ func startIndexerRun(t *testing.T, put func(context.Context, buildLog), before .
|
||||
}
|
||||
start()
|
||||
t.Cleanup(func() { stop() })
|
||||
// restart stops the program and starts it again on the same bus, as the node-engine does with a new build.
|
||||
restart := func() { stop(); start() }
|
||||
// restart stops the program and starts it again on the same bus, as the node-engine does with a new build, once the bus has
|
||||
// closed every connection of the stopped one (restartWaits).
|
||||
gone := restartWaits(t, srv)
|
||||
restart := func() { gone(stop); start() }
|
||||
|
||||
return js, ctx, candidates, modules, restart
|
||||
}
|
||||
|
||||
// restartWaits gives a stop that returns only once the bus has closed every connection the indexer held, heard on the system
|
||||
// account's disconnect events, never by sleeping. A program's stop closes its connections on its side alone; until the bus
|
||||
// has closed them its pulls on a durable still count, and a source-moved said in between is delivered to the stopped
|
||||
// program, unacknowledged for the durable's whole acknowledgement wait, while the branch's durable delivers one message
|
||||
// at a time (design 47 H §743).
|
||||
func restartWaits(t *testing.T, srv *server.Server) func(stop func()) {
|
||||
t.Helper()
|
||||
sys, err := nats.Connect(srv.ClientURL(), nats.UserInfo("sys", "pw"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(sys.Close)
|
||||
return func(stop func()) {
|
||||
t.Helper()
|
||||
disconnects, err := sys.SubscribeSync("$SYS.ACCOUNT.MESH.DISCONNECT")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = disconnects.Unsubscribe() }()
|
||||
if err := sys.Flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
open, err := srv.Connz(&server.ConnzOptions{User: "n1.mesh-delivery-indexer"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stop()
|
||||
for left := open.NumConns; left > 0; {
|
||||
m, err := disconnects.NextMsg(waitBound)
|
||||
if err != nil {
|
||||
t.Fatalf("the bus closed %d of the stopped indexer's %d connections within %s: %v", open.NumConns-left, open.NumConns, waitBound, err)
|
||||
}
|
||||
var ev server.DisconnectEventMsg
|
||||
if json.Unmarshal(m.Data, &ev) == nil && ev.Client.User == "n1.mesh-delivery-indexer" {
|
||||
left--
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The build seats and their holders as the mesh has them (design 47:482-485 and 1583: a language's build module is the
|
||||
// module claiming the seat whose `acts` is step build on that language): the seat definitions as modules/mesh-delivery-contracts/seats/<seat>/
|
||||
// seat.json has them (acts included) and the manifests as the catalog's modules/mesh-build-go and mesh-build-node claim them.
|
||||
@@ -691,6 +740,7 @@ func TestIndexerBuildsARunsCandidateAndDropsItWhenEveryMembersPipelineEnded(t *t
|
||||
func TestIndexerCountsOnlyThePlacedBuildNodesToolchains(t *testing.T) {
|
||||
const goSum = "3b5028f0c1e9bde04dd766abd63eb5931bc516bae695cf46f00abcd8510b0381"
|
||||
var assignments, toolchains jetstream.KeyValue
|
||||
var heard *takeIns
|
||||
place := func(ctx context.Context, t *testing.T, node string, modules ...string) {
|
||||
p := meshmoduleassigner.Assignments{Node: node}
|
||||
for _, m := range modules {
|
||||
@@ -712,6 +762,7 @@ func TestIndexerCountsOnlyThePlacedBuildNodesToolchains(t *testing.T) {
|
||||
assignerLate = up
|
||||
t.Cleanup(func() { assignerLate = nil })
|
||||
js, ctx, _, modules, restart := startIndexerRun(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
|
||||
heard = hearTakeIns(t, js.Conn())
|
||||
registerAvahi(t, ctx, js, "main")
|
||||
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.ToolchainsBucket("mesh-build-go"), History: 1})
|
||||
if err != nil {
|
||||
@@ -762,6 +813,10 @@ func TestIndexerCountsOnlyThePlacedBuildNodesToolchains(t *testing.T) {
|
||||
if !agreed(held) {
|
||||
t.Fatalf("within 20 s avahi has fp2 %q, none2 %q, toolchains %v: want a fingerprint of n1's go1.27 alone", held.Fp2, held.None2, held.Toolchains)
|
||||
}
|
||||
// The module is written before its take-in ends: each restart below waits for the source-moved's acknowledgement, the
|
||||
// take-in's end (design 47 H §743), so the stop cancels no take-in and leaves none unacknowledged ahead of the next one
|
||||
// on the branch's durable, which delivers one message at a time.
|
||||
heard.acked(t, "main")
|
||||
place(ctx, t, "n2", "mesh-build-go")
|
||||
key, _ := index.ToolchainKey("n2", "go")
|
||||
value, err := index.EncodeToolchain(nodebuildgo.Toolchain{Language: "go", Version: "go1.28.1", Recipe: "1", At: ptr(time.Now().Add(time.Second))})
|
||||
@@ -789,6 +844,7 @@ func TestIndexerCountsOnlyThePlacedBuildNodesToolchains(t *testing.T) {
|
||||
if m := read(disagree); !disagree(m) {
|
||||
t.Fatalf("within 20 s of a merge after n2's assignments avahi has fp2 %q, none2 %q: want the builders to disagree", m.Fp2, m.None2)
|
||||
}
|
||||
heard.acked(t, "main")
|
||||
// The view moves only at a take-in (design 47 H-A-49, H-A-103): with n2's assignments taken away, the next take-in agrees.
|
||||
place(ctx, t, "n2")
|
||||
restart()
|
||||
|
||||
@@ -361,11 +361,13 @@ func absent(v []byte) bool { return v == nil }
|
||||
//
|
||||
// - main's first source revision (start true) is taken in with no mover and pins nothing; the next, moving avahi's tree, is one
|
||||
// revision main.11 carrying avahi as its one mover, pinned pipeline.main.11, said once as take-in.taken; the same source-moved
|
||||
// given again says the same from the kept movers and keeps no second revision;
|
||||
// - pipeline-started of main.12 pins it, a restart keeps main.11 while its pipeline runs and removes main.10;
|
||||
// given again says the same from the kept movers and keeps no second revision; main.10, the branch's previous revision, is
|
||||
// pinned pipeline.main.11 in the same write as validate's base (H-A-147);
|
||||
// - pipeline-started of main.12 pins it, a restart keeps main.11 and main.10 while main.11's pipeline runs;
|
||||
// - with the store full, main.13 is held, said once as take-in.pending, written whole in the state held and acknowledged
|
||||
// (H-A-114, H-A-118); nothing takes it in on a
|
||||
// timer: main.11's pipeline-ended frees its pin, the revision goes, the indexer says its room and takes main.13 in on it;
|
||||
// timer: main.11's pipeline-ended frees both its pins, main.10 goes (main.11 stays, main.12's base), the indexer says its
|
||||
// room and takes main.13 in on it;
|
||||
// - beta's take-in whose commit the forge cannot read is held while main's next goes on; the hand skip, with why, is recorded in
|
||||
// the hand-act log before it is asked, and take-in.taken says it skipped;
|
||||
// - a branch watched later is bound on registration-changed and its first revision taken in.
|
||||
@@ -429,6 +431,7 @@ func TestIndexerWhole(t *testing.T) {
|
||||
t.Fatalf("main.11 = %+v (%v), want it kept carrying the movers said", rev, err)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), pinned("pipeline.main.11"))
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 10), pinned("pipeline.main.11")) // validate's base, H-A-147
|
||||
info, err := objects.open(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -445,8 +448,8 @@ func TestIndexerWhole(t *testing.T) {
|
||||
t.Errorf("main.11 was written again (%v): a source-moved given again keeps no second revision", err)
|
||||
}
|
||||
|
||||
// pipeline-started pins its revision; a restart while main.11's pipeline runs keeps it, and the judge at the start removes
|
||||
// main.10, which nothing pins and which is no longer current.
|
||||
// pipeline-started pins its revision; a restart while main.11's pipeline runs keeps it and main.10, its validate base
|
||||
// (H-A-147), which the take-in pinned for it.
|
||||
sayMoved(t, ctx, js, "main", 12, c12, false)
|
||||
heard.next(t, "main", 12)
|
||||
if err := pins.Delete(ctx, index.PinKey("main", 12)); err != nil { // the take-in's own pin, so pipeline-started alone writes it below
|
||||
@@ -454,10 +457,16 @@ func TestIndexerWhole(t *testing.T) {
|
||||
}
|
||||
sayPipeline(t, ctx, js, false, "main", 12)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 12), pinned("pipeline.main.12"))
|
||||
// The restart waits for the take-ins' ends, their source-moved acknowledged (design 47 H §743: main 10, 11, 11 given
|
||||
// again and 12), so the stop cancels none and leaves none unacknowledged ahead of main 13.
|
||||
for range 4 {
|
||||
heard.acked(t, "main")
|
||||
}
|
||||
restart()
|
||||
untilRevisionGone(t, ctx, js, "main.10")
|
||||
if _, _, err := index.ReadRevision(ctx, objects, "main.11"); err != nil {
|
||||
t.Fatalf("main.11 is not kept across a restart while its pipeline runs: %v", err)
|
||||
for _, name := range []string{"main.10", "main.11"} {
|
||||
if _, _, err := index.ReadRevision(ctx, objects, name); err != nil {
|
||||
t.Fatalf("%s is not kept across a restart while main.11's pipeline runs: %v", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// The store full: held, said once, in the state held; taken in on the indexer's own room once a freed pin makes it.
|
||||
@@ -487,7 +496,8 @@ func TestIndexerWhole(t *testing.T) {
|
||||
t.Errorf("main 13 taken in on room said %+v, want avahi at %s", got, c13)
|
||||
}
|
||||
untilKey(t, ctx, held, keys.EscapeName("main"), absent)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), absent)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), pinned("pipeline.main.12")) // main.12's validate base stays (H-A-147)
|
||||
untilRevisionGone(t, ctx, js, "main.10") // the end freed both of main.11's pins
|
||||
if n := len(heard.pending); n != 0 {
|
||||
t.Errorf("take-in.pending said %d more times for one held source revision, want once", n)
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ func (ix *Indexer) viewEntries(ctx context.Context) (map[string]meshcatalog.Cata
|
||||
// KeepBranchEntries keeps entries as the catalog revision of a watched branch taken in from its source revision src (design
|
||||
// 47 H §743, H-A-32): <branch>.<src>, the trunk's included, numbered by the source, and says catalog-revision naming the
|
||||
// branch. movers are the take-in's: kept on the revision (H-A-92), and the revision pinned for the take-in's pipeline,
|
||||
// pipeline.<branch>.<src>, in the same write when there is one (A-449a). A revision already kept under that name is not written
|
||||
// pipeline.<branch>.<src>, in the same write when there is one (A-449a), with the branch's previous revision (H-A-147). A revision already kept under that name is not written
|
||||
// again (read before write, under the branch's one consumer); ErrObjectsFull is a store too full to keep it.
|
||||
func (ix *Indexer) KeepBranchEntries(ctx context.Context, branch string, src int64, entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) error {
|
||||
return ix.keepBranchEntries(ctx, branch, src, entries, movers)
|
||||
@@ -305,6 +305,12 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
return err
|
||||
}
|
||||
rev.Movers = movers
|
||||
// The base of the validate step's case before: the newest revision kept before this write, which the take-in pins for its
|
||||
// pipeline below, named on the revision in this same write (H-A-147, H-A-151, H-A-154); none on the branch's first take-in.
|
||||
pinsBase := len(movers) > 0 && ix.Pins != nil && newest.Revision > 0 && newest.Revision != src
|
||||
if pinsBase {
|
||||
rev.Base = newest.Revision
|
||||
}
|
||||
changed := changedEntries(newest.Entries, rev.Entries)
|
||||
used, capacity, fillErr := ix.Revisions.Fill(ctx)
|
||||
if fillErr == nil && capacity > 0 && used+newBytes(ctx, ix.Revisions, rev, objects) > capacity {
|
||||
@@ -330,6 +336,16 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
ix.logf("pins: the revision %s is not pinned for %s: %v", BranchObject(branch, src), record, err)
|
||||
return fmt.Errorf("the pin of %s: %w", BranchObject(branch, src), err)
|
||||
}
|
||||
// The branch's previous revision, the newest kept before this write, pinned for the same pipeline: it is the base of
|
||||
// the validate step's case before (H-A-108 (3), H-A-147), kept as long as the pipeline that needs it.
|
||||
if pinsBase {
|
||||
if err := ix.pin(ctx, PinKey(branch, rev.Base), record); err != nil {
|
||||
ix.logf("pins: the previous revision %s is not pinned for %s: %v", BranchObject(branch, newest.Revision), record, err)
|
||||
return fmt.Errorf("the pin of %s: %w", BranchObject(branch, newest.Revision), err)
|
||||
}
|
||||
} else {
|
||||
ix.logf("pins: %s has no revision before it on its branch: none is pinned for %s as its validate base", BranchObject(branch, src), record)
|
||||
}
|
||||
}
|
||||
// The revision before this one in its branch ceases to be current (§579): it goes unless a record pins it.
|
||||
if removed, err := ix.judgePinsLocked(ctx); err != nil {
|
||||
|
||||
@@ -72,7 +72,8 @@ func pinObject(key string) (string, bool) {
|
||||
}
|
||||
|
||||
// HeardPins applies one event of the seat mesh-pipeline-runner the indexer's durable consumers gave it (design 47 H §749): a
|
||||
// pipeline-started pins the revision it names under the record `pipeline.<pipeline>`, its pipeline-ended frees it. A body
|
||||
// pipeline-started pins the revision it names under the record `pipeline.<pipeline>`, its pipeline-ended frees it and every
|
||||
// other revision the record pins (H-A-147). A body
|
||||
// that is no such event, or names no revision, changes nothing; an error leaves the event unacknowledged, so the bus gives it
|
||||
// again; one applied twice changes nothing.
|
||||
func (ix *Indexer) HeardPins(ctx context.Context, started *runner.PipelineStarted, ended *runner.PipelineEnded) error {
|
||||
@@ -83,7 +84,34 @@ func (ix *Indexer) HeardPins(ctx context.Context, started *runner.PipelineStarte
|
||||
case started != nil && started.Revision > 0 && started.Pipeline != "":
|
||||
return ix.pin(ctx, PinKey(started.Branch, started.Revision), PipelineRecord(started.Pipeline))
|
||||
case ended != nil && ended.Revision > 0 && ended.Pipeline != "":
|
||||
return ix.unpin(ctx, PinKey(ended.Branch, ended.Revision), PipelineRecord(ended.Pipeline))
|
||||
record := PipelineRecord(ended.Pipeline)
|
||||
if err := ix.unpin(ctx, PinKey(ended.Branch, ended.Revision), record); err != nil {
|
||||
return err
|
||||
}
|
||||
return ix.unpinElsewhere(ctx, record)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// unpinElsewhere frees a record on every other key that lists it: the branch's previous revision the take-in pinned for the
|
||||
// same pipeline (H-A-147), which the pipeline-ended does not name.
|
||||
func (ix *Indexer) unpinElsewhere(ctx context.Context, record string) error {
|
||||
pinKeys, err := ix.Pins.Keys(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, k := range pinKeys {
|
||||
v, _, found, err := ix.Pins.Get(ctx, k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var pv PinValue
|
||||
if !found || json.Unmarshal(v, &pv) != nil || !slices.Contains(pv.Records, record) {
|
||||
continue
|
||||
}
|
||||
if err := ix.unpin(ctx, k, record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package index
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -102,3 +103,73 @@ func mustRecords(t *testing.T, v []byte) []string {
|
||||
slices.Sort(pv.Records)
|
||||
return pv.Records
|
||||
}
|
||||
|
||||
// H-A-147 (§743, §749, H-A-108 (3)): a take-in with a mover pins, in its write, the branch's previous revision (the newest kept
|
||||
// before the write) for the same pipeline record as its own, so the validate step's case before can read it while the pipeline
|
||||
// runs, and names it as its base on the revision it writes (H-A-151, H-A-154); a take-in with no revision before it pins only
|
||||
// its own and names no base; the pipeline's end frees both.
|
||||
func TestATakeInPinsTheBranchsPreviousRevisionForItsPipeline(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
reader := meshcatalog.CatalogEntry{Module: "reader", Repository: "novox/r", Manifest: map[string]any{}}
|
||||
mover := []meshcatalog.TakeInEntry{{Module: "reader", Commit: "c", Fingerprint: "f", Repository: "novox/r"}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
before []int64 // sources taken in with no mover before the take-in of source 5
|
||||
whileRuns []string
|
||||
afterTheEnd []string
|
||||
base int64 // the base main.5 names (H-A-154)
|
||||
}{
|
||||
{name: "the previous revision kept and pinned", before: []int64{3, 4}, whileRuns: []string{"main.4", "main.5"}, afterTheEnd: []string{"main.5"}, base: 4},
|
||||
{name: "the newest kept before, whatever its number", before: []int64{2}, whileRuns: []string{"main.2", "main.5"}, afterTheEnd: []string{"main.5"}, base: 2},
|
||||
{name: "no revision before it pins only its own", whileRuns: []string{"main.5"}, afterTheEnd: []string{"main.5"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Pins: newMem(), Findings: newFindings(),
|
||||
Now: func() time.Time { return time.Date(2026, 11, 20, 16, 0, 0, 0, time.UTC) },
|
||||
PinsPending: func(context.Context) (uint64, error) { return 0, nil }}
|
||||
keep := func(source int64, movers []meshcatalog.TakeInEntry) {
|
||||
t.Helper()
|
||||
e := reader
|
||||
e.Commit = fmt.Sprintf("c%d", source)
|
||||
if err := ix.KeepBranchEntries(ctx, "main", source, map[string]meshcatalog.CatalogEntry{"reader": e}, movers); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
kept := func() []string {
|
||||
n, _ := ix.Revisions.Names(ctx)
|
||||
n = slices.DeleteFunc(n, func(s string) bool { _, _, ok := RevisionGroup(s); return !ok })
|
||||
slices.Sort(n)
|
||||
return n
|
||||
}
|
||||
for _, s := range tc.before {
|
||||
keep(s, nil)
|
||||
}
|
||||
keep(5, mover)
|
||||
if rev, _, err := ReadRevision(ctx, ix.Revisions, "main.5"); err != nil || rev.Base != tc.base {
|
||||
t.Errorf("main.5 names the base %d (%v), want %d, the revision its take-in pinned (H-A-154)", rev.Base, err, tc.base)
|
||||
}
|
||||
if got := kept(); !slices.Equal(got, tc.whileRuns) {
|
||||
t.Errorf("while the pipeline runs: kept %v, want %v", got, tc.whileRuns)
|
||||
}
|
||||
for _, k := range tc.whileRuns {
|
||||
if v, _, _, _ := ix.Pins.Get(ctx, k); !slices.Equal(mustRecords(t, v), []string{"pipeline.main.5"}) {
|
||||
t.Errorf("the pin of %s holds %s, want the pipeline's record", k, v)
|
||||
}
|
||||
}
|
||||
if err := ix.HeardPins(ctx, nil, &runner.PipelineEnded{Branch: "main", Pipeline: "main.5", Revision: 5}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ix.JudgePins(ctx)
|
||||
if got := kept(); !slices.Equal(got, tc.afterTheEnd) {
|
||||
t.Errorf("after the pipeline's end: kept %v, want %v", got, tc.afterTheEnd)
|
||||
}
|
||||
if keys, _ := ix.Pins.Keys(ctx); len(keys) > 0 {
|
||||
for _, k := range keys {
|
||||
if v, _, _, _ := ix.Pins.Get(ctx, k); len(mustRecords(t, v)) > 0 {
|
||||
t.Errorf("after the pipeline's end the pin of %s holds %s, want none", k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,14 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[
|
||||
build := seat.StepResult{Step: seat.StepResultStepBuild, Module: m.Module, Status: seat.StepResultStatusRequired, Fingerprint: m.Fingerprint,
|
||||
Seat: builds.Seat, Outcome: seat.StepResultOutcomeRunning, Started: &now, Ask: AskID(startOf(p, now), p.Pipeline, m.Module, "", seat.StepResultStepBuild)}
|
||||
steps = append(steps, build)
|
||||
// A run on request's build step ask names no source (the seat mesh-builds' contract; H-A-162): its candidate's
|
||||
// fingerprints are never in the builder's picture of the branch, so it waits for no revision there.
|
||||
source := p.Source
|
||||
if p.Run != "" {
|
||||
source = 0
|
||||
}
|
||||
asks = append(asks, Asked{Seat: builds.Seat, ID: build.Ask, Commit: m.Commit, Ask: builds.StepRun{Pipeline: p.Pipeline, Step: builds.StepRunStepBuild, Branch: p.Branch,
|
||||
Revision: p.Revision, Source: p.Source, Entries: []builds.BuildEntry{{Module: m.Module, Commit: m.Commit, Fingerprint: m.Fingerprint}}}})
|
||||
Revision: p.Revision, Source: source, Entries: []builds.BuildEntry{{Module: m.Module, Commit: m.Commit, Fingerprint: m.Fingerprint}}}})
|
||||
for _, a := range arts {
|
||||
name := a.Ref
|
||||
if _, after, ok := strings.Cut(a.Ref, ":"); ok {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
)
|
||||
@@ -97,6 +98,19 @@ func TestRunOnRequest(t *testing.T) {
|
||||
if ids, _ := s.UnplacedRuns(); len(ids) != 0 {
|
||||
t.Errorf("a placed run is still unplaced: %v", ids)
|
||||
}
|
||||
// H-A-162: a run's build step asks name no source, as the seat mesh-builds' contract says of a run on request.
|
||||
builtAsks := 0
|
||||
for _, x := range asks.asks {
|
||||
if r, ok := x.(builds.StepRun); ok {
|
||||
builtAsks++
|
||||
if r.Source != 0 {
|
||||
t.Errorf("the run's build step ask names source %d, want none", r.Source)
|
||||
}
|
||||
}
|
||||
}
|
||||
if builtAsks == 0 {
|
||||
t.Errorf("the run asked no build step: %v", asks.asks)
|
||||
}
|
||||
if n, _ := s.PlaceRun(ev, Half{Revision: 12, Entries: cand}, base); n != 0 {
|
||||
t.Errorf("the revision heard again placed %d", n)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// at a commit of the repository that builds it. The indexer reads it so at each trunk merge (its packages state's series
|
||||
// keys), and the checker so at a delivery group member's head for a package new in the group, so the judge is handed one
|
||||
// name for each package whoever reads it (mesh-sdk composer.Request.Packages).
|
||||
// Design 47 H1, proof 2: this comment is the mesh-delivery-sdk half of a two-module change its pipeline delivers.
|
||||
package packagename
|
||||
|
||||
import (
|
||||
|
||||
@@ -647,19 +647,32 @@ func aRuntimeDeniedTheMarksHearsNoMarkedCall(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asker, askerRefused := bus.dial("a.asker")
|
||||
// The caller-named subject is process.Call's first: mesh.mod.<module>.call.<tool>.<caller's token>.
|
||||
for _, subject := range []string{"mesh.mod.shell.tool.execute", "mesh.mod.shell.call.execute.asker~a", "mesh.mod.shell.tool.read"} {
|
||||
// The caller-named subject is process.Call's first: mesh.mod.<module>.call.<tool>.<caller's token>, the token the
|
||||
// composer grants (buscompose.CallerToken: `a~asker` for the user a.asker).
|
||||
for _, subject := range []string{"mesh.mod.shell.tool.execute", "mesh.mod.shell.call.execute." + buscompose.CallerToken("a.asker"), "mesh.mod.shell.tool.read"} {
|
||||
if err := asker.Publish(subject, []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// The server says a refused publish asynchronously, in the order of the publishes: a probe the asker may not publish
|
||||
// (another caller's token) is refused after every refusal of the calls above, so waiting for it waits on what is asserted.
|
||||
const probe = "mesh.mod.shell.call.execute.a~someone"
|
||||
if err := asker.Publish(probe, []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := asker.Flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case e := <-askerRefused:
|
||||
t.Fatalf("the asker may not call: %s", e)
|
||||
default:
|
||||
for probed := false; !probed; {
|
||||
select {
|
||||
case e := <-askerRefused:
|
||||
if !strings.Contains(e, `"`+probe+`"`) {
|
||||
t.Fatalf("the asker may not call: %s", e)
|
||||
}
|
||||
probed = true
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the probe's refusal never came, so the calls' refusals are not known")
|
||||
}
|
||||
}
|
||||
select {
|
||||
case m := <-heard:
|
||||
|
||||
@@ -110,6 +110,34 @@ func (c creating) RaiseMaxBytes(stream string, to int64) (int64, bool, error) {
|
||||
return from, true, nil
|
||||
}
|
||||
|
||||
// SourceFilter brings the filter subject of a held stream's source from `source` to `filter` and changes nothing else
|
||||
// (design 47 H H-A-145): it reads the stream's configuration and updates with the rest as it was, so its messages stay. A
|
||||
// stream with no source from `source`, or one already at `filter`, is left as it is.
|
||||
func (c creating) SourceFilter(stream, source, filter string) (string, bool, error) {
|
||||
ctx, cancel := context.WithTimeout(c.ctx, requestWithin)
|
||||
defer cancel()
|
||||
s, err := c.js.Stream(ctx, stream)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
cfg := s.CachedInfo().Config
|
||||
i := slices.IndexFunc(cfg.Sources, func(src *jetstream.StreamSource) bool { return src != nil && src.Name == source })
|
||||
if i < 0 || cfg.Sources[i].FilterSubject == filter {
|
||||
if i < 0 {
|
||||
return "", false, nil
|
||||
}
|
||||
return cfg.Sources[i].FilterSubject, false, nil
|
||||
}
|
||||
from := cfg.Sources[i].FilterSubject
|
||||
src := *cfg.Sources[i]
|
||||
src.FilterSubject = filter
|
||||
cfg.Sources[i] = &src
|
||||
if _, err := c.js.UpdateStream(ctx, cfg); err != nil {
|
||||
return from, false, err
|
||||
}
|
||||
return from, true, nil
|
||||
}
|
||||
|
||||
// AddFilters adds filter subjects to a held consumer and changes nothing else.
|
||||
func (c creating) AddFilters(stream, name string, add []string) error {
|
||||
ctx, cancel := context.WithTimeout(c.ctx, requestWithin)
|
||||
|
||||
@@ -147,7 +147,10 @@ func TestTheGrantsPartWhole(t *testing.T) {
|
||||
consumers := []any{}
|
||||
names := st.ConsumerNames(ctx)
|
||||
for name := range names.Name() {
|
||||
c, _ := st.Consumer(ctx, name)
|
||||
c, err := st.Consumer(ctx, name)
|
||||
if err != nil {
|
||||
continue // deleted between the listing and its read: the bus module's tool lists what it can read
|
||||
}
|
||||
cfg := c.CachedInfo().Config
|
||||
consumers = append(consumers, map[string]any{"name": name, "filters": cfg.FilterSubjects, "max_deliver": cfg.MaxDeliver})
|
||||
}
|
||||
@@ -611,6 +614,35 @@ func TestTheGrantsPartWhole(t *testing.T) {
|
||||
if again, _ := stream.Info(ctx); !slices.Equal(again.Config.Subjects, []string{"a.>", "b.>"}) {
|
||||
t.Errorf("subjects after adding a held one: %v", again.Config.Subjects)
|
||||
}
|
||||
// A kept stream's source filter is brought to its definition's in place: the stream is not made again, its settings
|
||||
// stay, and an equal filter or a source of another stream changes nothing (design 47 H H-A-145, §746).
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "KEPTSRC", Subjects: []string{"ev.>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kept, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "KEPT", MaxAge: time.Hour,
|
||||
Sources: []*jetstream.StreamSource{{Name: "KEPTSRC", FilterSubject: "ev.ended.*.*.*"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
keptBefore, _ := kept.Info(ctx)
|
||||
for _, row := range []struct {
|
||||
source, filter, from, holds string
|
||||
changed bool
|
||||
}{
|
||||
{"KEPTSRC", "ev.ended.*.*", "ev.ended.*.*.*", "ev.ended.*.*", true},
|
||||
{"KEPTSRC", "ev.ended.*.*", "ev.ended.*.*", "ev.ended.*.*", false},
|
||||
{"OTHER", "ev.other", "", "ev.ended.*.*", false},
|
||||
} {
|
||||
from, changed, err := c.SourceFilter("KEPT", row.source, row.filter)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now, _ := kept.Info(ctx)
|
||||
if from != row.from || changed != row.changed || len(now.Config.Sources) != 1 || now.Config.Sources[0].FilterSubject != row.holds ||
|
||||
now.Config.MaxAge != keptBefore.Config.MaxAge || !now.Created.Equal(keptBefore.Created) {
|
||||
t.Errorf("source %s to %s: from %q changed %v, config %+v created %v", row.source, row.filter, from, changed, now.Config, now.Created)
|
||||
}
|
||||
}
|
||||
// The named asks' purge takes one subject's messages and no other's, and a named worker's delete is said done also
|
||||
// where the bus holds none (design 47 G §544).
|
||||
for _, subj := range []string{"b.one", "b.two"} {
|
||||
|
||||
@@ -202,6 +202,9 @@ func (b *fakeBus) AddSubjects(stream string, add []string) error {
|
||||
return errors.New("stream not found")
|
||||
}
|
||||
|
||||
// SourceFilter is the bus's update of a held stream's source filter: the fake holds no sources, so nothing changes.
|
||||
func (b *fakeBus) SourceFilter(string, string, string) (string, bool, error) { return "", false, nil }
|
||||
|
||||
// RaiseMaxBytes is the bus's raise of a held stream's size cap: only to a larger cap, an unbounded stream and every other
|
||||
// setting kept.
|
||||
func (b *fakeBus) RaiseMaxBytes(stream string, to int64) (int64, bool, error) {
|
||||
@@ -684,10 +687,10 @@ func TestGrants(t *testing.T) {
|
||||
if n := strings.Count(string(src), "CreateStream"); (path == createOnly && n != 1) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds CreateStream %d times: only create.go creates, once", path, n)
|
||||
}
|
||||
// The two updates of a stream: adding subjects to a held one (the operator, 2026-11-05) and raising its size cap
|
||||
// (2026-11-09), both in create.go.
|
||||
if n := strings.Count(string(src), "UpdateStream("); (path == createOnly && n != 2) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds UpdateStream %d times: only create.go updates a stream, twice, to add subjects and to raise a size cap", path, n)
|
||||
// The three updates of a stream: adding subjects to a held one (the operator, 2026-11-05), raising its size cap
|
||||
// (2026-11-09) and bringing a kept stream's source filter to its definition's (design 47 H H-A-145), all in create.go.
|
||||
if n := strings.Count(string(src), "UpdateStream("); (path == createOnly && n != 3) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds UpdateStream %d times: only create.go updates a stream, three times, to add subjects, to raise a size cap and to bring a kept stream's source filter", path, n)
|
||||
}
|
||||
// The one object bucket: the part's own, of the user list sealed to the bus node, in sealed.go (ADR 0547 clause 7).
|
||||
if path == sealedOnly {
|
||||
|
||||
@@ -1765,7 +1765,8 @@ const WatchmanModule = "mesh-delivery-watchman"
|
||||
// 2026-10-26 08:54): its create, and its information to read back what it holds. Each by its own name: a name that
|
||||
// is not one plain subject token is left out, since a wildcard there would be every stream. Its update is granted for the one
|
||||
// acts the part does on a held stream: adding the subjects a manifest's new events need (grants.Creator.AddSubjects) and
|
||||
// raising its size cap to the manifest's when larger (grants.Creator.RaiseMaxBytes; the operator, 2026-11-09); it never
|
||||
// raising its size cap to the manifest's when larger (grants.Creator.RaiseMaxBytes; the operator, 2026-11-09), and bringing
|
||||
// a kept stream's source filter to its definition's (grants.Creator.SourceFilter; design 47 H H-A-145); it never
|
||||
// removes a subject, lowers a limit or recreates the stream, and never deletes or purges one.
|
||||
func CreateStreamGrants(streams []string) []string {
|
||||
var out []string
|
||||
|
||||
@@ -21,6 +21,9 @@ func (c *askCreator) AddSubjects(string, []string) error { return nil }
|
||||
func (c *askCreator) RaiseMaxBytes(string, int64) (int64, bool, error) {
|
||||
return 0, false, nil
|
||||
}
|
||||
func (c *askCreator) SourceFilter(string, string, string) (string, bool, error) {
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
// A seat whose queues came with G (mesh-builds) gets its work-queue ask stream from the seat list, as the controller made one for
|
||||
// every seat before G; a seat that accepts nothing gets none, and a stream the bus holds is never made again (lead-47, 2026-11-15).
|
||||
|
||||
@@ -69,6 +69,10 @@ type Creator interface {
|
||||
// changes nothing else (the operator, 2026-11-09 09:07: "raise only"). It answers the cap it held and whether it
|
||||
// raised; a cap that is larger or equal, or an unbounded stream, is left as it is. It never lowers any limit.
|
||||
RaiseMaxBytes(stream string, to int64) (from int64, raised bool, err error)
|
||||
// SourceFilter brings the filter subject of a held stream's source from the stream `source` to `filter`, keeping its
|
||||
// messages and every other setting, the stream not made again (design 47 H H-A-145). It answers the filter it held and
|
||||
// whether it changed; a stream with no source from `source` is left as it is.
|
||||
SourceFilter(stream, source, filter string) (from string, changed bool, err error)
|
||||
}
|
||||
|
||||
// Raise is one held stream's size cap raised to the manifest's, said in the event and the journal.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"mesh-grants/internal/buscompose"
|
||||
)
|
||||
|
||||
@@ -39,3 +42,70 @@ func TestTheGrantsAccountMayCreateEachKeptEventStream(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// sourcing is a Creator holding kept streams by their source filter and message count: SourceFilter updates a held one in
|
||||
// place, so its messages stay; CreateDeclared makes one the bus lacks.
|
||||
type sourcing struct {
|
||||
Creator
|
||||
filters map[string]string // by stream, its source filter from EVENTS
|
||||
messages map[string]int
|
||||
made []string
|
||||
}
|
||||
|
||||
func (s *sourcing) SourceFilter(stream, source, filter string) (string, bool, error) {
|
||||
from, ok := s.filters[stream]
|
||||
if !ok || source != buscompose.EventsStream || from == filter {
|
||||
return from, false, nil
|
||||
}
|
||||
s.filters[stream] = filter
|
||||
return from, true, nil
|
||||
}
|
||||
|
||||
func (s *sourcing) CreateDeclared(cfg jetstream.StreamConfig) error {
|
||||
s.made = append(s.made, cfg.Name)
|
||||
s.filters[cfg.Name], s.messages[cfg.Name] = cfg.Sources[0].FilterSubject, 0
|
||||
return nil
|
||||
}
|
||||
|
||||
// H-A-145 (design 47 H §746): a held kept stream whose source filter the definition changed is brought to the definition's
|
||||
// filter in place, its messages kept and the change said with both filters; one at the definition's filter is untouched; one
|
||||
// the bus lacks is made.
|
||||
func TestAKeptStreamFollowsItsDefinitionsSourceFilter(t *testing.T) {
|
||||
const ended = "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.*.*"
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
held string // the held stream's source filter; "" for a stream the bus lacks
|
||||
made bool
|
||||
moved string
|
||||
filter string
|
||||
messages, keptMsgs int
|
||||
}{
|
||||
{name: "held at the definition's filter: untouched", held: ended, filter: ended, messages: 604, keptMsgs: 604},
|
||||
{name: "held at an earlier filter: brought to the definition's, messages kept", held: ended + ".*", filter: ended, messages: 604, keptMsgs: 604,
|
||||
moved: "SEAT_mesh-pipeline-runner_pipeline-ended: source filter " + ended + ".* brought to " + ended + ", its messages kept"},
|
||||
{name: "not held: made", made: true, filter: ended},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
k := buscompose.KeptEvent{Seat: "mesh-pipeline-runner", Event: "pipeline-ended", Stream: "SEAT_mesh-pipeline-runner_pipeline-ended", Filter: ended, MaxAgeDays: 90, MaxMiB: 192}
|
||||
c := &sourcing{filters: map[string]string{}, messages: map[string]int{}}
|
||||
held := map[string]Limits{}
|
||||
if row.held != "" {
|
||||
c.filters[k.Stream], c.messages[k.Stream] = row.held, row.messages
|
||||
held[k.Stream] = Limits{}
|
||||
}
|
||||
made, moved, notMade := createKept(c, &creations{}, []buscompose.KeptEvent{k}, held, false)
|
||||
if len(notMade) != 0 {
|
||||
t.Fatalf("not made: %v", notMade)
|
||||
}
|
||||
if (len(made) == 1) != row.made || len(c.made) != len(made) {
|
||||
t.Errorf("made %v (bus %v), want made %v", made, c.made, row.made)
|
||||
}
|
||||
if got := strings.Join(moved, "; "); got != row.moved {
|
||||
t.Errorf("moved %q, want %q", got, row.moved)
|
||||
}
|
||||
if c.filters[k.Stream] != row.filter || c.messages[k.Stream] != row.keptMsgs {
|
||||
t.Errorf("the stream holds filter %q and %d messages, want %q and %d", c.filters[k.Stream], c.messages[k.Stream], row.filter, row.keptMsgs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,14 +65,24 @@ func keptOutOfHearing(kept []buscompose.KeptEvent, watches []buscompose.Seat, co
|
||||
}
|
||||
|
||||
// createKept makes each kept event's stream the bus lacks, from the shared events stream's messages of its subject, and
|
||||
// says what it made. A stream the bus holds is left as it is; one made at this seat list and gone since is made again only on
|
||||
// a hand assert (the same rule as a manifest's streams: made once per definition). held is what the bus held at this pass.
|
||||
func createKept(c Creator, done *creations, kept []buscompose.KeptEvent, held map[string]Limits, force bool) (made, notMade []string) {
|
||||
// says what it made. A stream the bus holds keeps its messages and is not made again; its source filter is brought to the
|
||||
// definition's in place when the definition changed the event's subject (design 47 H H-A-145, §746: the runner's
|
||||
// pipeline-ended moved from three parts to two and its kept stream took nothing in), said in moved with the held and the
|
||||
// composed filter. One made at this seat list and gone since is made again only on a hand assert (the same rule as a
|
||||
// manifest's streams: made once per definition). held is what the bus held at this pass.
|
||||
func createKept(c Creator, done *creations, kept []buscompose.KeptEvent, held map[string]Limits, force bool) (made, moved, notMade []string) {
|
||||
for _, k := range kept {
|
||||
cfg := k.StreamConfig()
|
||||
if _, ok := held[k.Stream]; ok {
|
||||
from, changed, err := c.SourceFilter(k.Stream, buscompose.EventsStream, k.Filter)
|
||||
switch {
|
||||
case err != nil:
|
||||
notMade = append(notMade, k.Stream+": its source filter is not brought to "+k.Filter+": "+err.Error()+" (tried again at the next pass)")
|
||||
case changed:
|
||||
moved = append(moved, k.Stream+": source filter "+from+" brought to "+k.Filter+", its messages kept")
|
||||
}
|
||||
continue
|
||||
}
|
||||
cfg := k.StreamConfig()
|
||||
digest := fmt.Sprintf("%v", cfg.Sources[0].FilterSubject) + fmt.Sprint(k.Last, k.MaxAgeDays, k.MaxMiB)
|
||||
if !force && done.madeAt(k.Stream) == digest {
|
||||
notMade = append(notMade, k.Stream+": made at this definition and gone since; grants_assert makes it again")
|
||||
@@ -87,7 +97,7 @@ func createKept(c Creator, done *creations, kept []buscompose.KeptEvent, held ma
|
||||
notMade = append(notMade, k.Stream+": "+err.Error()+" (tried again at the next event)")
|
||||
}
|
||||
}
|
||||
return made, notMade
|
||||
return made, moved, notMade
|
||||
}
|
||||
|
||||
// eventSubjectsOf is, by seat, each event's subject pattern (`running.<node>.<module>`) of the events whose subject carries
|
||||
|
||||
@@ -565,11 +565,21 @@ func (p *Part) Compose() Result {
|
||||
}
|
||||
forced := ask.Assert
|
||||
if p.Create != nil && heldErr == nil {
|
||||
made, notMade := createKept(p.Create, &p.made, in.Kept, held, forced != "")
|
||||
made, moved, notMade := createKept(p.Create, &p.made, in.Kept, held, forced != "")
|
||||
if len(made) > 0 {
|
||||
res.Asserted = append(res.Asserted, "the seats' kept events: created "+strings.Join(made, ", "))
|
||||
p.say(&res, EventAsserted, map[string]any{"module": Module, "created": made})
|
||||
}
|
||||
for _, m := range moved {
|
||||
// Said in the journal with both filters (H-A-145).
|
||||
res.Asserted = append(res.Asserted, "the seats' kept events: "+m)
|
||||
if p.Logf != nil {
|
||||
p.Logf("kept stream %s", m)
|
||||
}
|
||||
}
|
||||
if len(moved) > 0 {
|
||||
p.say(&res, EventAsserted, map[string]any{"module": Module, "source-filters": moved})
|
||||
}
|
||||
for _, why := range notMade {
|
||||
res.NotAsserted = append(res.NotAsserted, "kept event "+why)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user