I5 digests-from-the-publisher: a Go package artifact's entry keeps its packages' digests, an importer's fingerprint reads them from the publishing entry, the import form takes no accepted-series override
Builds: design 47 H2 H-A-580, H-A-672 (DQ-21), H-A-521, H-A-530
This commit is contained in:
@@ -37,6 +37,7 @@ func (ix *Indexer) withArtifacts(ctx context.Context, e meshcatalog.CatalogEntry
|
||||
art := meshcatalog.Artifact{Ref: ArtifactRefOf(e.Module, a.Name), Language: a.Language, Kind: a.Kind}
|
||||
if pkg := ix.packageOf(ctx, e, a); pkg != nil {
|
||||
art.Package = pkg
|
||||
art.Digests = ix.digestsOf(ctx, pkg)
|
||||
}
|
||||
e.Artifacts = append(e.Artifacts, art)
|
||||
}
|
||||
@@ -82,3 +83,31 @@ func (ix *Indexer) packageOf(ctx context.Context, e meshcatalog.CatalogEntry, a
|
||||
}
|
||||
return &meshcatalog.ArtifactPackage{Ecosystem: ecosystem, Name: name}
|
||||
}
|
||||
|
||||
// digestsOf are the digests of the packages of a package artifact's module, one item per package, kept on the artifact of
|
||||
// the entry so an importer reads each imported package's digest from the entry that publishes it (design 47 H2 H-A-580):
|
||||
// those of the packages state's value of a Go module the artifact names, sorted by package; nil for an artifact of
|
||||
// another ecosystem, or while the state holds none of its module.
|
||||
func (ix *Indexer) digestsOf(ctx context.Context, pkg *meshcatalog.ArtifactPackage) []meshcatalog.ArtifactDigestsItem {
|
||||
if pkg.Ecosystem != EcosystemGo || ix.Packages == nil {
|
||||
return nil
|
||||
}
|
||||
key, err := PackagesKey(pkg.Name)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
value, _, found, err := ix.Packages.Get(ctx, key)
|
||||
if err != nil || !found {
|
||||
return nil
|
||||
}
|
||||
p, err := DecodePublishedPackages(value)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var out []meshcatalog.ArtifactDigestsItem
|
||||
for _, d := range p.Packages {
|
||||
out = append(out, meshcatalog.ArtifactDigestsItem{Package: d.Package, Digest: d.Digest})
|
||||
}
|
||||
slices.SortFunc(out, func(a, b meshcatalog.ArtifactDigestsItem) int { return strings.Compare(a.Package, b.Package) })
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package index
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -491,8 +492,10 @@ func anAcceptedSeriesPinsItsNewest(t *testing.T) {
|
||||
return ix.HearImportsReported(ctx, buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce"))
|
||||
})
|
||||
pinned := step("0.1.15 published from c3", hear("0.1.15", c3))
|
||||
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)
|
||||
// The import form takes no accepted-series override (design 47 H2 H-A-672): the series' contents (c3) move nothing, the
|
||||
// digests are the trunk entry's (c1) and the version is pinned.
|
||||
if pinned.Fp2 != before.Fp2 || pinned.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Fatalf("after 0.1.15: fp2 %q (was %q), versions %v; want unmoved by the series' contents, 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" {
|
||||
@@ -501,6 +504,24 @@ func anAcceptedSeriesPinsItsNewest(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
// A trunk merge that changes announce, a package it imports, moves it: its digest is read from the publisher's entry
|
||||
// of the revision, whatever series it accepts (design 47 H2 H-A-580, H-A-672).
|
||||
if m := step("trunk at c3", trunk(c3)); m.Fp2 == pinned.Fp2 || m.Packages[meshSDK] != "v0.1.15" {
|
||||
t.Errorf("a change of an imported package at the trunk did not move avahi: %q (was %q) %v", m.Fp2, pinned.Fp2, m.Packages)
|
||||
}
|
||||
// The publisher's entry keeps the digest of each package of its package artifact (design 47 H2 H-A-580).
|
||||
held, _ := ix.heldModules(ctx)
|
||||
raw, man, err := ix.manifestRaw(ctx, held["mesh-sdk"].Manifest)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
digests := 0
|
||||
for _, a := range ix.withArtifacts(ctx, CatalogEntryOf("mesh-sdk", held["mesh-sdk"], man, raw, graph.Node{}), man).Artifacts {
|
||||
digests += len(a.Digests)
|
||||
}
|
||||
if digests == 0 {
|
||||
t.Errorf("the entry of mesh-sdk keeps no digest of its packages")
|
||||
}
|
||||
// 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.3.0"), []byte(`{}`))
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -216,13 +217,21 @@ func (ix *Indexer) meshPackages(ctx context.Context, held map[string]meshcatalog
|
||||
// packagesPublishedBy are the packages meshPackages names, each with the repository of the module that publishes it, so a
|
||||
// take-in tells the packages its repository publishes (design 47 H2 H-A-520, H-A-539).
|
||||
func (ix *Indexer) packagesPublishedBy(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue) (map[string]string, error) {
|
||||
names, _, err := ix.publishedByEntries(ctx, held)
|
||||
return names, err
|
||||
}
|
||||
|
||||
// publishedByEntries are packagesPublishedBy's names, and with them the digests each Go package artifact of those entries
|
||||
// keeps, by the package's name (an artifact's `digests`, design 47 H2 H-A-580): what an importer's fingerprint reads.
|
||||
func (ix *Indexer) publishedByEntries(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue) (map[string]string, map[string][]meshcatalog.ArtifactDigestsItem, error) {
|
||||
if held == nil {
|
||||
var err error
|
||||
if held, err = ix.heldModules(ctx); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
names := map[string]string{}
|
||||
digests := map[string][]meshcatalog.ArtifactDigestsItem{}
|
||||
for name, cur := range held {
|
||||
if cur.Manifest == "" {
|
||||
continue
|
||||
@@ -234,10 +243,36 @@ func (ix *Indexer) packagesPublishedBy(ctx context.Context, held map[string]mesh
|
||||
for _, a := range ix.withArtifacts(ctx, CatalogEntryOf(name, cur, m, raw, graph.Node{}), m).Artifacts {
|
||||
if p := a.Package; p != nil && p.Name != "" && (p.Ecosystem == EcosystemGo || p.Ecosystem == EcosystemNpm) {
|
||||
names[p.Name] = cur.Repository
|
||||
if len(a.Digests) > 0 {
|
||||
digests[p.Name] = a.Digests
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return names, nil
|
||||
return names, digests, nil
|
||||
}
|
||||
|
||||
// fromEntries is published with the packages of each module an entry of the revision computed publishes taken at the
|
||||
// digests that entry keeps (design 47 H2 H-A-580): an importer's fingerprint reads a package's digest from the entry that
|
||||
// publishes it, so a publisher that moves in the same take-in is read at its new digests; a module no entry keeps digests
|
||||
// of stays as the state holds it. Nothing of published is changed in place.
|
||||
func fromEntries(published map[string]meshcatalog.PackagesByModuleValue, digests map[string][]meshcatalog.ArtifactDigestsItem) map[string]meshcatalog.PackagesByModuleValue {
|
||||
if len(digests) == 0 {
|
||||
return published
|
||||
}
|
||||
out := maps.Clone(published)
|
||||
for module, items := range digests {
|
||||
p, ok := out[module]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
p.Packages = make([]meshcatalog.PackagesByModuleValuePackagesItem, len(items))
|
||||
for i, d := range items {
|
||||
p.Packages[i] = meshcatalog.PackagesByModuleValuePackagesItem{Package: d.Package, Digest: d.Digest}
|
||||
}
|
||||
out[module] = p
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// inTheMesh are the imports a package of names holds, the package itself or a path under it (I9's reading); any other
|
||||
|
||||
@@ -165,15 +165,13 @@ func (ix *Indexer) SeriesAll(ctx context.Context) map[string]SeriesPackage {
|
||||
return out
|
||||
}
|
||||
|
||||
// acceptedSeries is the packages state as a module of repository whose manifest is m is fingerprinted against (DLV-I6;
|
||||
// ADR 0606 §4, ADR 0609 §1; design 32 *A package, its series, and the series its users accept*): each mesh Go module of
|
||||
// another repository whose package's series the module accepts (Manifest.AcceptedSeries) and a seat published, by that
|
||||
// series' newest version, its digests read at that version's commit, and pinned to the version itself (Go's form,
|
||||
// `v0.1.15`). A series with no published version yet, or whose contents the forge did not list, leaves the module's
|
||||
// latest published commit (the commit form, milestone § 2 item 4). A module of the same repository takes its sibling by
|
||||
// path, never by a series. With nothing to pin, published is answered as it is.
|
||||
func acceptedSeries(series map[string]SeriesPackage, m catalogue.Manifest, repository string, published map[string]meshcatalog.PackagesByModuleValue) (map[string]meshcatalog.PackagesByModuleValue, sdkstep.PackageVersions) {
|
||||
var out map[string]meshcatalog.PackagesByModuleValue
|
||||
// acceptedSeries are the pins of a module of repository whose manifest is m (DLV-I6; ADR 0606 §4, ADR 0609 §1; design 32
|
||||
// *A package, its series, and the series its users accept*): each mesh Go module of another repository whose package's
|
||||
// series the module accepts (Manifest.AcceptedSeries) and a seat published, pinned to the series' newest version (Go's form,
|
||||
// `v0.1.15`). The import form takes no accepted-series override of the packages' digests: it reads each digest from the
|
||||
// entry that publishes the package, whatever series the module accepts (design 47 H2 H-A-672, H-A-580), so only the version
|
||||
// line takes the pins. A module of the same repository takes its sibling by path, never by a series.
|
||||
func acceptedSeries(series map[string]SeriesPackage, m catalogue.Manifest, repository string) sdkstep.PackageVersions {
|
||||
var pins sdkstep.PackageVersions
|
||||
for _, key := range slices.Sorted(maps.Keys(series)) {
|
||||
s := series[key]
|
||||
@@ -184,18 +182,12 @@ func acceptedSeries(series map[string]SeriesPackage, m catalogue.Manifest, repos
|
||||
if repo, _, ok := trunk.PackageRepository(s.GoModule); !ok || trunk.SameRepository(repo, repository) {
|
||||
continue
|
||||
}
|
||||
if out == nil {
|
||||
out, pins = maps.Clone(published), sdkstep.PackageVersions{}
|
||||
if pins == nil {
|
||||
pins = sdkstep.PackageVersions{}
|
||||
}
|
||||
p := publishedOfContents(*pinned.Contents)
|
||||
version := "v" + pinned.Version
|
||||
p.Commit = version
|
||||
out[s.GoModule], pins[s.GoModule] = p, version
|
||||
pins[s.GoModule] = "v" + pinned.Version
|
||||
}
|
||||
if out == nil {
|
||||
return published, nil
|
||||
}
|
||||
return out, pins
|
||||
return pins
|
||||
}
|
||||
|
||||
// pinnedVersion is the version of a series its users are pinned to: its newest released one, never a reservation's
|
||||
|
||||
@@ -236,7 +236,8 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
return fmt.Errorf("no fingerprint is written: %w", err)
|
||||
}
|
||||
// The packages the module graph's entries publish: a reported import set counts only those (design 47 H2 H-A-539, H-A-540).
|
||||
publishedBy, err := ix.packagesPublishedBy(ctx, held)
|
||||
publishedBy, entryDigests, err := ix.publishedByEntries(ctx, held)
|
||||
published = fromEntries(published, entryDigests) // an importer reads the digests of the entry that publishes (H-A-580)
|
||||
mesh, ofRepository := map[string]bool{}, map[string]bool{}
|
||||
for name, repo := range publishedBy {
|
||||
mesh[name] = true
|
||||
@@ -313,7 +314,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
toolchains[artifact] = t.tc
|
||||
}
|
||||
var r result
|
||||
pub, pins := acceptedSeries(series, k.manifest, k.cur.Repository, published)
|
||||
pins := acceptedSeries(series, k.manifest, k.cur.Repository)
|
||||
switch {
|
||||
case k.contexts:
|
||||
r.none = None2Context
|
||||
@@ -321,11 +322,11 @@ 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, series, mesh); ok {
|
||||
if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, published, pins, series, mesh); ok {
|
||||
r = result{fp: fp, tcs: k.held.Toolchains, pkgs: pkgs}
|
||||
}
|
||||
default:
|
||||
f := formOf(module, k.cur.Repository, &kept, k.reported, mesh, toolchains, k.held, held, pub, pins, ix.logf)
|
||||
f := formOf(module, k.cur.Repository, &kept, k.reported, mesh, toolchains, k.held, held, published, pins, ix.logf)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user