P5 hand-verbs-reopen: start by hand follows one rule per module, place-unfinished takes key or all and answers placed and failed, and a pipeline reopened for a group is judged over it

start with module or modules adds to the head's pipeline that waits or runs (mover-added with the caller), starts a head with none, or reopens an ended one for a module whose step failed; startAgain, the .again.<n> and .unfinished starts go. place-unfinished puts a closed group in the head's pipeline or reopens the pipeline it left, one hand act per call.

Builds: design 47 H2 H-A-571, H-A-607 (3), H-A-609 (1), H-A-623, H-A-643, H-A-644, H-A-725
This commit is contained in:
2026-11-25 18:19:08 +01:00
parent 43d83c3a30
commit 9ac80923da
11 changed files with 563 additions and 297 deletions
@@ -37,7 +37,7 @@ func UnfinishedTools(st UnfinishedState, acts views.HandActs) []stdio.Tool {
str := map[string]any{"type": "string"}
return []stdio.Tool{
{Name: Prefix + "_unfinished",
Description: "The movers a pipeline's end left unfinished (design 47 H2 §786): each key <branch>.<module> with its fingerprint, the catalog revision and the pipeline it was left in, and that pipeline's outcome. Each is put in the pipeline of its branch's next catalog revision; runner_unfinished_place puts one in a pipeline of its own now, runner_unfinished_drop drops one.",
Description: "The movers a pipeline's end left unfinished (design 47 H2 §786): each key <branch>.<module> with its fingerprint, the catalog revision and the pipeline it was left in, and that pipeline's outcome. Each is put in the pipeline of its branch's next catalog revision; runner_unfinished_place puts the closed group of one key, or of every key with all, in a pipeline now, runner_unfinished_drop drops one.",
Input: map[string]any{"type": "object", "properties": map[string]any{}},
Run: func(map[string]any) (any, error) { return unfinishedOf(st) }},
{Name: Prefix + "_unfinished_drop",
@@ -19,7 +19,7 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.
}
return []stdio.Tool{
verbTool[seat.StartInput](ask, "start", seat.VerbStart,
"Start by hand the delivering pipeline of the head of a watched branch for a module, by the seat verb start: the branch, the module and why. A head whose pipeline is written already is refused by the verb, naming it. With modules instead of module, the named modules whose newest entry has no passed pipeline (a failed, cut or superseded one) are started again at the head, keyed <branch>.<revision>.again.<n>; a module whose newest entry passed is refused by name (design 47 H2 H-A-479).",
"Start by hand, by the seat verb start, the module or the modules at the head of a watched branch: the branch, exactly one of module or modules, and why. Each module follows one rule: a head with no pipeline is started with them; the head's pipeline that waits or runs takes the ones it does not move as movers, said by mover-added with the caller; once it ended, a module whose own step failed reopens it with its closed group, as runner_rerun does. No other pipeline is keyed (design 47 H2 H-A-571, H-A-643).",
obj([]string{"branch", "why"}, map[string]any{"branch": str, "module": str, "modules": map[string]any{"type": "array", "items": str}, "why": str}),
func(in seat.StartInput) string {
if in.Branch == "" || (in.Module == "") == (len(in.Modules) == 0) {
@@ -64,11 +64,11 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.
return whyOf(in.Why)
}),
verbTool[seat.PlaceUnfinishedInput](ask, "unfinished_place", seat.VerbPlaceUnfinished,
"Put a mover kept in the state unfinished in a pipeline of its own at once, by the seat verb place-unfinished (design 47 H2 §786): the entry's key <branch>.<module> (runner_unfinished lists them) and why; written in the hand-act log. The answer names the pipeline, keyed <branch>.<revision>.unfinished.<module>.",
obj([]string{"key", "why"}, map[string]any{"key": str, "why": str}),
"Put the closed group of a mover kept in the state unfinished in a pipeline at once, by the seat verb place-unfinished (design 47 H2 H-A-607 (3), H-A-644, H-A-725): exactly one of key (<branch>.<module>; runner_unfinished lists them) or all (every key whose carrier neither waits nor runs), and why; one hand act per call. A group none of whose movers failed joins the head's pipeline while that waits or runs; otherwise the pipeline it left is reopened for the whole group under its own key. With key the answer names the pipeline; with all it lists placed (key, pipeline) and failed (key, words), both always present, and says so when no key was there.",
obj([]string{"why"}, map[string]any{"key": str, "all": map[string]any{"type": "boolean"}, "why": str}),
func(in seat.PlaceUnfinishedInput) string {
if in.Key == "" {
return "place-unfinished names the unfinished entry's key"
if (in.Key == "") == !in.All {
return "place-unfinished names the unfinished entry's key or all, exactly one"
}
return whyOf(in.Why)
}),
@@ -43,7 +43,11 @@ func TestVerbTools(t *testing.T) {
// design 47 H2 §786, H-A-398: runner_unfinished_place asks the verb place-unfinished with the entry's key and why.
{"unfinished place", "runner_unfinished_place", "seat:mesh-pipeline-runner.place-unfinished", "", map[string]any{"key": "main.app", "why": "now"},
seat.PlaceUnfinishedInput{Key: "main.app", Why: "now"}},
{"unfinished place no key", "runner_unfinished_place", "", "entry's key", map[string]any{"why": "now"}, nil},
{"unfinished place no key", "runner_unfinished_place", "", "exactly one", map[string]any{"why": "now"}, nil},
// H-A-644: all places every key in one hand act; key and all together are refused.
{"unfinished place all", "runner_unfinished_place", "seat:mesh-pipeline-runner.place-unfinished", "", map[string]any{"all": true, "why": "now"},
seat.PlaceUnfinishedInput{All: true, Why: "now"}},
{"unfinished place key and all", "runner_unfinished_place", "", "exactly one", map[string]any{"key": "main.app", "all": true, "why": "now"}, nil},
{"ask-again no why", "runner_ask_again", "", "names why", map[string]any{"pipeline": "p"}, nil},
} {
t.Run(c.name, func(t *testing.T) {
@@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"slices"
"strings"
"sync/atomic"
"testing"
"time"
@@ -140,4 +141,45 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
if _, err := unfinished.Get(ctx, "main.app"); err == nil {
t.Error("main.app is still unfinished after main.2 passed")
}
// design 47 H2 H-A-609 (1), H-A-644, H-A-725 (AC-P5a, AC-P5d), whole: lib fails again in main.3, leaving app unfinished;
// place-unfinished with all puts app in one hand act by reopening main.3 for app alone, so main.3 ends again passed (its
// second end, the end count one higher) and no third end follows, lib staying a failed mover outside the group.
newest.Store(3)
rev, _ = json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 3, Kind: "trunk", Branch: "main", Source: 5, CallKind: catalog.CatalogRevisionEventCallKindTakeIn})
if _, err := w.js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil {
t.Fatal(err)
}
takeIn(5, 3, catalog.TakeInEntry{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, catalog.TakeInEntry{Module: "lib", Commit: "l1", Fingerprint: "src2:l1"})
waitFor(t, ctx, w.logs, answer("main.3", true))
if pe := endOf(); pe.Pipeline != "main.3" || pe.Outcome != seat.PipelineEndedOutcomeFailed || !slices.Equal(pe.Unfinished, []string{"app"}) {
t.Fatalf("pipeline-ended = %s %s unfinished %v, want main.3 failed leaving app unfinished\n%s", pe.Pipeline, pe.Outcome, pe.Unfinished, w.logs.String())
}
var placed seat.PlaceUnfinishedAnswer
waitFor(t, ctx, w.logs, func() bool {
raw, _ := json.Marshal(seat.PlaceUnfinishedInput{All: true, Why: "the whole test"})
m, err := w.nc.Request("mesh.seat."+seat.Seat+".call.place-unfinished.agent~dev", raw, 15*time.Second)
var reply struct {
Result json.RawMessage `json:"result"`
Error string `json:"error"`
}
if err != nil || json.Unmarshal(m.Data, &reply) != nil || strings.Contains(reply.Error, "not yet read") {
return false
}
if reply.Error != "" {
t.Fatalf("place-unfinished all: %s", reply.Error)
}
return json.Unmarshal(reply.Result, &placed) == nil
})
if len(placed.Placed) != 1 || placed.Placed[0].Key != "main.app" || placed.Placed[0].Pipeline != "main.3" || len(placed.Failed) != 0 {
t.Fatalf("place-unfinished all = %+v, want main.app placed in main.3", placed)
}
waitFor(t, ctx, w.logs, answer("main.3", false))
if pe := endOf(); pe.Pipeline != "main.3" || pe.Outcome != seat.PipelineEndedOutcomePassed || len(pe.Unfinished) != 0 {
t.Fatalf("main.3 ended again %s unfinished %v, want passed for app alone\n%s", pe.Outcome, pe.Unfinished, w.logs.String())
}
var third seat.Pipeline
if !readPipeline(ctx, w.pipelines, "main.3", &third) || third.EndCount != 2 || len(ended) != 0 {
t.Errorf("main.3 ended %d times and %d ends wait, want its second end and no third", third.EndCount, len(ended))
}
}
@@ -23,7 +23,7 @@ type AddedFrom struct {
// openPipeline says whether p waits or runs: a delivering pipeline that has not ended.
func openPipeline(p seat.Pipeline) bool {
return p.Run == "" && p.Outcome == seat.PipelineOutcomeRunning && p.Ended == nil
return p.Run == "" && (p.Outcome == seat.PipelineOutcomeRunning || p.Outcome == seat.PipelineOutcomeWaiting) && p.Ended == nil
}
// AddMovers adds to the pipeline key, which waits or runs, each of movers it does not move yet, tiers them with the rest from
@@ -134,10 +134,9 @@ func (m memUnfinished) Get(k string) ([]byte, error) {
func (m memUnfinished) Put(k string, v []byte) error { m[k] = string(v); return nil }
func (m memUnfinished) Delete(k string) error { delete(m, k); return nil }
func (m memUnfinished) Keys(filter string) ([]string, error) {
prefix := strings.TrimSuffix(filter, "*")
var out []string
for k := range m {
if strings.HasPrefix(k, prefix) {
if ok, _ := matchKey(filter, k); ok {
out = append(out, k)
}
}
@@ -0,0 +1,410 @@
package pipeline
import (
"errors"
"fmt"
"slices"
"strings"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// Start starts by hand the named modules at the head of a watched branch the runner's catalog half holds, recorded in the hand-act
// log first (design 47 H2 H-A-571, H-A-607 (3), H-A-643): exactly one of module or modules. Each module follows one rule: the
// head's pipeline `<branch>.<revision>` takes it as a mover while that pipeline waits or runs, said by mover-added with the
// caller; a head with no pipeline is started with the modules named; once the head's pipeline has ended, a module whose own step
// failed reopens that pipeline as rerun does, with its closed group. No other pipeline is keyed for it.
func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error) {
if in.Module != "" && len(in.Modules) > 0 {
return seat.StartAnswer{}, errors.New("start names the module or the modules, not both: nothing was started")
}
modules := in.Modules
if in.Module != "" {
modules = []string{in.Module}
}
if in.Branch == "" || len(modules) == 0 {
return seat.StartAnswer{}, errors.New("start names the watched branch and the module or the modules")
}
s := v.Starter
if s == nil || s.Store == nil || v.View == nil {
return seat.StartAnswer{}, errors.New("the runner cannot start a pipeline: it holds no starter or no catalog half")
}
half, ok := v.View(in.Branch)
if !ok || half.Source <= 0 {
return seat.StartAnswer{}, fmt.Errorf("the catalog half of %s is not held at a source revision yet: nothing was started", in.Branch)
}
var movers []seat.Mover
var absent []string
for _, m := range modules {
e, ok := half.Entries[m]
switch {
case !ok:
absent = append(absent, m)
case !slices.ContainsFunc(movers, func(x seat.Mover) bool { return x.Module == m }):
movers = append(movers, seat.Mover{Module: m, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
}
if len(absent) > 0 {
return seat.StartAnswer{}, fmt.Errorf("the head of %s (revision %d) holds no entry of %s: nothing was started", in.Branch, half.Revision, strings.Join(absent, ", "))
}
key := Key(in.Branch, keyRevision(Begin{Revision: half.Revision, Source: half.Source}))
held, err := s.Store.Keys(key)
if err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is not looked for: nothing was started: %w", key, err)
}
var head seat.Pipeline
if len(held) > 0 {
if head, _, err = s.Store.Get(key); err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is not read: nothing was started: %w", key, err)
}
}
names := moduleNames(movers)
what := fmt.Sprintf("started %s at the head of %s by hand", strings.Join(names, ", "), in.Branch)
switch {
case len(held) == 0:
if err := v.record(seat.VerbStart, what, in.Why); err != nil {
return seat.StartAnswer{}, err
}
movers = Tiers(movers, half.Entries, s.logf)
started, err := s.Start(Begin{Branch: in.Branch, Source: half.Source, Revision: half.Revision, Entries: half.Entries, Movers: movers})
if err != nil {
return seat.StartAnswer{}, err
}
if !started {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is started already: nothing was started", key)
}
return seat.StartAnswer{Pipeline: key}, nil
case openPipeline(head):
var add []seat.Mover
for _, m := range movers {
if !Moves(head, m.Module) {
add = append(add, m)
}
}
if len(add) == 0 {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s moves %s already: a step of it is asked again by rerun: nothing was started", key, strings.Join(names, ", "))
}
if err := v.record(seat.VerbStart, what, in.Why); err != nil {
return seat.StartAnswer{}, err
}
if _, err := s.AddMovers(key, add, half.Entries, AddedFrom{Caller: caller}, v.View); err != nil {
return seat.StartAnswer{}, err
}
return seat.StartAnswer{Pipeline: key}, nil
}
// The head's pipeline has ended: a module whose own step failed reopens it with its closed group, as a rerun does.
for _, m := range movers {
if !Moves(head, m.Module) || len(failedSteps(head, m.Module)) == 0 {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s ended %s and %s has no failed step in it: nothing was started", key, head.Outcome, m.Module)
}
}
entries := half.Entries
var group []string
for _, m := range movers {
group = appendNew(group, v.closedGroup(head, m.Module, entries)...)
}
if err := v.record(seat.VerbStart, what, in.Why); err != nil {
return seat.StartAnswer{}, err
}
if err := v.reopenGroup(caller, head, group, in.Why); err != nil {
return seat.StartAnswer{}, err
}
s.markCarriedKeys(head, group, head.Pipeline)
return seat.StartAnswer{Pipeline: key}, nil
}
func appendNew(into []string, add ...string) []string {
for _, a := range add {
if !slices.Contains(into, a) {
into = append(into, a)
}
}
return into
}
// closedGroup is the group of movers of p that go with module: closed under the tier edges and under every awaited edge from a
// mover that left unfinished or failed, so a mover goes only with every mover it has an edge from (design 47 H2 H-A-594 (2),
// H-A-646). A passed mover is never in it.
func (v Verbs) closedGroup(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) []string {
left := unfinishedOf(p)
universe := appendNew(slices.Clone(left), failedMovers(p)...)
group := []string{module}
for changed := true; changed; {
changed = false
for _, g := range tierGroups(universe, entries) {
if slices.ContainsFunc(g, func(m string) bool { return slices.Contains(group, m) }) {
for _, m := range g {
if !slices.Contains(group, m) {
group, changed = append(group, m), true
}
}
}
}
for _, m := range slices.Clone(group) {
for _, x := range awaited(p, m, entries) {
if from := moduleOf(x.From); slices.Contains(universe, from) && !slices.Contains(group, from) {
group, changed = append(group, from), true
}
}
}
}
slices.Sort(group)
return group
}
// markCarriedKeys names carrier as the carrier of the unfinished keys of group's modules of p's branch.
func (s *Starter) markCarriedKeys(p seat.Pipeline, group []string, carrier string) {
if s.Unfinished != nil {
s.Unfinished.markCarried(p.Branch, group, carrier)
}
}
// reopenGroup reopens the ended pipeline from for group alone (design 47 H2 H-A-607 (3), H-A-609 (1), H-A-623): the movers outside
// the group that left unfinished or failed leave its movers, so its next end judges the group; a group mover with a failed step
// asks it again as rerun asks it, and one with none has its steps placed again, its passed packages carried by their kept
// results. The group's hand act is the caller's.
func (v Verbs) reopenGroup(caller string, from seat.Pipeline, group []string, why string) error {
reopens, err := v.reopening(from.Pipeline)
if err != nil {
return err
}
if !reopens {
return fmt.Errorf("the pipeline %s is %s and cannot be reopened: nothing was placed", from.Pipeline, from.Outcome)
}
s := v.Starter
var failed []seat.StepResult
for _, m := range group {
failed = append(failed, failedSteps(from, m)...)
}
for {
cur, rev, err := s.Store.Get(from.Pipeline)
if err != nil {
return fmt.Errorf("the pipeline %s is not read: %w", from.Pipeline, err)
}
outside := appendNew(unfinishedOf(cur), failedMovers(cur)...)
cur.Movers = slices.DeleteFunc(slices.Clone(cur.Movers), func(m seat.Mover) bool {
return slices.Contains(outside, m.Module) && !slices.Contains(group, m.Module)
})
for _, m := range group {
if len(failedSteps(cur, m)) == 0 {
cur.Steps = slices.DeleteFunc(slices.Clone(cur.Steps), func(st seat.StepResult) bool { return st.Module == m })
// The steps placed again take ask ids of their own: an id is made from the pipeline's start, and one an earlier
// ask holds is kept once.
now := v.now()
cur.Started = &now
}
}
if len(failed) == 0 {
cur.Outcome, cur.Why, cur.Ended = seat.PipelineOutcomeRunning, "", nil
}
if _, err := s.Store.Update(from.Pipeline, cur, rev); errors.Is(err, ErrChanged) {
continue
} else if err != nil {
return fmt.Errorf("the pipeline %s is not written: %w", from.Pipeline, err)
}
break
}
w := v
w.noRecord = true
for i, st := range failed {
if _, err := w.rerun(caller, seat.RerunInput{Pipeline: from.Pipeline, Module: st.Module, Step: st.Step, Artifact: st.Artifact, Why: why}, reopens && i == 0); err != nil {
return fmt.Errorf("the %s step of %s in %s is not asked again: %w", st.Step, st.Module, from.Pipeline, err)
}
}
if len(failed) == 0 {
p, _, err := s.Store.Get(from.Pipeline)
if err != nil {
return fmt.Errorf("the pipeline %s is not read: %w", from.Pipeline, err)
}
v.sayReopened(p, true)
if _, err := s.Waiting(s.Store, p.Branch, v.View); err != nil {
return err
}
}
s.logf("%s reopened by hand for %s (H-A-607 (3))", from.Pipeline, strings.Join(group, ", "))
return nil
}
// handPlan is one group place-unfinished puts: the keys of its movers in the state unfinished, the pipeline they left and the
// movers that go.
type handPlan struct {
keys []string
from seat.Pipeline
group []string
movers []seat.Mover
// entries are the entries a carry tiers its movers from.
entries map[string]catalog.CatalogEntry
}
// planUnfinished is the group key belongs to (design 47 H2 H-A-607 (3)): refused, naming why, a key the state does not hold, one a
// pipeline that waits or runs carries, one whose pipeline no longer moves it, or one whose entry holds another fingerprint.
func (v Verbs) planUnfinished(key string) (handPlan, error) {
s := v.Starter
e, held, err := s.Unfinished.Entry(key)
if err != nil {
return handPlan{}, fmt.Errorf("the unfinished entry %s is not read: %w", key, err)
}
if !held {
return handPlan{}, fmt.Errorf("the state unfinished holds no %s", key)
}
b, m, _ := strings.Cut(key, ".")
branch, berr := keys.UnescapeName(b)
module, merr := keys.UnescapeName(m)
if berr != nil || merr != nil || branch == "" || module == "" {
return handPlan{}, fmt.Errorf("%s is no key <branch>.<module>", key)
}
if e.CarriedBy != "" {
if c, _, err := s.Store.Get(e.CarriedBy); err == nil && openPipeline(c) {
return handPlan{}, fmt.Errorf("%s carries it and waits or runs", e.CarriedBy)
}
}
from, _, err := s.Store.Get(e.Pipeline)
if err != nil || !Moves(from, module) {
return handPlan{}, fmt.Errorf("its pipeline %s is not read or moves %s no more", e.Pipeline, module)
}
var half Half
switch {
case s.Revision != nil:
if half, err = s.Revision(branch, e.Revision); err != nil {
return handPlan{}, fmt.Errorf("the revision %d of %s is not read: %w", e.Revision, branch, err)
}
case v.View != nil:
var ok bool
if half, ok = v.View(branch); !ok || half.Revision != e.Revision {
return handPlan{}, fmt.Errorf("the revision %d of %s is not held", e.Revision, branch)
}
default:
return handPlan{}, errors.New("the runner reads no catalog revision")
}
if entry, ok := half.Entries[module]; !ok || entry.Fp != e.Fingerprint || half.Source <= 0 {
return handPlan{}, fmt.Errorf("the revision %d of %s holds %s at %q, not its unfinished fingerprint %s", e.Revision, branch, module, entry.Fp, e.Fingerprint)
}
group := v.closedGroup(from, module, half.Entries)
plan := handPlan{from: from, group: group, entries: half.Entries}
if head, ok := v.View(branch); ok && head.Entries != nil {
plan.entries = head.Entries
}
for _, g := range group {
mv, _ := MoverOf(from, g)
plan.movers = append(plan.movers, mv)
if k := UnfinishedKey(branch, g); slices.ContainsFunc(unfinishedOf(from), func(x string) bool { return x == g }) {
if _, ok, _ := s.Unfinished.Entry(k); ok {
plan.keys = append(plan.keys, k)
}
}
}
return plan, nil
}
// PlaceUnfinished puts the closed group of a mover kept in the state unfinished in a pipeline at once, recorded in the hand-act log
// once for the call (design 47 H2 §786, H-A-607 (3), H-A-644, H-A-725): with `key` the one key's group, with `all` every key whose
// carrier neither waits nor runs. A group none of whose movers failed joins the head's pipeline while that waits or runs;
// otherwise the pipeline it left is reopened for the whole group under its own key and revision, a failed mover asked again as
// rerun asks it. With `all` the answer lists each key placed and each key not, with its words.
func (v Verbs) PlaceUnfinished(caller string, in seat.PlaceUnfinishedInput) (seat.PlaceUnfinishedAnswer, error) {
s := v.Starter
one := strings.TrimSpace(in.Key)
if (one == "") == !in.All {
return seat.PlaceUnfinishedAnswer{}, errors.New("place-unfinished names the unfinished entry's key or all, exactly one: nothing was placed")
}
if s == nil || s.Unfinished == nil || s.Store == nil {
return seat.PlaceUnfinishedAnswer{}, errors.New("the runner keeps no state unfinished: nothing was placed")
}
todo := []string{one}
if in.All {
var err error
if todo, err = s.Unfinished.Store.Keys("*.*"); err != nil {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the state unfinished is not listed: nothing was placed: %w", err)
}
slices.Sort(todo)
}
ans := seat.PlaceUnfinishedAnswer{Placed: []seat.PlaceUnfinishedAnswerPlacedItem{}, Failed: []seat.PlaceUnfinishedAnswerFailedItem{}}
type unit struct {
plan handPlan
keys []string
}
var units []unit
done := map[string]bool{}
for _, k := range todo {
if done[k] {
continue
}
plan, err := v.planUnfinished(k)
if err != nil {
if !in.All {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("%v: nothing was placed", err)
}
if e, held, _ := s.Unfinished.Entry(k); held && e.CarriedBy != "" && strings.Contains(err.Error(), "waits or runs") {
continue // carried already: nothing to place
}
ans.Failed = append(ans.Failed, seat.PlaceUnfinishedAnswerFailedItem{Key: k, Words: err.Error()})
continue
}
for _, pk := range plan.keys {
done[pk] = true
}
units = append(units, unit{plan: plan, keys: plan.keys})
}
var all []string
for _, u := range units {
all = append(all, u.keys...)
}
for _, f := range ans.Failed {
all = append(all, f.Key)
}
if len(all) == 0 {
if in.All {
ans.Said = "the state unfinished holds no key to place"
}
return ans, nil
}
if err := v.record(seat.VerbPlaceUnfinished, "put the unfinished movers "+strings.Join(all, ", ")+" in a pipeline by hand", in.Why); err != nil {
return seat.PlaceUnfinishedAnswer{}, err
}
w := v
w.noRecord = true
for _, u := range units {
pipe, err := w.placeGroup(caller, u.plan, in.Why)
if err != nil {
if !in.All {
return seat.PlaceUnfinishedAnswer{}, err
}
for _, k := range u.keys {
ans.Failed = append(ans.Failed, seat.PlaceUnfinishedAnswerFailedItem{Key: k, Words: err.Error()})
}
continue
}
ans.Pipeline = pipe
for _, k := range u.keys {
ans.Placed = append(ans.Placed, seat.PlaceUnfinishedAnswerPlacedItem{Key: k, Pipeline: pipe})
}
}
if in.All {
ans.Pipeline = ""
}
return ans, nil
}
// placeGroup puts one group (PlaceUnfinished): in the head's pipeline when none of its movers failed and that waits or runs,
// otherwise by reopening the pipeline it left. It answers the pipeline that carries the group now.
func (v Verbs) placeGroup(caller string, plan handPlan, why string) (string, error) {
s := v.Starter
failed := false
for _, m := range plan.group {
failed = failed || len(failedSteps(plan.from, m)) > 0
}
if !failed {
if carrier, ok := s.CarryToHead(plan.from, plan.movers, plan.entries, v.View); ok {
s.markCarriedKeys(plan.from, plan.group, carrier)
s.logf("%s puts %s in the head's pipeline %s by hand (H-A-607 (3))", plan.from.Pipeline, strings.Join(plan.group, ", "), carrier)
return carrier, nil
}
}
if err := v.reopenGroup(caller, plan.from, plan.group, why); err != nil {
return "", err
}
s.markCarriedKeys(plan.from, plan.group, plan.from.Pipeline)
return plan.from.Pipeline, nil
}
@@ -9,6 +9,7 @@ import (
"slices"
"strings"
"testing"
"time"
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
@@ -488,20 +489,38 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
if p, _, _ := mem.Get("main.14"); len(p.Movers) != 1 || !Moves(p, "batched") {
t.Errorf("main.14 moves %+v, want batched alone", p.Movers)
}
half.Revision = 11
delete(u, "dev.batched")
acts := &actLog{}
v := Verbs{Starter: s, View: view, Acts: acts}
if a, err := v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "now"}); err != nil || a.Pipeline != "main.11.unfinished.batched" || len(*acts) != 1 {
t.Errorf("place-unfinished = %+v (%v), %d hand acts", a, err, len(*acts))
}
if p, _, _ := mem.Get("main.11.unfinished.batched"); len(p.Movers) != 1 || !Moves(p, "batched") {
t.Errorf("main.11.unfinished.batched moves %+v, want batched", p.Movers)
}
for _, in := range []seat.PlaceUnfinishedInput{{Key: "main.batched", Why: "again"}, {Key: "main.none", Why: "x"}, {Key: "dev.batched"}} {
v := Verbs{Starter: s, View: view, Acts: acts, Hearer: &Hearer{Store: mem}}
// design 47 H2 H-A-607 (3), H-A-644, H-A-725: a key a pipeline that runs carries is refused, and `all` over it answers two empty lists
// and says so; exactly one of key and all is given.
for _, in := range []seat.PlaceUnfinishedInput{{Key: "main.batched", Why: "now"}, {Why: "x"}, {Key: "main.batched", All: true, Why: "x"}, {Key: "main.none", Why: "x"}} {
if _, err := v.PlaceUnfinished("agent.dev", in); err == nil {
t.Errorf("place-unfinished %+v is refused", in)
}
}
if a, err := v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{All: true, Why: "now"}); err != nil || a.Said == "" || len(a.Placed) != 0 || len(a.Failed) != 0 || len(*acts) != 0 {
t.Errorf("place-unfinished all over a carried key = %+v (%v), %d hand acts", a, err, len(*acts))
}
// The carrier ended failed, leaving batched: `all` reopens it for the group and answers it placed; a key whose entry holds
// another fingerprint is answered failed with its words, and the other is placed.
end := time.Unix(5, 0)
c, rev, _ := mem.Get("main.14")
c.Outcome, c.Ended = seat.PipelineOutcomeFailed, &end
if _, err := mem.Update("main.14", c, rev); err != nil {
t.Fatal(err)
}
u["main.batched"] = `{"fingerprint":"src2:bb","revision":14,"pipeline":"main.14","outcome":"failed"}`
u["main.odd"] = `{"fingerprint":"src2:zz","revision":14,"pipeline":"main.14","outcome":"failed"}`
half.Revision = 14
a, err := v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{All: true, Why: "now"})
if err != nil || len(a.Placed) != 1 || a.Placed[0] != (seat.PlaceUnfinishedAnswerPlacedItem{Key: "main.batched", Pipeline: "main.14"}) ||
len(a.Failed) != 1 || a.Failed[0].Key != "main.odd" || a.Failed[0].Words == "" || len(*acts) != 1 || !strings.Contains((*acts)[0], "main.odd") {
t.Errorf("place-unfinished all = %+v (%v), hand acts %v", a, err, *acts)
}
if p, _, _ := mem.Get("main.14"); p.Outcome != seat.PipelineOutcomeRunning || p.Ended != nil || !strings.Contains(u["main.batched"], `"carried-by":"main.14"`) {
t.Errorf("main.14 is %s ended %v, batched = %s: want reopened and carried by it", p.Outcome, p.Ended, u["main.batched"])
}
}
// R16/AC1 (design 47 H §765, H-A-58, H-A-98): a take-in.taken of the old form, with no call (or no branch or source), is
@@ -1035,6 +1035,9 @@ func endPipeline(p *seat.Pipeline, now time.Time, unplaced func(seat.Pipeline, s
switch {
case slices.Contains(p.Superseded, s.Module):
continue
case s.Module != "" && len(p.Movers) > 0 && !Moves(*p, s.Module):
// A mover a carry or a reopening took out of the pipeline is judged where it went (H-A-609 (1)).
continue
case s.Step == seat.StepResultStepApproval && s.Outcome == seat.StepResultOutcomeWaiting:
notAsked = append(notAsked, i)
continue
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"slices"
"strconv"
"strings"
"time"
@@ -34,6 +33,9 @@ type Verbs struct {
// at the time of the ask: nil when it is, an error wrapping ErrRevisionGone when it is removed (design 47 H2 H-A-479
// addendum (2)).
RevisionHeld func(branch string, revision int64) error
// noRecord says the call records no hand act: a verb that is one hand act and asks other verbs' acts inside it (design 47
// H2 H-A-607 (3), H-A-644).
noRecord bool
}
// ErrRevisionGone is a catalog revision the catalog no longer keeps (H-A-479 addendum (2)).
@@ -42,6 +44,9 @@ var ErrRevisionGone = errors.New("the catalog revision is gone")
func (v Verbs) now() time.Time { return v.Hearer.now() }
func (v Verbs) record(verb, what, why string) error {
if v.noRecord {
return nil
}
if v.Acts == nil {
return errors.New("no way to record a hand act is given: nothing was done")
}
@@ -735,158 +740,6 @@ func (v Verbs) Run(caller string, in seat.RunInput) (seat.RunAnswer, error) {
return v.Starter.Run(caller, in, NewRunID, v.View)
}
// Start starts by hand a delivering pipeline for the head of a watched branch the runner's catalog half holds, recorded in
// the hand-act log first (§306, §394): the pipeline of that branch's source revision and the module, as a take-in would
// start it. A head whose pipeline is written already starts nothing and is refused, naming the pipeline. With modules it
// starts the named modules again at the head instead (startAgain, H-A-479); exactly one of module or modules is given.
func (v Verbs) Start(_ string, in seat.StartInput) (seat.StartAnswer, error) {
if in.Module != "" && len(in.Modules) > 0 {
return seat.StartAnswer{}, errors.New("start names the module or the modules, not both: nothing was started")
}
if in.Branch != "" && len(in.Modules) > 0 {
return v.startAgain(in)
}
if in.Branch == "" || in.Module == "" {
return seat.StartAnswer{}, errors.New("start names the watched branch and the module or the modules")
}
if v.Starter == nil || v.View == nil {
return seat.StartAnswer{}, errors.New("the runner cannot start a pipeline: it holds no starter or no catalog half")
}
half, ok := v.View(in.Branch)
if !ok {
return seat.StartAnswer{}, fmt.Errorf("the catalog half of %s is not held yet: nothing was started", in.Branch)
}
e, ok := half.Entries[in.Module]
if !ok || half.Source <= 0 {
return seat.StartAnswer{}, fmt.Errorf("the catalog half of %s holds no entry of %s at a source revision: nothing was started", in.Branch, in.Module)
}
key := Key(in.Branch, keyRevision(Begin{Revision: half.Revision, Source: half.Source}))
if err := v.record(seat.VerbStart, "started the pipeline "+key+" by hand", in.Why); err != nil {
return seat.StartAnswer{}, err
}
// A hand start keys the newest revision's <branch>.<revision> with the module as its one mover (H-A-52, H-A-213 (4)).
started, err := v.Starter.Start(Begin{Branch: in.Branch, Source: half.Source, Revision: half.Revision, Entries: half.Entries,
Movers: []seat.Mover{{Module: in.Module, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository, Tier: 1}}})
if err != nil {
return seat.StartAnswer{}, err
}
if !started {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s of the head is started already: a step of it is asked again by rerun", key)
}
return seat.StartAnswer{Pipeline: key}, nil
}
// startAgain starts by hand, recorded in the hand-act log first, a pipeline at the head of a watched branch carrying the
// named modules whose newest entry, the head's, has no passed pipeline (a failed, cut or superseded one), with the head's
// revision as its candidate and the take-in's tiers (design 47 H2 H-A-479): keyed `<branch>.<revision>.again.<n>`, n from 1,
// taken by writing on absence (addendum (1)). Its pipeline-started pins the head's revision as a take-in's does, and its
// versions are reserved at its build steps as a take-in's are. A module the head holds no entry of, or whose newest entry
// passed in a pipeline, is refused by name, nothing started.
func (v Verbs) startAgain(in seat.StartInput) (seat.StartAnswer, error) {
if v.Starter == nil || v.View == nil || v.Hearer == nil || v.Hearer.Store == nil {
return seat.StartAnswer{}, errors.New("the runner cannot start a pipeline again: it holds no starter, no catalog half or no state pipelines")
}
half, ok := v.View(in.Branch)
if !ok || half.Source <= 0 {
return seat.StartAnswer{}, fmt.Errorf("the catalog half of %s is not held at a source revision yet: nothing was started", in.Branch)
}
movers := make([]seat.Mover, 0, len(in.Modules))
var absent []string
for _, m := range in.Modules {
e, ok := half.Entries[m]
if !ok {
absent = append(absent, m)
continue
}
if slices.ContainsFunc(movers, func(x seat.Mover) bool { return x.Module == m }) {
continue
}
movers = append(movers, seat.Mover{Module: m, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
if len(absent) > 0 {
return seat.StartAnswer{}, fmt.Errorf("the head of %s (revision %d) holds no entry of %s: nothing was started", in.Branch, half.Revision, strings.Join(absent, ", "))
}
passed, running, err := v.heldEntries(in.Branch, movers)
if err != nil {
return seat.StartAnswer{}, err
}
if len(passed) > 0 {
return seat.StartAnswer{}, fmt.Errorf("the newest entry of %s passed already: nothing was started", strings.Join(passed, ", "))
}
if len(running) > 0 {
return seat.StartAnswer{}, fmt.Errorf("the newest entry of %s: nothing was started", strings.Join(running, ", "))
}
movers = Tiers(movers, half.Entries, v.Starter.logf)
names := make([]string, 0, len(movers))
for _, m := range movers {
names = append(names, m.Module)
}
prefix := AgainPipelineKey(in.Branch, half.Revision, 0)
prefix = prefix[:len(prefix)-1]
held, err := v.Hearer.Store.Keys(prefix + "*")
if err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipelines started again at revision %d of %s are not listed: nothing was started: %w", half.Revision, in.Branch, err)
}
n := 1
for _, k := range held {
if i, err := strconv.Atoi(strings.TrimPrefix(k, prefix)); err == nil && i >= n {
n = i + 1
}
}
if err := v.record(seat.VerbStart, fmt.Sprintf("started %s again at the head of %s by hand", strings.Join(names, ", "), in.Branch), in.Why); err != nil {
return seat.StartAnswer{}, err
}
// The next n is taken without a bound: each refusal means the key exists (H-A-479 second addendum).
for ; ; n++ {
key := AgainPipelineKey(in.Branch, half.Revision, n)
started, err := v.Starter.Start(Begin{Branch: in.Branch, Source: half.Source, Revision: half.Revision, Entries: half.Entries,
Key: key, Movers: movers})
if err != nil {
return seat.StartAnswer{}, err
}
if started {
v.Starter.logf("%s starts %s again at the head by hand (H-A-479)", key, strings.Join(names, ", "))
return seat.StartAnswer{Pipeline: key}, nil
}
}
}
// heldEntries are the movers whose module, at the mover's fingerprint, a delivering pipeline of branch carries and did not
// leave: passed, those a passed pipeline holds (a newest entry that passed is not started again, H-A-479); running, those a
// pipeline not ended holds, each said "<module>: its pipeline <key> is running", so two pipelines never build one entry side
// by side (H-A-479 second addendum).
func (v Verbs) heldEntries(branch string, movers []seat.Mover) (passed, running []string, err error) {
pkeys, err := branchKeys(v.Hearer.Store, branch)
if err != nil {
return nil, nil, fmt.Errorf("the pipelines of %s are not listed, so nothing was started: %w", branch, err)
}
seen := map[string]bool{}
for _, key := range pkeys {
p, _, err := v.Hearer.Store.Get(key)
if err != nil {
return nil, nil, fmt.Errorf("the pipeline %s is not read, so nothing was started: %w", key, err)
}
open := p.Ended == nil && (p.Outcome == seat.PipelineOutcomeRunning || p.Outcome == seat.PipelineOutcomeWaiting)
if p.Run != "" || (p.Outcome != seat.PipelineOutcomePassed && !open) {
continue
}
for _, m := range movers {
if seen[m.Module] || slices.Contains(p.Superseded, m.Module) {
continue
}
if pm, ok := MoverOf(p, m.Module); ok && pm.Fingerprint == m.Fingerprint {
seen[m.Module] = true
if open {
running = append(running, m.Module+": its pipeline "+key+" is running")
} else {
passed = append(passed, m.Module+" (in "+key+")")
}
}
}
}
return passed, running, nil
}
// AskAgain asks a declined approval step once more (§306, §36), recorded in the hand-act log first: the step waits again,
// marked asked again by the caller the bus proved, and is asked at once when the pipeline's every other required step
// passed, under an ask of its own (the earlier ask's decision ended it).
@@ -948,63 +801,3 @@ func (v Verbs) Place(caller string, in seat.PlaceInput) (seat.PlaceAnswer, error
p, _, err = s.Store.Get(in.Pipeline)
return seat.PlaceAnswer{Pipeline: p}, err
}
// PlaceUnfinished puts a mover kept in the state unfinished in a pipeline of its own at once, recorded in the hand-act log
// first (design 47 H2 §786, H-A-398): keyed `<branch>.<revision>.unfinished.<module>`, its steps placed from the entries of
// the catalog revision the entry names, the mover at the entry's fingerprint. The key stays until that pipeline ends passed.
// A key the state does not hold, a revision whose entry holds another fingerprint, or a pipeline written already is refused,
// nothing done.
func (v Verbs) PlaceUnfinished(_ string, in seat.PlaceUnfinishedInput) (seat.PlaceUnfinishedAnswer, error) {
s := v.Starter
if strings.TrimSpace(in.Key) == "" {
return seat.PlaceUnfinishedAnswer{}, errors.New("place-unfinished names the unfinished entry's key")
}
if s == nil || s.Unfinished == nil {
return seat.PlaceUnfinishedAnswer{}, errors.New("the runner keeps no state unfinished: nothing was placed")
}
e, held, err := s.Unfinished.Entry(in.Key)
if err != nil {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the unfinished entry %s is not read: %w", in.Key, err)
}
if !held {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the state unfinished holds no %s: nothing was placed", in.Key)
}
b, m, _ := strings.Cut(in.Key, ".")
branch, berr := keys.UnescapeName(b)
module, merr := keys.UnescapeName(m)
if berr != nil || merr != nil || branch == "" || module == "" {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("%s is no key <branch>.<module>: nothing was placed", in.Key)
}
var half Half
switch {
case s.Revision != nil:
if half, err = s.Revision(branch, e.Revision); err != nil {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s is not read: nothing was placed: %w", e.Revision, branch, err)
}
case v.View != nil:
var ok bool
if half, ok = v.View(branch); !ok || half.Revision != e.Revision {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s is not held: nothing was placed", e.Revision, branch)
}
default:
return seat.PlaceUnfinishedAnswer{}, errors.New("the runner reads no catalog revision: nothing was placed")
}
entry, ok := half.Entries[module]
if !ok || entry.Fp != e.Fingerprint || half.Source <= 0 {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s holds %s at %q, not its unfinished fingerprint %s: nothing was placed", e.Revision, branch, module, entry.Fp, e.Fingerprint)
}
key := UnfinishedPipelineKey(branch, e.Revision, module)
if err := v.record(seat.VerbPlaceUnfinished, "put the unfinished mover "+module+" of "+branch+" in the pipeline "+key+" by hand", in.Why); err != nil {
return seat.PlaceUnfinishedAnswer{}, err
}
started, err := s.Start(Begin{Branch: branch, Source: half.Source, Revision: e.Revision, Entries: half.Entries, Key: key,
Movers: []seat.Mover{{Module: module, Commit: entry.Commit, Fingerprint: entry.Fp, Repository: entry.Repository, Tier: 1}}})
if err != nil {
return seat.PlaceUnfinishedAnswer{}, err
}
if !started {
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the pipeline %s is started already: nothing was placed", key)
}
s.logf("%s puts the unfinished mover %s in a pipeline of its own by hand (§786)", key, module)
return seat.PlaceUnfinishedAnswer{Pipeline: key}, nil
}
@@ -373,7 +373,7 @@ func (failingActs) RecordHandAct(views.HandAct) error { return errors.New("no ho
func TestStartAndAskAgain(t *testing.T) {
v, store, _, _, acts, _ := verbsFixture()
made := created{}
v.Starter.Pipelines, v.Starter.Say = made, func(string, any) error { return nil }
v.Starter.Pipelines, v.Starter.Say, v.Starter.Store = made, func(string, any) error { return nil }, store
_, entries := placeFixture()
v.View = func(string) (Half, bool) { return Half{Source: 7, Revision: 3, Entries: entries}, true }
a, err := v.Start("operator", seat.StartInput{Branch: "main", Module: "app", Why: "no pipeline for the head"})
@@ -472,17 +472,18 @@ func TestAValidateRerunMovesEveryMoversValidateAndReopensItsCompositions(t *test
}
}
// H-A-479: start with modules starts a pipeline at the head keyed <branch>.<revision>.again.<n> carrying the named modules
// whose newest entry has no passed pipeline, at the take-in's tiers; a module whose newest entry passed is refused by name,
// nothing started; exactly one of module or modules is given; a second start takes the next n.
func TestStartWithModulesStartsAFailedMoverAgainAtTheHead(t *testing.T) {
v, store, _, _, acts, _ := verbsFixture()
// H-A-571, H-A-607 (3), H-A-643 (design 47 H2): start with modules follows one rule per module: a head with no pipeline is started
// with the modules named, the head's pipeline that runs takes the modules it does not move as movers said by mover-added with
// the caller, and an ended one reopens for a module whose own step failed; no `.again.<n>` pipeline is ever keyed, and a module
// whose head pipeline passed or does not move it is refused by name; exactly one of module or modules is given.
func TestStartWithModulesJoinsTheHeadsPipelineOrReopensIt(t *testing.T) {
v, store, _, asks, acts, _ := verbsFixture()
made := created{}
var started []seat.PipelineStarted
v.Starter.Pipelines = made
var added []seat.MoverAdded
v.Starter.Pipelines, v.Starter.Store = made, store
v.Starter.Say = func(_ string, body any) error {
if ps, ok := body.(seat.PipelineStarted); ok {
started = append(started, ps)
if ev, ok := body.(seat.MoverAdded); ok {
added = append(added, ev)
}
return nil
}
@@ -491,76 +492,71 @@ func TestStartWithModulesStartsAFailedMoverAgainAtTheHead(t *testing.T) {
app.Fp, app.Commit, app.Repository = "src2:aa", "c1", "o/app"
entries["app"] = app
entries["lib"] = catalog.CatalogEntry{Module: "lib", Fp: "src2:bb", Commit: "c2", Repository: "o/lib"}
v.View = func(string) (Half, bool) { return Half{Source: 7, Revision: 9, Entries: entries}, true }
// The fixture's main.5 moves app at src2:aa and failed; lib's newest entry passed in main.8.
e := store[pkey]
e.p.Outcome = seat.PipelineOutcomeFailed
store[pkey] = e
store["main.8"] = struct {
p seat.Pipeline
rev uint64
}{seat.Pipeline{Pipeline: "main.8", Branch: "main", Source: 6, Revision: 8, Outcome: seat.PipelineOutcomePassed,
Movers: []seat.Mover{{Module: "lib", Fingerprint: "src2:bb"}, {Module: "app", Fingerprint: "src2:aa"}}, Superseded: []string{"app"}}, 1}
revision := int64(9)
v.View = func(string) (Half, bool) { return Half{Source: 7, Revision: revision, Entries: entries}, true }
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Module: "app", Modules: []string{"app"}, Why: "x"}); err == nil {
t.Error("a start naming both module and modules was taken")
}
// A pipeline still running at app's head entry refuses the start: two pipelines never build one entry side by side.
store["main.7"] = struct {
p seat.Pipeline
rev uint64
}{seat.Pipeline{Pipeline: "main.7", Branch: "main", Source: 6, Revision: 7, Outcome: seat.PipelineOutcomeRunning,
Movers: []seat.Mover{{Module: "app", Fingerprint: "src2:aa"}}}, 1}
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "its pipeline main.7 is running") {
t.Errorf("a start of app while main.7 runs it = %v; want refused naming main.7", err)
}
delete(store, "main.7")
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app", "lib"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "lib") {
t.Errorf("a start naming lib, whose newest entry passed, = %v; want refused naming lib", err)
}
if len(made) != 0 {
t.Fatalf("a refused start wrote %d pipelines", len(made))
}
a, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "its pipeline failed at an unchanged entry"})
if err != nil || a.Pipeline != "main.9.again.1" || made["main.9.again.1"] == nil {
// A head with no pipeline starts one with both modules, keyed by the revision.
a, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app", "lib"}, Why: "no pipeline for the head"})
if err != nil || a.Pipeline != "main.9" || made["main.9"] == nil {
t.Fatalf("start with modules = %+v, %v; written %v", a, err, len(made))
}
var p seat.Pipeline
if err := json.Unmarshal(made["main.9.again.1"], &p); err != nil {
t.Fatal(err)
if err := json.Unmarshal(made["main.9"], &p); err != nil || len(p.Movers) != 2 {
t.Fatalf("the pipeline = %+v (%v), want app and lib", p, err)
}
if p.Revision != 9 || p.Source != 7 || len(p.Movers) != 1 || p.Movers[0].Module != "app" || p.Movers[0].Fingerprint != "src2:aa" || p.Movers[0].Tier != 1 {
t.Errorf("the pipeline = %+v, want app at src2:aa, tier 1, at revision 9 of source 7", p)
}
if len(started) != 1 || started[0].Pipeline != "main.9.again.1" || started[0].Revision != 9 {
t.Errorf("pipeline-started = %+v, want main.9.again.1 at revision 9 (its revision pinned)", started)
}
// The next start at the same head, once main.9.again.1 failed, takes the next n.
at := time.Unix(3, 0)
p.Outcome, p.Ended = seat.PipelineOutcomeFailed, &at
store["main.9.again.1"] = struct {
// The head's pipeline runs and moves app alone: start of both adds lib, said with the caller; one it moves already is refused.
p.Movers = p.Movers[:1]
store["main.9"] = struct {
p seat.Pipeline
rev uint64
}{p, 1}
if a, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "again"}); err != nil || a.Pipeline != "main.9.again.2" {
t.Errorf("a second start with modules = %+v, %v; want main.9.again.2", a, err)
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app", "lib"}, Why: "lib joins"}); err != nil || a.Pipeline != "main.9" {
t.Fatalf("start of lib while main.9 runs = %+v, %v", a, err)
}
if len(*acts) != 2 {
t.Errorf("hand acts %v, want the two starts recorded", *acts)
if got, _, _ := store.Get("main.9"); !Moves(got, "lib") || len(got.Movers) != 2 || len(added) != 1 || added[0].Module != "lib" || added[0].Caller != "operator" || added[0].Pipeline != "main.9" {
t.Errorf("main.9 moves %+v, mover-added %+v, want lib added by the caller", got.Movers, added)
}
// main.9.again.1 passed: its version is written into it as into any pipeline of its source, and a further start of app is
// refused naming it, read through the branch's key forms.
p.Outcome = seat.PipelineOutcomePassed
store["main.9.again.1"] = struct {
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "main.9") {
t.Errorf("a start of app, which main.9 moves, = %v; want refused naming main.9", err)
}
// The head's pipeline ended: a module with no failed step in it is refused; one whose step failed reopens it.
got, _, _ := store.Get("main.9")
end := time.Unix(3, 0)
got.Outcome, got.Ended, got.Why, got.Steps = seat.PipelineOutcomeFailed, &end, "required steps not passed", nil
e := store["main.9"]
e.p = got
store["main.9"] = e
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "no failed step") {
t.Errorf("a start of app with no failed step in main.9 = %v; want refused", err)
}
p5 := store[pkey].p
for i := range p5.Steps {
if p5.Steps[i].Step == seat.StepResultStepLint {
p5.Steps[i].Outcome, p5.Steps[i].Ended = seat.StepResultOutcomeFailed, &end
}
}
p5.Outcome, p5.Ended, p5.Revision = seat.PipelineOutcomeFailed, &end, 5
store[pkey] = struct {
p seat.Pipeline
rev uint64
}{p, 1}
if wrote, err := v.Hearer.Released(catalog.VersionReleasedEvent{Module: "app", Version: "0.1.2", Source: 7}, "main"); err != nil || wrote != 1 ||
store["main.9.again.1"].p.Movers[0].Version != "0.1.2" {
t.Errorf("the release of app 0.1.2 wrote %d (%v), the again pipeline's mover %+v; want its version written", wrote, err, store["main.9.again.1"].p.Movers)
}{p5, 2}
revision = 5
asked := len(asks.asks)
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "its lint failed"}); err != nil || a.Pipeline != pkey {
t.Fatalf("start of app whose step failed in %s = %+v, %v", pkey, a, err)
}
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "main.9.again.1") {
t.Errorf("a start of app after main.9.again.1 passed = %v; want refused naming it", err)
if got, _, _ := store.Get(pkey); got.Outcome != seat.PipelineOutcomeRunning || got.Ended != nil || len(asks.asks) == asked {
t.Errorf("%s is %s ended %v, %d asks since: want reopened and its failed step asked again", pkey, got.Outcome, got.Ended, len(asks.asks)-asked)
}
for k := range made {
if strings.Contains(k, ".again.") {
t.Errorf("a start keyed %s", k)
}
}
if len(*acts) != 3 {
t.Errorf("hand acts %v, want the three accepted starts recorded", *acts)
}
if !IsStepsKey(StepsKey("main.9.again.1", "app")) {
t.Error("a mover key of an again pipeline is not read as a mover's steps")