assigner: match a trunk build's release by the source its fingerprint was built at

namedBuild matched a trunk entry's version-released by the kept assignment graph's source revision, so after any merge
that does not rebuild a module its wants and candidates carry no version and no parts. It now matches by the entry's
fp-src, the source revision its fingerprint was built at, which is version-released.source for that build; an entry
whose release is not heard, or that names no fp-src, is said once, naming the module, the fingerprint and the source.

Builds: design 47 G A-419, A-96, A-67
This commit is contained in:
2026-11-15 03:15:58 +01:00
parent 2beb39c371
commit ce839ba602
5 changed files with 59 additions and 18 deletions
@@ -2,7 +2,9 @@ package main
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
@@ -54,9 +56,10 @@ func TestAVersionReleasedHeardNamesItsVersionAndPartsBySource(t *testing.T) {
}
}
// Design 47 G §379, A-96: the trunk's entry takes its version and parts from the version-released of the kept assignment graph
// revision's source; a kept build from its end; no revision kept, or another fingerprint, names none.
func TestATrunkEntryTakesItsVersionFromTheReleaseOfTheKeptRevisionsSource(t *testing.T) {
// Design 47 G §379, A-96, A-419: the trunk's entry takes its version and parts from the version-released of the source its
// fingerprint was built at (its fp-src), whatever source the kept assignment graph revision is at; a kept build from its end; no
// revision kept, another fingerprint, an fp-src with no release or none names none, and an unheard release is said once.
func TestATrunkEntryTakesItsVersionFromTheReleaseOfItsFingerprintsSource(t *testing.T) {
w := newWorld()
raw, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "mail", Source: 7, Version: "1.2.3", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "image", Digest: "sha256:9"}}})
if err := w.released.put(raw); err != nil {
@@ -66,8 +69,9 @@ func TestATrunkEntryTakesItsVersionFromTheReleaseOfTheKeptRevisionsSource(t *tes
if err := w.ends.put(endRaw); err != nil {
t.Fatal(err)
}
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 7}}
named := p.namedBuild("mail", "t")
var logs []string
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 7}, logf: func(f string, a ...any) { logs = append(logs, fmt.Sprintf(f, a...)) }}
named := p.namedBuild("mail", "t", 7)
if k, ok := named("t"); !ok || k.Version != "1.2.3" || k.Parts["mail:image"] != "sha256:9" || k.KeptOn != "" {
t.Errorf("trunk entry = %+v, %v", k, ok)
}
@@ -77,12 +81,22 @@ func TestATrunkEntryTakesItsVersionFromTheReleaseOfTheKeptRevisionsSource(t *tes
if _, ok := named("other"); ok {
t.Error("another fingerprint names a release")
}
p.graph.source = 8
if _, ok := named("t"); ok {
t.Error("a source with no release names a version")
p.graph.source = 8 // a later merge that did not rebuild mail
if k, ok := named("t"); !ok || k.Version != "1.2.3" {
t.Errorf("after a later merge the trunk entry = %+v, %v; want the release of its fingerprint's source", k, ok)
}
if _, ok := p.namedBuild("mail", "t", 8)("t"); ok {
t.Error("an fp-src with no release names a version")
}
_, _ = p.namedBuild("mail", "t", 8)("t")
if _, ok := p.namedBuild("mail", "t", 0)("t"); ok {
t.Error("an entry naming no fp-src names a version")
}
if len(logs) != 2 || !strings.Contains(logs[0], "the release of mail at fingerprint t is not heard: no version-released of it from source 8") || !strings.Contains(logs[1], "fp-src") {
t.Errorf("logs = %q, want each unheard release said once, naming the module, the fingerprint and the source", logs)
}
p.graph.ok = false
if _, ok := p.namedBuild("mail", "t")("t"); ok {
if _, ok := p.namedBuild("mail", "t", 7)("t"); ok {
t.Error("no revision kept names a release")
}
}
@@ -28,12 +28,13 @@ func (p *passer) addedOf(node string, laid *mma.Assignments, current map[string]
if p.ends.following() {
branch = p.ends.branchOf(module, placed[module])
}
fp := p.w.trunkOf(branch)[module].Fp2
entry := p.w.trunkOf(branch)[module]
fp := entry.Fp2
if fp == "" {
p.skippedAdd(node, module, "", "the branch "+branch+" names no fingerprint of it")
continue
}
k, ok := p.namedBuild(module, fp)(fp)
k, ok := p.namedBuild(module, fp, entry.FpSrc)(fp)
if !ok {
p.skippedAdd(node, module, fp, "no version-released of it is heard for that fingerprint, so the candidate carries no version and no parts")
continue
@@ -17,7 +17,7 @@ import (
func TestACandidateThatAddsAModuleCarriesItsParts(t *testing.T) {
w := newWorld()
for _, m := range []string{"mail", "web", "db"} {
w.putModule("main", m, meshcatalog.ModulesByModuleValue{Fp2: "fp-" + m}, graph.Node{}, nil)
w.putModule("main", m, meshcatalog.ModulesByModuleValue{Fp2: "fp-" + m, FpSrc: 7}, graph.Node{}, nil)
}
w.first = "main"
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "mail", Source: 7, Version: "1.2.3", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "image", Digest: "sha256:9"}}})
@@ -29,7 +29,7 @@ func TestACandidateThatAddsAModuleCarriesItsParts(t *testing.T) {
t.Fatal(err)
}
w.put(buckets.Wants(), "want.ace.web", []byte(`{}`))
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 7}}
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 9}} // a later merge: the release is matched by fp-src (A-419)
laid := &mma.Assignments{Node: "ace", Modules: []mma.PlacedModule{{Module: "mail"}, {Module: "web"}, {Module: "db"}, {Module: "old"}}}
current := map[string]mma.Assignments{"ace": {Node: "ace", Modules: []mma.PlacedModule{{Module: "old"}}}}
c := p.candidateOf("p1", "ace", laid, current)
@@ -178,8 +178,9 @@ func (p *passer) sayWanted(node, module, fp string, removed bool) {
// namedBuild answers what a want of module at fp names of its build (design 47 G §379, §526, A-96): a kept build's or another watched
// branch's parts and keeping node from the builder's `build.ended`; for the trunk's entry (fp is the module's, trunkFP), the released
// version and the parts of the `version-released` whose source is the one the kept assignment graph revision was computed from (A-67).
func (p *passer) namedBuild(module, trunkFP string) func(fp string) (assign.KeptBuild, bool) {
// version and the parts of the `version-released` of the module whose source is the one its fingerprint was built at, the entry's
// `fp-src` (A-419: a merge that does not rebuild the module leaves it so). A trunk entry whose release is not heard is said, once.
func (p *passer) namedBuild(module, trunkFP string, fpSrc int64) func(fp string) (assign.KeptBuild, bool) {
return func(fp string) (assign.KeptBuild, bool) {
if k, ok := p.w.ends.partsOf(module, fp); ok {
return k, true
@@ -187,6 +188,30 @@ func (p *passer) namedBuild(module, trunkFP string) func(fp string) (assign.Kept
if fp != trunkFP || p.graph == nil || !p.graph.ok {
return assign.KeptBuild{}, false
}
return p.w.released.of(module, p.graph.source)
if fpSrc == 0 {
p.unheardRelease(module, fp, "its catalog entry names no source revision its fingerprint was built at (fp-src)")
return assign.KeptBuild{}, false
}
k, ok := p.w.released.of(module, fpSrc)
if !ok {
p.unheardRelease(module, fp, fmt.Sprintf("no version-released of it from source %d, the one its fingerprint was built at, is heard", fpSrc))
}
return k, ok
}
}
// unheardRelease says once per module, fingerprint and why that a trunk entry's release is not heard, so its wants and candidates
// carry no version and no parts (design 47 G A-419).
func (p *passer) unheardRelease(module, fp, why string) {
key := "release " + module + "@" + fp + ": " + why
if p.skipped[key] {
return
}
if p.skipped == nil {
p.skipped = map[string]bool{}
}
p.skipped[key] = true
if p.logf != nil {
p.logf("the release of %s at fingerprint %s is not heard: %s; its wants and candidates carry no version and no parts", module, fp, why)
}
}
@@ -47,7 +47,8 @@ type passer struct {
// pass says a condition once and a restart says it again (the router keeps one per key).
say func(oc.Condition) error
said map[string]bool
// skipped are the added modules whose absence from a candidate's added was said (skippedAdd), once each.
// skipped are the added modules whose absence from a candidate's added was said (skippedAdd), and the trunk entries whose
// release is not heard (unheardRelease), once each.
skipped map[string]bool
// findings is the assigner's findings bucket (its said conditions, ADR 0564 §2).
findings assign.Findings
@@ -350,7 +351,7 @@ func (p *passer) wants(ctx context.Context) {
held, _ := mwc.HeldKey(name, fp)
grant, _ := grantsstate.PartGrantKey(name, fp)
hold, _ := asks.HoldAskKey(name, fp)
m.KeptBuilds = p.namedBuild(name, m.FP)
m.KeptBuilds = p.namedBuild(name, m.FP, trunk[name].FpSrc)
m.Released = p.answeredWith(hold, "release")
m.Kept = p.answeredWith(hold, "keep")
m.Built, m.Held, m.Granted = p.w.built(name, fp), p.w.has(buckets.Wants(), held) && !m.Released, p.w.has(grants, grant)