B18 pin-from-newer-entry-or-publisher: a blank pin is the version a newer entry of the build's branch names, else the publisher's build in the build's revision (the published rule); the wait is held in the state waits and VersionAt goes

Builds: design 47 H2 H-A-707 (3), (4), (5)
This commit is contained in:
2026-11-25 17:59:22 +01:00
parent 697716ca48
commit 3dc67f4dc8
11 changed files with 201 additions and 124 deletions
@@ -191,9 +191,9 @@ func (rv *reservations) TakenOver(ctx context.Context, module, fingerprint strin
return rv.r.TakenOver(ctx, module, fingerprint)
}
// VersionAt is the version module's artifact is published at from the source revision of branch (H-A-547 (3), H-A-551).
func (rv *reservations) VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error) {
return rv.r.VersionAt(ctx, module, artifact, branch, source)
// PublishedOf answers the seat mesh-builds' published rule for the build's pins (H-A-328, design 47 H2 H-A-707 (4)).
func (rv *reservations) PublishedOf(ctx context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error) {
return rv.r.PublishedOf(ctx, module, artifact, fingerprint)
}
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
@@ -57,7 +57,7 @@ func newWaitsKept(kv *process.AwaitedBucket, say func(context.Context, string, s
func (w *waitsKept) body(t build.ToolchainWait, how string) waitBody {
b := waitBody{Step: waitStepBuilding, On: t.On(), Part: t.Package, Module: t.Module, Fingerprint: t.Fingerprint, Since: t.Since, Bound: w.bound.String(), How: how,
Publisher: t.Publisher, Until: t.Until}
if t.Publisher != "" { // a pin wait says the bound of `package-wait-minutes`, which it carries, and the revision it holds
if !t.Until.IsZero() { // a pin wait says the bound of `package-wait-minutes`, which it carries, and the revision it holds
b.Bound, b.Revision = t.Bound, t.Revision
}
if t.IsRevision() { // a step ask's wait for its revision: `step` build, its own bound (design 47 H2 H-A-577 (1))
@@ -136,9 +136,9 @@ type Reservations interface {
// artifact a registry holds there for the build's fingerprint, marking it published, before a build module is asked for the
// fingerprint again (design 47 H2 H-A-588 (4)). A read that does not answer is said and the build goes on.
MarkRegistryHeld(ctx context.Context, v versions.ReservedVersion)
// VersionAt is the version module's artifact is published at from the source revision of branch: its reservation of that
// origin with the artifact published, else its release recorded at that source revision (design 47 H2 H-A-547 (3), H-A-551).
VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error)
// PublishedOf is the seat mesh-builds' published rule (design 47 H-A-328): whether artifact of module built at fingerprint is
// published, and its version; the pin a blank package takes is the publisher's build in the build's revision (H2 H-A-707 (4)).
PublishedOf(ctx context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error)
}
// reserves says whether a look at a trunk build is one that reserves: the build has a series of the form MAJOR.MINOR
@@ -37,24 +37,24 @@ type fakeReservations struct {
marks []string // the versions MarkRegistryHeld was told, with the asks the build module had by then (H-A-588 (4))
asked func() int
atMu sync.Mutex
at map[string]string // by "<module>:<artifact>@<branch>.<source>", the version VersionAt answers (H-A-547 (3))
at map[string]string // by "<module>:<artifact>@<fingerprint>", the version PublishedOf answers (H2 H-A-707 (4))
}
func (f *fakeReservations) VersionAt(_ context.Context, module, artifact, branch string, source int64) (string, bool, error) {
func (f *fakeReservations) PublishedOf(_ context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error) {
f.atMu.Lock()
defer f.atMu.Unlock()
v, ok := f.at[fmt.Sprintf("%s:%s@%s.%d", module, artifact, branch, source)]
return v, ok, nil
v, ok := f.at[fmt.Sprintf("%s@%s", artifact, fingerprint)]
return meshbuilds.PublishedAnswer{Published: ok, Version: v}, nil
}
// publishAt makes VersionAt answer version for module's artifact at the origin branch and source.
func (f *fakeReservations) publishAt(module, artifact, branch string, source int64, version string) {
// publishAt makes PublishedOf answer version for module's artifact built at fingerprint (design 47 H2 H-A-707 (4)).
func (f *fakeReservations) publishAt(module, artifact, fingerprint, version string) {
f.atMu.Lock()
defer f.atMu.Unlock()
if f.at == nil {
f.at = map[string]string{}
}
f.at[fmt.Sprintf("%s:%s@%s.%d", module, artifact, branch, source)] = version
f.at[fmt.Sprintf("%s:%s@%s", module, artifact, fingerprint)] = version
}
func (f *fakeReservations) MarkRegistryHeld(_ context.Context, v versions.ReservedVersion) {
@@ -2,6 +2,7 @@ package build
import (
"context"
"errors"
"fmt"
"maps"
"slices"
@@ -262,36 +263,92 @@ func (b *Builder) PackagePublished(name, version string) {
b.pictureMoved()
}
// versionAtOrigin is the version, as Go names it, the module that publishes the package holds at the source revision of the
// key's origin (H-A-547 (3), H-A-551), and words saying why there is none.
func (b *Builder) versionAtOrigin(ctx context.Context, key, pkg string) (version, none string) {
if b.Members == nil || b.Reserved == nil {
return "", "no module that publishes it can be read"
}
module, artifact, found, err := b.Members(ctx, pkg)
if err != nil || !found {
if err != nil {
return "", fmt.Sprintf("the module that publishes it cannot be read: %v", err)
}
return "", "no entry names the module that publishes it"
}
// pinOf is the version of package pkg for the build of module at fp, which holds origin, and what it waited for when there is none
// (design 47 H2 H-A-707 (3), (4)). First the entry the picture holds for the module on the branch of origin, when it is of fp and
// names a version for the package: a newer entry of the key's fingerprint has the pin its earlier entry lacked, and an entry of
// another branch is never read. Else the version of the publisher's build in the build's revision: the module that publishes the
// package (Members), its fingerprint in the catalog revision origin names (the picture while it holds that revision, else the
// revision read by number, once), and the version the seat mesh-builds' published rule answers (Reserver.PublishedOf, H-A-328).
// publisher is `<module>@<fingerprint>` of that build, empty where no module publishes the package.
func (b *Builder) pinOf(ctx context.Context, module, fp, pkg string, origin Origin) (version, publisher, none string) {
hk := origin.Branch + "\x00" + module
b.mu.Lock()
o := b.origin[key]
h, heard := b.heard[hk]
at := b.heardAt[hk]
b.mu.Unlock()
v, found, err := b.Reserved.VersionAt(ctx, module, artifact, o.Branch, o.Source)
if heard && h.Fp2 == fp && h.Packages[pkg] != "" {
if _, told := b.pinTold.LoadOrStore(module+"@"+fp+" "+pkg, true); !told {
b.logf("%s at %s: %s takes %s, the pin of the entry of revision %d, heard while the build from revision %d waited", module, fp, pkg, h.Packages[pkg], at.Revision, origin.Revision)
}
return h.Packages[pkg], "", ""
}
if b.Members == nil || b.Reserved == nil {
return "", "", "no module that publishes it can be read"
}
pubModule, artifact, found, err := b.Members(ctx, pkg)
if err != nil {
return "", fmt.Sprintf("the version %s holds at source revision %d cannot be read: %v", module, o.Source, err)
return "", "", fmt.Sprintf("the module that publishes it cannot be read: %v", err)
}
if !found {
return "", fmt.Sprintf("%s publishes no version of it at source revision %d of %s", module, o.Source, o.Branch)
return "", "", fmt.Sprintf("no module of revision %d publishes it", origin.Revision)
}
return "v" + strings.TrimPrefix(v, "v"), ""
pubFP, err := b.fingerprintAt(ctx, origin, pubModule)
if err != nil {
return "", pubModule + "@", fmt.Sprintf("%s's fingerprint in revision %d cannot be read: %v", pubModule, origin.Revision, err)
}
publisher = pubModule + "@" + pubFP
if pubFP == "" {
return "", publisher, fmt.Sprintf("%s has no entry in revision %d of %s", pubModule, origin.Revision, origin.Branch)
}
a, err := b.Reserved.PublishedOf(ctx, pubModule, pubModule+":"+artifact, pubFP) // the reservation keeps an artifact by its ref
if err != nil {
return "", publisher, fmt.Sprintf("the version %s holds at %s cannot be read: %v", pubModule, pubFP, err)
}
if !a.Published {
return "", publisher, fmt.Sprintf("%s at %s (revision %d) is not published", pubModule, pubFP, origin.Revision)
}
return "v" + strings.TrimPrefix(a.Version, "v"), publisher, ""
}
// awaitPublished fills each package of packages with no pin from the version its publisher holds at the key's origin
// (versionAtOrigin), waiting for one (H-A-521, H-A-165). It answers the packages with every pin, or an outcome and its words:
// failed past the bound naming the package, could not run when the builder stops.
func (b *Builder) awaitPublished(ctx context.Context, module, fp string, packages map[string]string) (map[string]string, string, string) {
// fingerprintAt is module's fingerprint in the catalog revision origin names: in the picture of the branch while the picture holds
// that revision (or the origin names none), else in the revision read by number through the seat mesh-catalog, kept once read.
func (b *Builder) fingerprintAt(ctx context.Context, origin Origin, module string) (string, error) {
hk := origin.Branch + "\x00" + module
b.mu.Lock()
h, heard := b.heard[hk]
at := b.heardAt[hk]
b.mu.Unlock()
if heard && (origin.Revision <= 0 || at.Revision == origin.Revision) {
return h.Fp2, nil
}
if b.KeptRevision == nil || origin.Revision <= 0 {
return "", errors.New("the picture does not hold the revision and none can be read by its number")
}
rk := fmt.Sprintf("%s\x00%d", origin.Branch, origin.Revision)
b.mu.Lock()
fps, ok := b.keptFPs[rk]
b.mu.Unlock()
if !ok {
_, read, err := b.KeptRevision(ctx, origin.Branch, origin.Revision)
if err != nil {
return "", err
}
fps = read
b.mu.Lock()
if b.keptFPs == nil {
b.keptFPs = map[string]map[string]string{}
}
b.keptFPs[rk] = fps
b.mu.Unlock()
}
return fps[module], nil
}
// awaitPublished fills each package of packages with no pin (pinOf), waiting for one (H-A-521, H-A-165). The wait is kept in the
// state waits in the one wait form, held under the build's key with the package's path, the publisher, the catalog revision and the
// time it ends, ended published or failed (H-A-707 (5)). It answers the packages with every pin, or an outcome and its words: failed
// past the bound naming the publisher and its fingerprint, could not run when the builder stops.
func (b *Builder) awaitPublished(ctx context.Context, module, fp string, packages map[string]string, origin Origin) (map[string]string, string, string) {
var unpinned []string
for p, v := range packages {
if v == "" {
@@ -302,25 +359,30 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
return packages, "", ""
}
slices.Sort(unpinned)
key, err := builds.BuilderBuildKey(module, fp)
if err != nil {
if _, err := builds.BuilderBuildKey(module, fp); err != nil {
return nil, meshbuilds.StepEndedOutcomeCouldNotRun, err.Error()
}
bound := b.packageWait()
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
defer stop()
told := false
since := b.now()
endWait := func(how string) {
if told && b.Waits != nil {
b.Waits.End(ctx, module, fp, how)
}
}
for {
b.mu.Lock()
moved := b.moved
b.mu.Unlock()
pins := map[string]string{}
missing, why := "", ""
missing, why, publisher := "", "", ""
for _, p := range unpinned {
v, none := b.versionAtOrigin(wait, key, p)
v, pub, none := b.pinOf(wait, module, fp, p, origin)
pins[p] = v
if v == "" && missing == "" {
missing, why = p, none
missing, why, publisher = p, none, pub
}
}
if missing == "" {
@@ -328,6 +390,7 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
maps.Copy(out, pins)
if told {
b.logf("%s at %s: every package it names is published: built with %v", module, fp, pins)
endWait(WaitPublished)
}
return out, "", ""
}
@@ -336,6 +399,10 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
b.logf("%s at %s: %s yet: the build waits for its publish, at most %s", module, fp, notPublished, bound)
told = true
}
if b.Waits != nil {
b.Waits.Hold(ctx, ToolchainWait{Module: module, Fingerprint: fp, Since: since, Package: missing, Publisher: publisher,
Revision: origin.Revision, Bound: bound.String(), Until: since.Add(bound)})
}
select {
case <-moved:
case <-wait.Done():
@@ -343,6 +410,7 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
return nil, meshbuilds.StepEndedOutcomeCouldNotRun, notPublished + ": the builder stopped before it was"
}
b.logf("%s at %s: %s within %s: the build fails, nothing is built", module, fp, notPublished, bound)
endWait(WaitFailed)
return nil, meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s within %s", notPublished, bound)
}
}
@@ -135,10 +135,14 @@ type Builder struct {
once sync.Once
// Faults are the keys whose newest revision failed on a transport fault (H-A-683 (2)), filled by Sweep and kept by every write.
Faults *Faulted
sem chan struct{}
wg sync.WaitGroup
mu sync.Mutex
Faults *Faulted
sem chan struct{}
wg sync.WaitGroup
mu sync.Mutex
// pinTold are the pins taken from a newer entry, said once each; keptFPs the fingerprints of a kept catalog revision, by branch and
// revision, read once (design 47 H2 H-A-707 (3), (4)).
pinTold sync.Map
keptFPs map[string]map[string]string
known map[string]meshcatalog.ModulesByModuleValue // by modules key: the first watched branch's
heard map[string]meshcatalog.ModulesByModuleValue // by branch and module (take): what supersedes what
heardAt map[string]Origin // by branch and module (take): the revision the heard entry came from (H-A-557)
@@ -870,7 +874,7 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
b.mu.Lock()
b.builds[key] = withdraw
b.mu.Unlock()
result = b.build(run, module, m, plan, planErr, prior, only, b.notes(cl), reserved.Version)
result = b.build(run, module, m, plan, planErr, prior, only, b.notes(cl, origin), reserved.Version)
b.mu.Lock()
delete(b.builds, key)
b.mu.Unlock()
@@ -1209,10 +1213,12 @@ type askNotes struct {
resumed map[string]string
// step is the step words of a key taken over at start: an ask asked again says its asking there (askingOf).
step string
// origin is the origin the build holds from its start (design 47 H2 H-A-707 (1)), which its pins are read at.
origin Origin
}
func (b *Builder) notes(cl *Claim) *askNotes {
n := &askNotes{b: b, cl: cl}
func (b *Builder) notes(cl *Claim, origin Origin) *askNotes {
n := &askNotes{b: b, cl: cl, origin: origin}
if cl.Build.State == builds.BuildBuilding && len(cl.Build.Asks) > 0 {
n.resumed, n.step = maps.Clone(cl.Build.Asks), cl.Build.Step
}
@@ -1281,7 +1287,7 @@ func (b *Builder) runLane(ctx context.Context, l *lane, repository string, m mes
// them into the workspace, whatever the repository's go.mod names. A package the entry names with no pin waits for
// its publish and is built with the version its publisher holds at the key's origin; past the bound the lane fails
// naming it, and no ask is put (H-A-521, H-A-547 (3), H-A-165).
pinned, outcome, said := b.awaitPublished(ctx, module, m.Fp2, m.Packages)
pinned, outcome, said := b.awaitPublished(ctx, module, m.Fp2, m.Packages, asked.origin)
if outcome != "" {
l.err = errors.New(said)
return
@@ -153,7 +153,10 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
}
// A package the entry names with no pin is built against its publisher's version at the key's origin, waited for
// (H-A-521, H-A-547 (3), H-A-165).
pinned, outcome, said := b.awaitPublished(ctx, entry.Module, entry.Fp, entry.Packages)
b.mu.Lock()
origin := b.originLocked(func() string { k, _ := builds.BuilderBuildKey(entry.Module, entry.Fp); return k }())
b.mu.Unlock()
pinned, outcome, said := b.awaitPublished(ctx, entry.Module, entry.Fp, entry.Packages, origin)
if outcome != "" {
return outcome, said
}
@@ -194,6 +194,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
t.Run("H-A-547 (3): a package with no pin waits for its publisher's version at the key's origin and is built with it", aPackageWithNoPinWaitsForItsRelease)
t.Run("H-A-165: past its bound a package with no version at the origin fails the step", aPackageWithNoReleaseFailsPastItsBound)
t.Run("H-A-547 (3): a lane waits for an unpinned package's version at its origin and fails past its bound", aLaneWaitsForAnUnpinnedPackage)
t.Run("H-A-707 (3) (5): a newer entry of the branch names the pin and ends the wait, never one of another branch", aNewerEntrysPinEndsTheWait)
}
// unpinnedRig is a rig whose step entry m names the package x with no version, x published by the artifact x of the module xm,
@@ -210,6 +211,8 @@ func unpinnedRig(t *testing.T) (*rig, *fakeReservations, meshcatalog.CatalogEntr
r.b.init()
r.b.mu.Lock()
r.b.origin[r.key] = Origin{Branch: "main", Source: 41, First: true}
// the publisher's entry of the build's revision the picture holds (H2 H-A-707 (4))
r.b.heard["main\x00xm"], r.b.heardAt["main\x00xm"] = meshcatalog.ModulesByModuleValue{Fp2: fpX}, Origin{Branch: "main", Source: 41, First: true}
r.b.mu.Unlock()
waiting := make(chan struct{}, 1)
r.b.Logf = func(format string, args ...any) {
@@ -224,6 +227,11 @@ func unpinnedRig(t *testing.T) (*rig, *fakeReservations, meshcatalog.CatalogEntr
return r, res, entry, waiting
}
var (
fpX = "src2:" + strings.Repeat("c", 64) // the publisher xm's fingerprint in the build's revision
fpXOld = "src2:" + strings.Repeat("d", 64)
)
const unpinnedX = "git.novox.be/novox/mesh-contracts/go/seats/x"
// awaitWaiting fails the test unless the build started its wait before ended said anything.
@@ -254,8 +262,8 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
mu.Unlock()
}
}
res.publishAt("xm", "x", "main", 40, "0.1.2") // another source revision than the key's origin: no pin
r.b.PackagePublished(unpinnedX, "v0.1.9") // the newest heard: no pin (H-A-547 (3))
res.publishAt("xm", "x", fpXOld, "0.1.2") // another fingerprint of the publisher than its build in the revision: no pin
r.b.PackagePublished(unpinnedX, "v0.1.9") // the newest heard: no pin (H-A-547 (3))
ended := make(chan meshbuilds.StepEnded, 1)
go func() {
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
@@ -265,7 +273,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
if _, ok := r.st.vals[r.key]; ok {
t.Fatal("the build was made before the package was published")
}
res.publishAt("xm", "x", "main", 41, "0.1.3")
res.publishAt("xm", "x", fpX, "0.1.3")
r.b.PackagePublished(unpinnedX, "v0.1.3")
var end meshbuilds.StepEnded
select {
@@ -284,7 +292,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
t.Errorf("the end reports the pins %v; want the ones it was built with", end.Packages)
}
// A done key reports the pins it keeps it was built with, never a newer one published now (H-A-207).
res.publishAt("xm", "x", "main", 41, "0.1.5")
res.publishAt("xm", "x", fpX, "0.1.5")
again := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
if again.Outcome != meshbuilds.StepEndedOutcomePassed || again.Packages[unpinnedX] != "v0.1.3" {
@@ -320,11 +328,11 @@ func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) {
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
r.b.Wait()
if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || built ||
!strings.Contains(end.Said, "package "+unpinnedX+" has no published version: xm publishes no version of it at source revision 41 of main") {
!strings.Contains(end.Said, "package "+unpinnedX+" has no published version: xm at "+fpX+" (revision 0) is not published") {
t.Errorf("end = %+v, built %v; want failed naming the package, nothing built", end, built)
}
// A version its publisher holds at the origin gives the pin at once.
res.publishAt("xm", "x", "main", 41, "0.1.2")
res.publishAt("xm", "x", fpX, "0.1.2")
if end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); strings.Contains(end.Said, "no published version") {
t.Errorf("a version at the origin did not pin the package: %+v", end)
@@ -345,7 +353,7 @@ func aLaneWaitsForAnUnpinnedPackage(t *testing.T) {
if asks := r.asks.Asks(); len(asks) != 0 {
t.Fatalf("a build was asked without the package's pin: %+v", asks)
}
res.publishAt("xm", "x", "main", 41, "0.1.5")
res.publishAt("xm", "x", fpX, "0.1.5")
r.b.PackagePublished(unpinnedX, "0.1.5")
select {
case <-done:
@@ -811,3 +819,61 @@ func aBuildHoldsItsNewestEntryAndOrigin(t *testing.T) {
t.Errorf("the build woken by revision 510's value holds %+v at %+v; want revision 511's entry and origin", m.Commit, o)
}
}
// H-A-707 (3), (5): while a build waits for a blank pin its wait stands in the state waits with the package's path, the publisher and its
// fingerprint, the revision and its end; an entry of another branch with the pin changes nothing, and a newer entry of the key's
// branch and fingerprint that names it ends the wait published and the build is made with it; one never published fails past the bound
// naming the publisher and its fingerprint, its wait ended failed.
func aNewerEntrysPinEndsTheWait(t *testing.T) {
r, _, _, waiting := unpinnedRig(t)
w := &memWaits{}
r.b.Waits = w
ended := make(chan meshbuilds.StepEnded, 1)
go func() {
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
}()
awaitWaiting(t, waiting, ended)
w.mu.Lock()
held := w.held["m."+fp1]
w.mu.Unlock()
if held.Package != unpinnedX || held.Publisher != "xm@"+fpX || held.Until.IsZero() || held.Bound == "" {
t.Fatalf("the pin wait held is %+v, want the package's path, xm@%s, its end and bound", held, fpX)
}
pin := func(branch string) {
r.b.mu.Lock()
r.b.heard[branch+"\x00m"], r.b.heardAt[branch+"\x00m"] = meshcatalog.ModulesByModuleValue{Fp2: fp1, Manifest: mdigest('a'), Path: "modules/m", Repository: "novox/m", Commit: "3333333333333333333333333333333333333333", Toolchains: CatalogToolchains(agreedToolchains), Packages: map[string]string{unpinnedX: "v0.1.8"}}, Origin{Branch: branch, Source: 42, First: true}
r.b.mu.Unlock()
r.b.pictureMoved()
}
pin("feature")
select {
case end := <-ended:
t.Fatalf("an entry of another branch ended the wait: %+v", end)
case <-time.After(100 * time.Millisecond):
}
pin("main")
var end meshbuilds.StepEnded
select {
case end = <-ended:
case <-time.After(5 * time.Second):
t.Fatal("a newer entry's pin did not end the wait")
}
r.b.Wait()
asks := r.asks.Asks()
w.mu.Lock()
endedWaits := slices.Clone(w.ended)
w.mu.Unlock()
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(asks) == 0 || asks[0].Packages[unpinnedX] != "v0.1.8" || !slices.Equal(endedWaits, []string{WaitPublished}) {
t.Errorf("end %+v, asks %+v, waits ended %v; want passed, built with v0.1.8, the wait ended published", end, asks, endedWaits)
}
// Never published: past the bound the key fails naming the publisher and its fingerprint, and the wait ends failed.
r2, _, _, _ := unpinnedRig(t)
w2 := &memWaits{}
r2.b.Waits, r2.b.PackageWait = w2, time.Nanosecond
end = r2.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
if end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "xm at "+fpX+" (revision 0) is not published within") || !slices.Equal(w2.ended, []string{WaitFailed}) {
t.Errorf("end %+v, waits ended %v; want failed naming xm and its fingerprint, the wait ended failed", end, w2.ended)
}
}
@@ -43,7 +43,7 @@ func (w *memWaits) End(_ context.Context, module, fp, how string) bool {
defer w.mu.Unlock()
k := module + "." + fp
t, ok := w.held[k]
if !ok || (t.Package != "") != (how == WaitPublished) { // as the builder's waitsKept ends them: a package wait by its publishing alone
if !ok || (how != WaitFailed && (t.Package != "") != (how == WaitPublished)) { // as the builder's waitsKept ends them: a package wait by its publishing alone
return false
}
delete(w.held, k)
@@ -623,47 +623,6 @@ func (r *Reserver) PublishedOf(ctx context.Context, module, artifact, fingerprin
return meshbuilds.PublishedAnswer{Published: false}, nil
}
// VersionAt answers the version artifact of module is published at from the source revision of branch (design 47 H2 H-A-547
// (3), H-A-551): the standing reservation of that branch and source revision whose artifact a registry seat said published, its
// number not withdrawn, first; else the module's release recorded at that branch and source revision (H-A-558 (2)), the newest such. A reservation of
// that origin not yet published answers none, so the importer's build waits for the publish (H-A-521).
func (r *Reserver) VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error) {
if module == "" || artifact == "" || source <= 0 {
return "", false, nil
}
ref := module + ":" + artifact
keys, err := r.Store.KeysOf(ctx, NameFilter(module))
if err != nil {
return "", false, fmt.Errorf("the reservations of %s cannot be listed: %w", module, err)
}
sort.Strings(keys)
for _, k := range keys {
cur, _, found, err := r.get(ctx, k)
if err != nil {
return "", false, err
}
if found && cur.Module == module && cur.Branch == branch && cur.Source == source && cur.Published[ref] && !hasKey(cur.Withdrawn, cur.Version) {
return cur.Version, true, nil
}
}
if r.Releases == nil {
return "", false, nil
}
raw, _, found, err := r.Releases.Get(ctx, ReleasedKey(module))
if err != nil {
return "", false, fmt.Errorf("the releases of %s cannot be read: %w", module, err)
}
var rec ReleasedRecord
if found && json.Unmarshal(raw, &rec) == nil {
for i := len(rec.Kept) - 1; i >= 0; i-- {
if rec.Kept[i].Branch == branch && rec.Kept[i].Source == source {
return rec.Kept[i].Version, true, nil
}
}
}
return "", false, nil
}
// keepRelease adds a release to the module's record, dropping the oldest past ReleasedKept.
func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests, withdrawn map[string]string, branch string, source int64) error {
n := r.ReleasedKept
@@ -232,44 +232,19 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
if all, _ := r.All(ctx); len(all) != 0 {
t.Errorf("reservations left: %v", all)
}
// Design 47 H2 H-A-547 (3), H-A-551: an importer's version at the source revision of its key's origin is the standing
// reservation of that origin once its artifact is published, then the release recorded at that source revision.
w, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:cc", Branch: "main", Revision: 41})
if err != nil {
t.Fatal(err)
}
at := func(branch string, source int64) string {
v, found, err := r.VersionAt(ctx, "m", "a", branch, source)
if err != nil || found != (v != "") {
t.Fatalf("VersionAt %s.%d: %q %v %v", branch, source, v, found, err)
}
return v
}
if v := at("main", 41); v != "" {
t.Errorf("a reservation not yet published answers %q, want none", v)
}
if _, _, err := r.Built(ctx, "m", w.Version, map[string]string{"m:a": "sha256:cc"}, nil); err != nil {
t.Fatal(err)
}
if _, _, err := r.Published(ctx, "m/a", w.Version, "sha256:cc"); err != nil {
t.Fatal(err)
}
if v := at("main", 41); v != w.Version {
t.Errorf("the published reservation at main.41 answers %q, want %s", v, w.Version)
}
if v, v2 := at("main", 40), at("feat", 41); v != "" || v2 != "" {
t.Errorf("another source revision or branch answers %q %q, want none", v, v2)
}
if _, err := r.Released(ctx, "m", w.Version); err != nil {
t.Fatal(err)
}
if v := at("main", 41); v != w.Version {
t.Errorf("once released, main.41 answers %q, want %s from the release's record", v, w.Version)
}
// H-A-558 (2): the record keeps the origin's branch with its source revision, so another branch's equal number never meets it.
if v := at("feat", 41); v != "" {
t.Errorf("once released, feat.41 answers %q, want none", v)
}
// One key per module holds the last releases, the oldest dropped (A-456b).
for _, fp := range []string{"src2:b1", "src2:b2"} {
n, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp})