B3: the builder's dead readers of the indexer's packages state go
The builder reads package names from the catalog half's entries alone and never the indexer's state (design 47 G §348): PackagesState, NamesIn, NamedModule, Carriers and ModuleOf, which read that state and are wired nowhere, go; the reservation's name test reads its carriers from the entries. Builds: design 47 G §348, spec 25
This commit is contained in:
@@ -98,9 +98,8 @@ func (b *Builder) RecordAgain(ctx context.Context, module, fp, when string) (str
|
||||
return res.Version, nil
|
||||
}
|
||||
|
||||
// PackageNamed looks at a module again when the indexer's packages state names a name for one of its packages
|
||||
// (versions.NamedModule): a done trunk build that left the package unnumbered, its name not known at its claim, is
|
||||
// numbered then with the done build's digests, and version.numbered says them for its build module's late publish.
|
||||
// PackageNamed looks at a module again when the catalog half's entry of it names a package's name in its ecosystem
|
||||
// (design 47 G §348): a done build is looked at and nothing is built again.
|
||||
func (b *Builder) PackageNamed(ctx context.Context, module string) {
|
||||
b.init()
|
||||
b.mu.Lock()
|
||||
|
||||
@@ -4,121 +4,15 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// PackagesState is the indexer's packages state as the builder reads it (its manifest's reads grant): its keys, and one
|
||||
// key's value (found false when it holds none).
|
||||
type PackagesState interface {
|
||||
Keys(ctx context.Context) ([]string, error)
|
||||
Get(ctx context.Context, key string) (value []byte, found bool, err error)
|
||||
}
|
||||
|
||||
// NamesIn are a package's names in its ecosystem as the indexer's packages state holds them (design 32): the name of the
|
||||
// series key that names module and artifact as what it is built from. A series key is named `<name>.<series>`; a key
|
||||
// with no dot is a mesh Go module's published packages, not a series. A value that does not decode is passed over.
|
||||
func NamesIn(s PackagesState) PackageNames {
|
||||
return func(ctx context.Context, module, artifact string) (string, bool, error) {
|
||||
keys, err := s.Keys(ctx)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
sort.Strings(keys)
|
||||
built := NameOf(module, artifact)
|
||||
for _, key := range keys {
|
||||
if !isSeriesKey(key) {
|
||||
continue
|
||||
}
|
||||
value, found, err := s.Get(ctx, key)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
v, _, err := meshcatalog.DecodePackagesByPackageSeriesValue(value) // the indexer's value of a series key (mesh-sdk's contract, J4)
|
||||
if err != nil || v.Package != built {
|
||||
continue
|
||||
}
|
||||
return v.Name, true, nil
|
||||
}
|
||||
return "", false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// NamedModule is the module a value of the indexer's packages state names a package's name for (design 32), and that
|
||||
// name: a series key whose value names a name and the <module>/<artifact> it is built from. The builder looks at that module again when
|
||||
// the value is heard, so a done build that left the package unnumbered (its name not known at its claim) is numbered then.
|
||||
func NamedModule(key string, value []byte) (module, name string, ok bool) {
|
||||
if !isSeriesKey(key) {
|
||||
return "", "", false
|
||||
}
|
||||
v, _, err := meshcatalog.DecodePackagesByPackageSeriesValue(value)
|
||||
if err != nil || v.Name == "" {
|
||||
return "", "", false
|
||||
}
|
||||
module, artifact, cut := strings.Cut(v.Package, "/")
|
||||
if !cut || module == "" || artifact == "" {
|
||||
return "", "", false
|
||||
}
|
||||
return module, v.Name, true
|
||||
}
|
||||
|
||||
// isSeriesKey says whether a key of the indexer's packages state is a series key (`<package>.<series>`), not a per-module one.
|
||||
func isSeriesKey(key string) bool {
|
||||
_, _, ok := meshcatalog.ParsePackagesByPackageSeriesKey(key)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Built is a module's artifact, which a package's name is the name of.
|
||||
type Built struct{ Module, Artifact string }
|
||||
|
||||
// Carriers are the module artifacts a package's name in its ecosystem is the name of, as the catalog half's packages view
|
||||
// holds them (the inverse of NamesIn; design 47 G §572, §478): each distinct module and artifact of a series key whose value
|
||||
// names that name, sorted. A name no entry carries answers none.
|
||||
func Carriers(s PackagesState) func(ctx context.Context, name string) ([]Built, error) {
|
||||
return func(ctx context.Context, name string) ([]Built, error) {
|
||||
keys, err := s.Keys(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Strings(keys)
|
||||
seen := map[Built]bool{}
|
||||
var out []Built
|
||||
for _, key := range keys {
|
||||
if !isSeriesKey(key) {
|
||||
continue
|
||||
}
|
||||
value, found, err := s.Get(ctx, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
v, _, err := meshcatalog.DecodePackagesByPackageSeriesValue(value)
|
||||
if err != nil || v.Name != name {
|
||||
continue
|
||||
}
|
||||
if module, artifact, cut := strings.Cut(v.Package, "/"); cut && module != "" && artifact != "" && !seen[Built{module, artifact}] {
|
||||
seen[Built{module, artifact}] = true
|
||||
out = append(out, Built{module, artifact})
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ModuleOf is the module and artifact a package's name is built from (Carriers), found false for a name no entry carries; more
|
||||
// than one entry carrying it is an error naming them.
|
||||
func ModuleOf(s PackagesState) func(ctx context.Context, name string) (module, artifact string, found bool, err error) {
|
||||
return moduleOfCarriers(Carriers(s))
|
||||
}
|
||||
|
||||
// moduleOfCarriers is ModuleOf over one way of finding the carriers.
|
||||
// moduleOfCarriers is the module and artifact a package's name is built from, found false for a name no entry carries; more
|
||||
// than one entry carrying it is an error naming them. The carriers are read from the catalog half's entries (CarriersFrom,
|
||||
// design 47 G §348), never from the indexer's state.
|
||||
func moduleOfCarriers(carriers func(ctx context.Context, name string) ([]Built, error)) func(ctx context.Context, name string) (module, artifact string, found bool, err error) {
|
||||
return func(ctx context.Context, name string) (string, string, bool, error) {
|
||||
got, err := carriers(ctx, name)
|
||||
|
||||
@@ -12,17 +12,20 @@ import (
|
||||
)
|
||||
|
||||
// TestReservedByNameAnswersFromTheViewAndTheCatalog: design 47 G §572, §582, A-70 — a package's name (an npm name or a Go
|
||||
// module path) is mapped to its module from the catalog half's view; the reserved version answers as for the module, a version
|
||||
// module path) is mapped to its module from the catalog half's entries (design 47 G §348); the reserved version answers as for the module, a version
|
||||
// no reservation holds is asked of the catalog's versions and answers released with the release's digests, and a name no entry
|
||||
// carries, one more than one carries, or a version neither reserved nor released answers error, set alone.
|
||||
func TestReservedByNameAnswersFromTheViewAndTheCatalog(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
view := packagesMem{
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go.0.1": []byte(`{"v":1,"name":"git.novox.be/novox/mesh-sdk/go","package":"mesh-sdk/go","series":"0.1"}`),
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go.0.2": []byte(`{"v":1,"name":"git.novox.be/novox/mesh-sdk/go","package":"mesh-sdk/go","series":"0.2"}`),
|
||||
"@novox/mesh-sdk.0.1": []byte(`{"v":1,"name":"@novox/mesh-sdk","package":"mesh-sdk/ts","series":"0.1"}`),
|
||||
"twice.0.1": []byte(`{"v":1,"name":"twice","package":"a/x","series":"0.1"}`),
|
||||
"twice-b.0.1": []byte(`{"v":1,"name":"twice","package":"b/y","series":"0.1"}`),
|
||||
pkg := func(ref, name string) meshcatalog.Artifact {
|
||||
return meshcatalog.Artifact{Ref: ref, Kind: KindPackage, Package: &meshcatalog.ArtifactPackage{Name: name}}
|
||||
}
|
||||
entries := func() []meshcatalog.CatalogEntry {
|
||||
return []meshcatalog.CatalogEntry{
|
||||
{Module: "mesh-sdk", Artifacts: []meshcatalog.Artifact{pkg("mesh-sdk:go", "git.novox.be/novox/mesh-sdk/go"), pkg("mesh-sdk:ts", "@novox/mesh-sdk")}},
|
||||
{Module: "a", Artifacts: []meshcatalog.Artifact{pkg("a:x", "twice")}},
|
||||
{Module: "b", Artifacts: []meshcatalog.Artifact{pkg("b:y", "twice")}},
|
||||
}
|
||||
}
|
||||
store := &reserveMem{mem: newMem()}
|
||||
r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"0.1.3"}, nil }}
|
||||
@@ -40,7 +43,7 @@ func TestReservedByNameAnswersFromTheViewAndTheCatalog(t *testing.T) {
|
||||
asked = append(asked, module)
|
||||
return []meshcatalog.VersionEntry{{Module: module, Version: "0.1.2", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "mesh-sdk:go", Digest: "sha256:dd"}}}}, nil
|
||||
}
|
||||
carriers := Carriers(view)
|
||||
carriers := CarriersFrom(entries)
|
||||
ask := func(name, version string) meshbuilds.ReservedAnswer {
|
||||
t.Helper()
|
||||
got, err := AnswerReservedByName(ctx, rd, carriers, released, name, version)
|
||||
@@ -81,7 +84,8 @@ func TestReservedByNameAnswersFromTheViewAndTheCatalog(t *testing.T) {
|
||||
if got := ask("@novox/mesh-sdk", "9.9.9"); !strings.Contains(got.Error, "reserved or released") {
|
||||
t.Errorf("a version never reserved = %+v, want refused as neither reserved nor released", got)
|
||||
}
|
||||
if _, err := AnswerReservedByName(ctx, rd, Carriers(packagesMem(nil)), released, "x", ""); err == nil {
|
||||
unreadable := func(context.Context, string) ([]Built, error) { return nil, errors.New("down") }
|
||||
if _, err := AnswerReservedByName(ctx, rd, unreadable, released, "x", ""); err == nil {
|
||||
t.Error("an unreadable view was answered as if no entry carried the name")
|
||||
}
|
||||
if _, err := AnswerReservedByName(ctx, rd, carriers, func(context.Context, string) ([]meshcatalog.VersionEntry, error) { return nil, errors.New("down") }, "git.novox.be/novox/mesh-sdk/go", "0.1.2"); err == nil {
|
||||
|
||||
@@ -3,10 +3,7 @@ package versions
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"maps"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -76,23 +73,6 @@ func (m *mem) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// packagesMem is the indexer's packages state as the builder reads it, in memory.
|
||||
type packagesMem map[string][]byte
|
||||
|
||||
func (p packagesMem) Keys(context.Context) ([]string, error) {
|
||||
if p == nil {
|
||||
return nil, errors.New("not readable")
|
||||
}
|
||||
return slices.Collect(maps.Keys(p)), nil
|
||||
}
|
||||
|
||||
func (p packagesMem) Get(_ context.Context, key string) ([]byte, bool, error) {
|
||||
v, ok := p[key]
|
||||
return v, ok, nil
|
||||
}
|
||||
|
||||
func (p packagesMem) failing() packagesMem { return nil }
|
||||
|
||||
// TestTheBuildersVersions holds design 51 *The versions*, *The floor* and *Tagged versions* (DLV-B1, DLV-B2, DLV-B3):
|
||||
// one table per rule, the unit cases of the builder's numbering.
|
||||
func TestTheBuildersVersions(t *testing.T) {
|
||||
@@ -211,20 +191,4 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("a closed window closes again: old-form-closed would be said twice")
|
||||
}
|
||||
})
|
||||
t.Run("the packages state's names", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
state := packagesMem{
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go": []byte(`{"v":1,"module":"git.novox.be/novox/mesh-sdk/go"}`),
|
||||
"broken.0.1": []byte(`not json`),
|
||||
"new.0.1": []byte(`{"v":1,"name":"new","package":"mesh-sdk/new","series":"0.1"}`),
|
||||
}
|
||||
for key, want := range map[string]string{"new.0.1": "mesh-sdk", "git=2enovox=2ebe/novox/mesh-sdk/go": "", "broken.0.1": ""} {
|
||||
if module, name, ok := NamedModule(key, state[key]); module != want || ok != (want != "") || (ok && name != "new") {
|
||||
t.Errorf("NamedModule(%s) = %q, %q, %v, want %q", key, module, name, ok, want)
|
||||
}
|
||||
}
|
||||
if _, _, err := NamesIn(packagesMem(nil).failing())(ctx, "m", "a"); err == nil {
|
||||
t.Error("a packages state that cannot be read is no error")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user