builder: answer reserved for a bundle's or an archive's name, and log a name no entry carries
distribution's tag of mesh-delivery-pipeline 0.1.6 was refused: reserved answered 'no entry carries the name mesh-delivery-pipeline/program', since the lookup matched only an artifact's package name and a bundle's entry names none. A bundle's or an archive's name is <module>/<artifact>, read from its reference through NameOf; a name no entry carries is said in the builder's log with the entries looked at. Builds: design 47 G A-418, §478, §572
This commit is contained in:
@@ -411,7 +411,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// The seat mesh-builds' verb reserved, answered here (A-115, A-127): the reservations, the catalog half's carriers and the seat
|
||||
// mesh-catalog's versions.
|
||||
stopReserved, err := calls.AnswerSeat(meshbuilds.Seat, seatlist.Definition(seatGate.Reader, meshbuilds.Seat), map[string]process.SeatHandler{
|
||||
meshbuilds.VerbReserved: reservedVerb(ctx, reservedReader(ctx, reserved.r.Store), versions.CarriersFrom(versions.EntriesOf(branches)), catalogReleased(calls.Call))})
|
||||
meshbuilds.VerbReserved: reservedVerb(ctx, reservedReader(ctx, reserved.r.Store), versions.CarriersFrom(versions.EntriesOf(branches)), catalogReleased(calls.Call),
|
||||
func(name string) {
|
||||
logger.Printf("reserved: no entry carries the name %s; the entries looked at: %s", name, versions.LookedAt(versions.EntriesOf(branches)))
|
||||
})})
|
||||
if err != nil {
|
||||
return fmt.Errorf("answering the verb reserved: %w", err)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,9 @@ func reservedReader(ctx context.Context, store versions.Store) versions.Reader {
|
||||
}}
|
||||
}
|
||||
|
||||
// reservedVerb is the handler of the verb reserved.
|
||||
func reservedVerb(ctx context.Context, rr versions.Reader, carriers func(context.Context, string) ([]versions.Built, error), released versions.CatalogVersions) process.SeatHandler {
|
||||
// reservedVerb is the handler of the verb reserved; missed is told each name no entry carries, for the builder's log (design 47 G
|
||||
// A-418).
|
||||
func reservedVerb(ctx context.Context, rr versions.Reader, carriers func(context.Context, string) ([]versions.Built, error), released versions.CatalogVersions, missed func(name string)) process.SeatHandler {
|
||||
return func(_ string, body json.RawMessage) (any, error) {
|
||||
var in meshbuilds.ReservedInput
|
||||
if len(body) > 0 {
|
||||
@@ -38,7 +39,11 @@ func reservedVerb(ctx context.Context, rr versions.Reader, carriers func(context
|
||||
}
|
||||
}
|
||||
if name := strings.TrimSpace(in.Name); name != "" {
|
||||
return versions.AnswerReservedByName(ctx, rr, carriers, released, name, in.Version)
|
||||
a, err := versions.AnswerReservedByName(ctx, rr, carriers, released, name, in.Version)
|
||||
if err == nil && missed != nil && strings.HasPrefix(a.Error, versions.NoEntryCarries) {
|
||||
missed(name)
|
||||
}
|
||||
return a, err
|
||||
}
|
||||
return versions.AnswerReservedVerb(rr, in.Module, in.Version)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ func TestTheProcessAnswersReserved(t *testing.T) {
|
||||
return json.Marshal(meshcatalog.VersionsAnswer{Versions: []meshcatalog.VersionEntry{{Module: "mesh-sdk", Version: "0.1.2",
|
||||
Artifacts: []meshcatalog.VersionArtifact{{Artifact: "mesh-sdk:ts", Digest: "sha256:dd"}}}}})
|
||||
})
|
||||
handle := reservedVerb(context.Background(), none, carriers, released)
|
||||
var missed []string
|
||||
handle := reservedVerb(context.Background(), none, carriers, released, func(name string) { missed = append(missed, name) })
|
||||
got, err := handle("", json.RawMessage(`{"name":"@novox/mesh-sdk","version":"0.1.2"}`))
|
||||
a, ok := got.(meshbuilds.ReservedAnswer)
|
||||
if err != nil || !ok || !a.Released || a.Module != "mesh-sdk" || len(a.Artifacts) != 1 || a.Artifacts[0].Digest != "sha256:dd" {
|
||||
@@ -36,6 +37,10 @@ func TestTheProcessAnswersReserved(t *testing.T) {
|
||||
if len(asked) != 1 || asked[0] != "seat:mesh-catalog.versions" {
|
||||
t.Errorf("the released versions were asked of %v, want the seat mesh-catalog's versions", asked)
|
||||
}
|
||||
// Design 47 G A-418: a name no entry carries is answered error and told for the builder's log.
|
||||
if got, err := handle("", json.RawMessage(`{"name":"nobody/program","version":"0.1.6"}`)); err != nil || got.(meshbuilds.ReservedAnswer).Error == "" || len(missed) != 1 || missed[0] != "nobody/program" {
|
||||
t.Errorf("a name no entry carries: %+v (%v), told %v", got, err, missed)
|
||||
}
|
||||
if _, err := handle("", json.RawMessage(`{"module":"mesh-sdk"}`)); err == nil {
|
||||
t.Error("a module with no reservation was answered")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -38,7 +39,9 @@ func NamesFrom(all Entries) PackageNames {
|
||||
}
|
||||
|
||||
// CarriersFrom are the module artifacts a package's name in its ecosystem is the name of, as the entries hold them (design 47 G
|
||||
// §572, §478), each distinct module and artifact once, sorted; a name no entry carries answers none.
|
||||
// §572, §478), each distinct module and artifact once, sorted; a name no entry carries answers none. A bundle's or an archive's
|
||||
// name is `<module>/<artifact>` (NameOf), read from its artifact reference `<module>:<artifact>`: the entry gives it no
|
||||
// `package` (design 47 G A-418).
|
||||
func CarriersFrom(all Entries) func(ctx context.Context, name string) ([]Built, error) {
|
||||
return func(_ context.Context, name string) ([]Built, error) {
|
||||
seen := map[Built]bool{}
|
||||
@@ -46,7 +49,7 @@ func CarriersFrom(all Entries) func(ctx context.Context, name string) ([]Built,
|
||||
for _, e := range all() {
|
||||
for _, a := range e.Artifacts {
|
||||
artifact, ok := artifactOf(e.Module, a.Ref)
|
||||
if !ok || a.Package == nil || a.Package.Name != name || seen[Built{e.Module, artifact}] {
|
||||
if !ok || !carries(e.Module, artifact, a, name) || seen[Built{e.Module, artifact}] {
|
||||
continue
|
||||
}
|
||||
seen[Built{e.Module, artifact}] = true
|
||||
@@ -58,6 +61,39 @@ func CarriersFrom(all Entries) func(ctx context.Context, name string) ([]Built,
|
||||
}
|
||||
}
|
||||
|
||||
// carries says whether artifact a of module is named name: its package's name, or a bundle's or an archive's NameOf (A-418).
|
||||
func carries(module, artifact string, a meshcatalog.Artifact, name string) bool {
|
||||
if a.Package != nil {
|
||||
return a.Package.Name == name
|
||||
}
|
||||
return (a.Kind == KindBundle || a.Kind == KindArchive) && NameOf(module, artifact) == name
|
||||
}
|
||||
|
||||
// LookedAt says the entries a name was looked for in, for the log of a name no entry carries (design 47 G A-418): how many,
|
||||
// and each module's artifacts with the name each is carried as.
|
||||
func LookedAt(all Entries) string {
|
||||
entries := all()
|
||||
var out []string
|
||||
for _, e := range entries {
|
||||
for _, a := range e.Artifacts {
|
||||
artifact, ok := artifactOf(e.Module, a.Ref)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case a.Package != nil:
|
||||
out = append(out, a.Ref+" as "+a.Package.Name)
|
||||
case a.Kind == KindBundle || a.Kind == KindArchive:
|
||||
out = append(out, a.Ref+" as "+NameOf(e.Module, artifact))
|
||||
default:
|
||||
out = append(out, a.Ref+" ("+a.Kind+", named nothing)")
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return fmt.Sprintf("%d entries: %s", len(entries), strings.Join(out, ", "))
|
||||
}
|
||||
|
||||
// ModuleFrom is the module and artifact a package's name is built from, from the entries (CarriersFrom); more than one entry
|
||||
// carrying it is an error naming them.
|
||||
func ModuleFrom(all Entries) func(ctx context.Context, name string) (module, artifact string, found bool, err error) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package versions
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -19,7 +20,8 @@ func named(module, artifact, name string) meshcatalog.CatalogEntry {
|
||||
func TestPackageNamesAreReadFromTheCatalogHalfsEntries(t *testing.T) {
|
||||
entries := func() []meshcatalog.CatalogEntry {
|
||||
return []meshcatalog.CatalogEntry{named("mesh-sdk", "go", "git.novox.be/novox/mesh-sdk/go"), named("netcheck", "lib", "netcheck"),
|
||||
named("twin-a", "lib", "twin"), named("twin-b", "lib", "twin"), {Module: "bare"}}
|
||||
named("twin-a", "lib", "twin"), named("twin-b", "lib", "twin"), {Module: "bare"},
|
||||
{Module: "pipe", Artifacts: []meshcatalog.Artifact{{Ref: "pipe:program", Kind: KindBundle}, {Ref: "pipe:img", Kind: KindImage}}}}
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, c := range []struct {
|
||||
@@ -48,6 +50,17 @@ func TestPackageNamesAreReadFromTheCatalogHalfsEntries(t *testing.T) {
|
||||
if _, _, _, err := ModuleFrom(entries)(ctx, "twin"); err == nil {
|
||||
t.Error("ModuleFrom(twin): two entries carry it, want an error")
|
||||
}
|
||||
// Design 47 G A-418: a bundle is carried as <module>/<artifact>, from its reference, with no package in its entry; a kind
|
||||
// that is neither a bundle nor an archive is not named so.
|
||||
if got, _ := CarriersFrom(entries)(ctx, "pipe/program"); !reflect.DeepEqual(got, []Built{{"pipe", "program"}}) {
|
||||
t.Errorf("CarriersFrom(pipe/program) = %v, want the bundle pipe:program", got)
|
||||
}
|
||||
if got, _ := CarriersFrom(entries)(ctx, "pipe/img"); len(got) != 0 {
|
||||
t.Errorf("CarriersFrom(pipe/img) = %v, want none: an image with no package is named nothing", got)
|
||||
}
|
||||
if looked := LookedAt(entries); !strings.Contains(looked, "6 entries") || !strings.Contains(looked, "pipe:program as pipe/program") {
|
||||
t.Errorf("LookedAt = %q, want the six entries and the bundle's name", looked)
|
||||
}
|
||||
got, _ := CarriersFrom(entries)(ctx, "twin")
|
||||
if want := []Built{{"twin-a", "lib"}, {"twin-b", "lib"}}; !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("CarriersFrom(twin) = %v, want %v", got, want)
|
||||
|
||||
@@ -581,7 +581,7 @@ func AnswerReservedByName(ctx context.Context, r Reader, carriers func(context.C
|
||||
}
|
||||
switch {
|
||||
case len(got) == 0:
|
||||
return meshbuilds.ReservedAnswer{Error: "no entry carries the name " + name}, nil
|
||||
return meshbuilds.ReservedAnswer{Error: NoEntryCarries + name}, nil
|
||||
case len(got) > 1:
|
||||
return meshbuilds.ReservedAnswer{Error: MoreThanOne(name, got)}, nil
|
||||
}
|
||||
@@ -612,6 +612,9 @@ func AnswerReservedByName(ctx context.Context, r Reader, carriers func(context.C
|
||||
return meshbuilds.ReservedAnswer{Error: fmt.Sprintf("%s (%s) has no reserved version", name, module)}, nil
|
||||
}
|
||||
|
||||
// NoEntryCarries opens the answer of reserved given a name no entry carries.
|
||||
const NoEntryCarries = "no entry carries the name "
|
||||
|
||||
// The descriptions of the reservation's tools.
|
||||
const (
|
||||
ReservedDescription = "The versions the builder reserved (its state reserved, design 47 G section 369): one per module and MAJOR.MINOR, " +
|
||||
|
||||
Reference in New Issue
Block a user