Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/movers.go
T
jschoubben b7b3891a4a T1 indexer: blank only a mover's entry (issue 1984)
The take-in blanked a package's pin in every import-form entry, the
node-engine's among them though it was no mover, and nothing filled it:
every composition of main.506 could not run. A module that is no mover
of the take-in keeps its pins, since no step of that pipeline builds it.

Tests: TestMoversOf gains the subcase "an import-form importer that is no
mover keeps its pin of a package a mover publishes" (1984/AC7); I12's
subcase is kept as 1984/AC8. TestASourceRevisionMovingMeshSDKNamesItAndItsImporters
(integration) asserted the old blank for importer at m3's take-in, where
the take-in makes importer no mover (its fingerprint does not move,
noted on issue 1984 as note 24); its assertion now follows H-A-628 (1):
blank where importer is a mover of that take-in, its pin kept where not.

Builds: design 47 H2 H-A-628 (1) (hq cea6404c); D1 H-A-532 DMC-1; D2 H-A-547 (2)
2026-11-23 21:55:02 +01:00

108 lines
4.3 KiB
Go

package index
import (
"maps"
"slices"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
)
// moversOf are the movers of one take-in (design 47 H §743, A-476a as H2 H-A-520 amends it): of the modules registered for
// a repository the source revision moved (moved, by the entry's repository), those whose fingerprint differs from their
// entry in before, the branch's newest catalog revision (one it does not hold included); every module, in any repository,
// whose import set is reported (its entry's import form, H-A-536, H-A-538) and whose fingerprint differs from its entry
// in before, since its fingerprint moves only with a package it imports (H-A-520, ADR 0593 §3); and every module with no
// reported import set that requires a package one of the fingerprint's movers publishes, by its packages (the fallback
// that exists, H-A-528). A module whose reported set holds no changed package is no mover. A module with no fingerprint
// (no build) is no mover. One {module, commit, fingerprint, repository} per mover, by module name.
func moversOf(before []meshcatalog.CatalogEntry, after map[string]meshcatalog.CatalogEntry, moved []string) []meshcatalog.TakeInEntry {
was := make(map[string]string, len(before))
for _, e := range before {
was[e.Module] = e.Fp
}
inMoved := func(repository string) bool {
return slices.ContainsFunc(moved, func(r string) bool { return trunk.SameRepository(r, repository) })
}
movers := map[string]bool{}
published := map[string]bool{} // the packages the fingerprint's movers publish, by name
for name, e := range after {
if e.Fp == "" {
continue
}
fp, held := was[name]
_, reported := importSetOf(e)
if !inMoved(e.Repository) && !(reported && held) || held && fp == e.Fp {
continue
}
movers[name] = true
for _, a := range e.Artifacts {
if a.Package != nil && a.Package.Name != "" {
published[a.Package.Name] = true
}
}
}
for name, e := range after {
if _, reported := importSetOf(e); movers[name] || e.Fp == "" || reported {
continue
}
for p := range e.Packages {
if published[p] {
movers[name] = true
break
}
}
}
out := make([]meshcatalog.TakeInEntry, 0, len(movers))
for _, name := range slices.Sorted(maps.Keys(movers)) {
e := after[name]
out = append(out, meshcatalog.TakeInEntry{Module: name, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
return out
}
// unpinnedByMovers are the entries of a take-in with no version named, in an importer's packages, for a package a mover of
// the same take-in publishes (design 47 H2 H-A-532 DMC-1, H-A-547 Q5): the version that pipeline publishes is not released
// at the take-in, so the importer's build waits for that package's publish and is made against it (H-A-165, H-A-521). Only
// the entry of a mover of the take-in is touched (H-A-628 (1)): a module that is no mover keeps its pins, since no step of
// that pipeline builds it, so no build waits for the publish the blank serves. Of a mover, only an entry on the import form
// is touched (its import set reported, H-A-538): a version-line entry's fingerprint takes its pins (H-A-167, H-A-530), so
// it keeps them. A mover's own packages are left as they are. The entries are written anew where one changes; the others
// are the same values.
func unpinnedByMovers(entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry {
published := map[string]string{} // package name to the mover that publishes it
moving := make(map[string]bool, len(movers))
for _, m := range movers {
moving[m.Module] = true
for _, a := range entries[m.Module].Artifacts {
if a.Package != nil && a.Package.Name != "" {
published[a.Package.Name] = m.Module
}
}
}
if len(published) == 0 {
return entries
}
out := make(map[string]meshcatalog.CatalogEntry, len(entries))
for name, e := range entries {
out[name] = e
if _, reported := importSetOf(e); !reported || !moving[name] {
continue
}
var pkgs map[string]string
for p, v := range e.Packages {
if by, ok := published[p]; ok && by != name && v != "" {
if pkgs == nil {
pkgs = maps.Clone(e.Packages)
}
pkgs[p] = ""
}
}
if pkgs != nil {
e.Packages = pkgs
out[name] = e
}
}
return out
}