A trunk build reserving while its series is reserved by an older build never released drops the older reservation's bound and finding and says so in the journal. builder_reserve_done (a hand act, reasks mode reserve-done) reserves the series' next version for a done trunk build that reserved none, with the done key's digests, and queues its publish as builder_publish_again does. Builds: design 47 G A-455, §369, §588
83 lines
4.0 KiB
Go
83 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"mesh-delivery-builder/internal/build"
|
|
"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
|
|
// 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.
|
|
func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool {
|
|
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
|
|
return []stdio.Tool{
|
|
{Name: versions.ReservedTool, Description: versions.ReservedDescription,
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"module": map[string]any{"type": "string", "description": "only this module's reservations"}}},
|
|
Run: func(args map[string]any) (any, error) { return versions.AnswerReserved(rr, str(args, "module")) }},
|
|
{Name: versions.ReservedDropTool, Description: versions.ReservedDropDescription,
|
|
Input: map[string]any{"type": "object", "required": []string{"module", "series", "why"}, "properties": map[string]any{
|
|
"module": map[string]any{"type": "string", "description": "the module"},
|
|
"series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"},
|
|
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "series")),
|
|
Why: str(args, "why"), Cause: versions.ReservedDropTool, Verb: "reserved-drop"}); err != nil {
|
|
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was dropped: %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
|
|
}},
|
|
{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
|
|
}},
|
|
}
|
|
}
|