diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended.go index 5c09da9d..90fac974 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended.go @@ -4,6 +4,9 @@ import ( "context" "encoding/json" "fmt" + "maps" + "strconv" + "strings" "sync" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" @@ -116,6 +119,41 @@ func (r *releasedVersions) put(data []byte) error { return nil } +// withParts is the version of module whose release named exactly parts (`:` -> digest), the newest such when +// more than one did; false when none did or parts is empty (design 47 G A-421). +func (r *releasedVersions) withParts(module string, parts map[string]string) (assign.KeptBuild, bool) { + if len(parts) == 0 { + return assign.KeptBuild{}, false + } + r.mu.Lock() + defer r.mu.Unlock() + var out assign.KeptBuild + found := false + for key, k := range r.seen { + if m, _, ok := strings.Cut(key, "@"); !ok || m != module || !maps.Equal(k.Parts, parts) { + continue + } + if !found || compareVersion(k.Version, out.Version) > 0 { + out, found = k, true + } + } + return out, found +} + +// madeOf is what module's done build at fp made, by `:`, as its build.ended names it; none for a build not heard +// or not done (design 47 G A-421). +func (b *builtEnds) madeOf(module, fp string) map[string]string { + e, ok := b.endOf(module, fp) + if !ok || e.Outcome != builds.BuildDone { + return nil + } + parts := map[string]string{} + for name, digest := range e.Made { + parts[module+":"+name] = digest + } + return parts +} + // of is the version of module released from the source revision, with its parts' digests; false before it is heard. func (r *releasedVersions) of(module string, source int64) (assign.KeptBuild, bool) { r.mu.Lock() @@ -168,3 +206,21 @@ func hearTaken(hub *process.EventHub, taken *takenSources, wake func(), logf fun wake() }) } + +// compareVersion orders two MAJOR.MINOR.PATCH versions by their numbers; a part that is no number counts as 0. +func compareVersion(a, b string) int { + pa, pb := strings.Split(a, "."), strings.Split(b, ".") + for i := 0; i < 3; i++ { + var x, y int + if i < len(pa) { + x, _ = strconv.Atoi(pa[i]) + } + if i < len(pb) { + y, _ = strconv.Atoi(pb[i]) + } + if x != y { + return x - y + } + } + return 0 +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended_test.go index 3469cf74..cd621df4 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/buildended_test.go @@ -90,9 +90,17 @@ func TestATrunkEntryTakesItsVersionFromTheReleaseOfItsFingerprintsSource(t *test } _, _ = 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") + t.Error("an entry naming no fp-src, whose build.ended is not heard, 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") { + // A-421: an entry naming no fp-src takes the release whose parts are what its build.ended made. + made, _ := json.Marshal(builds.BuildEnded{Module: "mail", Fingerprint: "t", Made: map[string]string{"image": "sha256:9"}}) + if err := w.ends.put(made); err != nil { + t.Fatal(err) + } + if k, ok := p.namedBuild("mail", "t", 0)("t"); !ok || k.Version != "1.2.3" { + t.Errorf("an entry naming no fp-src, its build made the released digests: %+v, %v", k, ok) + } + 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], "names no fp-src, and no version-released of it names the parts its build.ended made") { t.Errorf("logs = %q, want each unheard release said once, naming the module, the fingerprint and the source", logs) } p.graph.ok = false diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go index db8c98f1..3538242b 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go @@ -179,7 +179,8 @@ 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` 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. +// `fp-src` (A-419: a merge that does not rebuild the module leaves it so), or for an entry naming none the one whose parts are the +// digests its build.ended made (A-421). A trunk entry whose release is not heard is said, once, naming which was tried. 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 { @@ -189,7 +190,11 @@ func (p *passer) namedBuild(module, trunkFP string, fpSrc int64) func(fp string) return assign.KeptBuild{}, false } if fpSrc == 0 { - p.unheardRelease(module, fp, "its catalog entry names no source revision its fingerprint was built at (fp-src)") + // No fp-src (its fingerprint moved with no merge): the release whose parts are what its build made (A-421). + if k, ok := p.w.released.withParts(module, p.w.ends.madeOf(module, fp)); ok { + return k, true + } + p.unheardRelease(module, fp, "its catalog entry names no fp-src, and no version-released of it names the parts its build.ended made") return assign.KeptBuild{}, false } k, ok := p.w.released.of(module, fpSrc)