Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/asks.go
T
jschoubben e335e859d5 BM3: the Node build module installs a module's npm tree and publishes it as <module>:node-modules
An install ask's body runs npm ci from the lock with no install script and no
link, packs the tree alone under modules/<module>/node_modules, publishes it to
the artifact store as the archive <module>:node-modules under the ask's version
and answers its reference, which the step's end carries. The package.json npm
ci needs is written from the lock's root entry, a lock without one refused. The
integration level's setup bound in code goes: half of the level's bound, which
each level's script gets as MESH_TEST_LEVEL_BOUND.

Builds: design 47 H2 §800; H-A-399 (2), H-A-403, H-A-427
2026-11-22 01:24:44 +01:00

137 lines
6.1 KiB
Go

package main
import (
"context"
"path/filepath"
"time"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
buildrun "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildrun"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/busstate"
)
// **The module pulls its seat's asks** (novox/hq ADR 0525 §2-§6, ADR 0536 §4; issue 1887 A3node), as mesh-build-go
// does: the seat node-build-node, delivery first, then check, then recheck, at most the node's build capacity at once
// (its setting `capacity`); each ask runs with the step bodies its tools run, behind the same guard, and ends on the key
// <node>.<ask id>. The tools stay as the hand path (ADR 0525 §8).
// Seat is the node seat this module holds.
const Seat = "node-build-node"
func (m *Module) askSteps(steps []StepTool) steprun.AskSteps {
byName := map[string]steprun.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 steprun.AskSteps{
Fetch: byName["build_node_fetch"], Build: byName["build_node_build"], Test: byName["build_node_test"],
Compare: steprun.CompareStep(steprun.GeneratedRootTS, 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(), Digest: m.programDigest(installed)}, nil
},
Release: func(ws string) error { return m.spaces().Release(ws) },
Logf: m.Say,
Has: m.Has,
Install: m.installTreeStep,
Lint: m.lintStep,
Node: m.Node,
SayStep: m.sayStep(),
Outputs: m.outputs(),
}
}
// outputs are the outputs objects a test step keeps its run's output in and the verb output reads (design 47 H2 §791,
// §820): Outputs when a test sets it, else the module's own objects store on the bus.
func (m *Module) outputs() steprun.OutputObjects {
if m.Outputs != nil {
return m.Outputs
}
return busstate.ObjectsOf(steprun.OutputsStore)
}
// sayStep says a pipeline step's end on this node's subject of the seat (design 47 G §24, *Asked on a work queue, ended by an
// event*): 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 steprun.SayStepOn(sdkstep.AskNode, m.Node, stdio.SeatPublish)
}
// 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 steprun.AskSource) *steprun.Puller {
if source == nil {
source = &steprun.SeatAsks{Language: sdkstep.AskNode, Logf: m.Say}
}
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() (*steprun.BuildWindow, string)
settings := ""
if capacity == nil {
hours = steprun.NodeBuildHours(m.Settings, m.Node, m.Say)
capacity = steprun.NodeCapacity(m.Settings, m.Node, m.Say)
settings = m.Settings
watch = steprun.WatchConfigServed
cores = steprun.NodeCoresPerStep(m.Settings, steprun.DefaultCoresPerStep[sdkstep.AskNode], m.Say)
}
ask := m.askSteps(steps)
var load func(string) ([]byte, error)
if m.ReadPauses.Get != nil {
load = func(key string) ([]byte, error) { return m.ReadPauses.Get(key) }
}
var say func(string, any, string) error
if m.SayEvent != nil {
say = steprun.SayOn(sdkstep.AskNode, m.Node, m.SayEvent)
}
return &steprun.Puller{KeepAnswer: steprun.KeepAnswerIn(m.Answers), Source: source, Language: sdkstep.AskNode, Say: say, Prior: steprun.PriorRuns(m.ReadSteps.Get), 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,
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) {
if err := m.Prepare(ctx); err != nil {
return nil, err
}
if err := m.room(); err != nil {
return nil, err
}
return steprun.RunAsk(ctx, ask, a)
}}
}
// SeatTools are the seat's verbs on this node (ADR 0525 §10).
func (m *Module) SeatTools(p *steprun.Puller) []stdio.Tool {
return append(steprun.SeatTools(Seat, "Node", p), m.stepsTool(), m.keptArtifactVerb(), steprun.OutputTool(Seat, m.Node, m.outputs(), steprun.EndedHere(m.Node, m.ReadSteps.Keys, m.ReadSteps.Get)),
steprun.AnswerTool(Seat, steprun.ReadAnswerFrom(m.Answers)))
}
// StepEndTool ends one step left running (issue 1890); the module's steps state is the one it reads and writes.
const StepEndTool = "build_node_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))
}