B14 reserve-done-goes: builder_reserve_done and its mode go whole; a build with no version names builder_build_again

Builds: design 47 H2 H-A-661, H-A-665, H-A-706 (DQ-39)
This commit is contained in:
2026-11-25 17:21:33 +01:00
parent dd78f05b56
commit b7a3d85514
15 changed files with 9 additions and 322 deletions
@@ -13,7 +13,7 @@ import (
"mesh-delivery-builder/internal/versions"
)
// reservedTools are builder_reserved, builder_reserved_drop and builder_reserve_done (A-455) (design 47 G section 369), served as tools of the bundle. The drop is a hand act: it is recorded in the hand-act log first, then written to
// reservedTools are builder_reserved and builder_reserved_drop (design 47 G section 369), served as tools of the bundle. The drop is a hand act: it is recorded in the hand-act log first, then written to
// reasks for the builder, which owns the reservations, to answer.
//
// The seat's verb reserved is the builder's process's (design 47 G A-115, A-127), not the bundle's.
@@ -52,32 +52,5 @@ func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, act
}
return map[string]any{"key": key, "answer": a.Answer}, nil
}},
{Name: versions.ReserveDoneTool, Description: versions.ReserveDoneDescription,
Input: map[string]any{"type": "object", "required": []string{"module", "fp", "why"}, "properties": map[string]any{
"module": map[string]any{"type": "string", "description": "the module"},
"fp": map[string]any{"type": "string", "description": "the fingerprint of its done trunk build"},
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
Run: func(args map[string]any) (any, error) {
key, value, err := build.NewReserveDone(str(args, "module"), str(args, "fp"), str(args, "why"), stdio.CallerOf(args), now())
if err != nil {
return nil, err
}
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("reserved a version for the done build of %s at %s by hand", str(args, "module"), str(args, "fp")),
Why: str(args, "why"), Cause: versions.ReserveDoneTool, Verb: "reserve-done"}); err != nil {
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was reserved: %w", err)
}
raw, err := ask(key, value)
if err != nil {
return nil, err
}
a, err := build.DecodeReAsk(raw)
if err != nil {
return nil, err
}
if a.Refused {
return nil, errors.New(a.Answer)
}
return map[string]any{"key": key, "answer": a.Answer}, nil
}},
}
}
@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
"errors"
"strings"
"testing"
"time"
@@ -45,56 +44,3 @@ func TestWaitsToolsListTheWaitsAndReleaseAfterTheHandAct(t *testing.T) {
t.Fatalf("release: %v, %d recorded, asked %+v", err, recorded, asked)
}
}
// Design 47 G A-455: builder_reserve_done records the hand act first and only then asks the builder through reasks; the builder's
// answer (the version and its queued publish) is the tool's answer, its refusal the tool's error, and an act that was not
// recorded asks nothing.
func TestReserveDoneRecordsTheHandActFirstAndAnswersTheBuilders(t *testing.T) {
var order []string
var asked []build.ReAsk
reply := func(refuse bool) func(string, []byte) (json.RawMessage, error) {
return func(key string, value []byte) (json.RawMessage, error) {
order = append(order, "asked")
a, _ := build.DecodeReAsk(value)
asked = append(asked, a)
a.Answered, a.Answer, a.Refused = time.Now(), "reserved 0.1.13 for node-tools and queued 1 versions to publish: node-tools@0.1.13", refuse
if refuse {
a.Answer = "the build key is not done"
}
return json.Marshal(a)
}
}
record := func(fail bool) meshhandactsclient.Recorder {
return meshhandactsclient.Recorder{Ask: func(string, any) (json.RawMessage, error) {
order = append(order, "recorded")
if fail {
return nil, errors.New("no responders")
}
return json.RawMessage(`{}`), nil
}}
}
run := func(ask func(string, []byte) (json.RawMessage, error), acts meshhandactsclient.Recorder, args map[string]any) (any, error) {
for _, tl := range reservedTools(versions.Reader{}, ask, time.Now, acts) {
if tl.Name == versions.ReserveDoneTool {
return tl.Run(args)
}
}
t.Fatal("the bundle serves no builder_reserve_done")
return nil, nil
}
args := map[string]any{"module": "node-tools", "fp": "src2:7df8", "why": "its build ended done with no version"}
out, err := run(reply(false), record(false), args)
if err != nil || len(order) != 2 || order[0] != "recorded" || order[1] != "asked" || asked[0].Mode != build.ModeReserveDone || asked[0].Name != "node-tools" || asked[0].FP != "src2:7df8" {
t.Fatalf("answer %v, %v; order %v, asked %+v", out, err, order, asked)
}
if ans := out.(map[string]any)["answer"].(string); !strings.Contains(ans, "reserved 0.1.13") || !strings.Contains(ans, "queued 1 versions") {
t.Errorf("the answer %q names no version and queued publish", ans)
}
if _, err := run(reply(true), record(false), args); err == nil || !strings.Contains(err.Error(), "not done") {
t.Errorf("the builder's refusal is not the tool's error: %v", err)
}
order = nil
if _, err := run(reply(false), record(true), args); err == nil || len(order) != 1 || order[0] != "recorded" {
t.Errorf("an unrecorded act was asked of the builder: %v, %v", err, order)
}
}
@@ -326,8 +326,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
acts.PublishDrop = func(ctx context.Context, module, version, by, why string) (string, error) {
return pq.drop(ctx, items, module, version, by, why)
}
// builder_reserve_done: a done trunk build that reserved none is given a version, and its publish queued as publish again does.
acts.ReserveDone = reserveDoneAct(b.ReserveDone, republish.Republish, logger.Printf)
// 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)}
retakeActed := awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}
@@ -65,7 +65,7 @@ func reAsked(ctx context.Context, b askAgainer, acts versions.Acts, items *publi
released(ctx, b, kv, e, r, logf)
return
}
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop || r.Mode == build.ModeReserveDone {
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop {
// A version's hand act (design 51 *Tools of the builder*) may build again, so it is answered beside the watch.
go versionActed(ctx, acts, kv, e, r, logf)
return
@@ -196,7 +196,7 @@ func emitBuildEnded(ctx context.Context, js jetstream.JetStream, cred process.Ac
return nil
}
// versionActed answers a reasks value of builder_publish_again, builder_publish_drop, builder_reserve_done, builder_reserved_drop or builder_old_form's drop, a hand act said in the log.
// versionActed answers a reasks value of builder_publish_again, builder_publish_drop, builder_reserved_drop or builder_old_form's drop, a hand act said in the log.
func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue, e jetstream.KeyValueEntry, r build.ReAsk, logf func(string, ...any)) {
var err error
if r.Mode == build.ModeRepublish {
@@ -215,12 +215,6 @@ func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue
} else {
r.Answer, err = act(ctx, r.Module, r.Version, r.By, r.Why)
}
} else if r.Mode == build.ModeReserveDone {
if acts.ReserveDone == nil {
err = errors.New("this builder keeps no reservations")
} else {
r.Answer, err = acts.ReserveDone(ctx, r.Name, r.FP, r.By, r.Why, r.At)
}
} else if r.Mode == build.ModeReservedDrop {
if acts.DropReserved == nil {
err = errors.New("this builder keeps no reservations")
@@ -582,25 +582,6 @@ func (rv *reservations) noMark(ctx context.Context, o versions.Outcome, read []v
return strings.Join(out, "; ") + " (" + standing + "; a published heard before the build recorded its digests is kept until it does)"
}
// reserveDoneAct is builder_reserve_done's act (design 47 G A-455): the next version of the series is reserved for a done trunk build
// that reserved none, and its publish is queued as builder_publish_again queues it. Its answer says the version and the queued
// publishes; a reservation whose publish could not be queued is said so, with the tool that queues it.
func reserveDoneAct(reserve func(ctx context.Context, module, fp string) (versions.ReservedVersion, error),
republish func(ctx context.Context, module, version string) ([]string, error), logf func(string, ...any)) func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error) {
return func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error) {
res, err := reserve(ctx, module, fp)
if err != nil {
return "", err
}
logf("%s at %s: version %s is reserved by hand (%s, %s) for the done build", module, fp, res.Version, by, why)
queued, err := republish(ctx, module, res.Version)
if err != nil {
return "", fmt.Errorf("%s is reserved for %s at %s, but its publish is not queued (builder_publish_again queues it): %w", res.Version, module, fp, err)
}
return fmt.Sprintf("reserved %s for %s at %s and queued %d versions to publish: %s; builder_publish_queue shows them", res.Version, module, fp, len(queued), strings.Join(queued, ", ")), nil
}
}
// ReleasedFor says whether a version was released for the build of fingerprint (design 47 G A-456a).
func (rv *reservations) ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error) {
return rv.r.ReleasedFor(ctx, module, fingerprint)
@@ -20,7 +20,6 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
stdio "git.novox.be/novox/mesh-sdk/go"
"mesh-delivery-builder/internal/build"
"mesh-delivery-builder/internal/versions"
)
@@ -667,62 +666,6 @@ func (e ansEntry) Revision() uint64 { return 1 }
func (e ansEntry) Value() []byte { return e.value }
func (e ansEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
// TestAReserveDoneIsAnsweredWithTheVersionAndItsQueuedPublish: design 47 G A-455 — the reasks value of builder_reserve_done reaches
// the act, which reserves for the done build and queues the publish as publish again does, and its answer names both; a
// refusal of the reserving queues nothing and is the answer; a publish that cannot be queued says the version is reserved.
func TestAReserveDoneIsAnsweredWithTheVersionAndItsQueuedPublish(t *testing.T) {
ctx := context.Background()
var queued []string
var logged []string
logf := func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }
reserve := func(_ context.Context, module, fp string) (versions.ReservedVersion, error) {
if fp == "refused" {
return versions.ReservedVersion{}, fmt.Errorf("the build key of %s at %s is not done", module, fp)
}
return versions.ReservedVersion{Module: module, Version: "0.1.13", Fingerprint: fp}, nil
}
republish := func(_ context.Context, module, version string) ([]string, error) {
if module == "nope" {
return nil, fmt.Errorf("the queue is full")
}
queued = append(queued, module+"@"+version)
return []string{module + "@" + version}, nil
}
acts := versions.Acts{ReserveDone: reserveDoneAct(reserve, republish, logf)}
for _, c := range []struct {
module, fp, want string
refused bool
}{
{"node-tools", "src2:7df8", "reserved 0.1.13 for node-tools at src2:7df8 and queued 1 versions to publish: node-tools@0.1.13", false},
{"node-tools", "refused", "not done", true},
{"nope", "src2:1", "0.1.13 is reserved for nope at src2:1, but its publish is not queued", true},
} {
value, err := json.Marshal(build.ReAsk{V: 1, Why: "w", By: "me", Mode: build.ModeReserveDone, Name: c.module, FP: c.fp})
if err != nil {
t.Fatal(err)
}
kv := &ansKV{wrote: make(chan []byte, 1)}
// reAsked sends a reserve-done to the version acts (b is not asked), and the answer is written back to the key.
reAsked(ctx, nil, acts, nil, kv, ansEntry{key: "reserve-done." + c.module, value: value}, logf)
var wrote []byte
select {
case wrote = <-kv.wrote:
case <-time.After(10 * time.Second):
t.Fatalf("%s at %s: no answer was written to the key", c.module, c.fp)
}
var got build.ReAsk
if err := json.Unmarshal(wrote, &got); err != nil || got.Refused != c.refused || !strings.Contains(got.Answer, c.want) || got.Answered.IsZero() {
t.Errorf("%s at %s: written %s (%v), want refused=%v containing %q", c.module, c.fp, wrote, err, c.refused, c.want)
}
}
if !slices.Equal(queued, []string{"node-tools@0.1.13"}) {
t.Errorf("queued %v, want only node-tools@0.1.13", queued)
}
if !slices.ContainsFunc(logged, func(l string) bool { return strings.Contains(l, "0.1.13 is reserved by hand") }) {
t.Errorf("the reserving by hand is not said in the log: %q", logged)
}
}
// TestARegistrysRecordEndsOrMovesAPublish: design 47 H H-A-274 — the artifacts a registry's record holds with the built digest are
// marked published from it and package-published is said, as a heard published would; H-A-275 — a done build whose number a
// registry holds at another digest (H-A-279) has its number withdrawn, raises version-held-elsewhere naming both digests, and is