Design 47 H1: a pin is the version the registry published for the package path within the module's accepted series (H-A-183, H-A-184, H-A-185) #287
@@ -123,9 +123,21 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
|
||||
moved.Fp2, before.Fp2, moved.Inputs2.ImportForm, moved.Packages)
|
||||
}
|
||||
|
||||
// mesh-sdk releases 0.1.20: the import form's fingerprint takes the pin too and moves, once (H-A-172).
|
||||
// mesh-sdk's module releases 0.1.97 while the registry has published nothing of its Go package: the module's release
|
||||
// number is never the package's pin (H-A-183), so avahi stays unpinned and where it was.
|
||||
ix.Versions = newMem()
|
||||
ix.Versions.(*memStore).put(meshcatalog.VersionsByModuleVersionKey("mesh-sdk", "0.1.20"), []byte(`{}`))
|
||||
ix.Versions.(*memStore).put(meshcatalog.VersionsByModuleVersionKey("mesh-sdk", "0.1.97"), []byte(`{}`))
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, _ := moduleOf(t, mods, "avahi"); m.Fp2 != moved.Fp2 || m.Packages[meshSDK] != "" {
|
||||
t.Fatalf("after mesh-sdk's module release alone: fp2 %q (was %q), versions %v; want it unpinned where it was", m.Fp2, moved.Fp2, m.Packages)
|
||||
}
|
||||
// The registry publishes its Go package at 0.1.20, another version than the module's release: the import form's
|
||||
// fingerprint takes that pin and moves, once (H-A-172, H-A-183).
|
||||
if _, err := ix.HearVersion(ctx, HeardVersion{Package: "mesh-sdk/go", Seat: "go-package-registry", Version: "0.1.20", Commit: c3, GoModule: meshSDK, Published: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for range 2 {
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -283,17 +295,18 @@ func anAcceptedSeriesPinsItsNewest(t *testing.T) {
|
||||
if pinned.Fp2 == before.Fp2 || pinned.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Fatalf("after 0.1.15: fp2 %q (was %q), versions %v; want moved by c3's announce, pinned to v0.1.15", pinned.Fp2, before.Fp2, pinned.Packages)
|
||||
}
|
||||
// A publish in a series avahi does not accept pins nothing and moves nothing (H-A-184).
|
||||
if m := step("0.2.0 published from c1", hear("0.2.0", c1)); m.Fp2 != pinned.Fp2 || m.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Errorf("a publish of a series avahi does not accept moved it: %q %v", m.Fp2, m.Packages)
|
||||
}
|
||||
if m := step("trunk at c2", trunk(c2)); m.Fp2 != pinned.Fp2 || m.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Errorf("a trunk merge moved avahi off its accepted series' newest: %q %v", m.Fp2, m.Packages)
|
||||
}
|
||||
// mesh-sdk releases 0.1.20: an accepted series' older version never stands over a newer release (H-A-167).
|
||||
// mesh-sdk's module releases 0.3.0: a module's release number is never a package's pin (H-A-183).
|
||||
ix.Versions = newMem()
|
||||
ix.Versions.(*memStore).put(meshcatalog.VersionsByModuleVersionKey("mesh-sdk", "0.1.20"), []byte(`{}`))
|
||||
if m := step("0.1.20 released", func() error { return nil }); m.Packages[meshSDK] != "v0.1.20" {
|
||||
t.Errorf("a newer release left avahi on its series' older version: %v", m.Packages)
|
||||
ix.Versions.(*memStore).put(meshcatalog.VersionsByModuleVersionKey("mesh-sdk", "0.3.0"), []byte(`{}`))
|
||||
if m := step("0.3.0 released", func() error { return nil }); m.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Errorf("a module's release pinned its package: %v", m.Packages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,8 +218,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
ix.logf("no fingerprint is written by this pass: %v", err)
|
||||
return fmt.Errorf("no fingerprint is written: %w", err)
|
||||
}
|
||||
series := ix.SeriesAll(ctx) // each package's series, the newest a user accepting it takes (DLV-I6)
|
||||
released := ix.releasedOf(ctx) // each module's newest released version, what a package is pinned to (H-A-161)
|
||||
series := ix.SeriesAll(ctx) // each package's series, the newest a user accepting it takes (DLV-I6)
|
||||
type result struct {
|
||||
fp, none string
|
||||
tcs map[string]meshcatalog.ToolchainUsed // by language, when there is a fingerprint
|
||||
@@ -291,7 +290,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
r.none = strings.Join(missing, "; ")
|
||||
case noToolchain != "":
|
||||
r.none = noToolchain
|
||||
if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins, ix.sourceHeads(), released); ok {
|
||||
if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins, ix.sourceHeads(), series); ok {
|
||||
r = result{fp: fp, tcs: k.held.Toolchains, pkgs: pkgs}
|
||||
}
|
||||
default:
|
||||
@@ -299,7 +298,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
r.fp, r.none = f.fp, f.none
|
||||
if r.fp != "" {
|
||||
// a pin is a released version, never a commit (H-A-161), and the version line's fingerprint takes it (H-A-167)
|
||||
r.fp, r.pkgs = pinnedOf(f, held, released)
|
||||
r.fp, r.pkgs = pinnedOf(f, series, k.manifest)
|
||||
r.tcs = toolchainsUsed(toolchains)
|
||||
}
|
||||
}
|
||||
@@ -498,7 +497,7 @@ func hasContext(m catalogue.Manifest) bool {
|
||||
// with the toolchains it was computed with in place of the languages agreed on none, give it again, in its form. Any
|
||||
// other input that moved (a merge, a base, an agreed toolchain, an imported package) gives another fingerprint, and the
|
||||
// module has none until they agree.
|
||||
func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string, released map[string]string) (string, sdkstep.PackageVersions, bool) {
|
||||
func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string, series map[string]SeriesPackage) (string, sdkstep.PackageVersions, bool) {
|
||||
if k.held.Fp2 == "" {
|
||||
return "", nil, false
|
||||
}
|
||||
@@ -518,7 +517,7 @@ func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2,
|
||||
if f.none != "" || f.fp == "" {
|
||||
return "", nil, false
|
||||
}
|
||||
fp, pkgs := pinnedOf(f, held, released)
|
||||
fp, pkgs := pinnedOf(f, series, k.manifest)
|
||||
return fp, pkgs, fp == k.held.Fp2
|
||||
}
|
||||
|
||||
|
||||
@@ -805,17 +805,34 @@ func TestAModuleKeepsTheToolchainsItsFingerprintWasComputedWith(t *testing.T) {
|
||||
t.Fatal("a release whose re-pin failed was acknowledged")
|
||||
}
|
||||
mods.keysErr = nil
|
||||
// The registry published mesh-sdk's Go package at 0.1.18, not at the module's release number 0.1.20, in the series
|
||||
// avahi accepts (the default 0.1), with no contents read: the pin is that version (H-A-183, H-A-185).
|
||||
ix.Packages = newMem()
|
||||
if _, err := ix.HearVersion(context.Background(), HeardVersion{Package: "mesh-sdk/go", Seat: "go-package-registry", Version: "0.1.18", Commit: strings.Repeat("1", 40), GoModule: sdk, Published: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ix.HearPackagePublished(context.Background(), release); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ix.Revisions = revisions
|
||||
if a, _ := moduleOf(t, mods, "avahi"); a.Fp2 == first.Fp2 || a.Fp2 == "" || !reflect.DeepEqual(a.Packages, map[string]string{sdk: "v0.1.20"}) {
|
||||
t.Fatalf("after mesh-sdk's release: fp2 %q (was %q) packages %v, want a new fingerprint pinned to v0.1.20", a.Fp2, first.Fp2, a.Packages)
|
||||
if a, _ := moduleOf(t, mods, "avahi"); a.Fp2 == first.Fp2 || a.Fp2 == "" || !reflect.DeepEqual(a.Packages, map[string]string{sdk: "v0.1.18"}) {
|
||||
t.Fatalf("after mesh-sdk's release: fp2 %q (was %q) packages %v, want a new fingerprint pinned to v0.1.18", a.Fp2, first.Fp2, a.Packages)
|
||||
} else {
|
||||
// A 0.2.0 publish, of a series avahi does not accept, leaves it alone, contents or none (H-A-184, H-A-185).
|
||||
if _, err := ix.HearVersion(context.Background(), HeardVersion{Package: "mesh-sdk/go", Seat: "go-package-registry", Version: "0.2.0", Commit: strings.Repeat("1", 40), GoModule: sdk, Published: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ix.Repin(context.Background(), "mesh-sdk"); err != nil { // the pass for avahi alone: mesh-tools is held stale here
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b, _ := moduleOf(t, mods, "avahi"); b.Fp2 != a.Fp2 || b.Packages[sdk] != "v0.1.18" {
|
||||
t.Fatalf("a publish of another series moved avahi: fp2 %q (was %q) packages %v", b.Fp2, a.Fp2, b.Packages)
|
||||
}
|
||||
}
|
||||
if o, _ := moduleOf(t, mods, "mesh-tools"); o.Fp2 != tools.Fp2 {
|
||||
t.Errorf("a re-pin moved mesh-tools, which holds no package of mesh-sdk: %q (was %q)", o.Fp2, tools.Fp2)
|
||||
}
|
||||
second := sdkMerge(strings.Repeat("2", 40), "tree-sdk-2", "v0.1.20")
|
||||
second := sdkMerge(strings.Repeat("2", 40), "tree-sdk-2", "v0.1.18")
|
||||
if second.Fp2 == first.Fp2 {
|
||||
t.Errorf("a mesh-sdk trunk merge kept avahi's fingerprint %q", first.Fp2)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"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"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
|
||||
"mesh-delivery-indexer/internal/fingerprint"
|
||||
@@ -366,51 +367,28 @@ func isFloor(raw []byte) bool {
|
||||
return json.Unmarshal(raw, &v) == nil && len(v.Artifacts) == 0
|
||||
}
|
||||
|
||||
// releasedOf is the newest released version of each module the state versions keeps (§349; design 47 H-A-161), by module;
|
||||
// nil when the indexer keeps no such state or it cannot be listed, said.
|
||||
func (ix *Indexer) releasedOf(ctx context.Context) map[string]string {
|
||||
if ix.Versions == nil {
|
||||
return nil
|
||||
}
|
||||
all, err := ix.Versions.Keys(ctx)
|
||||
if err != nil {
|
||||
ix.logf("versions: the state cannot be listed, so no package is pinned by this pass: %v", err)
|
||||
return nil
|
||||
}
|
||||
out := map[string]string{}
|
||||
for _, k := range all {
|
||||
m, v, ok := meshcatalog.ParseVersionsByModuleVersionKey(k)
|
||||
if _, parts := versionParts(v); !ok || !parts {
|
||||
continue
|
||||
}
|
||||
if cur, has := out[m]; !has || compareVersions(v, cur) > 0 {
|
||||
out[m] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// releasedPins are a module's pins (its catalog entry's packages, which the builder builds it against) from the versions its
|
||||
// fingerprint was computed with (design 47 H-A-161, G §370): a package the held module holding it has released is pinned
|
||||
// to that module's newest released version, as Go names it (v<version>); a version already in that form (an accepted
|
||||
// series' newest, DLV-I6) stands; any other, a commit, is no pin: its package is kept with no version, so its kind-1 edge
|
||||
// stands (H §746) and no build is made against a commit. nil for none.
|
||||
func releasedPins(versions sdkstep.PackageVersions, held map[string]meshcatalog.ModulesByModuleValue, released map[string]string) sdkstep.PackageVersions {
|
||||
// fingerprint was computed with (design 47 H-A-161, H-A-183, H-A-184, H-A-185, G §370): each package is pinned to the
|
||||
// newest version the registry published for its path (the seats' published, kept in the package's series by HearVersion)
|
||||
// within the series the module accepts, the one its manifest m names or the default (Manifest.AcceptedSeries), whether
|
||||
// or not that series holds contents yet; a publish in another series pins nothing and moves nothing, and a module's
|
||||
// release number is never a pin. A package with none published in that series is kept with no version, so its kind-1
|
||||
// edge stands (H §746) and its build waits for the publish (H-A-165). nil for none.
|
||||
func releasedPins(versions sdkstep.PackageVersions, series map[string]SeriesPackage, m catalogue.Manifest) sdkstep.PackageVersions {
|
||||
if len(versions) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := sdkstep.PackageVersions{}
|
||||
for p, v := range versions {
|
||||
rel := released[moduleOfKey(fingerprint.HolderOf(p, held))]
|
||||
series := sdkstep.PackageSemver.MatchString(v)
|
||||
_, plain := versionParts(strings.TrimPrefix(v, "v"))
|
||||
switch {
|
||||
case rel != "" && (!series || !plain || compareVersions(rel, strings.TrimPrefix(v, "v")) > 0):
|
||||
out[p] = "v" + rel // never an older series' version over a newer release (H-A-167)
|
||||
case series:
|
||||
out[p] = v
|
||||
default:
|
||||
out[p] = ""
|
||||
for p := range versions {
|
||||
out[p] = ""
|
||||
for _, s := range series {
|
||||
if s.GoModule != p || s.Newest == nil || s.Series != m.AcceptedSeries(s.Name) {
|
||||
continue
|
||||
}
|
||||
v := strings.TrimPrefix(s.Newest.Version, "v")
|
||||
if _, ok := versionParts(v); ok && (out[p] == "" || compareVersions(v, strings.TrimPrefix(out[p], "v")) > 0) {
|
||||
out[p] = "v" + v
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
@@ -420,8 +398,8 @@ func releasedPins(versions sdkstep.PackageVersions, held map[string]meshcatalog.
|
||||
// form's fingerprint takes them (design 47 H-A-167, H-A-172; ADR 0573 §4) and a re-pin moves it, the module a mover
|
||||
// built again against the release; a fingerprint with no pin is the form's as it is. The held fingerprint of a build that
|
||||
// stands is kept while its pins are the ones it was built with, else its import form takes the new pins.
|
||||
func pinnedOf(f form, held map[string]meshcatalog.ModulesByModuleValue, released map[string]string) (string, sdkstep.PackageVersions) {
|
||||
pins := releasedPins(f.versions, held, released)
|
||||
func pinnedOf(f form, series map[string]SeriesPackage, m catalogue.Manifest) (string, sdkstep.PackageVersions) {
|
||||
pins := releasedPins(f.versions, series, m)
|
||||
if f.stands {
|
||||
if maps.Equal(f.built, map[string]string(pins)) {
|
||||
return f.fp, pins
|
||||
|
||||
Reference in New Issue
Block a user