mesh-delivery-indexer: a release re-pins an import-form entry's packages, never its fingerprint, and keeps a revision with no movers

Builds: design 47 H2 H-A-763 (1), (2); H-A-530, H-A-204, H-A-165, H-A-161, H-A-167
This commit is contained in:
2026-11-25 22:48:47 +01:00
parent 788b57a164
commit 7bb1a147b5
3 changed files with 81 additions and 19 deletions
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
"slices"
"strings"
"testing"
@@ -58,6 +59,7 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
t.Run("an unread packages state writes no fingerprint, and they are computed again by hand (issue 1966)", anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain)
t.Run("an accepted series' newest published version pins it, by that version's contents", anAcceptedSeriesPinsItsNewest)
t.Run("only the version line's fingerprint takes a release's pin", onlyTheVersionLineTakesAPin)
t.Run("a release re-pins an import-form entry's packages, never its fingerprint, and keeps a revision with no movers", aReleaseRepinsAnImportFormEntryWithNoMovers)
t.Run("a reported set is a key of the state imports, an empty one too, or a set held before it", aReportedSetIsAKeyOrAHeldSet)
ctx := context.Background()
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
@@ -192,6 +194,72 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
}
}
// Design 47 H2 H-A-763 (1), (2), H-A-530, H-A-204: a release re-pins the packages of an entry on the import form pinned
// below the series' newest (repinned names it), its fingerprint stays, and the branch's next revision is kept all the same,
// its call the release and no mover.
func aReleaseRepinsAnImportFormEntryWithNoMovers(t *testing.T) {
ctx := context.Background()
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
ix.Packages, ix.Files, ix.Imports, ix.Revisions = newMem(), forge{c1: sdkFiles("a1", "b1")}.files, newMem(), newMemObjects(1<<20)
setPackages(t, mods, "avahi", []string{meshSDK})
meshSDKPublished(t, ix, mods)
held, _ := ix.heldModules(ctx)
if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil {
t.Fatal(err)
}
if err := ix.Recompute(ctx); err != nil {
t.Fatal(err)
}
before, _ := moduleOf(t, mods, "avahi")
if err := ix.HearImportsReported(ctx, buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce")); err != nil {
t.Fatal(err)
}
if err := ix.Recompute(ctx); err != nil {
t.Fatal(err)
}
old, _ := moduleOf(t, mods, "avahi")
if old.Inputs2 == nil || old.Inputs2.ImportForm == "" {
t.Fatalf("no import form kept from the report: %+v", old.Inputs2)
}
old.Fp2, old.Packages = old.Inputs2.ImportForm, map[string]string{meshSDK: "v0.1.19"}
raw, err := meshcatalogclient.EncodeModule(old)
if err != nil {
t.Fatal(err)
}
mods.put("avahi", raw)
if err := ix.Recompute(ctx); err != nil { // the held fingerprint stands (H-A-529): the graph and the value agree
t.Fatal(err)
}
entries, err := ix.viewEntries(ctx)
if err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, TrunkBranch, 5, entries, nil); err != nil {
t.Fatal(err)
}
if _, err := hearReleased(ctx, ix, HeardVersion{Package: "mesh-sdk/go", Seat: "go-package-registry", Version: "0.1.20", Commit: c1, GoModule: meshSDK, Published: true}, "mesh-sdk", "go"); err != nil {
t.Fatal(err)
}
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || !only["avahi"] {
t.Fatalf("a re-pin of mesh-sdk names %v (%v), want avahi, on the import form", only, err)
}
if n, err := ix.Repin(ctx, "mesh-sdk", "0.1.20"); err != nil || n != 1 {
t.Fatalf("a release re-pinned %d modules (%v), want avahi", n, err)
}
now, _ := moduleOf(t, mods, "avahi")
if now.Fp2 != old.Fp2 || now.Packages[meshSDK] != "v0.1.20" {
t.Fatalf("avahi after the re-pin: fp2 %q (was %q), packages %v; want the fingerprint as it was, pinned to v0.1.20", now.Fp2, old.Fp2, now.Packages)
}
rev, kept, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil || !found || rev.Revision != 2 || rev.Source != 5 || rev.CallKind != meshcatalog.CatalogRevisionCallKindRelease || len(rev.Movers) != 0 {
t.Fatalf("main's newest = %+v (%v), want revision 2 of source 5, its call the release, no movers", rev, err)
}
if i := slices.IndexFunc(kept, func(e meshcatalog.CatalogEntry) bool { return e.Module == "avahi" }); i < 0 || kept[i].Packages[meshSDK] != "v0.1.20" || kept[i].Fp != old.Fp2 {
t.Fatalf("the kept entries hold %+v for avahi, want it at %s pinned to v0.1.20", kept, old.Fp2)
}
}
// Design 47 H2 H-A-530: only the version line's fingerprint takes a release's pin, so a release moves a module with no
// reported import set (I4/AC2, H-A-167 for the version line); a held fingerprint made with a pin from before stands
// while the import form computes to the one its build reported (I4/AC3, ADR 0593 §4, H-A-529).
@@ -80,16 +80,6 @@ func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) {
if _, err := hearReleased(ctx, ix, HeardVersion{Package: "mesh-sdk/go", GoModule: "git.novox.be/novox/mesh-sdk/go", Version: "0.1.27", Published: true}, "mesh-sdk", "go"); err != nil {
t.Fatal(err)
}
// I5/AC1 (design 47 H2 H-A-530): a module on the import form (its import form set, H-A-538) is named by no re-pin;
// I5/AC2: on the version line, as g is, it is.
onImports := g
in := *g.Inputs2
in.Imports, in.ImportForm = []string{"git.novox.be/novox/mesh-sdk/go"}, "src2:"+strings.Repeat("a", 64)
onImports.Inputs2 = &in
mods.put("g", mustEncode(t, onImports))
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || only["g"] {
t.Errorf("a re-pin of mesh-sdk names %v (%v), want no module on the import form", only, err)
}
mods.put("g", mustEncode(t, g))
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || !only["g"] {
t.Errorf("a re-pin of mesh-sdk names %v (%v), want g, on the version line", only, err)
@@ -717,9 +717,9 @@ func (ix *Indexer) repinModules(ctx context.Context, branch string, modules []st
}
// repinned are the modules the indexer's modules state holds whose packages name a package of module: by their pins, and
// by their kept requirements, which name a package they hold no pin of yet (design 47 H-A-204, H-A-165, H-A-167). Only a
// module on the version line is named: one on the import form (its import form set, H2 H-A-538) takes no pin into its
// fingerprint, so a release never moves it (H-A-530).
// by their kept requirements, which name a package they hold no pin of yet (design 47 H-A-204, H-A-165, H-A-167). A module
// on the import form is named as one on the version line: its packages take the release, its fingerprint stays (H-A-530,
// H-A-763 (1)).
func (ix *Indexer) repinned(ctx context.Context, module string) (map[string]bool, error) {
held, err := ix.heldModules(ctx)
if err != nil {
@@ -727,9 +727,6 @@ func (ix *Indexer) repinned(ctx context.Context, module string) (map[string]bool
}
only := map[string]bool{}
for key, m := range held {
if m.Inputs2 != nil && m.Inputs2.ImportForm != "" {
continue
}
names := slices.Collect(maps.Keys(m.Packages))
if m.Inputs2 != nil {
names = append(names, m.Inputs2.Packages...)
@@ -763,9 +760,11 @@ func (ix *Indexer) keepRepinned(ctx context.Context, x *Indexer, branch string,
return err
}
was := make(map[string]string, len(before))
wasPkgs := make(map[string]map[string]string, len(before))
for _, e := range before {
was[e.Module] = e.Fp
was[e.Module], wasPkgs[e.Module] = e.Fp, e.Packages
}
pinsMoved := false // an entry whose packages moved with no fingerprint (an import-form entry, H-A-530) is kept with no mover (H-A-763 (2))
var movers []meshcatalog.TakeInEntry
moved := slices.Sorted(maps.Keys(only))
if only == nil { // a take-in again or a recompute: every module whose fingerprint moved (H-A-212, H-A-217)
@@ -773,13 +772,18 @@ func (ix *Indexer) keepRepinned(ctx context.Context, x *Indexer, branch string,
}
for _, key := range moved {
e, ok := entries[key]
if ok && e.Fp != "" && was[e.Module] == e.Fp && !maps.Equal(wasPkgs[e.Module], e.Packages) {
if _, had := was[e.Module]; had {
pinsMoved = true
}
}
if !ok || e.Fp == "" || was[e.Module] == e.Fp {
continue
}
movers = append(movers, meshcatalog.TakeInEntry{Module: e.Module, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
if len(movers) == 0 {
ix.logf("re-pin (%s): no fingerprint of %s moved, so no revision is kept", call.Call, branch)
if len(movers) == 0 && !pinsMoved {
ix.logf("re-pin (%s): no fingerprint or pin of %s moved, so no revision is kept", call.Call, branch)
return nil
}
number, err := ix.keepBranchEntries(ctx, branch, newest.Source, call, entries, movers)