A3: the view tools' usage reader is built by one function main and its test use

Builds: design 47 G A-128
This commit is contained in:
2026-11-12 23:29:33 +01:00
parent 6f03ceac26
commit 33991dafa9
2 changed files with 26 additions and 5 deletions
@@ -461,6 +461,17 @@ func seatStateRead(holder func(seat string) (string, bool), read func(name strin
Get: func(key string) (json.RawMessage, error) { return at().Get(key) }}
}
// usageReaderOf is the usage tools' reader: the haves, the config's resolved values and the checker's tries read as they are, a
// build seat's steps and pauses in the state of the seat's holder (ofHolder), and the backlog the view program's socket answers;
// main and its test wire it the one way.
func usageReaderOf(haves view.StateRead, seats *buildrun.BuildSeats, holder func(seat string) (string, bool), state func(name string) view.StateRead, backlog func() ([]view.BacklogRow, error)) view.UsageReader {
return view.UsageReader{Haves: haves, Resolved: state("mesh-config.resolved"), Tries: state("mesh-delivery-checker.tries"),
Seats: seats,
StepsOf: ofHolder(holder, state, view.StepsState),
PausesOf: ofHolder(holder, state, buildstep.PausesState),
Backlog: backlog}
}
func main() {
logf := func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-view-tools] "+f+"\n", a...) }
// The catalog half per watched branch, followed by the bundle itself through meshcatalogclient's branch follower on
@@ -500,11 +511,7 @@ func main() {
}
return nil
}, holderOf(stdio.Ask))
u := view.UsageReader{Haves: r.HavesState, Resolved: read(stdio.State("mesh-config.resolved")), Tries: read(stdio.State("mesh-delivery-checker.tries")),
Seats: seats,
StepsOf: ofHolder(holderOf(stdio.Ask), func(name string) view.StateRead { return read(stdio.State(name)) }, view.StepsState),
PausesOf: ofHolder(holderOf(stdio.Ask), func(name string) view.StateRead { return read(stdio.State(name)) }, buildstep.PausesState),
Backlog: backlogOf(socket())}
u := usageReaderOf(r.HavesState, seats, holderOf(stdio.Ask), func(name string) view.StateRead { return read(stdio.State(name)) }, backlogOf(socket()))
// view_first_views and view_first_view_again: where the view's process stands with its first views of the indexer's and
// the assigner's states (ADR 0615 §6), and a re-read by hand.
tools := append(Tools(r, u), gate.Tools()...)
@@ -18,6 +18,7 @@ import (
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshwatchdogsclient"
"git.novox.be/novox/mesh-contracts/identity-and-access/go/clients/meshvaultclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/busretry"
@@ -675,6 +676,19 @@ func TestBuildSeatStatesAreReadInTheHoldersState(t *testing.T) {
if _, err := signers.Get(view.SignersKeyKey); err != nil || !slices.Equal(named, []string{"acme-mesh-vault.signers"}) {
t.Errorf("the signers read %v, %v; want acme-mesh-vault.signers", named, err)
}
// The usage reader main wires reads the same way: the steps and pauses at the holder, the checker's tries and the config's
// resolved values by their names, the haves and the backlog as given.
named = nil
seats := &buildrun.BuildSeats{}
u := usageReaderOf(view.StateRead{}, seats, holder, read, func() ([]view.BacklogRow, error) { return []view.BacklogRow{{}}, nil })
u.StepsOf("node-build-go")
u.PausesOf("node-build-go")
if want := []string{"mesh-config.resolved", "mesh-delivery-checker.tries", "acme-node-build-go.steps", "acme-node-build-go.pauses"}; !slices.Equal(named, want) || u.Seats != seats {
t.Errorf("the usage reader reads %v, seats %p; want %v, %p", named, u.Seats, want, seats)
}
if rows, err := u.Backlog(); err != nil || len(rows) != 1 {
t.Errorf("the usage reader's backlog = %v, %v", rows, err)
}
// So are the provisioner's provisions (A-318).
named = nil
provisions := seatStateRead(holder, read, view.ProvisionsSeat, view.ProvisionsState)