A-473: the builder asks the tagged publish of a reserved version when its build ends #246

Merged
mesh-tools merged 1 commits from fix/a473-builder-publishes-at-build-end into main 2026-11-17 14:09:34 +00:00
5 changed files with 49 additions and 0 deletions
@@ -245,6 +245,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
Unreleased: reserved.unreleasedWords, Max: republishMax, Logf: logger.Printf,
Holders: holders} // a registry seat's holder from the seat-holders view, from the start (design 47 G A-416, A-416a)
acts.Republish = republish.Republish
reserved.publishAtEnd = republish.Ended
again := &republishing{rp: republish}
// The operator is asked once a key's event builds are spent (design 47 G §568): the builder's asker on the seat operator-channel.
decided := &decisions{subject: oc.SubjectDecided(cred.Module)}
@@ -51,6 +51,8 @@ type reservations struct {
call toolCaller
// say says package-published on the seat mesh-builds; nil says none.
say func(context.Context, meshbuilds.PackagePublished) error
// publishAtEnd asks the tagged publish of a reservation whose build has ended (design 47 G A-473); nil asks none.
publishAtEnd func(ctx context.Context, module, version string) ([]string, error)
}
// newReservations makes the reserving over store; the released versions of a module are asked of the seat mesh-catalog's
@@ -107,6 +109,12 @@ func (rv *reservations) Built(ctx context.Context, module, version string, diges
for _, m := range marked {
rv.sayPublished(ctx, m, m.Reserved.Artifacts[m.Artifact])
}
// The build's end asks the tagged publish itself, at the holder of each artifact's registry seat (design 47 G A-473).
if rv.publishAtEnd != nil {
if _, err := rv.publishAtEnd(ctx, module, version); err != nil {
rv.logf("the publish of %s %s is not asked at the build's end: %v", module, version, err)
}
}
return nil
}
@@ -102,9 +102,17 @@ func TestTheCatalogsWordsMoveTheReservations(t *testing.T) {
if err != nil || res.Version != "1.4.3" {
t.Fatalf("reserved %q (%v), want 1.4.3 after the catalog's 1.4.2", res.Version, err)
}
var asked []string
rv.publishAtEnd = func(_ context.Context, module, version string) ([]string, error) {
asked = append(asked, module+" "+version)
return nil, nil
}
if err := rv.Built(ctx, "m", "1.4.3", map[string]string{"m:a": "sha256:a", "m:b": "sha256:b"}, nil); err != nil {
t.Fatal(err)
}
if len(asked) != 1 || asked[0] != "m 1.4.3" {
t.Fatalf("the build's end asked the publish of %v, want m 1.4.3 once (A-473)", asked)
}
boundKey := versions.ReservedBoundKey("m", "1.4")
if !bounds.keys[boundKey] {
t.Fatalf("the publish's bound is not armed: %v", bounds.keys)
@@ -444,6 +444,18 @@ func (r *Republisher) Republish(ctx context.Context, module, version string) ([]
return r.queue(ctx, vs, r.holdersFn, 0)
}
// Ended queues a reserved version whose build has just ended (built-at set, every artifact's digest known) at the holder of
// each artifact's registry seat, as a holder's running does, and drains it (design 47 G A-473). A version with no built-at, or
// whose artifacts are all published, queues nothing. A holder that refuses or does not answer leaves the version in
// version-unreleased with its words (send says it); a seat with no holder leaves it for the holder's running.
func (r *Republisher) Ended(ctx context.Context, module, version string) ([]string, error) {
v, ok, err := r.Reserved.Of(ctx, module, version)
if err != nil || !ok || v.BuiltAt.IsZero() || len(v.Missing()) == 0 {
return nil, err
}
return r.queue(ctx, []ReservedVersion{v}, r.holdersFn, 0)
}
// Queued are the queued versions, per holder in the order they are sent, and the acted keys with their sequences:
// builder_publish_queue.
type Queued struct {
@@ -119,6 +119,26 @@ func TestRepublish(t *testing.T) {
t.Errorf("a key stays in the queue after its outcome: %v", keys)
}
})
t.Run("a build's end queues its version at the holders, without any event (A-473)", func(t *testing.T) {
b := newRepublishBed(t, 50)
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
b.now = b.now.Add(time.Minute)
v, err := b.Reserved.Reserve(ctx, "m", "0.1", []string{"m:prog", "m:lib"}, Source{Fingerprint: "src2:m"})
if err != nil {
t.Fatal(err)
}
if _, err := b.Ended(ctx, "m", v.Version); err != nil || len(b.sent) != 0 {
t.Fatalf("a build not ended sent %d (%v)", len(b.sent), err)
}
for ref, d := range map[string]string{"m:prog": "sha256:aa", "m:lib": "sha256:bb"} {
if _, err := b.Reserved.Built(ctx, "m", v.Version, ref, d, nil); err != nil {
t.Fatal(err)
}
}
if queued, err := b.Ended(ctx, "m", v.Version); err != nil || len(queued) != 1 || len(b.sent) != 1 || b.sent[0].Name != "m/prog" || b.sent[0].Digest != "sha256:aa" {
t.Fatalf("the ended build queued %v, sent %+v (%v), want the bundle at the oci holder", queued, b.sent, err)
}
})
t.Run("returned acts at the seat's holder, started does not", func(t *testing.T) {
b := newRepublishBed(t, 50)
b.reserve(t, "m")