view: keep the pipeline runner's pipelines and serve view_pipelines

The view hears the seat mesh-pipeline-runner's pipeline-started, step-started, step-ended and pipeline-ended and the build seats' step-progress, keeps each pipeline whole in its own state pipelines (newest 500) and the latest progress per running ask in pipeline-progress (200), and view_pipelines reads them.

Builds: the lead's handover of 2026-11-16 (part 1 of the delivery view through its own pipeline); design 47 G, Pipelines per module (no milestone line cited by the handover)
This commit is contained in:
2026-11-16 21:37:07 +01:00
parent fb257f549b
commit 7a32a8b783
13 changed files with 982 additions and 8 deletions
@@ -130,6 +130,27 @@ func Tools(r view.Reader, u view.UsageReader) []stdio.Tool {
module, _ := args["module"].(string)
return r.Reach(repository, module)
}},
{Name: view.PipelinesReadTool,
Description: "The pipeline runner's pipelines as the view keeps them from its events (the newest " + fmt.Sprint(view.MaxPipelines) + "), newest first, " +
"each whole: its module, branch, source and catalog revision, commit, group or run, fingerprint, outcome (running, passed, failed, refused, superseded, " +
"cancelled) and why, when it started and ended, its test counts, and each step with its status in the policy, its outcome, why, what it waits on, " +
"its ask and the node and times; a running step carries the latest progress its build seat said of its ask (phase fetch, build, run or report, " +
"and when it was said). Narrow by branch, module, outcome and since (an RFC 3339 time: only pipelines the view kept an event of at or after it); " +
"at most limit (default " + fmt.Sprint(view.DefaultPipelinesLimit) + ", at most " + fmt.Sprint(view.MaxPipelinesLimit) + "); matching says how many fit and cut that the limit cut them. " +
"The runner's step log lines are not here. Read-only.",
Input: map[string]any{"type": "object", "properties": map[string]any{
"branch": map[string]any{"type": "string", "description": "only this branch's pipelines"},
"module": map[string]any{"type": "string", "description": "only this module's pipelines"},
"outcome": map[string]any{"type": "string", "description": "only pipelines with this outcome"},
"since": map[string]any{"type": "string", "description": "RFC 3339 time: only pipelines kept an event of at or after it"},
"limit": map[string]any{"type": "integer", "description": "at most this many pipelines, newest first"}}},
Run: func(args map[string]any) (any, error) {
q, err := view.ParsePipelinesQuery(args)
if err != nil {
return nil, err
}
return r.Pipelines(q)
}},
{Name: view.TiersTool,
Description: "A source revision's tiers, worked out now and never stored (novox/hq ADR 0603 §6): the modules the revision moves " +
"(each whose fingerprint last changed at it), ordered by the module graph (a module after the bases, the providers " +
@@ -488,6 +509,7 @@ func main() {
r.Builds, r.HavesState = read(stdio.State("mesh-delivery-builder.builds")), read(stdio.State("node-engine.have"))
r.ReachState = read(stdio.State("reach"))
r.WaitsState = read(stdio.State(viewstate.WaitsState))
r.PipelinesState, r.ProgressState = read(stdio.State(viewstate.PipelinesState)), read(stdio.State(viewstate.PipelineProgressState))
r.SignersState = seatStateRead(holderOf(stdio.Ask), func(name string) view.StateRead { return read(stdio.State(name)) }, view.VaultSeat, view.SignersState)
r.ConditionsState, r.AttemptsState = read(stdio.State(view.StatusConditionsState)), read(stdio.State(view.StatusAttemptsState))
r.PresenceState, r.StuckState = read(stdio.State(view.StatusPresenceState)), read(stdio.State(view.StatusStuckState))
@@ -66,6 +66,7 @@ const (
func TestModuleToolAnswersTheStoredValue(t *testing.T) {
t.Run("indexer_packages answers the published modules", packagesToolAnswersThePublishedModules)
t.Run("view_tiers names each module's wait", tiersToolSaysEachModulesWait)
t.Run("view_pipelines reads the kept pipelines", pipelinesToolReadsThePipelines)
t.Run("each tool answers through the owners' read tools as before", ownersAnswerTheToolsAsBefore)
t.Run("node_manifest_reads asks every node's engine in one call", manifestReadsAsksEveryNode)
r := fake{"a": withFP2, "b": withNone}.reader()
@@ -696,3 +697,27 @@ func TestBuildSeatStatesAreReadInTheHoldersState(t *testing.T) {
t.Errorf("the provisions read %v, %v; want acme-mesh-provisioner.provisions", named, err)
}
}
// view_pipelines answers the view's kept pipelines with their steps and the progress of a running step, narrowed by its arguments, and
// refuses a since that is no time.
func pipelinesToolReadsThePipelines(t *testing.T) {
r := view.Reader{
PipelinesState: fake{
"main.9.web": `{"pipeline":"main.9.web","module":"web","branch":"main","commit":"c","outcome":"running","heard":"2026-11-16T03:00:00Z","started":"2026-11-16T02:00:00Z",` +
`"steps":[{"step":"build","artifact":"web:program","status":"required","outcome":"running","ask":"a1"}]}`,
"feat.8.db": `{"pipeline":"feat.8.db","module":"db","branch":"feat","commit":"d","outcome":"passed","heard":"2026-11-16T01:00:00Z","steps":[]}`,
}.reader().State,
ProgressState: fake{"a1": `{"ask":"a1","phase":"fetch","at":"2026-11-16T03:00:00Z","seat":"node-build-go","node":"ace"}`}.reader().State,
}
out, err := run(t, r, view.PipelinesReadTool, map[string]any{"branch": "main", "since": "2026-11-16T02:30:00Z", "limit": float64(5)})
a, ok := out.(view.PipelinesAnswer)
if err != nil || !ok || len(a.Pipelines) != 1 || a.Pipelines[0].Module != "web" || a.Pipelines[0].Steps[0].Progress == nil || a.Pipelines[0].Steps[0].Progress.Phase != "fetch" {
t.Fatalf("%+v %v", out, err)
}
if out, _ := run(t, r, view.PipelinesReadTool, map[string]any{}); len(out.(view.PipelinesAnswer).Pipelines) != 2 {
t.Errorf("no arguments gives every pipeline: %+v", out)
}
if _, err := run(t, r, view.PipelinesReadTool, map[string]any{"since": "soon"}); err == nil {
t.Error("a since that is no time was answered")
}
}
@@ -191,6 +191,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if err := hearWaits(ctx, hub, js, own.Waits, logger.Printf); err != nil {
return fmt.Errorf("the waits' events are not handled: %w", err)
}
if err := hearPipelines(ctx, hub, js, own.Pipelines, own.Progress, time.Now, logger.Printf); err != nil {
return fmt.Errorf("the pipelines' events are not handled: %w", err)
}
if err := hub.StartUntilBound(ctx, js, cred, nil, nil); err != nil {
logger.Printf("the consumer is not heard yet (tried again until it is): %v", err)
}
@@ -0,0 +1,108 @@
package main
import (
"context"
"errors"
"time"
view "mesh-delivery-view/internal/view"
"git.novox.be/novox/mesh-sdk/go/process"
"github.com/nats-io/nats.go/jetstream"
)
// bucketStore is a key-value bucket of the view's own as view.PipelineStore: a put over a revision is a compare-and-set.
type bucketStore struct {
ctx context.Context
js jetstream.JetStream
bucket string
}
func (s bucketStore) kv() (jetstream.KeyValue, error) { return s.js.KeyValue(s.ctx, s.bucket) }
func (s bucketStore) Get(key string) ([]byte, uint64, error) {
kv, err := s.kv()
if err != nil {
return nil, 0, err
}
e, err := kv.Get(s.ctx, key)
if errors.Is(err, jetstream.ErrKeyNotFound) {
return nil, 0, view.ErrNotKept
}
if err != nil {
return nil, 0, err
}
if e.Operation() != jetstream.KeyValuePut {
return nil, 0, view.ErrNotKept
}
return e.Value(), e.Revision(), nil
}
func (s bucketStore) Put(key string, value []byte, revision uint64) error {
kv, err := s.kv()
if err != nil {
return err
}
if revision == 0 {
_, err = kv.Create(s.ctx, key, value)
return err
}
_, err = kv.Update(s.ctx, key, value, revision)
return err
}
func (s bucketStore) Delete(key string) error {
kv, err := s.kv()
if err != nil {
return err
}
if err := kv.Delete(s.ctx, key); errors.Is(err, jetstream.ErrKeyNotFound) {
return view.ErrNotKept
} else {
return err
}
}
func (s bucketStore) Keys() ([]string, error) {
kv, err := s.kv()
if err != nil {
return nil, err
}
keys, err := kv.Keys(s.ctx)
if errors.Is(err, jetstream.ErrNoKeysFound) {
return nil, nil
}
return keys, err
}
// hearPipelines registers the handlers for the pipeline runner's pipeline and step events and the build seats' step-progress on the
// process's hub, each kept in the view's states pipelines and pipeline-progress; one that could not be kept is not acknowledged, so
// the bus gives it again (design 47 G *Pipelines per module*).
func hearPipelines(ctx context.Context, hub *process.EventHub, js jetstream.JetStream, pipelines, progress string, now func() time.Time, logf func(string, ...any)) error {
ps, gs := bucketStore{ctx, js, pipelines}, bucketStore{ctx, js, progress}
for _, subject := range view.PipelineSubjects() {
if err := hub.Handle(subject, func(m jetstream.Msg) {
if err := view.ApplyPipelineEvent(m.Subject(), m.Data(), ps, gs, now()); err != nil {
logf("the pipeline event %s is not kept (the bus gives it again): %v", m.Subject(), err)
_ = m.Nak()
return
}
_ = m.Ack()
}); err != nil {
return err
}
}
for _, subject := range view.ProgressSubjects() {
if err := hub.Handle(subject, func(m jetstream.Msg) {
if err := view.ApplyProgress(m.Subject(), m.Data(), gs); err != nil {
logf("the step progress %s is not kept (the bus gives it again): %v", m.Subject(), err)
_ = m.Nak()
return
}
_ = m.Ack()
}); err != nil {
return err
}
}
return nil
}
@@ -0,0 +1,80 @@
//go:build integration
package main
import (
"context"
"encoding/json"
"errors"
"mesh-delivery-view/internal/view"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
)
// The pipelines are kept in the view's own buckets of a real bus: a compare-and-set that loses is refused, a key not there reads as not
// kept, and the events fill them whole.
func TestPipelinesAreKeptInTheViewsBucketsOnTheBus(t *testing.T) {
srv, err := server.NewServer(&server.Options{Host: "127.0.0.1", Port: -1, JetStream: true, StoreDir: t.TempDir(), NoLog: true, NoSigs: true})
if err != nil {
t.Fatal(err)
}
go srv.Start()
if !srv.ReadyForConnections(10 * time.Second) {
t.Fatal("the bus did not come up")
}
t.Cleanup(srv.Shutdown)
nc, err := nats.Connect(srv.ClientURL())
if err != nil {
t.Fatal(err)
}
t.Cleanup(nc.Close)
js, err := jetstream.New(nc)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
b := viewstate.BucketsOf(testView)
for _, name := range []string{b.Pipelines, b.Progress} {
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: 1}); err != nil {
t.Fatal(err)
}
}
ps, gs := bucketStore{ctx, js, b.Pipelines}, bucketStore{ctx, js, b.Progress}
if _, _, err := ps.Get("nothing"); !errors.Is(err, view.ErrNotKept) {
t.Fatalf("a key not there: %v", err)
}
now := time.Now()
const sub = "mesh.seat.mesh-pipeline-runner.event."
if err := view.ApplyPipelineEvent(sub+"pipeline-started.m.main.c1", []byte(`{"v":1,"pipeline":"main.1.m","module":"m","branch":"main","commit":"c1","steps":[{"step":"build","artifact":"m:program","status":"required"}]}`), ps, gs, now); err != nil {
t.Fatal(err)
}
if err := view.ApplyPipelineEvent(sub+"step-started.m.main.c1", []byte(`{"v":1,"pipeline":"main.1.m","module":"m","branch":"main","commit":"c1","result":{"step":"build","artifact":"m:program","status":"required","outcome":"running","ask":"a1"}}`), ps, gs, now); err != nil {
t.Fatal(err)
}
if err := view.ApplyProgress("mesh.seat.node-build-go.event.step-progress.ace", []byte(`{"asker":"r","ask":"a1","phase":"run","at":"2026-11-16T03:01:00Z"}`), gs); err != nil {
t.Fatal(err)
}
_, rev, err := ps.Get("main.1.m")
if err != nil || rev == 0 {
t.Fatalf("the pipeline is kept: %d %v", rev, err)
}
if err := ps.Put("main.1.m", []byte(`{}`), rev-1); err == nil {
t.Error("a write over a stale revision was kept")
}
if err := ps.Put("main.1.m", []byte(`{}`), 0); err == nil {
t.Error("a create over a kept key was kept")
}
read := func(s bucketStore) view.StateRead {
return view.StateRead{Keys: s.Keys, Get: func(k string) (json.RawMessage, error) { v, _, err := s.Get(k); return v, err }}
}
a, err := (view.Reader{PipelinesState: read(ps), ProgressState: read(gs)}).Pipelines(view.PipelinesQuery{})
if err != nil || len(a.Pipelines) != 1 || a.Pipelines[0].Steps[0].Progress == nil || a.Pipelines[0].Steps[0].Progress.Phase != "run" {
t.Fatalf("%+v %v", a, err)
}
}
@@ -0,0 +1,24 @@
package main
import (
"testing"
view "mesh-delivery-view/internal/view"
"git.novox.be/novox/mesh-sdk/go/process"
"github.com/nats-io/nats.go/jetstream"
)
// The pipelines' and the progress's subjects overlap none of the waits' nor each other: the hub gives a message one taker.
func TestPipelineSubjectsOverlapNoOtherHandler(t *testing.T) {
hub := process.NewEventHub(func(string, ...any) {})
patterns := append(append(waitPatterns(), view.PipelineSubjects()...), view.ProgressSubjects()...)
if len(patterns) != len(waitPatterns())+4+3 {
t.Fatalf("patterns %v", patterns)
}
for _, p := range patterns {
if err := hub.Handle(p, func(jetstream.Msg) {}); err != nil {
t.Fatalf("the pattern %s overlaps another: %v", p, err)
}
}
}
+4
View File
@@ -16,6 +16,10 @@ require (
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildimage v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun v0.0.0-00010101000000-000000000000
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds v0.0.0-00010101000000-000000000000
@@ -0,0 +1,474 @@
package view
import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildimage"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// The view keeps the pipeline runner's pipelines in its own state `pipelines` and the latest progress of each running ask in its
// state `pipeline-progress`, from the seat mesh-pipeline-runner's events pipeline-started, step-started, step-ended and
// pipeline-ended and the build seats' step-progress; view_pipelines reads them (design 47 G *Pipelines per module*).
// PipelinesReadTool reads the view's pipelines, each whole with its steps and the progress of the steps that run.
const PipelinesReadTool = "view_pipelines"
// MaxPipelines is how many pipelines the state `pipelines` keeps: when more are kept, the longest unheard ones go. MaxProgress is the
// same for the state `pipeline-progress`, whose entry also goes when its step ends. DefaultPipelinesLimit is how many a read gives
// when no limit is asked, MaxPipelinesLimit the most.
const (
MaxPipelines = 500
MaxProgress = 200
DefaultPipelinesLimit = 50
MaxPipelinesLimit = 500
pruneSlack = 50 // a state over its cap by less than this is not cut yet, so a replay does not read it at every new key
pipelineWrites = 5 // how often a write over a changed key is tried again before the event is left for the bus to give again
)
// The seat events the view hears for its pipelines, and the build seats whose step-progress it hears.
const (
EventStepProgress = "step-progress"
)
// PipelineSubjects are the subjects of the pipeline runner's events the view hears, each the seat contract's.
func PipelineSubjects() []string {
return []string{meshpipelinerunner.SubjectPipelineStartedAll, meshpipelinerunner.SubjectStepStartedAll,
meshpipelinerunner.SubjectStepEndedAll, meshpipelinerunner.SubjectPipelineEndedAll}
}
// ProgressSubjects are the build seats' step-progress subjects the view hears, each the seat contract's.
func ProgressSubjects() []string {
return []string{nodebuildgo.SubjectStepProgressAll, nodebuildimage.SubjectStepProgressAll, nodebuildnode.SubjectStepProgressAll}
}
// PipelineRecord is the value of a pipelines key: the pipeline as the runner said it (the steps with their outcomes, why, times)
// and Heard, when the view last kept an event of it.
type PipelineRecord struct {
meshpipelinerunner.Pipeline
Heard time.Time `json:"heard"`
}
// ProgressRecord is the value of a pipeline-progress key: the latest progress said of one ask, with the seat and the node that said it.
type ProgressRecord struct {
Ask string `json:"ask"`
Asker string `json:"asker,omitempty"`
Phase string `json:"phase"`
At time.Time `json:"at"`
Seat string `json:"seat"`
Node string `json:"node,omitempty"`
}
// ErrNotKept is what a store's Get says of a key it does not hold.
var ErrNotKept = errors.New("not kept")
// PipelineStore is the view's own bucket as the pipelines are kept in it: a write over a revision is refused when the key moved
// (revision 0 creates it).
type PipelineStore interface {
Get(key string) (value []byte, revision uint64, err error)
Put(key string, value []byte, revision uint64) error
Delete(key string) error
Keys() ([]string, error)
}
// ProgressKey is the key of an ask's progress.
func ProgressKey(ask string) string { return keys.EscapeName(ask) }
// ApplyPipelineEvent keeps one of the pipeline runner's events (its subject names which) in pipelines, and the progress of an ask a
// step's end or the pipeline's end closes in progress. An event that cannot be kept is an error and the bus gives it again.
func ApplyPipelineEvent(subject string, body []byte, pipelines, progress PipelineStore, now time.Time) error {
parts := strings.Split(subject, ".")
if len(parts) < 5 || parts[0] != "mesh" || parts[1] != "seat" || parts[3] != "event" {
return fmt.Errorf("%s is no seat event's subject", subject)
}
event := parts[4]
switch event {
case meshpipelinerunner.EventPipelineStarted:
var e meshpipelinerunner.PipelineStarted
if err := json.Unmarshal(body, &e); err != nil {
return fmt.Errorf("%s: %w", subject, err)
}
return changePipeline(pipelines, e.Pipeline, now, func(p *PipelineRecord) {
fillPipeline(p, e.Pipeline, e.Module, e.Branch, e.Commit, e.Group, e.Run, e.Fingerprint, e.Revision, e.Source)
if e.Published != nil {
p.Published = e.Published
}
if p.Started == nil {
p.Started = e.At
}
for _, s := range e.Steps {
if stepIndex(p.Steps, s.Step, s.Artifact) < 0 {
p.Steps = append(p.Steps, meshpipelinerunner.StepResult{Step: s.Step, Artifact: s.Artifact, Status: s.Status})
}
}
})
case meshpipelinerunner.EventStepStarted, meshpipelinerunner.EventStepEnded:
var e meshpipelinerunner.StepEvent
if err := json.Unmarshal(body, &e); err != nil {
return fmt.Errorf("%s: %w", subject, err)
}
err := changePipeline(pipelines, e.Pipeline, now, func(p *PipelineRecord) {
fillPipeline(p, e.Pipeline, e.Module, e.Branch, e.Commit, e.Group, e.Run, e.Fingerprint, e.Revision, e.Source)
i := stepIndex(p.Steps, e.Result.Step, e.Result.Artifact)
switch {
case i < 0:
p.Steps = append(p.Steps, e.Result)
case p.Outcome != meshpipelinerunner.PipelineEndedOutcomeRunning && p.Outcome != "" && p.Steps[i].Outcome != "":
// The pipeline's end said every step whole: a step's event heard after it changes nothing.
default:
p.Steps[i] = e.Result
}
})
if err != nil {
return err
}
if event == meshpipelinerunner.EventStepEnded && e.Result.Ask != "" {
return deleteKey(progress, ProgressKey(e.Result.Ask))
}
return nil
case meshpipelinerunner.EventPipelineEnded:
var e meshpipelinerunner.PipelineEnded
if err := json.Unmarshal(body, &e); err != nil {
return fmt.Errorf("%s: %w", subject, err)
}
err := changePipeline(pipelines, e.Pipeline, now, func(p *PipelineRecord) {
fillPipeline(p, e.Pipeline, e.Module, e.Branch, e.Commit, e.Group, e.Run, e.Fingerprint, e.Revision, e.Source)
p.Outcome, p.Why, p.Steps, p.Tests, p.OverBudget, p.Widens = e.Outcome, e.Why, e.Steps, e.Tests, e.OverBudget, e.Widens
p.EndCount, p.Ended = e.EndCount, e.Ended
if e.Started != nil {
p.Started = e.Started
}
})
if err != nil {
return err
}
for _, s := range e.Steps {
if s.Ask != "" {
if err := deleteKey(progress, ProgressKey(s.Ask)); err != nil {
return err
}
}
}
return nil
}
return fmt.Errorf("%s is no pipeline event the view hears", subject)
}
// fillPipeline puts what an event names of its pipeline into p; a pipeline first heard of by a step's event has an outcome of
// running until its end says another.
func fillPipeline(p *PipelineRecord, pipeline, module, branch, commit, group, run, fingerprint string, revision, source int64) {
q := &p.Pipeline
q.Pipeline, q.Module, q.Branch, q.Commit = pipeline, module, branch, commit
q.Group, q.Run, q.Fingerprint, q.Revision, q.Source = group, run, fingerprint, revision, source
if q.Outcome == "" {
q.Outcome = meshpipelinerunner.PipelineEndedOutcomeRunning
}
}
func stepIndex(steps []meshpipelinerunner.StepResult, step, artifact string) int {
for i, s := range steps {
if s.Step == step && s.Artifact == artifact {
return i
}
}
return -1
}
// changePipeline reads a pipeline's record (a new one when none), lets change alter it and writes it over the revision it read,
// again when the key moved in between; a new key over the cap cuts the oldest heard (prune).
func changePipeline(store PipelineStore, key string, now time.Time, change func(*PipelineRecord)) error {
if strings.TrimSpace(key) == "" {
return errors.New("the event names no pipeline")
}
var err error
for try := 0; try < pipelineWrites; try++ {
var rec PipelineRecord
raw, rev, gerr := store.Get(key)
if gerr != nil && !errors.Is(gerr, ErrNotKept) {
return gerr
}
if rev != 0 && len(raw) > 0 {
if jerr := json.Unmarshal(raw, &rec); jerr != nil {
return fmt.Errorf("the pipeline %s is kept in a form that does not read: %w", key, jerr)
}
}
change(&rec)
rec.Heard = now.UTC()
out, jerr := json.Marshal(rec)
if jerr != nil {
return jerr
}
if err = store.Put(key, out, rev); err == nil {
if rev == 0 {
return prunePipelines(store, MaxPipelines)
}
return nil
}
}
return fmt.Errorf("the pipeline %s moved while it was kept: %w", key, err)
}
func deleteKey(store PipelineStore, key string) error {
if err := store.Delete(key); err != nil && !errors.Is(err, ErrNotKept) {
return err
}
return nil
}
// prunePipelines cuts the pipelines to max when more than max plus the slack are kept: the ones heard longest ago go.
func prunePipelines(store PipelineStore, max int) error {
all, err := store.Keys()
if err != nil || len(all) <= max+pruneSlack {
return err
}
type kept struct {
key string
heard time.Time
}
var ks []kept
for _, k := range all {
raw, _, err := store.Get(k)
if err != nil {
if errors.Is(err, ErrNotKept) {
continue
}
return err
}
var h struct {
Heard time.Time `json:"heard"`
}
_ = json.Unmarshal(raw, &h)
ks = append(ks, kept{k, h.Heard})
}
sort.Slice(ks, func(i, j int) bool { return ks[i].heard.Before(ks[j].heard) })
for i := 0; i < len(ks)-max; i++ {
if err := deleteKey(store, ks[i].key); err != nil {
return err
}
}
return nil
}
// ApplyProgress keeps one build seat's step-progress (a subject mesh.seat.<seat>.event.step-progress.<node>): the latest per ask, so a
// progress older than the one kept changes nothing.
func ApplyProgress(subject string, body []byte, progress PipelineStore) error {
parts := strings.Split(subject, ".")
if len(parts) != 6 || parts[0] != "mesh" || parts[1] != "seat" || parts[3] != "event" || parts[4] != EventStepProgress {
return fmt.Errorf("%s is no step-progress subject", subject)
}
var e struct {
Ask string `json:"ask"`
Asker string `json:"asker"`
Phase string `json:"phase"`
At time.Time `json:"at"`
}
if err := json.Unmarshal(body, &e); err != nil {
return fmt.Errorf("%s: %w", subject, err)
}
if e.Ask == "" || e.Phase == "" {
return fmt.Errorf("%s names no ask or no phase", subject)
}
key := ProgressKey(e.Ask)
rec := ProgressRecord{Ask: e.Ask, Asker: e.Asker, Phase: e.Phase, At: e.At.UTC(), Seat: parts[2], Node: parts[5]}
out, err := json.Marshal(rec)
if err != nil {
return err
}
for try := 0; try < pipelineWrites; try++ {
raw, rev, gerr := progress.Get(key)
if gerr != nil && !errors.Is(gerr, ErrNotKept) {
return gerr
}
if rev != 0 {
var have ProgressRecord
if json.Unmarshal(raw, &have) == nil && !have.At.Before(rec.At) {
return nil
}
}
if err = progress.Put(key, out, rev); err == nil {
if rev == 0 {
return pruneProgress(progress, MaxProgress)
}
return nil
}
}
return fmt.Errorf("the progress of %s moved while it was kept: %w", e.Ask, err)
}
// pruneProgress cuts the progress to max when more than max plus the slack are kept: the oldest said go (an ask whose end was never
// heard).
func pruneProgress(store PipelineStore, max int) error {
all, err := store.Keys()
if err != nil || len(all) <= max+pruneSlack {
return err
}
type kept struct {
key string
at time.Time
}
var ks []kept
for _, k := range all {
raw, _, err := store.Get(k)
if err != nil {
if errors.Is(err, ErrNotKept) {
continue
}
return err
}
var p ProgressRecord
_ = json.Unmarshal(raw, &p)
ks = append(ks, kept{k, p.At})
}
sort.Slice(ks, func(i, j int) bool { return ks[i].at.Before(ks[j].at) })
for i := 0; i < len(ks)-max; i++ {
if err := deleteKey(store, ks[i].key); err != nil {
return err
}
}
return nil
}
// PipelinesQuery is what view_pipelines asks: each field narrows, none means all.
type PipelinesQuery struct {
Branch, Module, Outcome string
Since time.Time // pipelines the view kept an event of at or after it
Limit int
}
// StepProgressView is a running step's latest progress: its phase and when it was said.
type StepProgressView struct {
Phase string `json:"phase"`
At time.Time `json:"at"`
Seat string `json:"seat"`
Node string `json:"node,omitempty"`
}
// PipelineStepView is a step as the runner said it, with the progress of the step's ask while it runs.
type PipelineStepView struct {
meshpipelinerunner.StepResult
Progress *StepProgressView `json:"progress,omitempty"`
}
// PipelineView is a pipeline whole with its steps, Heard when the view last kept an event of it.
type PipelineView struct {
meshpipelinerunner.Pipeline
Steps []PipelineStepView `json:"steps"`
Heard time.Time `json:"heard"`
}
// PipelinesAnswer is view_pipelines' answer: the pipelines newest first, Matching how many fit before the limit cut them.
type PipelinesAnswer struct {
Pipelines []PipelineView `json:"pipelines"`
Matching int `json:"matching"`
Cut bool `json:"cut,omitempty"`
// Unreadable names the keys of a state that do not read.
Unreadable []string `json:"unreadable,omitempty"`
}
// ParsePipelinesQuery reads the tool's arguments; since is an RFC 3339 time, limit a whole number.
func ParsePipelinesQuery(args map[string]any) (PipelinesQuery, error) {
var q PipelinesQuery
q.Branch, _ = args["branch"].(string)
q.Module, _ = args["module"].(string)
q.Outcome, _ = args["outcome"].(string)
if raw, _ := args["since"].(string); strings.TrimSpace(raw) != "" {
at, err := time.Parse(time.RFC3339Nano, strings.TrimSpace(raw))
if err != nil {
return q, fmt.Errorf("since %q is not an RFC 3339 time: %w", raw, err)
}
q.Since = at
}
switch l := args["limit"].(type) {
case nil:
case float64:
if l < 0 || l != float64(int(l)) {
return q, fmt.Errorf("limit %v is no count", l)
}
q.Limit = int(l)
default:
return q, fmt.Errorf("limit %v is no count", l)
}
return q, nil
}
// Pipelines is view_pipelines: the kept pipelines that fit q, newest first (by their start, else when heard), each with the latest
// progress of its running steps from the progress state.
func (r Reader) Pipelines(q PipelinesQuery) (PipelinesAnswer, error) {
out := PipelinesAnswer{Pipelines: []PipelineView{}}
if r.PipelinesState.Keys == nil && r.PipelinesState.All == nil {
return out, errors.New("the pipelines state cannot be read here")
}
all, err := values(r.PipelinesState)
if err != nil {
return out, err
}
var progress map[string]json.RawMessage
if r.ProgressState.Keys != nil || r.ProgressState.All != nil {
if progress, err = values(r.ProgressState); err != nil {
return out, fmt.Errorf("the pipelines' progress cannot be read: %w", err)
}
}
var found []PipelineView
for _, key := range sortedKeys(all) {
var rec PipelineRecord
if err := json.Unmarshal(all[key], &rec); err != nil {
out.Unreadable = append(out.Unreadable, key)
continue
}
if q.Branch != "" && rec.Branch != q.Branch || q.Module != "" && rec.Module != q.Module || q.Outcome != "" && rec.Outcome != q.Outcome ||
!q.Since.IsZero() && rec.Heard.Before(q.Since) {
continue
}
pv := PipelineView{Pipeline: rec.Pipeline, Heard: rec.Heard, Steps: make([]PipelineStepView, 0, len(rec.Steps))}
for _, s := range rec.Steps {
sv := PipelineStepView{StepResult: s}
if s.Ask != "" && s.Outcome == "running" {
var p ProgressRecord
if raw := progress[ProgressKey(s.Ask)]; len(raw) > 0 && json.Unmarshal(raw, &p) == nil {
sv.Progress = &StepProgressView{Phase: p.Phase, At: p.At, Seat: p.Seat, Node: p.Node}
}
}
pv.Steps = append(pv.Steps, sv)
}
found = append(found, pv)
}
when := func(p PipelineView) time.Time {
if p.Started != nil {
return *p.Started
}
return p.Heard
}
sort.SliceStable(found, func(i, j int) bool { return when(found[i]).After(when(found[j])) })
out.Matching = len(found)
limit := q.Limit
if limit <= 0 {
limit = DefaultPipelinesLimit
}
if limit > MaxPipelinesLimit {
limit = MaxPipelinesLimit
}
if len(found) > limit {
found, out.Cut = found[:limit], true
}
if found != nil {
out.Pipelines = found
}
return out, nil
}
func sortedKeys(m map[string]json.RawMessage) []string {
ks := make([]string, 0, len(m))
for k := range m {
ks = append(ks, k)
}
sort.Strings(ks)
return ks
}
@@ -0,0 +1,197 @@
package view
import (
"encoding/json"
"errors"
"fmt"
"sort"
"testing"
"time"
)
// memStore is a bucket in memory with a revision per key; failPuts makes that many puts fail as a moved key does.
type memStore struct {
vals map[string][]byte
revs map[string]uint64
next uint64
failPuts int
}
func newMem() *memStore { return &memStore{vals: map[string][]byte{}, revs: map[string]uint64{}} }
func (m *memStore) Get(k string) ([]byte, uint64, error) {
v, ok := m.vals[k]
if !ok {
return nil, 0, ErrNotKept
}
return v, m.revs[k], nil
}
func (m *memStore) Put(k string, v []byte, rev uint64) error {
if m.failPuts > 0 {
m.failPuts--
return errors.New("wrong last sequence")
}
if m.revs[k] != rev {
return errors.New("wrong last sequence")
}
m.next++
m.vals[k], m.revs[k] = v, m.next
return nil
}
func (m *memStore) Delete(k string) error { delete(m.vals, k); delete(m.revs, k); return nil }
func (m *memStore) Keys() ([]string, error) {
var ks []string
for k := range m.vals {
ks = append(ks, k)
}
sort.Strings(ks)
return ks, nil
}
func (m *memStore) read() StateRead {
return StateRead{Keys: m.Keys, Get: func(k string) (json.RawMessage, error) { return m.vals[k], nil }}
}
const runner = "mesh.seat.mesh-pipeline-runner.event."
func pat(h int) time.Time { return time.Date(2026, 11, 16, h, 0, 0, 0, time.UTC) }
func started(p, module string, h int) string {
return fmt.Sprintf(`{"v":1,"pipeline":%q,"module":%q,"branch":"main","commit":"c1","at":%q,"steps":[{"step":"build","artifact":%q,"status":"required"},{"step":"unit","status":"required"}]}`,
p, module, pat(h).Format(time.RFC3339), module+":program")
}
func TestPipelinesAreKeptFromTheRunnersEventsAndReadWithTheirProgress(t *testing.T) {
ps, gs := newMem(), newMem()
apply := func(subject, body string, h int) {
t.Helper()
if err := ApplyPipelineEvent(subject, []byte(body), ps, gs, pat(h)); err != nil {
t.Fatalf("%s: %v", subject, err)
}
}
apply(runner+"pipeline-started.adwaita.main.c1", started("main.969.adwaita", "adwaita", 1), 1)
apply(runner+"pipeline-started.avahi.main.c1", started("main.970.avahi", "avahi", 2), 2)
running := `{"v":1,"pipeline":"main.969.adwaita","module":"adwaita","branch":"main","commit":"c1","result":{"step":"build","artifact":"adwaita:program","status":"required","outcome":"running","ask":"ask/1","seat":"node-build-go"}}`
apply(runner+"step-started.adwaita.main.c1", running, 3)
if err := ApplyProgress("mesh.seat.node-build-go.event.step-progress.ace", []byte(`{"asker":"mesh-pipeline-runner","ask":"ask/1","phase":"build","at":"2026-11-16T03:01:00Z"}`), gs); err != nil {
t.Fatal(err)
}
// An older progress of the same ask changes nothing: the latest is kept.
if err := ApplyProgress("mesh.seat.node-build-go.event.step-progress.g14", []byte(`{"asker":"x","ask":"ask/1","phase":"fetch","at":"2026-11-16T03:00:00Z"}`), gs); err != nil {
t.Fatal(err)
}
r := Reader{PipelinesState: ps.read(), ProgressState: gs.read()}
got, err := r.Pipelines(PipelinesQuery{})
if err != nil || len(got.Pipelines) != 2 || got.Pipelines[0].Module != "avahi" || got.Pipelines[1].Module != "adwaita" {
t.Fatalf("newest first: %+v, %v", got, err)
}
ad := got.Pipelines[1]
if ad.Outcome != "running" || len(ad.Steps) != 2 || ad.Steps[0].Progress == nil || ad.Steps[0].Progress.Phase != "build" || ad.Steps[0].Progress.Node != "ace" ||
!ad.Steps[0].Progress.At.Equal(time.Date(2026, 11, 16, 3, 1, 0, 0, time.UTC)) || ad.Steps[1].Progress != nil || ad.Steps[1].Status != "required" {
t.Fatalf("the running step carries the latest progress: %+v", ad.Steps)
}
// The step's end closes its progress; the pipeline's end says the outcome and every step whole.
apply(runner+"step-ended.adwaita.main.c1", `{"v":1,"pipeline":"main.969.adwaita","module":"adwaita","branch":"main","commit":"c1","result":{"step":"build","artifact":"adwaita:program","status":"required","outcome":"passed","ask":"ask/1"}}`, 4)
if len(gs.vals) != 0 {
t.Errorf("the progress of an ended step stays: %v", gs.vals)
}
apply(runner+"pipeline-ended.adwaita.main.c1", `{"v":1,"pipeline":"main.969.adwaita","module":"adwaita","branch":"main","commit":"c1","outcome":"failed","why":"unit failed","ended":"2026-11-16T05:00:00Z",
"steps":[{"step":"build","artifact":"adwaita:program","status":"required","outcome":"passed"},{"step":"unit","status":"required","outcome":"failed","why":"TestX"}]}`, 5)
// A step event heard after the end changes nothing.
apply(runner+"step-started.adwaita.main.c1", running, 6)
for _, tc := range []struct {
name string
q PipelinesQuery
want []string
}{
{"all", PipelinesQuery{}, []string{"avahi", "adwaita"}},
{"outcome", PipelinesQuery{Outcome: "failed"}, []string{"adwaita"}},
{"module", PipelinesQuery{Module: "avahi"}, []string{"avahi"}},
{"branch", PipelinesQuery{Branch: "other"}, nil},
{"since heard", PipelinesQuery{Since: pat(6)}, []string{"adwaita"}},
{"limit", PipelinesQuery{Limit: 1}, []string{"avahi"}},
} {
a, err := r.Pipelines(tc.q)
var mods []string
for _, p := range a.Pipelines {
mods = append(mods, p.Module)
}
if err != nil || fmt.Sprint(mods) != fmt.Sprint(tc.want) {
t.Errorf("%s: %v, %v (want %v)", tc.name, mods, err, tc.want)
}
}
a, _ := r.Pipelines(PipelinesQuery{Limit: 1})
if !a.Cut || a.Matching != 2 {
t.Errorf("a cut says so: %+v", a)
}
a, _ = r.Pipelines(PipelinesQuery{Outcome: "failed"})
if w := a.Pipelines[0]; w.Why != "unit failed" || w.Ended == nil || w.Steps[1].Outcome != "failed" || w.Steps[0].Progress != nil || w.Steps[0].Outcome != "passed" {
t.Errorf("the ended pipeline is whole: %+v", w)
}
}
func TestAStepEventBeforeItsPipelinesStartCreatesThePipelineAndTheStartFillsIt(t *testing.T) {
ps, gs := newMem(), newMem()
if err := ApplyPipelineEvent(runner+"step-ended.m.main.c1", []byte(`{"v":1,"pipeline":"main.1.m","module":"m","branch":"main","commit":"c1","result":{"step":"build","artifact":"m:program","status":"required","outcome":"passed"}}`), ps, gs, pat(1)); err != nil {
t.Fatal(err)
}
if err := ApplyPipelineEvent(runner+"pipeline-started.m.main.c1", []byte(started("main.1.m", "m", 0)), ps, gs, pat(2)); err != nil {
t.Fatal(err)
}
a, _ := Reader{PipelinesState: ps.read()}.Pipelines(PipelinesQuery{})
if p := a.Pipelines[0]; len(p.Steps) != 2 || p.Steps[0].Outcome != "passed" || p.Steps[1].Step != "unit" || p.Started == nil || p.Outcome != "running" {
t.Fatalf("%+v", p)
}
}
func TestPipelineWritesRetryAMovedKeyAndRefuseWhatDoesNotReadAndPruneToTheCap(t *testing.T) {
ps, gs := newMem(), newMem()
ps.failPuts = pipelineWrites - 1
if err := ApplyPipelineEvent(runner+"pipeline-started.m.main.c1", []byte(started("main.1.m", "m", 0)), ps, gs, pat(1)); err != nil || len(ps.vals) != 1 {
t.Fatalf("a moved key is tried again: %v", err)
}
ps.failPuts = pipelineWrites
if err := ApplyPipelineEvent(runner+"pipeline-started.m.main.c1", []byte(started("main.1.m", "m", 0)), ps, gs, pat(1)); err == nil {
t.Error("a key that keeps moving is left for the bus to give again")
}
for _, bad := range [][2]string{{runner + "pipeline-started.m.main.c1", `{`}, {runner + "pipeline-started.m.main.c1", `{"module":"m"}`}, {runner + "wait-held.m.main.c1", `{}`}, {"mesh.mod.x.y", `{}`}} {
if err := ApplyPipelineEvent(bad[0], []byte(bad[1]), ps, gs, pat(1)); err == nil {
t.Errorf("%s %s was kept", bad[0], bad[1])
}
}
if err := ApplyProgress("mesh.seat.node-build-go.event.step-progress.ace", []byte(`{"ask":"","phase":"build"}`), gs); err == nil {
t.Error("a progress of no ask was kept")
}
// Over its cap by more than the slack, the longest unheard go, the newest stay.
ps = newMem()
for i := 0; i < MaxPipelines+pruneSlack+1; i++ {
p := fmt.Sprintf("main.%d.m", i)
if err := ApplyPipelineEvent(runner+"pipeline-started.m.main.c1", []byte(started(p, "m", 0)), ps, gs, pat(0).Add(time.Duration(i)*time.Second)); err != nil {
t.Fatal(err)
}
}
if len(ps.vals) != MaxPipelines {
t.Fatalf("%d pipelines kept, the cap is %d", len(ps.vals), MaxPipelines)
}
if _, _, err := ps.Get("main.0.m"); err == nil {
t.Error("the oldest heard stays")
}
if _, _, err := ps.Get(fmt.Sprintf("main.%d.m", MaxPipelines+pruneSlack)); err != nil {
t.Error("the newest heard went")
}
}
func TestPipelinesQueryReadsItsArguments(t *testing.T) {
q, err := ParsePipelinesQuery(map[string]any{"branch": "main", "since": "2026-11-16T01:00:00Z", "limit": float64(3)})
if err != nil || q.Branch != "main" || q.Limit != 3 || !q.Since.Equal(pat(1)) {
t.Fatalf("%+v %v", q, err)
}
for _, bad := range []map[string]any{{"since": "yesterday"}, {"limit": "3"}, {"limit": float64(-1)}, {"limit": 1.5}} {
if _, err := ParsePipelinesQuery(bad); err == nil {
t.Errorf("%v was read", bad)
}
}
if _, err := (Reader{}).Pipelines(PipelinesQuery{}); err == nil {
t.Error("a state that cannot be read here reads as none")
}
}
@@ -57,6 +57,8 @@ type Reader struct {
DifferencesState StateRead // the assigner's differences
HavesState StateRead // the node-engine's haves
ReachState StateRead // the view's own reach (ADR 0556)
PipelinesState StateRead // the view's own pipelines, from the pipeline runner's events
ProgressState StateRead // the view's own pipeline-progress: the latest progress of each running ask
WaitsState StateRead // the view's own waits: the parts' wait-held (design 47 G §512, A-242)
// HeardState is the FORGE messages the indexer handled (issue 1126 note 76); unset reads none.
HeardState StateRead
+13 -4
View File
@@ -198,7 +198,9 @@ func TestManifestIsTakenAndReadsOnly(t *testing.T) { // 1134/AC7
"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-delivery-indexer.views.candidates", "mesh-delivery-indexer.views.taken", "mesh-delivery-teller.views.answers",
"mesh-wants.wait-held", "mesh-wants.wait-ended", "node-engine.wait-held", "node-engine.wait-ended", "mesh-pipeline-runner.wait-held", "mesh-pipeline-runner.wait-ended",
"mesh-grants.wait-held", "mesh-grants.wait-ended", "mesh-delivery-builder.wait-held", "mesh-delivery-builder.wait-ended",
"mesh-broker.recreated", "mesh-broker.dropped"}; !reflect.DeepEqual(m.Consumes, want) { // design 47 G §512, A-242: every part's wait-held and wait-ended
"mesh-broker.recreated", "mesh-broker.dropped",
"mesh-pipeline-runner.pipeline-started", "mesh-pipeline-runner.step-started", "mesh-pipeline-runner.step-ended", "mesh-pipeline-runner.pipeline-ended",
"node-build-go.step-progress", "node-build-image.step-progress", "node-build-node.step-progress"}; !reflect.DeepEqual(m.Consumes, want) { // design 47 G §512, A-242: every part's wait-held and wait-ended
t.Errorf("consumes = %v, want %v", m.Consumes, want)
}
// The one event the view says: a source revision is delivered (1906/D9, ADR 0539 §17), derived by it from the wants and the haves.
@@ -212,7 +214,7 @@ func TestManifestIsTakenAndReadsOnly(t *testing.T) { // 1134/AC7
// The states the view writes: the operator's answers to the asks that need no proof (ADR 0528 clause 6, 1297/B9), which the
// teller reads, and how far each repository reached (ADR 0556 clause 2, issue 1280), which the gate reads.
// Its first views of the owners' states and the finding of one unanswered past its bound (ADR 0615 §6).
if want := []state{{Name: "answers", History: 5}, {Name: "reach", History: 1}, {Name: "waits", History: 1}, {Name: "first-views", History: 1}, {Name: "view-marks", History: 1}}; !reflect.DeepEqual(m.State, want) {
if want := []state{{Name: "answers", History: 5}, {Name: "reach", History: 1}, {Name: "waits", History: 1}, {Name: "pipelines", History: 1}, {Name: "pipeline-progress", History: 1}, {Name: "first-views", History: 1}, {Name: "view-marks", History: 1}}; !reflect.DeepEqual(m.State, want) {
t.Errorf("state = %+v, want %+v", m.State, want)
}
if _, ok := m.OwnSecrets["broker"]; !ok || len(m.OwnSecrets) != 1 {
@@ -223,7 +225,7 @@ func TestManifestIsTakenAndReadsOnly(t *testing.T) { // 1134/AC7
}
// The two read tools of the indexer's modules (issue 1562), carried by a bundle the runtime launches; the indexer
// itself serves no tool (ADR 0437 §4). Carrying them gives the tool runner read access to every bucket the view reads.
if want := []string{"view_status", "indexer_module", "indexer_modules", "indexer_candidate", "indexer_candidates", "indexer_predefined", "indexer_config_candidates", "indexer_packages", "builder_build", "builder_builds", "builder_history", "assigner_wants", "assigner_want", "assigner_differences", "node_haves", "node_trusts", "build_usage", "view_reach", "indexer_module_history", "indexer_heard", "view_tiers", "view_first_views", "view_first_view_again", "node_manifest_reads", "view_seat_list", "view_seat_list_again", "answers"}; !reflect.DeepEqual(m.Tools, want) {
if want := []string{"view_status", "indexer_module", "indexer_modules", "indexer_candidate", "indexer_candidates", "indexer_predefined", "indexer_config_candidates", "indexer_packages", "builder_build", "builder_builds", "builder_history", "assigner_wants", "assigner_want", "assigner_differences", "node_haves", "node_trusts", "build_usage", "view_reach", "view_pipelines", "indexer_module_history", "indexer_heard", "view_tiers", "view_first_views", "view_first_view_again", "node_manifest_reads", "view_seat_list", "view_seat_list_again", "answers"}; !reflect.DeepEqual(m.Tools, want) {
t.Errorf("tools = %v, want %v", m.Tools, want)
}
// D-11: the holders and buckets the view names are its manifest's (no contract names a holder, novox/hq ADR 0634 §1): a
@@ -285,11 +287,18 @@ func TestManifestIsTakenAndReadsOnly(t *testing.T) { // 1134/AC7
own = append(own, "a-view_"+s.Name)
}
b := viewstate.BucketsOf("a-view")
for _, want := range []string{b.Answers, b.Reach, b.Waits} {
for _, want := range []string{b.Answers, b.Reach, b.Waits, b.Pipelines, b.Progress} {
if !slices.Contains(own, want) {
t.Errorf("the view keeps %s, its manifest's states are %v", want, own)
}
}
// The pipelines are the runner's events and the progress the build seats': each subject the view hears is of an event its manifest consumes.
for _, subject := range append(view.PipelineSubjects(), view.ProgressSubjects()...) {
p := strings.Split(subject, ".") // mesh.seat.<seat>.event.<event>...
if want := p[2] + "." + p[4]; !slices.Contains(m.Consumes, want) {
t.Errorf("the view hears %s, its manifest consumes %v", subject, m.Consumes)
}
}
// The packages key is the seat's key of its state packages for a module (<module>), as the indexer writes it: the
// escaped path, with no dot, so a reader never takes it for a <package>.<series> key.
const path = "git.novox.be/novox/mesh-sdk/go"
+17 -1
View File
@@ -22,6 +22,7 @@
"node_trusts",
"build_usage",
"view_reach",
"view_pipelines",
"indexer_module_history",
"indexer_heard",
"view_tiers",
@@ -60,6 +61,14 @@
"name": "waits",
"history": 1
},
{
"name": "pipelines",
"history": 1
},
{
"name": "pipeline-progress",
"history": 1
},
{
"name": "first-views",
"history": 1
@@ -94,7 +103,14 @@
"mesh-delivery-builder.wait-held",
"mesh-delivery-builder.wait-ended",
"mesh-broker.recreated",
"mesh-broker.dropped"
"mesh-broker.dropped",
"mesh-pipeline-runner.pipeline-started",
"mesh-pipeline-runner.step-started",
"mesh-pipeline-runner.step-ended",
"mesh-pipeline-runner.pipeline-ended",
"node-build-go.step-progress",
"node-build-image.step-progress",
"node-build-node.step-progress"
],
"invokes": [
"mesh-delivery-assigner.assigner_read_differences",
+13 -3
View File
@@ -26,12 +26,22 @@ const modulesHistory = 20
// ReachState is the delivery view's state `reach`: one key per repository (RepositoryKey), how far its modules reached.
const ReachState = "reach"
// Buckets are the delivery view's own state buckets, `<module>_<state>`: waits, reach and answers.
type Buckets struct{ Waits, Reach, Answers string }
// PipelinesState is the delivery view's state `pipelines`: one key per pipeline (its name, <branch>.<revision>.<module>), the
// pipeline whole with its steps as the pipeline runner's events said them, and PipelineProgressState its state
// `pipeline-progress`: one key per running ask, the latest progress a build seat said of it.
const (
PipelinesState = "pipelines"
PipelineProgressState = "pipeline-progress"
)
// Buckets are the delivery view's own state buckets, `<module>_<state>`: waits, reach, answers, pipelines and the pipelines'
// progress.
type Buckets struct{ Waits, Reach, Answers, Pipelines, Progress string }
// BucketsOf names the view's own buckets from module, its credential's, never a constant (design 47 G A-296).
func BucketsOf(module string) Buckets {
return Buckets{Waits: module + "_" + WaitsState, Reach: module + "_" + ReachState, Answers: module + "_" + ViewAnswersState}
return Buckets{Waits: module + "_" + WaitsState, Reach: module + "_" + ReachState, Answers: module + "_" + ViewAnswersState,
Pipelines: module + "_" + PipelinesState, Progress: module + "_" + PipelineProgressState}
}
// Reach is the value of a reach key: how far the modules of one repository reached on the nodes. Indexed is the last