Merge remote-tracking branch 'origin/main' into fix/fp-imports

This commit is contained in:
2026-11-23 12:33:10 +01:00
18 changed files with 817 additions and 136 deletions
@@ -14,13 +14,13 @@ const Seat = "mesh-pipeline-runner"
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
// a reader of a value of another form says "form N, this reader knows M".
const Form = 10
const Form = 11
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "10"
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=e3f4c58f93c8 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=f58dbdcaf2d4 PipelineStarted=582f8ff3b28d PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
generatedForms = "11"
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=e3f4c58f93c8 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=397a8219a855 PipelineStarted=582f8ff3b28d PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
)
const (
@@ -73,7 +73,7 @@ func VerbDescription(verb string) string {
case VerbShow:
return "One pipeline: naming a mover, its steps alone; with no mover, each mover's row (its module, outcome and failed step), never every step of every mover, or the steps of any mover the step and state filters hold; and its step log, with the stores' fill (design 47 H2 §789, H-A-376). Reads only."
case VerbList:
return "The pipelines and runs of a module, a branch or a commit, newest first: by default one short row per pipeline, the newest 20 (its key, call, source, revision, start, end, outcome, movers' count, its steps counted per outcome and first failed or could-not-run step with its module and why); the whole pipelines, each record with its movers and steps counted, never its steps (show gives those), only with full and a limit (design 47 H2 H-A-376, H-A-467). Reads only."
return "The pipelines and runs of a module, a branch or a commit, newest first, of every branch when none is named (design 47 H2 H-A-533): by default one short row per pipeline, the newest 20 (its key, branch, call, source, revision, start, end, outcome, movers' count, its steps counted per outcome and first failed or could-not-run step with its module and why); the whole pipelines, each record with its movers and steps counted, never its steps (show gives those), only with full and a limit (design 47 H2 H-A-376, H-A-467). Reads only."
case VerbStands:
return "What stands still, and since when: each step not ended and each wait held. Reads only."
case VerbWhyCarried:
@@ -921,6 +921,8 @@ const (
// PipelineRow is one pipeline in list's short form, with its source, revision and its steps counted per outcome (design 47 H2 H-A-376, H-A-467).
type PipelineRow struct {
// the watched branch, or the branch of a run on request: a column of the pipelines page, which lists every branch's together (design 47 H2 H-A-533)
Branch string `json:"branch,omitempty"`
// the merge call whose source revision the take-in took in
Call string `json:"call,omitempty"`
Ended *time.Time `json:"ended,omitempty"`
@@ -178,7 +178,7 @@
},
{
"name": "list",
"description": "The pipelines and runs of a module, a branch or a commit, newest first: by default one short row per pipeline, the newest 20 (its key, call, source, revision, start, end, outcome, movers' count, its steps counted per outcome and first failed or could-not-run step with its module and why); the whole pipelines, each record with its movers and steps counted, never its steps (show gives those), only with full and a limit (design 47 H2 H-A-376, H-A-467). Reads only.",
"description": "The pipelines and runs of a module, a branch or a commit, newest first, of every branch when none is named (design 47 H2 H-A-533): by default one short row per pipeline, the newest 20 (its key, branch, call, source, revision, start, end, outcome, movers' count, its steps counted per outcome and first failed or could-not-run step with its module and why); the whole pipelines, each record with its movers and steps counted, never its steps (show gives those), only with full and a limit (design 47 H2 H-A-376, H-A-467). Reads only.",
"input": {
"type": "object",
"properties": {
@@ -2296,6 +2296,10 @@
"type": "string",
"description": "the pipeline's key"
},
"branch": {
"type": "string",
"description": "the watched branch, or the branch of a run on request: a column of the pipelines page, which lists every branch's together (design 47 H2 H-A-533)"
},
"call": {
"type": "string",
"description": "the merge call whose source revision the take-in took in"
@@ -2378,5 +2382,5 @@
]
}
},
"form": 10
"form": 11
}
@@ -430,6 +430,8 @@ export interface PipelineEnded {
/** one pipeline in list's short form, with its source, revision and its steps counted per outcome (design 47 H2 H-A-376, H-A-467) */
export interface PipelineRow {
/** the watched branch, or the branch of a run on request: a column of the pipelines page, which lists every branch's together (design 47 H2 H-A-533) */
"branch"?: string;
/** the merge call whose source revision the take-in took in */
"call"?: string;
"ended"?: string;
@@ -249,7 +249,8 @@ func MoverRows(p seat.Pipeline) []seat.MoverRow {
return out
}
// List is the pipelines and runs of a module, a branch, a commit or a run, newest started first (§83): by default one
// List is the pipelines and runs of a module, a branch, a commit or a run, newest started first (§83), of every branch when
// none is named, each row naming its branch (design 47 H2 H-A-533): by default one
// short row per pipeline, the newest ListRows or Limit (design 47 H2 H-A-376); with Full and a Limit each one's record with
// its movers and steps counted, its steps empty (H-A-191).
func (r Reads) List(in seat.ListInput) (seat.ListAnswer, error) {
@@ -288,7 +289,7 @@ func (r Reads) List(in seat.ListInput) (seat.ListAnswer, error) {
for _, p := range out {
// A row carries its source, its revision and its steps counted per outcome (design 47 H2 H-A-467): a page's list is
// one read of the short form.
rows = append(rows, seat.PipelineRow{Pipeline: p.Pipeline, Call: p.Call, Source: p.Source, Revision: p.Revision,
rows = append(rows, seat.PipelineRow{Pipeline: p.Pipeline, Branch: p.Branch, Call: p.Call, Source: p.Source, Revision: p.Revision,
Started: p.Started, Ended: p.Ended, Outcome: p.Outcome, MoverCount: p.MoverCount, Steps: stepCounts(steps[p.Pipeline]),
Failed: firstFailed(steps[p.Pipeline])})
}
@@ -157,12 +157,21 @@ func TestReads(t *testing.T) {
a, err := r.List(seat.ListInput{Branch: "gone"})
raw, _ := json.Marshal(a.Rows)
return fmt.Sprint(string(raw), " ", len(a.Pipelines)), err
}, `[{"call":"call-2","ended":"2026-11-11T10:01:00Z","failed":{"artifact":"zeta:program","module":"zeta","outcome":"could not run","step":"unit","why":"its node lacks node-build-node"},"mover-count":1,"outcome":"failed","pipeline":"gone.2","revision":5,"source":2,"started":"2026-11-11T10:00:00Z","steps":{"could not run":1,"failed":1}}] 0`},
}, `[{"branch":"gone","call":"call-2","ended":"2026-11-11T10:01:00Z","failed":{"artifact":"zeta:program","module":"zeta","outcome":"could not run","step":"unit","why":"its node lacks node-build-node"},"mover-count":1,"outcome":"failed","pipeline":"gone.2","revision":5,"source":2,"started":"2026-11-11T10:00:00Z","steps":{"could not run":1,"failed":1}}] 0`},
// Design 47 H2 H-A-467: a row counts the steps per outcome, a mover's kept steps (H-A-187) with them.
{"list's row counts its steps per outcome", func() (string, error) {
a, err := r.List(seat.ListInput{Branch: "next"})
return fmt.Sprint(a.Rows[0].Source, " ", a.Rows[0].Steps), err
}, "8 map[passed:2 waiting:1]"},
// Design 47 H2 H-A-533: naming no branch, list answers every branch's pipelines together, each row naming its branch.
{"list with no branch answers every branch's, newest first, each row naming its branch", func() (string, error) {
a, err := r.List(seat.ListInput{})
var s []string
for _, row := range a.Rows {
s = append(s, row.Branch+":"+row.Pipeline)
}
return strings.Join(s, " "), err
}, "beta:beta.3.alpha main:main.7.gamma gone:gone.2 main:main.7.alpha next:next.8"},
{"list's full needs a limit", func() (string, error) {
_, err := r.List(seat.ListInput{Full: true})
return "", err
@@ -561,6 +561,12 @@ func TestPauseCapacityAndComposerKey(t *testing.T) {
if !IsPassing(fmt.Errorf("fetch: %w", &Passing{Err: errors.New("s")})) || IsPassing(errors.New("i/o timeout")) {
t.Error("a wrapped Passing is a Passing error and a bare error is none")
}
// A call a stopping tool runner did not take is passing by its typed fault, wrapped or not; its words alone, and a bare
// "timeout", are not (design 47 H2 H-A-542).
if !IsPassing(kindedFault("stopping")) || !IsPassing(fmt.Errorf("publish: %w", kindedFault("stopping"))) ||
IsPassing(kindedFault("away")) || IsPassing(errors.New("the tool runner is stopping")) || IsPassing(errors.New("timeout")) {
t.Error("a stopping tool runner's fault is passing by its kind alone")
}
if Ended(Step{State: StepRunning}) || Ended(Step{State: StepAgain}) || !Ended(Step{State: StepPassed}) || !Ended(Step{State: StepFailed}) {
t.Error("Ended: running and again are no end")
}
@@ -710,3 +716,9 @@ func TestAskSubjectBy(t *testing.T) {
t.Error("a subject of four tokens after accept parses")
}
}
// kindedFault is an error with a typed fault, as mesh-sdk's stdio hands a runtime's answer naming one.
type kindedFault string
func (k kindedFault) Error() string { return "the call was not taken: " + string(k) }
func (k kindedFault) ErrorKind() string { return string(k) }
+13 -2
View File
@@ -14,10 +14,21 @@ type Passing struct{ Err error }
func (p *Passing) Error() string { return p.Err.Error() }
func (p *Passing) Unwrap() error { return p.Err }
// IsPassing says err is, or wraps, a Passing.
// IsPassing says err is, or wraps, a Passing, or a call a stopping tool runner did not take (errorKindStopping): the one
// place every step's fault reading counts stopping as passing, by its kind and never by its words (design 47 H2 H-A-542).
func IsPassing(err error) bool {
var p *Passing
return errors.As(err, &p)
return errors.As(err, &p) || stopping(err)
}
// errorKindStopping is the typed fault a stopping tool runner answers each call it does not take with, mesh-sdk stdio's
// ErrorKindStopping (design 47 H2 H-A-542); this package reaches no bus, so it reads the kind by the error's ErrorKind.
const errorKindStopping = "stopping"
// stopping says err is, or wraps, an error whose typed fault is stopping (ErrorKind() string).
func stopping(err error) bool {
var kinded interface{ ErrorKind() string }
return errors.As(err, &kinded) && kinded.ErrorKind() == errorKindStopping
}
// passingWords are the words of a network that did not answer, lower-cased: go's and git's (a lookup, a timeout, a refused or
@@ -3,6 +3,7 @@ package steprun
import (
"context"
"errors"
"fmt"
"strings"
"testing"
"time"
@@ -10,11 +11,20 @@ import (
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
)
// stoppingFault is a call a stopping tool runner did not take, as mesh-sdk's stdio hands it: its typed fault stopping.
type stoppingFault struct{}
func (stoppingFault) Error() string {
return "registry's publish was not taken: the tool runner is stopping"
}
func (stoppingFault) ErrorKind() string { return "stopping" }
// Design 47 H2 §799: a fetch met by a forge's 401 or a connection fault, and a publish met by no responders or a bundle
// that exited, end their run `again` after again-delays' delay, with no seat call; a third run's fault ends the step failed
// with the why `fetch: <words>` or `publish: <words>`. ADR 0664 §1 with the bus's count above the runs that started: an ask
// given back twice before its first run (the bus says delivered 3, the step key 1 run began) meets its fault in run 2,
// given again after again-delays' second, 60 s, not 3.
// given again after again-delays' second, 60 s, not 3. A publish met by a stopping tool runner is one too (H-A-542); a
// bare timeout is not.
func TestAFetchOrAPublishMetAwayIsATransportFault(t *testing.T) {
delay, err := AgainDelays("")
if err != nil || delay(1) != 15*time.Second || delay(2) != time.Minute || delay(3) != time.Minute {
@@ -37,6 +47,8 @@ func TestAFetchOrAPublishMetAwayIsATransportFault(t *testing.T) {
{"a publish met by a bundle that exited", "publish: ", PublishFault(errors.New("the bundle exited"))},
{"a fetch of a commit that is not there", "", gitFailure("fetch", "fatal: unknown revision or path not in the working tree")},
{"a publish refused", "", PublishFault(errors.New("refused: the digest differs"))},
{"a publish met by a stopping tool runner", "publish: ", PublishFault(fmt.Errorf("asked again: %w", stoppingFault{}))},
{"a publish met by a bare timeout", "", PublishFault(errors.New("timeout"))},
} {
t.Run(tc.name, func(t *testing.T) {
if tc.why == "" {
+9 -5
View File
@@ -10,6 +10,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
@@ -81,15 +82,18 @@ func PublishParts(ctx context.Context, call SeatCall, seat string, in reg.Publis
return sent, PublishFault(err)
}
// PublishFault is err, or, when a publish met no responders or a registry's bundle that exited, a sdkstep.Passing whose
// words open with "publish: " (design 47 H2 §799, ADR 0664 §1): the run ends `again`, with no seat call to learn why,
// and a third run's fault ends the step failed with the why `publish: <words>`. Any other error is returned as it is.
// PublishFault is err, or, when a publish met no responders, a registry's bundle that exited or a stopping tool runner (its
// typed fault stopping, which sdkstep.IsPassing counts, design 47 H2 H-A-542), a sdkstep.Passing whose words open with
// "publish: " (design 47 H2 §799, ADR 0664 §1): the run ends `again`, with no seat call to learn why, and a third run's
// fault ends the step failed with the why `publish: <words>`. Any other error, a bare "timeout" among them, is returned as
// it is.
func PublishFault(err error) error {
if err == nil || sdkstep.IsPassing(err) {
var passing *sdkstep.Passing
if err == nil || errors.As(err, &passing) {
return err
}
words := strings.ToLower(err.Error())
if !strings.Contains(words, "no responders") && !strings.Contains(words, "bundle exited") {
if !sdkstep.IsPassing(err) && !strings.Contains(words, "no responders") && !strings.Contains(words, "bundle exited") {
return err
}
return &sdkstep.Passing{Err: fmt.Errorf("publish: %w", err)}
@@ -3,8 +3,8 @@
// to write the operator's answer to an ask that needs no proof of who answered (the view refuses the merge's Approve). `holds`
// lists every fingerprint the assigner holds with its node, cause and answer; `hold-release <module> <fingerprint> [words]` and
// `hold-keep <module> <fingerprint> [words]` answer its hold ask, again when the operator changes their mind (issue 1906).
// `pipelines [branch]` and `pipeline <pipeline> [mover]` are the pipelines page (design 47 H2 H-A-467): a branch's newest
// pipelines, one pipeline's mover rows or one mover's steps; with -follow printed again at each change the runner's events say.
// `pipelines [module]` and `pipeline <pipeline> [mover]` are the pipelines page (design 47 H2 H-A-467, H-A-533): every
// branch's newest pipelines (of a module when named), one pipeline by tier and stage, or one mover's steps; with -follow printed again at each change the runner's events say.
package main
import (
@@ -17,7 +17,6 @@ import (
"text/tabwriter"
"time"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"mesh-delivery-view/internal/view"
)
@@ -37,7 +36,7 @@ func run(args []string, socket string, out, errOut io.Writer) int {
asJSON := fs.Bool("json", false, "print the rows as JSON")
follow := fs.Bool("follow", false, "pipelines and pipeline: print again at each change the runner's events say, until interrupted")
next := fs.String("next", "", "pipeline: the cursor of the next page a pipeline's answer named")
limit := fs.Int("limit", view.DefaultPipelinesLimit, "pipelines: the newest this many pipelines of the branch")
limit := fs.Int("limit", view.DefaultPipelinesLimit, "pipelines: the newest this many pipelines")
if err := fs.Parse(args); err != nil {
return 2
}
@@ -67,7 +66,7 @@ func run(args []string, socket string, out, errOut io.Writer) int {
}
if fs.NArg() > 0 {
if fs.Arg(0) != "answer" || fs.NArg() < 3 {
fmt.Fprintln(errOut, "mesh-delivery-cli shows the rows, or answers: mesh-delivery-cli answer <ask key> <option> [words]; holds; hold-release|hold-keep <module> <fingerprint> [words]; [-follow] [-limit <n>] pipelines [branch]; [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
fmt.Fprintln(errOut, "mesh-delivery-cli shows the rows, or answers: mesh-delivery-cli answer <ask key> <option> [words]; holds; hold-release|hold-keep <module> <fingerprint> [words]; [-follow] [-limit <n>] pipelines [module]; [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
return 2
}
key, option := fs.Arg(1), fs.Arg(2)
@@ -96,14 +95,14 @@ func run(args []string, socket string, out, errOut io.Writer) int {
return 0
}
// pipelines prints the pipelines page (design 47 H2 H-A-467): `pipelines [branch]` the newest pipelines of a branch (main by
// default), `pipeline <pipeline> [mover]` one pipeline's mover rows or one mover's steps; with -follow again at each change.
// pipelines prints the pipelines page (design 47 H2 H-A-467, H-A-533): `pipelines [module]` the newest pipelines of every
// branch, of those carrying the module when named, `pipeline <pipeline> [mover]` one pipeline's mover rows or one mover's steps; with -follow again at each change.
func pipelines(socket string, args []string, next string, limit int, follow, asJSON bool, out, errOut io.Writer) int {
var branch, pipeline, mover string
var module, pipeline, mover string
switch {
case args[0] == "pipelines" && len(args) <= 2:
if len(args) == 2 {
branch = args[1]
module = args[1]
}
case args[0] == "pipeline" && (len(args) == 2 || len(args) == 3):
pipeline = args[1]
@@ -111,11 +110,11 @@ func pipelines(socket string, args []string, next string, limit int, follow, asJ
mover = args[2]
}
default:
fmt.Fprintln(errOut, "mesh-delivery-cli [-follow] [-limit <n>] pipelines [branch]; mesh-delivery-cli [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
fmt.Fprintln(errOut, "mesh-delivery-cli [-follow] [-limit <n>] pipelines [module]; mesh-delivery-cli [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
return 2
}
var failed error
err := view.AskPipelines(socket, branch, limit, pipeline, mover, next, follow, func(page view.PipelinesPage, show *seatShow) bool {
err := view.AskPipelines(socket, module, limit, pipeline, mover, next, follow, func(page view.PipelinesPage, show *seatShow) bool {
if follow {
fmt.Fprintf(out, "--- %s ---\n", time.Now().Format("15:04:05"))
}
@@ -148,8 +147,8 @@ func pipelines(socket string, args []string, next string, limit int, follow, asJ
return 0
}
// seatShow is the seat's answer of show, as the view hands it on.
type seatShow = seat.ShowAnswer
// seatShow is the view's answer of one pipeline: show's, with the pipeline's page by tier and stage naming no mover.
type seatShow = view.PipelineAnswer
// holds prints every hold: module, fingerprint, node, since, answer, words.
func holds(socket string, asJSON bool, out, errOut io.Writer) int {
@@ -306,18 +306,19 @@ func rawAsk(t *testing.T, a oc.Ask) json.RawMessage {
const testView = "acme-view"
// Design 47 H2 H-A-467: the terminal view's pipelines page: a branch's newest pipelines, and one pipeline's mover rows.
// Design 47 H2 H-A-467, H-A-531: the terminal view's pipelines page: a branch's newest pipelines, and one pipeline by tier and
// stage.
func TestThePipelinesCommands(t *testing.T) {
m := view.New(testView)
call := func(key string, body any) (json.RawMessage, error) {
switch key {
case view.PipelinesListVerb:
in := body.(pseat.ListInput)
if in.Branch != "next" {
if in.Branch != "" || (in.Module != "" && in.Module != "alpha") { // every branch's, of a module when named (H-A-533)
return json.Marshal(pseat.ListAnswer{})
}
rows := []pseat.PipelineRow{{Pipeline: "next.3", Source: 2, Revision: 3, Outcome: "passed", MoverCount: 1, Steps: map[string]int64{"passed": 4}},
{Pipeline: "next.2", Source: 2, Revision: 2, Outcome: "superseded", MoverCount: 1}}
rows := []pseat.PipelineRow{{Pipeline: "next.3", Branch: "next", Source: 2, Revision: 3, Outcome: "passed", MoverCount: 1, Steps: map[string]int64{"passed": 4}},
{Pipeline: "next.2", Branch: "next", Source: 2, Revision: 2, Outcome: "superseded", MoverCount: 1}}
return json.Marshal(pseat.ListAnswer{Rows: rows[:min(int(in.Limit), len(rows))]})
case view.PipelinesShowVerb:
return json.Marshal(pseat.ShowAnswer{Pipeline: pseat.Pipeline{Pipeline: "next.3", Outcome: "passed", Movers: []pseat.Mover{{Module: "alpha", Fingerprint: "src2:aa", Version: "0.2.1"}}},
@@ -343,10 +344,14 @@ func TestThePipelinesCommands(t *testing.T) {
args []string
want string
}{
{[]string{"pipelines", "next"}, "next.3 3 2 passed 1 4 0 0 0 0 0 0 0"},
{[]string{"pipelines", "next"}, "next.2"}, // the newest 20 by default
{[]string{"-limit", "1", "pipelines", "next"}, "next.3"},
{[]string{"pipeline", "next.3"}, "alpha src2:aa 0.2.1 passed"},
{[]string{"pipelines"}, "PIPELINES PIPELINE BRANCH REVISION"},
{[]string{"pipelines"}, "next.3 next 3 2 passed 1 4 0 0 0 0 0 0 0"},
{[]string{"pipelines"}, "next.2"}, // the newest 20 by default
{[]string{"pipelines", "alpha"}, "PIPELINES CARRYING alpha"},
{[]string{"pipelines", "alpha"}, "next.3 next"},
{[]string{"-limit", "1", "pipelines"}, "next.3"},
{[]string{"pipeline", "next.3"}, "TIER 1 MOVER OUTCOME BUILD LINT UNIT INTEGRATION VALIDATE COMPOSITION CODE REVIEW APPROVAL alpha passed - - - - - - - -"},
{[]string{"pipeline", "next.3"}, "PIPELINE next.3: passed; 0 of 1 movers run their build on every node they are placed on; 1 is placed on none"},
{[]string{"-json", "pipeline", "next.3"}, `"fingerprint": "src2:aa"`},
} {
var out, errOut bytes.Buffer
@@ -355,7 +360,11 @@ func TestThePipelinesCommands(t *testing.T) {
}
}
var out, errOut bytes.Buffer
if code := run([]string{"-limit", "1", "pipelines", "next"}, path, &out, &errOut); code != 0 || strings.Contains(out.String(), "next.2") {
if code := run([]string{"pipelines", "zeta"}, path, &out, &errOut); code != 0 || strings.Contains(out.String(), "next.3") {
t.Errorf("pipelines zeta = %d %q, want none: no pipeline carries zeta", code, out.String())
}
out.Reset()
if code := run([]string{"-limit", "1", "pipelines"}, path, &out, &errOut); code != 0 || strings.Contains(out.String(), "next.2") {
t.Errorf("-limit 1 = %d %q, want only the newest", code, out.String())
}
for _, args := range [][]string{{"pipeline"}, {"-limit", "0", "pipelines"}} {
@@ -896,7 +896,7 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
pipelines.set(pseat.PipelineRow{Pipeline: "release.9", Source: rev, Revision: 9, Outcome: "passed", MoverCount: 1},
pseat.PipelineRow{Pipeline: "release.8", Source: rev, Revision: 8, Outcome: "superseded", MoverCount: 1})
var seen [][]string
err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], catalogBranch, 0, "", "", "", true, func(page view.PipelinesPage, _ *pseat.ShowAnswer) bool {
err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], "", 0, "", "", "", true, func(page view.PipelinesPage, _ *view.PipelineAnswer) bool {
var keys []string
for _, r := range page.Rows {
keys = append(keys, r.Pipeline)
@@ -949,8 +949,8 @@ func pipelinesRunner(t *testing.T, nc *nats.Conn) *fakeList {
_ = json.Unmarshal(m.Data, &in)
f.mu.Lock()
a := pseat.ListAnswer{}
if in.Branch == catalogBranch && in.Limit == view.DefaultPipelinesLimit {
a.Rows = f.rows
if (in.Branch == catalogBranch || in.Branch == "") && in.Module == "" && in.Limit == view.DefaultPipelinesLimit {
a.Rows = f.rows // the one watched branch's, which are every branch's too (design 47 H2 H-A-533)
}
f.mu.Unlock()
raw, _ := json.Marshal(map[string]any{"result": a, "node": "n0"})
@@ -19,10 +19,9 @@ const (
PipelinesShowVerb = "seat:" + seat.Seat + "." + seat.VerbShow
)
// The pipelines page's defaults (design 47 H2 H-A-467 (1)): the branch main and the newest 20.
// The pipelines page's default (design 47 H2 H-A-467 (1)): the newest 20, of every branch (H-A-533).
const (
DefaultPipelinesBranch = "main"
DefaultPipelinesLimit = 20
DefaultPipelinesLimit = 20
// DefaultPipelinesHeard is the default of the setting pipelines-heard: how many pipelines' last changes the view keeps
// for its pages before it forgets them all (principle 11).
DefaultPipelinesHeard = 1024
@@ -41,9 +40,11 @@ func PipelineEventPatterns() []string {
return out
}
// PipelinesPage is one branch's list as the page shows it: the rows list answered, or why it could not be read.
// PipelinesPage is the list as the page shows it (design 47 H2 H-A-533): the newest pipelines of every branch together,
// each row naming its branch, or only those that carry Module when one is named; the rows list answered, or why it could not
// be read.
type PipelinesPage struct {
Branch string `json:"branch"`
Module string `json:"module,omitempty"`
Rows []seat.PipelineRow `json:"rows"`
Error string `json:"error,omitempty"`
}
@@ -53,21 +54,21 @@ type PipelinesPage struct {
// of the view's own: what it read is read again at each event.
type Pipelines struct {
call func(key string, body any) (json.RawMessage, error)
branches func() []string // the watched branches followed beside the default; nil for none
branches func() []string // the watched branches whose lists the deliveries' links read; nil for none
logf func(string, ...any)
dirty chan struct{}
mu sync.Mutex
lists map[string]PipelinesPage // by branch, the branches followed
all *PipelinesPage // every branch's newest, as last read; nil before the first reading
lists map[string]PipelinesPage // by branch, the watched branches, for the deliveries' links
subs map[chan string]struct{}
version uint64
heard map[string]uint64 // the version of the last change of each pipeline heard
most int // the pipelines heard kept before heard is forgotten whole: the setting pipelines-heard
}
// NewPipelines is a reader of the pipelines through call; branches, when given, names the watched branches whose list is
// followed beside the default branch's, for the deliveries' links (design 47 H2 H-A-467 (3)); heard is the setting
// pipelines-heard, its default below one.
// NewPipelines is a reader of the pipelines through call; branches, when given, names the watched branches whose lists are
// read for the deliveries' links (design 47 H2 H-A-467 (3)); heard is the setting pipelines-heard, its default below one.
func NewPipelines(call func(key string, body any) (json.RawMessage, error), branches func() []string, heard int, logf func(string, ...any)) *Pipelines {
if logf == nil {
logf = func(string, ...any) {}
@@ -79,23 +80,30 @@ func NewPipelines(call func(key string, body any) (json.RawMessage, error), bran
lists: map[string]PipelinesPage{}, subs: map[chan string]struct{}{}, heard: map[string]uint64{}, most: heard}
}
// List asks the seat's verb list for one branch's newest limit pipelines in its short form; a limit below one is the
// default's.
func (p *Pipelines) List(branch string, limit int) ([]seat.PipelineRow, error) {
// List asks the seat's verb list for the newest limit pipelines in its short form: of one branch when named, of every
// branch when not (H-A-533), and only those carrying module when named; a limit below one is the default's.
func (p *Pipelines) List(branch, module string, limit int) ([]seat.PipelineRow, error) {
if limit < 1 {
limit = DefaultPipelinesLimit
}
raw, err := p.call(PipelinesListVerb, seat.ListInput{Branch: branch, Limit: int64(limit)})
of := "every branch"
if branch != "" {
of = branch
}
if module != "" {
of += " carrying " + module
}
raw, err := p.call(PipelinesListVerb, seat.ListInput{Branch: branch, Module: module, Limit: int64(limit)})
if err != nil {
return nil, fmt.Errorf("%s of %s: %w", PipelinesListVerb, branch, err)
return nil, fmt.Errorf("%s of %s: %w", PipelinesListVerb, of, err)
}
answer, said, ok := buscalls.Unwrap(raw)
if !ok {
return nil, fmt.Errorf("%s of %s answered: %s", PipelinesListVerb, branch, said)
return nil, fmt.Errorf("%s of %s answered: %s", PipelinesListVerb, of, said)
}
var a seat.ListAnswer
if err := json.Unmarshal(answer, &a); err != nil {
return nil, fmt.Errorf("the answer of %s of %s is not a list: %w", PipelinesListVerb, branch, err)
return nil, fmt.Errorf("the answer of %s of %s is not a list: %w", PipelinesListVerb, of, err)
}
return a.Rows, nil
}
@@ -104,6 +112,11 @@ func (p *Pipelines) List(branch string, limit int) ([]seat.PipelineRow, error) {
// (design 47 H2 H-A-467 (2)); next is the cursor of a page show answered.
func (p *Pipelines) Show(pipeline, mover, next string) (seat.ShowAnswer, error) {
raw, err := p.call(PipelinesShowVerb, seat.ShowInput{Pipeline: pipeline, Mover: mover, Next: next})
return showAnswer(raw, err, pipeline)
}
// showAnswer reads an answer of show.
func showAnswer(raw json.RawMessage, err error, pipeline string) (seat.ShowAnswer, error) {
if err != nil {
return seat.ShowAnswer{}, fmt.Errorf("%s of %s: %w", PipelinesShowVerb, pipeline, err)
}
@@ -118,9 +131,9 @@ func (p *Pipelines) Show(pipeline, mover, next string) (seat.ShowAnswer, error)
return a, nil
}
// followed is the default branch and the watched branches, each once.
// followed is the watched branches, each once, whose lists the deliveries' links read.
func (p *Pipelines) followed() []string {
out := []string{DefaultPipelinesBranch}
var out []string
if p.branches != nil {
for _, b := range p.branches() {
if b != "" && !slices.Contains(out, b) {
@@ -131,29 +144,27 @@ func (p *Pipelines) followed() []string {
return out
}
// Page is one branch's newest limit pipelines (the default's below one): a followed branch's at the default limit as last
// read, any other branch or limit read now.
func (p *Pipelines) Page(branch string, limit int) PipelinesPage {
if branch = strings.TrimSpace(branch); branch == "" {
branch = DefaultPipelinesBranch
}
// Page is the newest limit pipelines of every branch (the default's below one), of those carrying module when named
// (design 47 H2 H-A-533): with no module at the default limit as last read, else read now.
func (p *Pipelines) Page(module string, limit int) PipelinesPage {
module = strings.TrimSpace(module)
if limit < 1 {
limit = DefaultPipelinesLimit
}
if limit == DefaultPipelinesLimit {
if module == "" && limit == DefaultPipelinesLimit {
p.mu.Lock()
page, ok := p.lists[branch]
all := p.all
p.mu.Unlock()
if ok {
return page
if all != nil {
return *all
}
}
return p.read(branch, limit)
return p.read("", module, limit)
}
func (p *Pipelines) read(branch string, limit int) PipelinesPage {
rows, err := p.List(branch, limit)
page := PipelinesPage{Branch: branch, Rows: rows}
func (p *Pipelines) read(branch, module string, limit int) PipelinesPage {
rows, err := p.List(branch, module, limit)
page := PipelinesPage{Module: module, Rows: rows}
if err != nil {
page.Error = err.Error()
}
@@ -163,23 +174,28 @@ func (p *Pipelines) read(branch string, limit int) PipelinesPage {
return page
}
// Refresh reads the list of every followed branch again and says the lists changed.
// Refresh reads the list of every branch, and of each watched branch for the deliveries' links, again and says the lists
// changed.
func (p *Pipelines) Refresh() {
all := p.read("", "", DefaultPipelinesLimit)
if all.Error != "" {
p.logf("the pipelines are not read (read again at the runner's next event): %s", all.Error)
}
lists := map[string]PipelinesPage{}
for _, b := range p.followed() {
page := p.read(b, DefaultPipelinesLimit)
page := p.read(b, "", DefaultPipelinesLimit)
if page.Error != "" {
p.logf("the pipelines of %s are not read (read again at the runner's next event): %s", b, page.Error)
}
lists[b] = page
}
p.mu.Lock()
p.lists = lists
p.all, p.lists = &all, lists
p.mu.Unlock()
p.notify("")
}
// Of is the pipeline of a delivery: of the branch's followed list, the newest whose source is the delivery's source
// Of is the pipeline of a delivery: of the branch's list, then of every branch's, the newest whose source is the delivery's source
// revision (design 47 H2 H-A-467 (3)); "" when none. A branch whose list is not read yet (a watched branch the reader
// learnt of after its last reading) has the lists read again, once.
func (p *Pipelines) Of(branch string, source uint64) string {
@@ -189,11 +205,21 @@ func (p *Pipelines) Of(branch string, source uint64) string {
if !ok {
p.owe()
}
if source == 0 {
return ""
}
for _, r := range page.Rows { // newest first, as list answers them
if source != 0 && r.Source == int64(source) {
if r.Source == int64(source) {
return r.Pipeline
}
}
if p.all != nil {
for _, r := range p.all.Rows { // every branch's newest, each naming its branch (H-A-533)
if r.Branch == branch && r.Source == int64(source) {
return r.Pipeline
}
}
}
return ""
}
@@ -211,6 +237,14 @@ func (p *Pipelines) Hear(data []byte) error {
return nil
}
// deliveryKey is what heard keeps the last change of the delivery under: a want, a have or an assignment the view heard,
// which every pipeline's page shows (design 47 H2 H-A-531). No pipeline's key holds a NUL.
const deliveryKey = "\x00delivery"
// Delivered tells every pipeline's page that the delivery changed: a want, a have or an assignment the view heard, on the
// events it already hears for "What each node runs" (design 47 H2 H-A-531), never a timer. The lists are not read again.
func (p *Pipelines) Delivered() { p.notify(deliveryKey) }
// owe has Run read the lists again.
func (p *Pipelines) owe() {
select {
@@ -266,7 +300,7 @@ func (p *Pipelines) Version() uint64 {
func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool {
ch := make(chan string, 1)
p.mu.Lock()
if p.heard[what] > since {
if p.changedSince(what, since) {
p.mu.Unlock()
return true
}
@@ -283,7 +317,7 @@ func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool
return false
case <-ch: // any change: a note dropped while one waited is read from heard, never lost
p.mu.Lock()
changed := p.heard[what] > since
changed := p.changedSince(what, since)
p.mu.Unlock()
if changed {
return true
@@ -291,3 +325,9 @@ func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool
}
}
}
// changedSince says whether what changed after since: a pipeline's page changes with the delivery too (design 47 H2
// H-A-531), the lists do not. The caller holds p.mu.
func (p *Pipelines) changedSince(what string, since uint64) bool {
return p.heard[what] > since || (what != "" && p.heard[deliveryKey] > since)
}
@@ -6,13 +6,18 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"net/http"
"net/http/httptest"
"slices"
"strings"
"sync"
"testing"
"time"
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
)
@@ -22,6 +27,7 @@ type fakeRunner struct {
mu sync.Mutex
rows map[string][]seat.PipelineRow // by branch
shows map[string]seat.ShowAnswer // by pipeline, or pipeline/mover
steps map[string][]seat.StepResult // by pipeline, every mover's steps, which show filtered by a step answers two a page
lists int
}
@@ -36,9 +42,40 @@ func (f *fakeRunner) call(key string, body any) (json.RawMessage, error) {
}
f.lists++
rows := f.rows[in.Branch]
if in.Branch == "" { // every branch's, each row naming its branch, newest first (design 47 H2 H-A-533)
rows = nil
for _, b := range slices.Sorted(maps.Keys(f.rows)) {
for _, r := range f.rows[b] {
carries := in.Module == ""
for _, mv := range f.shows[r.Pipeline].Pipeline.Movers {
carries = carries || mv.Module == in.Module
}
if r.Branch = b; carries {
rows = append(rows, r)
}
}
}
slices.SortStableFunc(rows, func(a, b seat.PipelineRow) int { return int(b.Revision - a.Revision) })
}
return json.Marshal(seat.ListAnswer{Rows: rows[:min(int(in.Limit), len(rows))]})
case PipelinesShowVerb:
in := body.(seat.ShowInput)
if in.Step != "" {
a := f.shows[in.Pipeline]
var held []seat.StepResult
for _, s := range f.steps[in.Pipeline] {
if s.Step == in.Step {
held = append(held, s)
}
}
from := 0
fmt.Sscan(in.Next, &from)
a.Pipeline.Steps = held[min(from, len(held)):min(from+2, len(held))]
if a.Next = ""; from+2 < len(held) {
a.Next = fmt.Sprint(from + 2)
}
return json.Marshal(a)
}
k := in.Pipeline
if in.Mover != "" {
k += "/" + in.Mover
@@ -58,6 +95,13 @@ func (f *fakeRunner) setRows(branch string, rows ...seat.PipelineRow) {
f.rows[branch] = rows
}
// The builds of the pipeline's movers, in the new form a want names.
var (
fpA = "src2:" + strings.Repeat("a", 64)
fpB = "src2:" + strings.Repeat("b", 64)
fpB0 = "src2:" + strings.Repeat("0", 64)
)
// changedWithin is p.Changed bounded, so a change never said fails the test instead of hanging it.
func changedWithin(ctx context.Context, p *Pipelines, what string, since uint64) bool {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
@@ -65,20 +109,26 @@ func changedWithin(ctx context.Context, p *Pipelines, what string, since uint64)
return p.Changed(ctx, what, since)
}
// Design 47 H2 H-A-467: the pipelines page reads the runner's list and show, refreshes on its events, never on a timer,
// and links each delivery to its pipeline by its source revision.
// Design 47 H2 H-A-467, H-A-531: the pipelines page reads the runner's list and show, refreshes on its events and on the wants'
// and haves', never on a timer, shows one pipeline by tier and stage with its nodes, and links each delivery to its pipeline.
func TestThePipelinesPage(t *testing.T) {
started, ended := t0, t0.Add(3*60e9)
taken := t0.Add(160e9) // a build node took the step 2m40s after its ask, and it ran 20s (design 47 H2 H-A-516)
runner := &fakeRunner{rows: map[string][]seat.PipelineRow{}, shows: map[string]seat.ShowAnswer{
"main.12": {Pipeline: seat.Pipeline{Pipeline: "main.12", Branch: "main", Source: 9, Revision: 12, Outcome: seat.PipelineOutcomeFailed,
Started: &started, Ended: &ended, Movers: []seat.Mover{{Module: "alpha", Fingerprint: "src2:aa", Version: "0.1.4"}, {Module: "beta", Fingerprint: "src2:bb"}}},
Started: &started, Ended: &ended, Movers: []seat.Mover{{Module: "alpha", Fingerprint: fpA, Version: "0.1.4", Tier: 1},
{Module: "beta", Fingerprint: fpB, Tier: 2}, {Module: "gamma", Fingerprint: fpNew, Tier: 2}, {Module: "delta", Fingerprint: fpOld}}},
Movers: []seat.MoverRow{{Module: "alpha", Outcome: seat.MoverRowOutcomePassed},
{Module: "beta", Outcome: seat.MoverRowOutcomeFailed, Failed: &seat.FailedStep{Step: "unit", Artifact: "beta:program", Outcome: "could not run", Why: "no build node"}}}},
{Module: "beta", Outcome: seat.MoverRowOutcomeFailed, Failed: &seat.FailedStep{Step: "unit", Artifact: "beta:program", Outcome: "could not run", Why: "no build node"}},
{Module: "gamma", Outcome: seat.MoverRowOutcomePassed}, {Module: "delta", Outcome: seat.MoverRowOutcomePassed}}},
"main.12/beta": {Pipeline: seat.Pipeline{Pipeline: "main.12", Branch: "main", Source: 9, Revision: 12, Outcome: seat.PipelineOutcomeFailed,
Steps: []seat.StepResult{{Module: "beta", Step: "unit", Artifact: "beta:program", Seat: "node-build-go", Node: "n1", Outcome: "could not run", AskedAt: &started, Started: &started, TakenAt: &taken, Ended: &ended, Why: "no build node"},
{Module: "beta", Step: "lint", Artifact: "beta:program", Seat: "node-build-go", Outcome: "could not run", AskedAt: &started, Ended: &ended}}}},
}}
}, steps: map[string][]seat.StepResult{"main.12": {
{Module: "alpha", Step: "build", Artifact: "alpha:program", Outcome: "passed"}, {Module: "alpha", Step: "build", Artifact: "alpha:image", Outcome: "carried"},
{Module: "alpha", Step: "build", Artifact: "alpha:tool", Outcome: "passed"}, {Module: "alpha", Step: "review", Outcome: "passed"},
{Module: "beta", Step: "unit", Artifact: "beta:program", Node: "n1", Outcome: "could not run", AskedAt: &started, TakenAt: &taken, Ended: &ended, Why: "no build node"},
{Module: "beta", Step: "unit", Artifact: "beta:tool", Outcome: "passed"}, {Module: "beta", Step: "approval", Outcome: "waiting", Why: "a person"}}}}
runner.setRows("main", seat.PipelineRow{Pipeline: "main.12", Source: 9, Revision: 12, Started: &started, Outcome: seat.PipelineOutcomeFailed, MoverCount: 2,
Steps: map[string]int64{"passed": 5, "failed": 1, "could not run": 1, "waiting for a build node": 2}})
runner.setRows(testBranch, seat.PipelineRow{Pipeline: "release.8", Source: 4, Revision: 8, Outcome: seat.PipelineOutcomePassed},
@@ -86,6 +136,15 @@ func TestThePipelinesPage(t *testing.T) {
p := NewPipelines(runner.call, func() []string { return []string{testBranch} }, 0, nil)
m := New(testView)
fill(m, sourceE(t, 4))
// alpha runs its build on both its nodes; beta is wanted on n1, applying on n2 and has no want on n3; gamma's build failed
// its health on n1 and the assigner holds it; delta is placed on no node (design 47 H2 H-A-531 and its addendum).
applying, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fpB0, Phase: nodeengineclient.PhaseApplying, Health: nodeengineclient.HealthWaits})
sick, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fpNew, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthFailed, Detail: "connection refused"})
delivery := []Entry{place(t, "n1", "alpha", "beta", "gamma"), place(t, "n2", "alpha", "beta", "gamma"), place(t, "n3", "beta"),
haveFP(t, "n1", "alpha", fpA, nodeengineclient.HealthOK), haveFP(t, "n2", "alpha", fpA, nodeengineclient.HealthOK),
wantE(t, "n1", "beta", meshwantsclient.Want{Fp: fpB}), wantE(t, "n2", "beta", meshwantsclient.Want{Fp: fpB}), haveE(t, "n2", "beta", applying, t0),
wantE(t, "n1", "gamma", meshwantsclient.Want{Fp: fpNew}), haveE(t, "n1", "gamma", sick, t0), heldE(t, "gamma", fpNew, "n1", "health failed on n1")}
fill(m, delivery...)
m.SetPipelines(p)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -113,13 +172,33 @@ func TestThePipelinesPage(t *testing.T) {
}{
{"the terminal view's list counts the steps per outcome", func() string {
return text(func(b *bytes.Buffer) { PipelinesTable(b, p.Page("", 0)) })
}, []string{"PIPELINES OF main", "PASSED FAILED COULD NOT RUN NOT ASKED WAITING WAITING FOR A BUILD NODE BYPASSED NOTHING TO RUN",
"main.12 12 9 2026-10-18", "failed 2 5 1 1 0 0 2 0 0"}},
}, []string{"PIPELINES PIPELINE BRANCH REVISION", "PASSED FAILED COULD NOT RUN NOT ASKED WAITING WAITING FOR A BUILD NODE BYPASSED NOTHING TO RUN",
"main.12 main 12 9 2026-10-18", "release.8 release 8 4", "failed 2 5 1 1 0 0 2 0 0"}},
{"the web list links each pipeline and reloads on the view's changes, never a timer", func() string { return web("/pipelines") }, []string{
`<a href="/pipelines/show?pipeline=main.12">main.12</a>`, `new EventSource("/pipelines/changes?since=`}},
{"a pipeline's page is its mover rows, each linking its steps", func() string { return web("/pipelines/show?pipeline=main.12") }, []string{
`<a href="/pipelines/show?mover=alpha&amp;pipeline=main.12">alpha</a></td><td>src2:aa</td><td>0.1.4</td><td>passed</td>`,
"<td>unit beta:program: could not run: no build node</td>", `changes?pipeline=main.12\u0026since=`}},
{"a pipeline's page is its header, then a block per tier, a row per mover with a cell per stage and per node", func() string {
return web("/pipelines/show?pipeline=main.12")
}, []string{
"failed; first failure: unit beta:program: could not run: no build node; 1 of 4 movers run their build on every node they are placed on; 1 is placed on none",
"<h2>TIER 1</h2>", "<th>MOVER</th><th>OUTCOME</th><th>BUILD</th><th>LINT</th><th>UNIT</th><th>INTEGRATION</th><th>VALIDATE</th><th>COMPOSITION</th><th>CODE REVIEW</th><th>APPROVAL</th><th>n1</th><th>n2</th><th>n3</th>",
`<a href="/pipelines/show?mover=alpha&amp;pipeline=main.12">alpha</a></td><td class="passed">passed</td><td class="passed" title="alpha:program: passed`,
`alpha:tool: passed">passed</td>`, `<td class="passed">running the pipeline&#39;s build</td><td class="passed">running the pipeline&#39;s build</td><td class="none"></td></tr>`,
`<td class="failed" title="beta:program: could not run, waited 2m40s, ran 20s on n1: no build node`, ">could not run 1/2</td>",
`<td class="waiting" title="approval: waiting: a person">waiting</td>`,
`<td class="wanted">wanted</td><td class="applying">applying</td><td class="not-run">no want written</td>`,
`<td class="held">held: connection refused</td><td class="held">held: health failed on n1</td>`,
"<h2>TIER 2</h2>", `changes?pipeline=main.12\u0026since=`}},
{"a stage's worst outcome follows the runner's step words, an unknown one counting as failed", func() string {
at := func(o ...string) string {
var ss []seat.StepResult
for _, x := range o {
ss = append(ss, seat.StepResult{Step: "unit", Outcome: x})
}
return stageCell(ss, t0).Text()
}
return strings.Join([]string{at("passed", "running", "waiting for a build node", "not asked", "running"), at("cancelled", "could not run"),
at("frobbed", "passed"), at("running", "running"), at("nothing to run"), at("failed", "passed", "carried"), at()}, "|")
}, []string{"not asked 1/5|could not run 1/2|frobbed 1/2|running|nothing to run|failed 1/3|"}},
{"a mover's page is its steps, each asked, taken and ended, how long it waited and how long it ran", func() string {
return web("/pipelines/show?pipeline=main.12&mover=beta")
}, []string{"<th>ASKED</th><th>TAKEN</th><th>ENDED</th><th>WAITED</th><th>RAN</th>",
@@ -130,7 +209,7 @@ func TestThePipelinesPage(t *testing.T) {
if err != nil {
return err.Error()
}
return text(func(b *bytes.Buffer) { PipelineTable(b, a, "beta") })
return text(func(b *bytes.Buffer) { PipelineTable(b, PipelineAnswer{ShowAnswer: a}, "beta") })
}, []string{"STEPS OF beta", "OUTCOME ASKED TAKEN ENDED WAITED RAN WHY", "could not run " + since(started) + " " + since(taken) + " " + since(ended) + " 2m40s 20s no build node"}},
{"a step still waiting counts its wait to now, one running its run", func() string {
now := t0.Add(400e9)
@@ -139,17 +218,38 @@ func TestThePipelinesPage(t *testing.T) {
w3, r3 := waitedRan(seat.StepResult{Ended: &ended}, now)
return fmt.Sprintf("waiting %s/%s; running %s/%s; never asked %q/%q", w1, r1, w2, r2, w3, r3)
}, []string{`waiting 6m40s/; running 2m40s/4m0s; never asked ""/""`}},
{"the terminal view's pipeline names each mover's fingerprint, version and failed step", func() string {
a, err := p.Show("main.12", "", "")
if err != nil {
{"the terminal view's pipeline is its header and a block per tier, as the page's", func() string {
path, sm := served(t)
fill(sm, delivery...)
sm.SetPipelines(p)
var got *PipelineAnswer
if err := AskPipelines(path, "", 0, "main.12", "", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { got = a; return true }); err != nil {
return err.Error()
}
return text(func(b *bytes.Buffer) { PipelineTable(b, a, "") })
}, []string{"PIPELINE main.12: failed, source 9, revision 12", "alpha src2:aa 0.1.4 passed", "beta src2:bb failed unit beta:program: could not run: no build node"}},
{"the web list asks the newest limit of a branch", func() string { return web("/pipelines?branch=" + testBranch + "&limit=1") }, []string{
"release.8", `name="limit" value="1"`}},
{"the web list is the newest 20 by default", func() string { return web("/pipelines?branch=" + testBranch) }, []string{
"release.8", "release.7", `name="limit" value="20"`}},
return text(func(b *bytes.Buffer) { PipelineTable(b, *got, "") })
}, []string{"PIPELINE main.12: failed; first failure: unit beta:program: could not run: no build node; 1 of 4 movers",
"TIER 1 MOVER OUTCOME BUILD LINT UNIT INTEGRATION VALIDATE COMPOSITION CODE REVIEW APPROVAL N1 N2 N3",
"alpha passed passed - - - - - passed - running the pipeline's build running the pipeline's build -",
"delta passed - - - - - - - - - - -", "TIER 2",
"beta failed - - could not run 1/2 - - - - waiting wanted applying no want written",
"gamma passed - - - - - - - - held: connection refused held: health failed on n1 -"}},
{"the web list asks the newest limit of every branch", func() string { return web("/pipelines?limit=1") }, []string{
"main.12", `name="limit" value="1"`}},
{"the web list is every branch's newest 20 by default, the branch a column", func() string { return web("/pipelines") }, []string{
"<h1>PIPELINES</h1>", `module <input name="module" value="">`, "<th>BRANCH</th>", "main.12</a></td><td>main</td>",
"release.8</a></td><td>release</td>", "release.7", `name="limit" value="20"`}},
{"the only filter is a module: the pipelines that carry it", func() string {
got := web("/pipelines?module=beta")
if strings.Contains(got, "release.8") {
return "release.8 does not carry beta: " + got
}
return got
}, []string{"<h1>PIPELINES CARRYING beta</h1>", "main.12</a></td><td>main</td>"}},
{"a delivery of a branch the view reads no list of links through every branch's list", func() string {
q := NewPipelines(runner.call, nil, 0, nil)
q.Refresh()
return q.Of(testBranch, 4) + " " + q.Of("main", 4)
}, []string{"release.8 "}},
{"a pipeline the runner does not hold says so", func() string { return web("/pipelines/show?pipeline=main.99") }, []string{"unreadable: ", "no pipeline main.99"}},
{"a delivery links to the newest pipeline of its source revision", func() string {
return text(func(b *bytes.Buffer) { Table(b, m.Snapshot()) }) + web("/")
@@ -165,8 +265,8 @@ func TestThePipelinesPage(t *testing.T) {
}
})
}
if got := web("/pipelines?branch=" + testBranch + "&limit=1"); strings.Contains(got, "release.7") {
t.Errorf("the newest 1 shows release.7: %s", got)
if got := web("/pipelines?limit=1"); strings.Contains(got, "release.8") {
t.Errorf("the newest 1 shows release.8: %s", got)
}
for _, l := range []string{"0", "x"} {
rec := httptest.NewRecorder()
@@ -224,12 +324,29 @@ func TestThePipelinesPage(t *testing.T) {
}
})
t.Run("a want or a have heard tells every pipeline's page, never the lists", func(t *testing.T) {
v := p.Version()
fill(m, haveFP(t, "n2", "gamma", fpNew, nodeengineclient.HealthOK))
if !changedWithin(ctx, p, "main.12", v) {
t.Fatal("the page of main.12 is not told of the have")
}
p.mu.Lock()
lists := p.changedSince("", v)
p.mu.Unlock()
if lists {
t.Error("a have tells the lists")
}
if got := web("/pipelines/show?pipeline=main.12"); !strings.Contains(got, `<td class="held">held: connection refused</td><td class="passed">running the pipeline&#39;s build</td>`) {
t.Errorf("the page does not show gamma running on n2: %s", got)
}
})
t.Run("the terminal view follows the list on the socket, again at each event", func(t *testing.T) {
path, sm := served(t)
sm.SetPipelines(p)
var seen []string
heard := false
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
seen = append(seen, page.Rows[0].Pipeline)
if !heard {
heard = true
@@ -244,14 +361,14 @@ func TestThePipelinesPage(t *testing.T) {
if err != nil || seen[len(seen)-1] != "main.14" {
t.Fatalf("followed %v, %v", seen, err)
}
var show *seat.ShowAnswer
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *seat.ShowAnswer) bool { show = a; return true }); err != nil {
var show *PipelineAnswer
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { show = a; return true }); err != nil {
t.Fatal(err)
}
if len(show.Pipeline.Steps) != 2 || show.Pipeline.Steps[0].Node != "n1" {
t.Fatalf("the mover's steps on the socket = %+v", show)
}
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *seat.ShowAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *PipelineAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
t.Fatalf("a pipeline the runner does not hold = %v", err)
}
})
@@ -293,7 +410,7 @@ func TestThePipelinesPage(t *testing.T) {
path, sm := served(t)
sm.SetPipelines(up)
var seen []PipelinesPage
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
seen = append(seen, page)
if len(seen) == 1 {
mu.Lock()
@@ -20,7 +20,7 @@ var PipelineCountOutcomes = []string{seat.StepResultOutcomePassed, seat.StepResu
seat.StepResultOutcomeBypassed, seat.StepResultOutcomeNothingToRun}
// PipelinesHead is the head of the list's rows.
var PipelinesHead = append([]string{"PIPELINE", "REVISION", "SOURCE", "STARTED", "OUTCOME", "MOVERS"}, upper(PipelineCountOutcomes)...)
var PipelinesHead = append([]string{"PIPELINE", "BRANCH", "REVISION", "SOURCE", "STARTED", "OUTCOME", "MOVERS"}, upper(PipelineCountOutcomes)...)
// MoversHead is the head of one pipeline's mover rows, StepsHead of one mover's steps (design 47 H2 H-A-467 (2)).
var (
@@ -77,7 +77,7 @@ func number(n int64) string {
// PipelineRowText is one list row's cells, in PipelinesHead's order.
func PipelineRowText(r seat.PipelineRow) []string {
out := []string{r.Pipeline, number(r.Revision), number(r.Source), timeOf(r.Started), r.Outcome, strconv.FormatInt(r.MoverCount, 10)}
out := []string{r.Pipeline, r.Branch, number(r.Revision), number(r.Source), timeOf(r.Started), r.Outcome, strconv.FormatInt(r.MoverCount, 10)}
for _, o := range PipelineCountOutcomes {
out = append(out, strconv.FormatInt(r.Steps[o], 10))
}
@@ -139,9 +139,14 @@ func table(w io.Writer, head []string, rows [][]string) {
tw.Flush()
}
// PipelinesTable prints one branch's newest pipelines, the terminal view's pipelines page.
// PipelinesTable prints the newest pipelines of every branch, of a module when named, the terminal view's pipelines page
// (design 47 H2 H-A-533).
func PipelinesTable(w io.Writer, p PipelinesPage) {
fmt.Fprintf(w, "PIPELINES OF %s\n", p.Branch)
if p.Module != "" {
fmt.Fprintf(w, "PIPELINES CARRYING %s\n", p.Module)
} else {
fmt.Fprintln(w, "PIPELINES")
}
if p.Error != "" {
fmt.Fprintf(w, "unreadable: %s\n", p.Error)
return
@@ -153,41 +158,109 @@ func PipelinesTable(w io.Writer, p PipelinesPage) {
table(w, PipelinesHead, rows)
}
// PipelineTable prints one pipeline as show answered it for mover: its mover rows, or that mover's steps.
func PipelineTable(w io.Writer, a seat.ShowAnswer, mover string) {
// PipelineAnswer is one pipeline as the socket answers it: show's answer, and naming no mover the pipeline's page by tier
// and stage with its nodes (design 47 H2 H-A-531).
type PipelineAnswer struct {
seat.ShowAnswer
View *PipelineView `json:"view,omitempty"`
}
// PipelineTable prints one pipeline for mover: naming none, its page by tier and stage with its nodes (design 47 H2
// H-A-531); naming one, that mover's steps.
func PipelineTable(w io.Writer, a PipelineAnswer, mover string) {
p := a.Pipeline
if mover == "" && a.View != nil {
ViewTable(w, *a.View)
return
}
fmt.Fprintf(w, "PIPELINE %s: %s, source %d, revision %d, started %s, ended %s\n", p.Pipeline, p.Outcome, p.Source, p.Revision, timeOf(p.Started), timeOf(p.Ended))
if p.Why != "" {
fmt.Fprintf(w, "why: %s\n", p.Why)
}
if mover == "" {
table(w, MoversHead, MoverRowsText(a))
table(w, MoversHead, MoverRowsText(a.ShowAnswer))
} else {
fmt.Fprintf(w, "STEPS OF %s\n", mover)
table(w, StepsHead, StepsText(a))
table(w, StepsHead, StepsText(a.ShowAnswer))
}
if a.Next != "" {
fmt.Fprintf(w, "more: -next %s\n", a.Next)
}
}
const pipelinesStyle = `<style>body{font:14px sans-serif;margin:1em}table{border-collapse:collapse}td,th{padding:2px 10px;text-align:left}</style>`
// ViewTable prints one pipeline's page: its header, then one block per tier, in tier order (design 47 H2 H-A-531).
func ViewTable(w io.Writer, v PipelineView) {
fmt.Fprintf(w, "PIPELINE %s: %s\n", v.Pipeline, v.Header())
for _, u := range v.Unread {
fmt.Fprintf(w, "unreadable: %s\n", u)
}
for _, t := range v.Tiers {
fmt.Fprintf(w, "TIER %d\n", t.Tier)
var rows [][]string
for _, r := range t.Movers {
cells := r.Cells()
for i, c := range cells {
if c == "" {
cells[i] = "-"
}
}
rows = append(rows, cells)
}
table(w, upper(v.TierHead()), rows)
}
}
const pipelinesStyle = `<style>body{font:14px sans-serif;margin:1em}table{border-collapse:collapse}td,th{padding:2px 10px;text-align:left}` +
`td[title]{cursor:help}.passed{color:#176f2c}.failed,.held{color:#b3261e;font-weight:bold}.waiting,.running,.applying,.wanted{color:#8a5a00}` +
`.not-run,.none{color:#777}</style>`
// changesScript reloads the page when the view says its part changed, on the runner's events (design 47 H2 H-A-467): never
// on a timer.
const changesScript = `<script>new EventSource({{.Changes}}).onmessage=function(){location.reload()}</script>`
var pipelinesPage = template.Must(template.New("pl").Parse(`<!doctype html><html><head><meta charset="utf-8">
<title>Pipelines of {{.Branch}}</title>` + pipelinesStyle + `</head>
<body><p><a href="/">What each node runs</a></p><h1>PIPELINES OF {{.Branch}}</h1>
<form method="get" action="/pipelines">branch <input name="branch" value="{{.Branch}}"> newest <input name="limit" value="{{.Limit}}" size="4"> <button>show</button></form>
<title>Pipelines{{with .Module}} carrying {{.}}{{end}}</title>` + pipelinesStyle + `</head>
<body><p><a href="/">What each node runs</a></p><h1>PIPELINES{{with .Module}} CARRYING {{.}}{{end}}</h1>
<form method="get" action="/pipelines">module <input name="module" value="{{.Module}}"> newest <input name="limit" value="{{.Limit}}" size="4"> <button>show</button></form>
{{if .Error}}<p>unreadable: {{.Error}}</p>{{else}}<table><tr>{{range .Head}}<th>{{.}}</th>{{end}}</tr>
{{range .Rows}}<tr><td><a href="{{.Link}}">{{index .Cells 0}}</a></td>{{range slice .Cells 1}}<td>{{.}}</td>{{end}}</tr>{{end}}</table>{{end}}
` + changesScript + `</body></html>`))
// pipelineViewPage is one pipeline's page (design 47 H2 H-A-531): its header, then a block per tier, a row per mover, a
// cell per stage (each artifact's waited, ran and why on hover) and a cell per node its module is placed on.
var pipelineViewPage = template.Must(template.New("pv").Funcs(template.FuncMap{"word": cellWord, "moverLink": PipelineLink}).Parse(`<!doctype html><html><head><meta charset="utf-8">
<title>Pipeline {{.Pipeline}}</title>` + pipelinesStyle + `</head>
<body><p><a href="/">What each node runs</a> · <a href="/pipelines">Pipelines</a></p>
<h1>PIPELINE {{.Pipeline}}</h1>
{{if .Error}}<p>unreadable: {{.Error}}</p>{{else}}{{with .View}}<p class="{{word .Outcome}}">{{.Header}}</p>
{{range .Unread}}<p>unreadable: {{.}}</p>{{end}}{{$v := .}}{{range .Tiers}}<h2>TIER {{.Tier}}</h2>
<table><tr>{{range $v.TierHead}}<th>{{.}}</th>{{end}}</tr>
{{range .Movers}}<tr><td><a href="{{moverLink $v.Pipeline .Module}}">{{.Module}}</a></td><td class="{{word .Outcome}}">{{.Outcome}}</td>{{range .Stages}}<td class="{{word .Outcome}}"{{with .Hover}} title="{{.}}"{{end}}>{{.Text}}</td>{{end}}{{range .Nodes}}<td class="{{if .Placed}}{{word .State}}{{else}}none{{end}}">{{.Text}}</td>{{end}}</tr>
{{end}}</table>{{end}}{{end}}{{end}}
` + changesScript + `</body></html>`))
// cellWord is a cell's class: the runner's step word of an outcome (H-A-531 addendum (2)), or a node's state's.
func cellWord(s string) string {
switch s {
case "":
return "none"
case NodeRuns, seat.MoverRowOutcomePassed:
return "passed"
case NodeHeld:
return "held"
case NodeApplies:
return "applying"
case NodeWanted:
return "wanted"
case NodeNoWant:
return "not-run"
}
return [...]string{"passed", "running", "waiting", "not-run", "failed"}[stepRank(s)]
}
var pipelinePage = template.Must(template.New("p1").Parse(`<!doctype html><html><head><meta charset="utf-8">
<title>Pipeline {{.Pipeline}}</title>` + pipelinesStyle + `</head>
<body><p><a href="/">What each node runs</a> · <a href="{{.Back}}">Pipelines of {{.Branch}}</a>{{if .Mover}} · <a href="{{.Up}}">Pipeline {{.Pipeline}}</a>{{end}}</p>
<body><p><a href="/">What each node runs</a> · <a href="/pipelines">Pipelines</a>{{if .Mover}} · <a href="{{.Up}}">Pipeline {{.Pipeline}}</a>{{end}}</p>
<h1>PIPELINE {{.Pipeline}}{{if .Mover}}: {{.Mover}}{{end}}</h1>
{{if .Error}}<p>unreadable: {{.Error}}</p>{{else}}<p>{{.Line}}</p>{{if .Why}}<p>why: {{.Why}}</p>{{end}}
<table><tr>{{range .Head}}<th>{{.}}</th>{{end}}</tr>
@@ -238,12 +311,25 @@ func webPipelines(m *Model, w http.ResponseWriter, r *http.Request) {
v := p.Version()
a, err := p.Show(key, mover, q.Get("next"))
data := map[string]any{"Pipeline": key, "Mover": mover, "Changes": changesLink(key, v), "Up": PipelineLink(key, "")}
if mover == "" && q.Get("next") == "" {
if err == nil {
pv, verr := m.PipelineView(p, a)
data["View"], err = pv, verr
}
if err != nil {
data["Error"] = err.Error()
} else {
data["Branch"] = a.Pipeline.Branch
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pipelineViewPage.Execute(w, data)
return
}
if err != nil {
data["Error"] = err.Error()
} else {
pl := a.Pipeline
data["Branch"] = pl.Branch
data["Back"] = "/pipelines?" + url.Values{"branch": {pl.Branch}}.Encode()
data["Line"] = fmt.Sprintf("%s, source %d, revision %d, started %s, ended %s", pl.Outcome, pl.Source, pl.Revision, timeOf(pl.Started), timeOf(pl.Ended))
data["Why"] = pl.Why
var rows []linkedRow
@@ -280,13 +366,13 @@ func webPipelines(m *Model, w http.ResponseWriter, r *http.Request) {
limit = n
}
v := p.Version()
page := p.Page(q.Get("branch"), limit)
page := p.Page(q.Get("module"), limit)
var rows []linkedRow
for _, row := range page.Rows {
rows = append(rows, linkedRow{Cells: PipelineRowText(row), Link: PipelineLink(row.Pipeline, "")})
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pipelinesPage.Execute(w, map[string]any{"Branch": page.Branch, "Error": page.Error, "Head": PipelinesHead, "Rows": rows, "Limit": limit, "Changes": changesLink("", v)})
pipelinesPage.Execute(w, map[string]any{"Module": page.Module, "Error": page.Error, "Head": PipelinesHead, "Rows": rows, "Limit": limit, "Changes": changesLink("", v)})
}
}
@@ -0,0 +1,361 @@
package view
import (
"fmt"
"maps"
"slices"
"strings"
"time"
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
)
// One pipeline as its page shows it (design 47 H2 H-A-531 and its addendum): a header with its outcome, its first failure's
// why and how many of its movers run on every node they are placed on; then one block per tier, in tier order, one row per
// mover, a cell per stage and a cell per node the mover's module is placed on. The stages are read through the runner's verb
// show, the nodes from what the view already reads for "What each node runs" (the seat's assignments, the wants and the
// haves); nothing is kept.
// Stage is one stage a mover passes, by its name on the page and the step kind the runner names it by.
type Stage struct {
Name string
Step string
}
// Stages are the stages in the order a mover passes them (design 47 H2 H-A-531).
var Stages = []Stage{{"build", seat.StepResultStepBuild}, {"lint", seat.StepResultStepLint}, {"unit", seat.StepResultStepUnit},
{"integration", seat.StepResultStepIntegration}, {"validate", seat.StepResultStepValidate},
{"composition", seat.StepResultStepComposition}, {"code review", seat.StepResultStepReview}, {"approval", seat.StepResultStepApproval}}
// The states of a mover's module on a node it is placed on (design 47 H2 H-A-531).
const (
NodeNoWant = "no want written"
NodeWanted = "wanted"
NodeApplies = "applying"
NodeRuns = "running the pipeline's build"
NodeHeld = "held"
)
// PipelineView is one pipeline's page: its header, its tiers and the nodes its movers' modules are placed on, by name.
type PipelineView struct {
Pipeline string `json:"pipeline"`
Branch string `json:"branch"`
Outcome string `json:"outcome"`
Failed *seat.FailedStep `json:"failed,omitempty"`
Why string `json:"why,omitempty"`
Movers int `json:"movers"`
// Running is how many movers run the pipeline's build on every node they are placed on, Unplaced how many are placed on
// none: those never count as running (H-A-531 addendum (4)).
Running int `json:"running"`
Unplaced int `json:"unplaced"`
Nodes []string `json:"nodes"`
Tiers []PipelineTier `json:"tiers"`
// Unread says each stage show could not read: its cells are then empty, never shown passed.
Unread []string `json:"unread,omitempty"`
}
// PipelineTier is one tier of the pipeline's delivery order, its movers by module.
type PipelineTier struct {
Tier int64 `json:"tier"`
Movers []MoverStage `json:"movers"`
}
// MoverStage is one mover's row: its stages' cells in Stages' order and its cells on the nodes in the view's Nodes' order.
type MoverStage struct {
Module string `json:"module"`
Fingerprint string `json:"fingerprint"`
Version string `json:"version,omitempty"`
Outcome string `json:"outcome"`
Stages []StageCell `json:"stages"`
Nodes []NodeCell `json:"nodes"`
}
// StageCell is one stage of one mover: the worst outcome over its artifacts, how many are in its group (failed, not run,
// waiting, running, passed) of how many, and each
// artifact's waited, ran and why, shown on hover.
type StageCell struct {
Outcome string `json:"outcome,omitempty"`
Count int `json:"count,omitempty"`
Of int `json:"of,omitempty"`
Steps []string `json:"steps,omitempty"`
}
// Text is the cell's outcome, with how many artifacts are in its group where fewer than all are (H-A-531 addendum (3), as read
// in hq d7e7d204): passed, carried and passed read "passed"; failed, passed and passed "failed 1/3".
func (c StageCell) Text() string {
if c.Count < c.Of {
return fmt.Sprintf("%s %d/%d", c.Outcome, c.Count, c.Of)
}
return c.Outcome
}
// Hover is each artifact's line, one per line.
func (c StageCell) Hover() string { return strings.Join(c.Steps, "\n") }
// NodeCell is the mover's module on one node: empty when it is not placed there.
type NodeCell struct {
Placed bool `json:"placed,omitempty"`
State string `json:"state,omitempty"`
Why string `json:"why,omitempty"`
}
// Text is the cell's state, with its why.
func (c NodeCell) Text() string {
if c.Why != "" {
return c.State + ": " + c.Why
}
return c.State
}
// stepRank is how bad a step's outcome is, by the runner's own step words (H-A-531 addendum (2)): failed, then not run, then
// waiting, then running, then passed; an outcome it does not know counts as failed.
func stepRank(outcome string) int {
switch outcome {
case seat.StepResultOutcomePassed, seat.StepResultOutcomeCarried, seat.StepResultOutcomeAccepted,
seat.StepResultOutcomeBypassed, seat.StepResultOutcomeNothingToRun:
return 0
case seat.StepResultOutcomeRunning:
return 1
case seat.StepResultOutcomeWaiting, seat.StepResultOutcomeWaitingForABuildNode:
return 2
case seat.StepResultOutcomeNotAsked, seat.StepResultOutcomeDeclined, seat.StepResultOutcomeSuperseded, seat.StepResultOutcomeCancelled:
return 3
}
return 4
}
// stageCell is the cell of one mover's steps of one stage.
func stageCell(steps []seat.StepResult, now time.Time) StageCell {
var c StageCell
worst := -1
for _, s := range steps {
c.Of++
switch r := stepRank(s.Outcome); {
case r > worst:
worst, c.Outcome, c.Count = r, s.Outcome, 1
case r == worst:
c.Count++
}
waited, ran := waitedRan(s, now)
line := s.Step
if s.Artifact != "" {
line = s.Artifact
}
line += ": " + s.Outcome
if waited != "" {
line += ", waited " + waited
}
if ran != "" {
line += ", ran " + ran
}
if s.Node != "" {
line += " on " + s.Node
}
if s.Why != "" {
line += ": " + s.Why
}
c.Steps = append(c.Steps, line)
}
return c
}
// stageSteps reads every step of one stage through show, page by page.
func (p *Pipelines) stageSteps(pipeline, step string) ([]seat.StepResult, error) {
var out []seat.StepResult
next := ""
for {
raw, err := p.call(PipelinesShowVerb, seat.ShowInput{Pipeline: pipeline, Step: step, Next: next})
a, err := showAnswer(raw, err, pipeline)
if err != nil {
return nil, err
}
out = append(out, a.Pipeline.Steps...)
if a.Next == "" || a.Next == next {
return out, nil
}
next = a.Next
}
}
// moverRows reads every mover's row through show, page by page, starting from the answer of the first page.
func (p *Pipelines) moverRows(a seat.ShowAnswer) ([]seat.MoverRow, error) {
rows := slices.Clone(a.Movers)
next := a.Next
for next != "" {
b, err := p.Show(a.Pipeline.Pipeline, "", next)
if err != nil {
return nil, err
}
rows = append(rows, b.Movers...)
if b.Next == next {
break
}
next = b.Next
}
return rows, nil
}
// nodeCell is module's state on node for the pipeline's build fp, from the wants, the haves and the holds the view reads.
// The caller holds m.mu.
func (m *Model) nodeCell(node, module, fp string) NodeCell {
c := NodeCell{Placed: true, State: NodeNoWant}
hk, err := nodeengineclient.HaveKey(node, module)
if err != nil {
return c
}
h, has := m.haves[hk]
has = has && h.err == ""
w, wanted := m.wants[hk]
wanted = wanted && w.err == "" && !w.value.Removed && w.value.Fp == fp
ours := has && h.have.Fp == fp
switch {
case ours && (h.have.Phase == nodeengineclient.PhaseFailed || h.have.Health == nodeengineclient.HealthFailed):
// A build that failed, or whose health failed, is held, never running (H-A-531 addendum (1)).
c.State, c.Why = NodeHeld, h.have.Detail
if c.Why == "" {
c.Why = "health " + string(h.have.Health) + ", phase " + string(h.have.Phase)
}
case ours && h.have.Phase == nodeengineclient.PhaseRunning:
c.State = NodeRuns
case has && (wanted || ours) && (h.have.Phase == nodeengineclient.PhaseHeld || h.have.Phase == nodeengineclient.PhaseWaitingYes):
c.State, c.Why = NodeHeld, h.have.Detail
if h.have.Wait != nil && h.have.Wait.Words != "" {
c.Why = h.have.Wait.Words
}
case ours:
c.State = NodeApplies
case wanted && has && (h.have.Phase == nodeengineclient.PhaseApplying || h.have.Phase == nodeengineclient.PhaseBackingUp ||
h.have.Phase == nodeengineclient.PhaseChecking):
c.State = NodeApplies
case wanted:
c.State = NodeWanted
default:
if key, err := meshwantsclient.HeldKey(module, fp); err == nil {
if held, ok := m.holds[key]; ok && held.err == "" {
c.State, c.Why = NodeHeld, held.value.Words
}
}
}
return c
}
// PipelineView is one pipeline's page from show's answer naming no mover (its movers' rows): its stages read through show
// per stage, its nodes from the view's own reading of the assignments, the wants and the haves (design 47 H2 H-A-531).
func (m *Model) PipelineView(p *Pipelines, a seat.ShowAnswer) (PipelineView, error) {
rows, err := p.moverRows(a)
if err != nil {
return PipelineView{}, err
}
pl := a.Pipeline
v := PipelineView{Pipeline: pl.Pipeline, Branch: pl.Branch, Outcome: pl.Outcome, Why: pl.Why, Movers: len(pl.Movers), Nodes: []string{}, Tiers: []PipelineTier{}}
outcome := map[string]string{}
for _, r := range rows {
outcome[r.Module] = r.Outcome
if v.Failed == nil && r.Failed != nil { // the first failure, in the runner's movers' order
v.Failed = r.Failed
}
}
steps := map[string]map[string][]seat.StepResult{} // by stage step, then module
for _, s := range Stages {
got, err := p.stageSteps(pl.Pipeline, s.Step)
if err != nil {
v.Unread = append(v.Unread, s.Name+": "+err.Error())
continue
}
steps[s.Step] = map[string][]seat.StepResult{}
for _, r := range got {
steps[s.Step][r.Module] = append(steps[s.Step][r.Module], r)
}
}
m.mu.Lock()
defer m.mu.Unlock()
byNode := m.placed.ByNode()
placedOn := map[string][]string{}
for node, modules := range byNode {
for _, mod := range modules {
placedOn[mod] = append(placedOn[mod], node)
}
}
nodes := map[string]bool{}
for _, mv := range pl.Movers {
for _, n := range placedOn[mv.Module] {
nodes[n] = true
}
}
v.Nodes = slices.Sorted(maps.Keys(nodes))
now := time.Now()
tiers := map[int64][]MoverStage{}
for _, mv := range pl.Movers {
row := MoverStage{Module: mv.Module, Fingerprint: mv.Fingerprint, Version: mv.Version, Outcome: outcome[mv.Module]}
for _, s := range Stages {
row.Stages = append(row.Stages, stageCell(steps[s.Step][mv.Module], now))
}
runs := len(placedOn[mv.Module]) > 0
for _, n := range v.Nodes {
if !slices.Contains(placedOn[mv.Module], n) {
row.Nodes = append(row.Nodes, NodeCell{})
continue
}
c := m.nodeCell(n, mv.Module, mv.Fingerprint)
runs = runs && c.State == NodeRuns
row.Nodes = append(row.Nodes, c)
}
switch {
case len(placedOn[mv.Module]) == 0:
v.Unplaced++
case runs:
v.Running++
}
tier := max(mv.Tier, 1)
tiers[tier] = append(tiers[tier], row)
}
for _, t := range slices.Sorted(maps.Keys(tiers)) {
ms := tiers[t]
slices.SortFunc(ms, func(a, b MoverStage) int { return strings.Compare(a.Module, b.Module) })
v.Tiers = append(v.Tiers, PipelineTier{Tier: t, Movers: ms})
}
return v, nil
}
// Header is the page's header line: the outcome, the first failure's why, and how many movers run on every node they are
// placed on, those placed on none said apart (H-A-531 addendum (4)).
func (v PipelineView) Header() string {
s := v.Outcome
switch {
case v.Failed != nil:
s += "; first failure: " + failedText(v.Failed)
case v.Why != "":
s += "; why: " + v.Why
}
s += fmt.Sprintf("; %d of %d movers run their build on every node they are placed on", v.Running, v.Movers)
switch {
case v.Unplaced == 1:
s += "; 1 is placed on none"
case v.Unplaced > 1:
s += fmt.Sprintf("; %d are placed on none", v.Unplaced)
}
return s
}
// TierHead is a tier block's head: the mover, its outcome, a column per stage, a column per node.
func (v PipelineView) TierHead() []string {
out := []string{"MOVER", "OUTCOME"}
for _, s := range Stages {
out = append(out, strings.ToUpper(s.Name))
}
return append(out, v.Nodes...)
}
// Cells is a mover row's cells in TierHead's order.
func (r MoverStage) Cells() []string {
out := []string{r.Module, r.Outcome}
for _, c := range r.Stages {
out = append(out, c.Text())
}
for _, c := range r.Nodes {
out = append(out, c.Text())
}
return out
}
@@ -15,8 +15,6 @@ import (
"strings"
"text/tabwriter"
"time"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
)
// ListenSocket listens on the unix socket at path, in a directory of mode 0755, with mode 0666 on the socket: the
@@ -50,9 +48,9 @@ type ask struct {
Words string `json:"words,omitempty"`
Module string `json:"module,omitempty"`
FP string `json:"fp,omitempty"`
// The pipelines page's asks (design 47 H2 H-A-467): pipelines of a branch, or one pipeline, of a mover when named; follow
// The pipelines page's asks (design 47 H2 H-A-467, H-A-533): pipelines of every branch, of a module when named, or one
// pipeline, of a mover when named; follow
// keeps the connection and answers again at each change the runner's events say.
Branch string `json:"branch,omitempty"`
Limit int `json:"limit,omitempty"` // the newest this many of the branch, the default's when left out
Pipeline string `json:"pipeline,omitempty"`
Mover string `json:"mover,omitempty"`
@@ -572,11 +570,20 @@ func answerPipelines(c net.Conn, m *Model, a ask) {
v := p.Version()
var err error
if a.Ask == "pipelines" {
err = enc.Encode(p.Page(a.Branch, a.Limit))
err = enc.Encode(p.Page(a.Module, a.Limit))
} else if sa, serr := p.Show(a.Pipeline, a.Mover, a.Next); serr != nil {
err = enc.Encode(pipelinesRefusal{Refused: serr.Error()})
} else {
err = enc.Encode(sa)
pa := PipelineAnswer{ShowAnswer: sa}
if a.Mover == "" && a.Next == "" { // the pipeline's page by tier and stage (design 47 H2 H-A-531)
pv, verr := m.PipelineView(p, sa)
if verr != nil {
enc.Encode(pipelinesRefusal{Refused: verr.Error()})
return
}
pa.View = &pv
}
err = enc.Encode(pa)
}
if err != nil || !a.Follow || !p.Changed(ctx, what, v) {
return
@@ -591,16 +598,17 @@ type pipelinesRefusal struct {
Refused string `json:"refused"`
}
// AskPipelines asks the socket at path for one branch's newest limit pipelines (the default's below one), or with pipeline
// AskPipelines asks the socket at path for the newest limit pipelines of every branch (the default's below one), of those
// carrying module when named (design 47 H2 H-A-533), or with pipeline
// set for that pipeline (of mover when named); with follow, each answers again at each change, handed to each until it
// answers false or the view leaves.
func AskPipelines(path, branch string, limit int, pipeline, mover, next string, follow bool, each func(PipelinesPage, *seat.ShowAnswer) bool) error {
func AskPipelines(path, module string, limit int, pipeline, mover, next string, follow bool, each func(PipelinesPage, *PipelineAnswer) bool) error {
c, err := net.DialTimeout("unix", path, 5*time.Second)
if err != nil {
return fmt.Errorf("cannot reach the view at %s: %w", path, err)
}
defer c.Close()
a := ask{Ask: "pipelines", Branch: branch, Limit: limit, Follow: follow}
a := ask{Ask: "pipelines", Module: module, Limit: limit, Follow: follow}
if pipeline != "" {
a = ask{Ask: "pipeline", Pipeline: pipeline, Mover: mover, Next: next, Follow: follow}
}
@@ -625,9 +633,9 @@ func AskPipelines(path, branch string, limit int, pipeline, mover, next string,
return errors.New(refused.Refused)
}
var page PipelinesPage
var show *seat.ShowAnswer
var show *PipelineAnswer
if pipeline != "" {
show = &seat.ShowAnswer{}
show = &PipelineAnswer{}
if err := json.Unmarshal(raw, show); err != nil {
return fmt.Errorf("the view's answer is not a pipeline: %w", err)
}
@@ -392,6 +392,7 @@ func (m *Model) Apply(e Entry) {
}
writes, reached := m.reachNow()
say, put := m.deliveredEvent, m.reachPut
pipes := m.pipelines
sayMotion := m.motionEvent
left, w := m.left, m.writer
m.left = nil
@@ -404,6 +405,9 @@ func (m *Model) Apply(e Entry) {
}
m.sendReach(put, say, writes, reached)
m.sayMotion(sayMotion, motion)
if pipes != nil && !e.History && (e.Bucket == WantsBucket || e.Bucket == HaveBucket || e.Bucket == AssignmentsBucket) {
pipes.Delivered() // a pipeline's page shows each mover's nodes (design 47 H2 H-A-531)
}
}
// deleteAnswers deletes the view's answers to the asks that left asks, after the model's lock is released; one not deleted is