P5 H-A-750 (2)(3)(4), H-A-751, H-A-753: start never refuses once the head ended; a key of unfinished reopens whatever its end; a step placed again takes an id of its own, the pipeline's started unmoved
Builds: design 47 H2 H-A-750 (2), H-A-750 (3), H-A-750 (4), H-A-751, H-A-753
This commit is contained in:
@@ -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, 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).",
|
||||
"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, start never refuses: a module it does not move is added to it as a mover, one whose own step failed or whose steps are unfinished reopens it with its closed group, as runner_rerun and runner_unfinished_place do, and one it delivered is answered by it with nothing started. 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,13 +64,7 @@ func (s *Starter) AddMovers(key string, movers []seat.Mover, entries map[string]
|
||||
var names []string
|
||||
for _, m := range added {
|
||||
names = append(names, m.Module)
|
||||
if s.Say == nil {
|
||||
continue
|
||||
}
|
||||
ev := seat.MoverAdded{Pipeline: p.Pipeline, Revision: p.Revision, Module: m.Module, Fingerprint: m.Fingerprint, From: from.From, Caller: from.Caller, TakeIn: from.TakeIn}
|
||||
if err := s.Say(runnerclient.RevisionSubject(seat.EventMoverAdded, p.Branch, subjectRevision(p)), ev); err != nil {
|
||||
s.logf("mover-added of %s in %s is not said: %v", m.Module, key, err)
|
||||
}
|
||||
s.sayMoverAdded(p, m, from)
|
||||
}
|
||||
s.logf("%s: %v added (%s)", key, names, from.describe())
|
||||
if view != nil {
|
||||
@@ -81,6 +75,17 @@ func (s *Starter) AddMovers(key string, movers []seat.Mover, entries map[string]
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// sayMoverAdded says mover-added for m of pipeline p with its origin (design 47 H2 H-A-645).
|
||||
func (s *Starter) sayMoverAdded(p seat.Pipeline, m seat.Mover, from AddedFrom) {
|
||||
if s.Say == nil {
|
||||
return
|
||||
}
|
||||
ev := seat.MoverAdded{Pipeline: p.Pipeline, Revision: p.Revision, Module: m.Module, Fingerprint: m.Fingerprint, From: from.From, Caller: from.Caller, TakeIn: from.TakeIn}
|
||||
if err := s.Say(runnerclient.RevisionSubject(seat.EventMoverAdded, p.Branch, subjectRevision(p)), ev); err != nil {
|
||||
s.logf("mover-added of %s in %s is not said: %v", m.Module, p.Pipeline, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (f AddedFrom) describe() string {
|
||||
switch {
|
||||
case f.From != "":
|
||||
|
||||
@@ -14,8 +14,9 @@ import (
|
||||
// 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.
|
||||
// caller; a head with no pipeline is started with the modules named; once the head's pipeline has ended, start never refuses (H-A-750
|
||||
// (2), H-A-751): a module it does not move reopens it as a mover, one whose own step failed or whose steps are unfinished reopens
|
||||
// it with its closed group as rerun and place-unfinished do, and one it delivered is answered by it. No other pipeline is keyed.
|
||||
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")
|
||||
@@ -94,27 +95,48 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
// The head's pipeline has ended and start never refuses (design 47 H2 H-A-750 (2), H-A-751): a module it does not move is added
|
||||
// to it as a mover; one it moves whose own step failed, or whose required steps did not all pass, reopens it with its closed
|
||||
// group, as rerun and place-unfinished do; one it moved and whose steps passed is delivered by it, nothing to start.
|
||||
entries := half.Entries
|
||||
var group []string
|
||||
var add []seat.Mover
|
||||
for _, m := range movers {
|
||||
group = appendNew(group, v.closedGroup(head, m.Module, entries)...)
|
||||
switch {
|
||||
case !Moves(head, m.Module):
|
||||
add = append(add, m)
|
||||
case len(failedSteps(head, m.Module)) > 0 || !allPassed(head, m.Module):
|
||||
group = appendNew(group, v.closedGroup(head, m.Module, entries)...)
|
||||
}
|
||||
}
|
||||
if len(group) == 0 && len(add) == 0 {
|
||||
return seat.StartAnswer{Pipeline: key}, nil
|
||||
}
|
||||
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 {
|
||||
if err := v.reopenGroup(caller, head, group, add, entries, in.Why); err != nil {
|
||||
return seat.StartAnswer{}, err
|
||||
}
|
||||
s.markCarriedKeys(head, group, head.Pipeline)
|
||||
return seat.StartAnswer{Pipeline: key}, nil
|
||||
}
|
||||
|
||||
// allPassed says whether module has required steps in p and every one passed, was carried or had nothing to run: the pipeline
|
||||
// delivered it.
|
||||
func allPassed(p seat.Pipeline, module string) bool {
|
||||
has := false
|
||||
for _, st := range p.Steps {
|
||||
if st.Module != module || st.Status != seat.StepResultStatusRequired {
|
||||
continue
|
||||
}
|
||||
if has = true; !stepPassed(st) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return has
|
||||
}
|
||||
|
||||
func appendNew(into []string, add ...string) []string {
|
||||
for _, a := range add {
|
||||
if !slices.Contains(into, a) {
|
||||
@@ -165,8 +187,8 @@ func (s *Starter) markCarriedKeys(p seat.Pipeline, group []string, carrier strin
|
||||
// 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)
|
||||
func (v Verbs) reopenGroup(caller string, from seat.Pipeline, group []string, add []seat.Mover, entries map[string]catalog.CatalogEntry, why string) error {
|
||||
reopens, err := v.reopeningFor(from.Pipeline, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -187,16 +209,18 @@ func (v Verbs) reopenGroup(caller string, from seat.Pipeline, group []string, wh
|
||||
cur.Movers = slices.DeleteFunc(slices.Clone(cur.Movers), func(m seat.Mover) bool {
|
||||
return slices.Contains(outside, m.Module) && !slices.Contains(group, m.Module)
|
||||
})
|
||||
// The modules start adds come after the movers outside the group left, and are tiered with the rest (H-A-750 (2)).
|
||||
if len(add) > 0 {
|
||||
cur.Movers = Tiers(append(cur.Movers, add...), entries, s.logf)
|
||||
}
|
||||
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
|
||||
// The steps placed again take ask ids of their own: an id is made from the pipeline's start and its end count, which the
|
||||
// reopen's next end raises (H-A-753); the pipeline's start stays its first (H-A-750 (4)).
|
||||
}
|
||||
}
|
||||
if len(failed) == 0 {
|
||||
if len(failed) == 0 || cur.Outcome == seat.PipelineOutcomeCancelled {
|
||||
cur.Outcome, cur.Why, cur.Ended = seat.PipelineOutcomeRunning, "", nil
|
||||
}
|
||||
if _, err := s.Store.Update(from.Pipeline, cur, rev); errors.Is(err, ErrChanged) {
|
||||
@@ -213,12 +237,21 @@ func (v Verbs) reopenGroup(caller string, from seat.Pipeline, group []string, wh
|
||||
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)
|
||||
// Each module added, and each group mover with no failed step whose steps are placed again, is said by mover-added with the
|
||||
// caller (H-A-750 (2), H-A-751).
|
||||
p, _, err := s.Store.Get(from.Pipeline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the pipeline %s is not read: %w", from.Pipeline, err)
|
||||
}
|
||||
for _, m := range p.Movers {
|
||||
if slices.ContainsFunc(add, func(a seat.Mover) bool { return a.Module == m.Module }) || (slices.Contains(group, m.Module) && !slices.ContainsFunc(failed, func(f seat.StepResult) bool { return f.Module == m.Module })) {
|
||||
s.sayMoverAdded(p, m, AddedFrom{Caller: caller})
|
||||
}
|
||||
}
|
||||
if len(failed) == 0 || len(add) > 0 {
|
||||
if len(failed) == 0 {
|
||||
v.sayReopened(p, true)
|
||||
}
|
||||
v.sayReopened(p, true)
|
||||
if _, err := s.Waiting(s.Store, p.Branch, v.View); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -402,7 +435,7 @@ func (v Verbs) placeGroup(caller string, plan handPlan, why string) (string, err
|
||||
return carrier, nil
|
||||
}
|
||||
}
|
||||
if err := v.reopenGroup(caller, plan.from, plan.group, why); err != nil {
|
||||
if err := v.reopenGroup(caller, plan.from, plan.group, nil, plan.entries, why); err != nil {
|
||||
return "", err
|
||||
}
|
||||
s.markCarriedKeys(plan.from, plan.group, plan.from.Pipeline)
|
||||
|
||||
@@ -78,10 +78,12 @@ func keptAskID(started time.Time, pipeline, module, artifact, step string, kept
|
||||
return strconv.FormatInt(started.UnixMilli(), 36) + hex.EncodeToString(sum[:3])
|
||||
}
|
||||
|
||||
// startOf is a pipeline's start time, the time its step ask ids open with (A-297); now for a pipeline that records none.
|
||||
// startOf is the time a pipeline's step ask ids open with (A-297): its start with its end count added as milliseconds, so a
|
||||
// pipeline never ended keeps every id it has and each reopen gives every later ask an id of its own, the same again at a restart
|
||||
// (design 47 H2 H-A-753); now for a pipeline that records no start.
|
||||
func startOf(p seat.Pipeline, now time.Time) time.Time {
|
||||
if p.Started != nil {
|
||||
return *p.Started
|
||||
return p.Started.Add(time.Duration(p.EndCount) * time.Millisecond)
|
||||
}
|
||||
return now
|
||||
}
|
||||
|
||||
@@ -97,6 +97,18 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) {
|
||||
t.Errorf("ask %d's id %q is not the usual form opened by the pipeline's start: %v", i, id, err)
|
||||
}
|
||||
}
|
||||
// H-A-753: a pipeline of end count 0 asks with the ids it has; one reopened after an end (count 1) asks the steps placed again
|
||||
// with ids of their own, the same on every computation, its start unchanged.
|
||||
m0 := p.Movers[0]
|
||||
same, sameAsks := Place(p, m0, reg, entries, *p.Started, "the-runner")
|
||||
p.EndCount = 1
|
||||
again, againAsks := Place(p, m0, reg, entries, *p.Started, "the-runner")
|
||||
again2, _ := Place(p, m0, reg, entries, p.Started.Add(time.Hour), "the-runner")
|
||||
if len(sameAsks) != len(asks.ids) || len(againAsks) != len(asks.ids) || same[0].Ask != asks.ids[0] || again[0].Ask == same[0].Ask || again[0].Ask != again2[0].Ask ||
|
||||
!strings.HasPrefix(again[0].Ask, strconv.FormatInt(p.Started.UnixMilli()+1, 36)) {
|
||||
t.Errorf("ids at end count 0 %q, at 1 %q and %q; want today's ids at 0, others at 1 that a later computation repeats", same[0].Ask, again[0].Ask, again2[0].Ask)
|
||||
}
|
||||
p.EndCount = 0
|
||||
// H-A-516: the build step's record carries its asked-at, as a test step's does.
|
||||
if p.Steps[0].AskedAt == nil || !p.Steps[0].AskedAt.Equal(*p.Steps[0].Started) {
|
||||
t.Errorf("the build step's asked-at = %v, want the time it was asked", p.Steps[0].AskedAt)
|
||||
|
||||
@@ -521,6 +521,19 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
|
||||
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"])
|
||||
}
|
||||
// H-A-750 (3): a key whose pipeline ended cancelled reopens it as a failed one is.
|
||||
c, rev, _ = mem.Get("main.14")
|
||||
c.Outcome, c.Ended = seat.PipelineOutcomeCancelled, &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":"cancelled"}`
|
||||
if a, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "again"}); err != nil || len(a.Placed) != 1 {
|
||||
t.Fatalf("place-unfinished of a key of a cancelled pipeline = %+v (%v), want it placed", a, err)
|
||||
}
|
||||
if p, _, _ := mem.Get("main.14"); p.Outcome != seat.PipelineOutcomeRunning || p.Ended != nil {
|
||||
t.Errorf("main.14 is %s ended %v, want the cancelled pipeline reopened", p.Outcome, p.Ended)
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -311,11 +311,16 @@ func (v Verbs) sayReopened(p seat.Pipeline, reopens bool) {
|
||||
}
|
||||
|
||||
// reopening says whether a rerun of pipeline key reopens an ended delivering pipeline, refusing it when its revision is
|
||||
// gone (H-A-479 addendum (2)). A pipeline not read, a run's, or one the rerun refuses anyway is left to the rerun.
|
||||
func (v Verbs) reopening(key string) (bool, error) {
|
||||
// gone (H-A-479 addendum (2)). A pipeline not read, a run's, or one the rerun refuses anyway is left to the rerun. With hand
|
||||
// set, a pipeline that ended cancelled is reopened too: a key of unfinished reopens the pipeline it names whatever its end
|
||||
// (design 47 H2 H-A-750 (3)).
|
||||
func (v Verbs) reopening(key string) (bool, error) { return v.reopeningFor(key, false) }
|
||||
|
||||
// reopeningFor is reopening, a pipeline that ended cancelled reopened too when hand is set.
|
||||
func (v Verbs) reopeningFor(key string, hand bool) (bool, error) {
|
||||
p, _, err := v.Hearer.Store.Get(key)
|
||||
if err != nil || p.Ended == nil || p.Run != "" || p.Revision <= 0 ||
|
||||
p.Outcome == seat.PipelineOutcomeCancelled || p.Outcome == seat.PipelineOutcomeSuperseded {
|
||||
if err != nil || p.Ended == nil || p.Run != "" || p.Revision <= 0 || p.Outcome == seat.PipelineOutcomeSuperseded ||
|
||||
(p.Outcome == seat.PipelineOutcomeCancelled && !hand) {
|
||||
return false, nil
|
||||
}
|
||||
// A reopening never builds beside an open pipeline carrying one of its movers at the same revision (H-A-479 third
|
||||
|
||||
@@ -522,15 +522,40 @@ func TestStartWithModulesJoinsTheHeadsPipelineOrReopensIt(t *testing.T) {
|
||||
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.
|
||||
// The head's pipeline ended and start never refuses (H-A-750 (2)): app, which it moved and whose steps passed, is answered
|
||||
// delivered by it, no act written and nothing said.
|
||||
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)
|
||||
got.Outcome, got.Ended, got.Why = seat.PipelineOutcomePassed, &end, ""
|
||||
got.Steps = []seat.StepResult{{Module: "app", Step: seat.StepResultStepBuild, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomePassed}}
|
||||
set := func(p seat.Pipeline) {
|
||||
e := store["main.9"]
|
||||
e.p = p
|
||||
store["main.9"] = e
|
||||
}
|
||||
set(got)
|
||||
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err != nil || a.Pipeline != "main.9" || len(*acts) != 2 || len(added) != 1 {
|
||||
t.Errorf("a start of app, delivered by main.9, = %+v, %v with %d acts and %d mover-added; want main.9, no act, nothing said", a, err, len(*acts), len(added))
|
||||
}
|
||||
// lib, which the ended head does not move, reopens it as a mover said by mover-added with the caller.
|
||||
got.Movers = got.Movers[:1]
|
||||
set(got)
|
||||
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"lib"}, Why: "lib reopens main.9"}); err != nil || a.Pipeline != "main.9" {
|
||||
t.Fatalf("start of lib, which ended main.9 does not move, = %+v, %v", a, err)
|
||||
}
|
||||
if got, _, _ = store.Get("main.9"); got.Outcome != seat.PipelineOutcomeRunning || got.Ended != nil || !Moves(got, "lib") || len(added) != 2 || added[1].Module != "lib" || added[1].Caller != "operator" {
|
||||
t.Errorf("main.9 is %s ended %v moving %+v, mover-added %+v; want it reopened with lib added by the caller", got.Outcome, got.Ended, got.Movers, added)
|
||||
}
|
||||
// A head that ended cancelled and left app unfinished (H-A-751): start of app reopens it with its group as place-unfinished
|
||||
// does, said by mover-added with the caller.
|
||||
first := time.Unix(1, 0)
|
||||
got.Outcome, got.Ended, got.Steps, got.Started = seat.PipelineOutcomeCancelled, &end, nil, &first
|
||||
set(got)
|
||||
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "app left unfinished"}); err != nil || a.Pipeline != "main.9" {
|
||||
t.Fatalf("start of app, which cancelled main.9 left unfinished, = %+v, %v", a, err)
|
||||
}
|
||||
if got, _, _ = store.Get("main.9"); got.Outcome != seat.PipelineOutcomeRunning || got.Ended != nil || len(added) != 3 || added[2].Module != "app" || added[2].Caller != "operator" || Moves(got, "lib") || got.Started == nil || !got.Started.Equal(first) {
|
||||
t.Errorf("main.9 is %s ended %v, mover-added %+v; want it reopened and its unfinished movers said by the caller", got.Outcome, got.Ended, added)
|
||||
}
|
||||
p5 := store[pkey].p
|
||||
for i := range p5.Steps {
|
||||
@@ -556,8 +581,8 @@ func TestStartWithModulesJoinsTheHeadsPipelineOrReopensIt(t *testing.T) {
|
||||
t.Errorf("a start keyed %s", k)
|
||||
}
|
||||
}
|
||||
if len(*acts) != 3 {
|
||||
t.Errorf("hand acts %v, want the three accepted starts recorded", *acts)
|
||||
if len(*acts) != 5 {
|
||||
t.Errorf("hand acts %v, want the five starts that did something 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")
|
||||
|
||||
Reference in New Issue
Block a user