The builder's version-reserved writes the series' numbered version with the contents of the module's entry commit, so acceptedSeries and releasedPins pin it; the indexer keeps each reservation in heard (reserved.<revision>.<module>, reserved-keep) and gathers a revision's reservations until its pipeline's start, its first step-ended or the expiry of settling.<revision> (reserved-settle), then keeps one re-pin revision of that branch. The release's package-published moves no fingerprint; a pipeline-ended not passed withdraws its reservations to the newest released version. Builds: design 47 H2 §805; H-A-418, H-A-420, H-A-424, H-A-436
164 lines
8.6 KiB
Go
164 lines
8.6 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"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"
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// Design 47 H-A-204, H-A-201, H-A-165: an entry's packages name every requirement of its module graph of another
|
|
// repository: one the form's versions leave out (an import form naming only what the build imported) is pinned by its
|
|
// series' newest published version, and one none publishes yet is kept with no version, never left out.
|
|
func TestAnEntryNamesEveryRequirementPinnedOrWaiting(t *testing.T) {
|
|
const (
|
|
wireguard = "git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go"
|
|
busgrants = "git.novox.be/novox/mesh-delivery/modules/mesh-grants/busgrants"
|
|
sdk = "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
series := map[string]SeriesPackage{"wg": {Name: "mesh-wireguard/go", GoModule: wireguard, Series: catalogue.DefaultSeries,
|
|
Newest: &meshcatalog.PackagesByPackageSeriesValueNewest{Version: "0.1.47"}}}
|
|
pins := releasedPins(sdkstep.PackageVersions{sdk: "c0ffee"}, series, catalogue.Manifest{}, "novox/mesh-catalog", []string{busgrants, sdk, wireguard})
|
|
want := sdkstep.PackageVersions{sdk: "", wireguard: "v0.1.47", busgrants: ""}
|
|
if len(pins) != len(want) {
|
|
t.Fatalf("pins = %v, want %v", pins, want)
|
|
}
|
|
for p, v := range want {
|
|
if got, named := pins[p]; !named || got != v {
|
|
t.Errorf("the pin of %s is %q (named %v), want %q", p, got, named, v)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 H-A-204, H-A-165: a release re-pins every kept entry naming one of its packages, of any repository and
|
|
// changed or not, by its pins or by its kept requirements alone: here g, of another repository, holds no pin of mesh-sdk.
|
|
// H-A-211, H-A-212, H-A-213: on every watched branch holding g, the re-pin keeps the branch's next revision, of the same
|
|
// source as the one before it, with the call "release of mesh-sdk 0.1.27" and g as its mover at its new fingerprint, and
|
|
// says catalog-revision with that call.
|
|
func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) {
|
|
ctx := context.Background()
|
|
objects := map[string]string{"modules/b/builds": strings.Repeat("b", 40), "modules/c/client": strings.Repeat("c", 40)}
|
|
ix, mods, _ := ptpIndexer(t, objects)
|
|
ix.Revisions, ix.Packages = newMemObjects(1<<20), newMem()
|
|
reportToolchain(t, ix, "mesh-build-go", "n1", "go", "1.26.0")
|
|
var said []meshcatalog.CatalogRevisionEvent
|
|
ix.SayCatalogRevision = func(_ context.Context, e meshcatalog.CatalogRevisionEvent) error { said = append(said, e); return nil }
|
|
f := withManifests(mergedMsg("novox/mesh-delivery", map[string]string{"modules/g": "gtree"}), map[string]string{"modules/g": ptpProgram}, nil)
|
|
if err := ix.Apply(ctx, f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
g, _ := moduleOf(t, mods, "g")
|
|
if g.Inputs2 == nil || !slices.Contains(g.Inputs2.Packages, "git.novox.be/novox/mesh-sdk/go") {
|
|
t.Fatalf("g = %+v, want mesh-sdk among its kept requirements", g.Inputs2)
|
|
}
|
|
g.Packages = nil
|
|
mods.put("g", mustEncode(t, g))
|
|
mods.put("mesh-sdk", mustEncode(t, meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Commit: strings.Repeat("1", 40),
|
|
Path: meshcatalogclient.RootPath, None2: None2Pending}))
|
|
entries, err := ix.viewEntries(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sources := map[string]int64{"main": 5, "feature/x": 9}
|
|
for branch, src := range sources {
|
|
if err := ix.KeepBranchEntries(ctx, branch, src, entries, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
said = nil
|
|
if _, err := ix.HearVersion(ctx, HeardVersion{Package: "mesh-sdk/go", GoModule: "git.novox.be/novox/mesh-sdk/go", Version: "0.1.27", Published: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n, err := ix.Repin(ctx, "mesh-sdk", "0.1.27"); err != nil || n != 2 {
|
|
t.Errorf("a release of mesh-sdk re-pinned %d modules (%v), want g on each of the two branches, which requires it with no pin", n, err)
|
|
}
|
|
now, _ := moduleOf(t, mods, "g")
|
|
if now.Fp2 == "" || now.Fp2 == g.Fp2 || now.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.27" {
|
|
t.Fatalf("g after the re-pin = %s pinned %v, want a new fingerprint pinned to v0.1.27 (was %s)", now.Fp2, now.Packages, g.Fp2)
|
|
}
|
|
for branch, src := range sources {
|
|
rev, kept, found, err := readNewestOf(ctx, ix.Revisions, branch)
|
|
if err != nil || !found || rev.Revision != 2 || rev.Source != src || rev.Call != "release of mesh-sdk 0.1.27" ||
|
|
rev.CallKind != meshcatalog.CatalogRevisionCallKindRelease || rev.Module != "mesh-sdk" || rev.Version != "0.1.27" || // H-A-215
|
|
len(rev.Movers) != 1 || rev.Movers[0].Module != "g" || rev.Movers[0].Fingerprint != now.Fp2 {
|
|
t.Errorf("%s's newest = %+v (%v), want revision 2 of source %d, its call the release, g its mover at %s", branch, rev, err, src, now.Fp2)
|
|
continue
|
|
}
|
|
if i := slices.IndexFunc(kept, func(e meshcatalog.CatalogEntry) bool { return e.Module == "g" }); i < 0 || kept[i].Fp != now.Fp2 {
|
|
t.Errorf("%s's newest holds no entry of g at %s", branch, now.Fp2)
|
|
}
|
|
}
|
|
if len(said) != 2 || said[0].Call != "release of mesh-sdk 0.1.27" || said[1].Call != said[0].Call ||
|
|
said[0].CallKind != meshcatalog.CatalogRevisionEventCallKindRelease || said[1].Module != "mesh-sdk" || said[1].Version != "0.1.27" {
|
|
t.Errorf("said %+v, want catalog-revision of each branch with the release's call", said)
|
|
}
|
|
|
|
// Design 47 H2 §805, H-A-418, H-A-420, H-A-424, H-A-436: a pipeline reserving twenty packages of mesh-sdk in main's
|
|
// revision 2 keeps one re-pin revision of main when its gathering settles, at its first step-ended; its release then
|
|
// keeps none on main, and a pipeline that did not pass withdraws its reservations back to the newest released version.
|
|
ix.Files = func(_ context.Context, _, _ string, dirs []string) (map[string]map[string]string, error) {
|
|
out := map[string]map[string]string{}
|
|
for _, d := range dirs {
|
|
out[d] = map[string]string{"go.mod": strings.Repeat("d", 40), "sdk.go": strings.Repeat("e", 40)}
|
|
}
|
|
return out, nil
|
|
}
|
|
heard := newMem()
|
|
ix.Heard = heard
|
|
revision := BranchObject("main", 2)
|
|
newest := func() int64 {
|
|
rev, _, _, err := readNewestOf(ctx, ix.Revisions, "main")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return rev.Revision
|
|
}
|
|
for i := range 20 {
|
|
e := meshbuilds.VersionReservedEvent{Module: "mesh-sdk", Artifact: fmt.Sprintf("mesh-sdk:p%d", i), Path: "mesh-sdk/go", Version: "0.1.28", Revision: revision}
|
|
if err := ix.HearVersionReserved(ctx, e); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if _, _, open, _ := heard.Get(ctx, SettlingKey(revision)); !open || newest() != 2 {
|
|
t.Fatalf("twenty reservations: gathering open %v, main's newest %d, want open and no revision kept before it settles", open, newest())
|
|
}
|
|
if err := ix.Settle(ctx, revision); err != nil || newest() != 3 {
|
|
t.Fatalf("the gathering settled (%v) keeping main's newest %d, want one re-pin revision, 3", err, newest())
|
|
}
|
|
if now, _ := moduleOf(t, mods, "g"); now.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.28" {
|
|
t.Errorf("g after the reservations is pinned %v, want v0.1.28", now.Packages)
|
|
}
|
|
if err := ix.Settle(ctx, revision); err != nil || newest() != 3 {
|
|
t.Errorf("a second step-ended settled (%v) keeping main's newest %d, want still 3", err, newest())
|
|
}
|
|
if _, err := ix.HearVersion(ctx, HeardVersion{Package: "mesh-sdk/go", GoModule: "git.novox.be/novox/mesh-sdk/go", Version: "0.1.28", Commit: strings.Repeat("1", 40), Published: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := ix.Repin(ctx, "mesh-sdk", "0.1.28"); err != nil || newest() != 3 {
|
|
t.Errorf("the release of the reserved 0.1.28 re-pinned (%v) keeping main's newest %d, want no revision more", err, newest())
|
|
}
|
|
next := BranchObject("main", 3)
|
|
if err := ix.HearVersionReserved(ctx, meshbuilds.VersionReservedEvent{Module: "mesh-sdk", Artifact: "mesh-sdk:p0", Path: "mesh-sdk/go", Version: "0.1.29", Revision: next}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ix.Settle(ctx, next); err != nil || newest() != 4 {
|
|
t.Fatalf("the reservation of 0.1.29 settled (%v) keeping main's newest %d, want 4", err, newest())
|
|
}
|
|
if err := ix.Withdraw(ctx, "main", 3); err != nil || newest() != 5 {
|
|
t.Fatalf("the withdrawal (%v) kept main's newest %d, want 5", err, newest())
|
|
}
|
|
if now, _ := moduleOf(t, mods, "g"); now.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.28" {
|
|
t.Errorf("g after the withdrawal is pinned %v, want the newest released v0.1.28", now.Packages)
|
|
}
|
|
if _, _, kept, _ := heard.Get(ctx, ReservedKey(next, "mesh-sdk")); kept {
|
|
t.Errorf("the withdrawn reservation is still kept")
|
|
}
|
|
}
|