Files
mesh-catalog/modules/mesh-build-go/cmd/mesh-build-go/asks.go
T
jschoubben cf383af441 W12.5 (Go): mesh-build-go keeps the store holder's refused build and serves kept-artifact (issue 1966)
Builds design 47 *The artifact store's holder takes its own new build even
when its seat is the one broken* (lines ~1811-1830, test 60): a trunk build of
a module claiming oci-artifact-registry that the seat refuses or does not
answer is kept as an object by digest and answered kept (BuildAnswer.Kept);
kept-artifact answers its store and object, refusing a module that claims no
oci-artifact-registry, one not kept here and one under another digest. The
store is the template objects (ADR 0666 §4: a part outside the foundation keeps
its data in ADR 0595's templates; design 47's "old objects form" contradicts
it for a non-foundation part, reported). Whether a module claims the seat is
asked of the seat mesh-catalog's verb module (ADR 0596). Callers are left to
the seat definition and the grants part (ADR 0666 §20). build_go_kept reads the
kept builds, build_go_kept_drop drops one (ADR 0666 §25).

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ

(Joined from 5e1cdade.)
Builds: design 47 G §271, test 60 (BLD9)

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 14:34:53 +01:00

134 lines
5.9 KiB
Go

package main
import (
"context"
"path/filepath"
"time"
"git.novox.be/novox/mesh-catalog/modules/mesh-build-go/buildstep"
seat "git.novox.be/novox/mesh-delivery/contracts/go/seats/nodebuildgo"
buildrun "git.novox.be/novox/mesh-delivery/sdk/buildrun"
sdkstep "git.novox.be/novox/mesh-delivery/sdk/buildstep"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// **The module pulls its seat's asks** (novox/hq ADR 0525 §2-§6, ADR 0536 §4; issue 1887 A3go). It holds the seat
// node-build-go on its node and pulls the seat's asks through its runtime (buildstep.SeatAsks): delivery first, then
// check, then recheck, at most the node's build capacity at once (its setting `capacity`, read at every pull). Each ask
// runs with the same step bodies its tools run, behind the same guard, and ends on the key <node>.<ask id> of its steps
// state. The tools stay as the hand path (ADR 0525 §8).
// Seat is the node seat this module holds.
const Seat = "node-build-go"
// askSteps are the module's step bodies for an ask, each holding its workspace while it runs, as a tool's does.
func (m *Module) askSteps(steps []StepTool) buildstep.AskSteps {
byName := map[string]buildstep.StepFunc{}
for _, s := range steps {
run := s.Run
byName[s.Name] = func(ctx context.Context, args map[string]any) (any, error) {
defer m.holdArg(args)()
return run(ctx, args)
}
}
return buildstep.AskSteps{
Fetch: byName["build_go_fetch"], Build: byName["build_go_build"], Digest: byName["build_go_digest"], Test: byName["build_go_test"],
Imports: byName[ImportsTool],
Compare: buildstep.CompareStep(buildstep.GeneratedRootGo, func(ws string) string { return filepath.Join(m.Work, ws, "tree") }),
Toolchain: func(ctx context.Context) (sdkstep.ToolchainUsed, error) {
installed, err := m.Probe(ctx)
if err != nil {
return sdkstep.ToolchainUsed{}, err
}
return sdkstep.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}, nil
},
// The kept results reach a test step in its ask (design 47 *Carried, not run*, line 593 at b229f5c4; issue 1966
// K1): this module reads no other part's kept state.
Has: m.Has,
Release: func(ws string) error { return m.spaces().Release(ws) },
Logf: m.Say,
Lint: m.lintStep,
Node: m.Node,
SayStep: m.sayStep(),
}
}
// Puller is the module's pull of its seat's asks, on source (the runtime's seat pull when nil).
func (m *Module) Puller(steps []StepTool, source buildstep.AskSource) *buildstep.Puller {
if source == nil {
source = buildstep.SeatAsks{Language: sdkstep.AskGo}
}
capacity := m.Capacity
// The capacity's own change wakes the puller (issue 1887): the runtime's watch of the config value as mesh-config
// resolved it; the settings file is read only when that watch cannot start. A test's Capacity is its own.
var watch func(string, func(stdio.ProvisionChange) error) error
// And the CPU bounds it (issue 1806's follow-up): the configured capacity is an upper bound, the node's build slice
// gives floor(its quota's cores / the module's cores-per-step) at once, read live; a test judges by its own Capacity.
// And the node's build hours (a node may build only in a window): outside them it takes
// nothing new.
var cores func() float64
var hours func() (*buildstep.BuildWindow, string)
settings := ""
if capacity == nil {
hours = buildstep.NodeBuildHours(m.Settings, m.Node, m.Say)
capacity = buildstep.NodeCapacity(m.Settings, m.Node, m.Say)
settings = m.Settings
watch = buildstep.WatchConfigServed
cores = buildstep.NodeCoresPerStep(m.Settings, buildstep.DefaultCoresPerStep[sdkstep.AskGo], m.Say)
}
ask := m.askSteps(steps)
var load func(string) ([]byte, error)
if m.ReadPauses.Get != nil {
load = func(key string) ([]byte, error) {
raw, err := m.ReadPauses.Get(key)
return raw, err
}
}
return &buildstep.Puller{Source: source, Language: sdkstep.AskGo, Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
Capacity: capacity, SettingsFile: settings, WatchConfig: watch, CoresPerStep: cores, BuildHours: hours, Logf: m.Say, Has: m.Has,
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) {
if err := m.Check(ctx); err != nil {
return nil, err
}
if err := m.room(); err != nil {
return nil, err
}
if a.Compose != nil {
return m.compose(ctx, ask.Fetch, a)
}
if a.Run != nil {
return m.run(ctx, ask.Fetch, a)
}
return buildstep.RunAsk(ctx, ask, a)
}}
}
// SeatTools are the seat's verbs on this node (ADR 0525 §10): what it runs, and its pause and resume.
func (m *Module) SeatTools(p *buildstep.Puller) []stdio.Tool {
return append(buildstep.SeatTools(Seat, "Go", p), m.stepsTool(), m.keptArtifactVerb())
}
// StepEndTool ends one step left running (issue 1890); the module's steps state is the one it reads and writes.
const StepEndTool = "build_go_step_end"
// endLeftRunning is the module's start sweep (issue 1890): it ends the steps of its node that a previous process left
// running (buildrun.EndStaleAtStart; every step names its owner). main runs it once at the start, and the module's test
// runs it through the conformance kit's left-running case.
func (m *Module) endLeftRunning(ctx context.Context, scan buildrun.Scan, booted time.Time, logf func(string, ...any)) {
buildrun.EndStaleAtStart(ctx, scan, m.Node, booted, logf)
}
// stepScan is the module's steps state as buildstep reads it.
func (m *Module) stepScan() buildrun.Scan {
return buildrun.ScanOf(stdio.State(seat.StateSteps))
}
// sayStep says a pipeline step's end on this node's subject of the seat (design 47 *Asked on a work queue, ended by an
// event*, lines 584-586 at b229f5c4): SayStep when a test sets it, else the runtime's seat publish.
func (m *Module) sayStep() func(sdkstep.StepEnded) error {
if m.SayStep != nil {
return m.SayStep
}
return buildstep.SayStepOn(sdkstep.AskGo, m.Node, stdio.SeatPublish)
}