diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go index 9c333f9d..a5167640 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go @@ -228,6 +228,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro return err } b.PackageWait = time.Duration(packageWait) * time.Minute + // Before it waits for an unpinned package, the build reads what the Go package registry seat holds of it (H-A-194). + b.PublishedVersions = publishedVersionsVia(calls.Call) waitsBucket := process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, build.WaitsState), "the toolchain waits are kept in memory only, and builder_waits shows none", logger.Printf) b.Waits = newWaitsKept(waitsBucket, func(ctx context.Context, event, id string, body any) error { return emitEvent(context.WithoutCancel(ctx), js, cred, event, id, body) diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/versions.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/versions.go index 1dfae047..fbd625ac 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/versions.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/versions.go @@ -13,6 +13,7 @@ import ( "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry" "git.novox.be/novox/mesh-sdk/go/process" "mesh-delivery-builder/internal/build" @@ -96,6 +97,28 @@ func (s awaitedVersions) KeysOf(ctx context.Context, filter string) ([]string, e return out, nil } +// publishedVersionsVia asks the Go package registry seat's verb versions for one package path (design 47 H H-A-194): its +// versions, newest first. +func publishedVersionsVia(call toolCaller) func(context.Context, string) ([]string, error) { + return func(_ context.Context, path string) ([]string, error) { + raw, err := call("seat:"+gopackageregistry.Seat+"."+gopackageregistry.VerbVersions, gopackageregistry.VersionsInput{Name: path}) + if err != nil { + return nil, err + } + var a gopackageregistry.VersionsAnswer + if err := json.Unmarshal(raw, &a); err != nil { + return nil, fmt.Errorf("%s's versions answered what is no list of versions: %w", gopackageregistry.Seat, err) + } + var out []string + for _, v := range a.Versions { + if v.Version != "" { + out = append(out, v.Version) + } + } + return out, nil + } +} + // floorVia is the floor's three sources as calls of the builder's own account (design 51 *The floor*): the seat's verb // versions, the seat git's tags and the requirements the catalog half's entries name (A-119). A call that fails is that source // silent. diff --git a/modules/mesh-delivery-builder/internal/build/revisionwait.go b/modules/mesh-delivery-builder/internal/build/revisionwait.go index 4205115d..2a052bbc 100644 --- a/modules/mesh-delivery-builder/internal/build/revisionwait.go +++ b/modules/mesh-delivery-builder/internal/build/revisionwait.go @@ -107,7 +107,8 @@ func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (ou // **A package with no pin waits for its publish** (design 47 H H-A-192, H-A-165, H-A-183, H-A-184, H-A-185): an entry // keeps a mesh package the registry has not published within the series its module accepts with an empty version. Its -// build, a step ask's or a lane's, waits for the registry seat's published of that package path in that series (the +// build, a step ask's or a lane's, first reads the versions the registry seat holds of the path (its verb versions, +// H-A-194), then waits for the registry seat's published of that package path in that series (the // series the module's manifest names in `packages`, else the default; catalogue.Manifest.AcceptedSeries), up to // PackageWait (the setting package-wait-minutes), and pins the version that event carries; the builder never derives a // pin (no release number of the module that holds the package). Past the bound the build fails, naming the package, and @@ -178,6 +179,20 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp, digest string, if err != nil { return nil, meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("the series %s accepts of %s cannot be read: its manifest %s: %v", module, unpinned[0], digest, err) } + // What the registry seat holds is read once before the wait (H-A-194): the publishes heard are a cache of it. + for _, p := range unpinned { + if b.PublishedVersions == nil || b.publishedPin(p, man.AcceptedSeries(p)) != "" { + continue + } + vs, err := b.PublishedVersions(ctx, p) + if err != nil { + b.logf("%s at %s: the versions the registry seat holds of %s cannot be read, so the build waits for its publish: %v", module, fp, p, err) + continue + } + for _, v := range vs { + b.PackagePublished(p, v) + } + } bound := b.packageWait() wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8) defer stop() diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index de1bb43b..7f76e535 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -117,6 +117,9 @@ type Builder struct { // package-wait-minutes (H-A-165); DefaultPackageWait when 0. Only a registry seat's published heard (PackagePublished) // gives a pin (H-A-192). PackageWait time.Duration + // PublishedVersions asks the Go package registry seat's verb versions for one package path, its versions newest first + // (H-A-194): read once before a build waits for that package. Nil reads none. + PublishedVersions func(ctx context.Context, path string) ([]string, error) // Forms answers what each node's engine states it reads (ADR 0618 §2, ADR 0624 §1): present, the nodes whose engine // answered when last asked, and counted, every node the assignments names, present or away, a node with no statement // stating nothing (the baseline's first forms). A done key names each artifact in the forms these keep, the oldest in diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 6fb5c0f0..6a777cf2 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "reflect" + "slices" "strings" "sync/atomic" "testing" @@ -122,6 +123,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) t.Run("H-A-165: a package with no pin waits for its release and is built with it", aPackageWithNoPinWaitsForItsRelease) t.Run("H-A-165: past its bound a package with no release fails the step", aPackageWithNoReleaseFailsPastItsBound) t.Run("H-A-192: a lane waits for an unpinned package's publish and fails past its bound", aLaneWaitsForAnUnpinnedPackage) + t.Run("H-A-194: what the registry seat holds pins the package before any wait", theSeatsVersionsPinBeforeTheWait) } // unpinnedRig is a rig whose step entry m names the package x with no version. Its manifest names no `packages`, so it @@ -207,6 +209,38 @@ func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) { } } +// H-A-194: the build reads the registry seat's versions of the path once before it waits: a version in the accepted series +// pins the package with no event heard; one only in another series leaves the build waiting for a publish. +func theSeatsVersionsPinBeforeTheWait(t *testing.T) { + r, _, _ := unpinnedRig(t) + r.b.PackageWait = time.Nanosecond // no wait: the seat's answer alone gives the pin + var read []string + r.b.PublishedVersions = func(_ context.Context, path string) ([]string, error) { + read = append(read, path) + return []string{"0.2.1", "0.1.9", "0.1.8"}, nil // newest first + } + end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + r.b.Wait() + asks := r.asks.Asks() + if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(asks) == 0 || asks[0].Packages[unpinnedX] != "v0.1.9" || !slices.Equal(read, []string{unpinnedX}) { + t.Errorf("end = %+v, asks %+v, read %v; want passed, built with x at v0.1.9 read once from the seat", end, asks, read) + } + r2, _, waiting := unpinnedRig(t) + r2.b.PublishedVersions = func(context.Context, string) ([]string, error) { return []string{"0.2.1"}, nil } + ended := make(chan meshbuilds.StepEnded, 1) + go func() { + ended <- r2.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + }() + awaitWaiting(t, waiting, ended) + r2.b.PackagePublished(unpinnedX, "0.1.10") + if end := <-ended; end.Outcome != meshbuilds.StepEndedOutcomePassed { + t.Errorf("end = %+v, want passed once x was published in its series", end) + } + r2.b.Wait() +} + // H-A-192, H-A-165: the lane of an entry taken in waits the same way, never asking a build without the pin, and fails the // key past the bound naming the package. func aLaneWaitsForAnUnpinnedPackage(t *testing.T) {