Merge pull request 'mesh-delivery-pipeline: a predecessor a newer revision moved ties nothing, in every path that reopens a pipeline or reads its ties (design 47 H2 H-A-770; issue 1984)' (#370) from fix/47-H2-770-moved-predecessor-unties into main

This commit was merged in pull request #370.
This commit is contained in:
2026-11-26 02:09:34 +00:00
9 changed files with 525 additions and 65 deletions
@@ -166,7 +166,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if err != nil {
return nil
}
return pipeline.HeldBehind(p, module, half.Entries)
// The head's revision says which movers a newer revision moved: they tie nothing (design 47 H2 H-A-594 (2), H-A-761).
head, _ := rv.Catalog.View(p.Branch)
return pipeline.HeldBehind(p, module, half.Entries, head)
}}
// Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state
// bounds. A step's ask is put as a kept call within the same bound (design 47 H2 §775).
@@ -297,6 +299,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
return kept
}
unfinished.Registered = func(module string) bool { _, ok := rv.Registrations.Registration(module); return ok }
// The head's revision, the newest the view holds (H-A-759): a mover a newer revision moved ties nothing at a pipeline's end
// (design 47 H2 H-A-594 (2), H-A-761).
unfinished.Head = rv.Catalog.View
unfinished.Add = func(from seat.Pipeline, group []seat.Mover) (string, bool) {
half, ok := rv.Catalog.View(from.Branch)
if !ok {
@@ -39,6 +39,8 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
{Module: "free", Branches: []string{"main"}, Origin: "o/free", Policy: catalog.Policy{Steps: steps}}}
var newest atomic.Int64
newest.Store(1)
var aged atomic.Int64 // a revision the catalog keeps no more, none until the H-A-608 step ages revision 1 out
aged.Store(-1)
w := startWhole(t, ctx, regs, func(in []byte) catalog.RevisionAnswer {
var q catalog.RevisionInput
_ = json.Unmarshal(in, &q)
@@ -46,7 +48,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
if n == 0 {
n = newest.Load()
}
if n == 99 { // a revision the catalog keeps no more
if n == aged.Load() { // a revision the catalog keeps no more
return catalog.RevisionAnswer{}
}
lib, goFp := "l1", "src2:go"
@@ -368,12 +370,14 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
t.Error("main.gitea is still unfinished after main.8 passed")
}
// design 47 H2 H-A-608 (AC-P4), whole: free's key names revision 99, which the catalog keeps no more; the take-in of revision 9
// design 47 H2 H-A-608 (AC-P4), whole: free's key names revision 1, which the catalog keeps no more; the take-in of revision 9
// reads it at the head's revision, where free holds the key's fingerprint, and carries it; ghost's fingerprint is held at neither
// revision, so its key is dropped and the journal names the fingerprint and the revisions looked at.
// revision, so its key is dropped and the journal names the fingerprint and the revisions looked at. The keys name a revision
// older than the head's, since a head not newer than a key's pipeline drops nothing (H-A-770 (5), (6)).
aged.Store(1)
for key, entry := range map[string]string{
"main.free": `{"fingerprint":"src2:f2","revision":99,"pipeline":"main.99","outcome":"failed"}`,
"main.ghost": `{"fingerprint":"src2:zz","revision":99,"pipeline":"main.99","outcome":"failed"}`,
"main.free": `{"fingerprint":"src2:f2","revision":1,"pipeline":"main.1","outcome":"failed"}`,
"main.ghost": `{"fingerprint":"src2:zz","revision":1,"pipeline":"main.1","outcome":"failed"}`,
} {
if _, err := unfinished.Put(ctx, key, []byte(entry)); err != nil {
t.Fatal(err)
@@ -384,7 +388,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
if pe := endOf(); pe.Pipeline != "main.9" || pe.Outcome != seat.PipelineEndedOutcomePassed || !moves("main.9", "app", "free") {
t.Fatalf("main.9 ended %s %s, moving free %t: want free read at the head's revision and carried\n%s", pe.Pipeline, pe.Outcome, moves("main.9", "free"), w.logs.String())
}
if _, ok := unfinishedEntry("main.ghost"); ok || !strings.Contains(w.logs.String(), "ghost is no longer unfinished at fingerprint src2:zz: its kept revision 99 is gone, the head's revision 9 of main holds it at") {
if _, ok := unfinishedEntry("main.ghost"); ok || !strings.Contains(w.logs.String(), "ghost is no longer unfinished at fingerprint src2:zz: its kept revision 1 is gone, the head's revision 9 of main holds it at") {
t.Errorf("main.ghost is kept, or the journal does not name its fingerprint and the revisions looked at:\n%s", w.logs.String())
}
@@ -164,8 +164,10 @@ func moduleNames(movers []seat.Mover) []string {
}
// HeldBehind are the movers of p, sorted, that the failed mover module holds back: those whose own steps held and that await
// it, directly or through others, or sit in the tier group of one that does (H-A-625 (2)).
func HeldBehind(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) []string {
// it, directly or through others, or sit in the tier group of one that does (H-A-625 (2)). With head, the head's revision, a
// mover of p a newer revision moved, the head's entry holding another fingerprint, ties nothing and is held behind nothing, as the
// carry reads it (design 47 H2 H-A-594 (2), H-A-761, H-A-770 (5)).
func HeldBehind(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry, head Half) []string {
failed := failedMovers(p)
var left []string
for _, m := range p.Movers {
@@ -173,6 +175,8 @@ func HeldBehind(p seat.Pipeline, module string, entries map[string]catalog.Catal
left = append(left, m.Module)
}
}
moved := movedAmong(p, appendNew(slices.Clone(left), failed...), head)
left, failed = without(left, moved), without(failed, moved)
var out []string
for m, by := range tiedTo(p, left, failed, entries) {
if slices.Contains(by, module) {
@@ -167,7 +167,7 @@ func TestEachFailingMoverIsAFindingAndItsNextPassedPipelineClearsIt(t *testing.T
Movers: []seat.Mover{{Module: "engine", Commit: "c1"}, {Module: "gitea"}},
Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed},
{Module: "gitea", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}}
fl := &Failures{Findings: f, Observer: "runner", Behind: func(p seat.Pipeline, m string) []string { return HeldBehind(p, m, entries) }}
fl := &Failures{Findings: f, Observer: "runner", Behind: func(p seat.Pipeline, m string) []string { return HeldBehind(p, m, entries, Half{}) }}
fl.StepEnded(nil, p, p.Steps[0])
got := f.held["delivery.engine.main.pipeline-failed"]
if !strings.Contains(got.Explanation, "gitea are held behind it") || !strings.Contains(got.Explanation, "runner_unfinished_place") {
@@ -3,6 +3,7 @@ package pipeline
import (
"errors"
"fmt"
"maps"
"slices"
"strings"
@@ -53,7 +54,7 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error
key := headKey(in.Branch, half)
// A module whose own step failed in a pipeline older than the head reopens that pipeline as rerun does, never joins the head's
// (design 47 H2 H-A-643, H-A-594 (3)); the call is one hand act.
older, movers, err := v.ownFailedPipelines(in.Branch, key, movers, half.Entries)
older, movers, err := v.ownFailedPipelines(in.Branch, key, movers, half)
if err != nil {
return seat.StartAnswer{}, err
}
@@ -62,6 +63,7 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error
return seat.StartAnswer{}, err
}
for _, o := range older {
s.passMovedOn(o.from, half.Revision, o.passed)
if err := v.reopenGroup(caller, o.from, o.group, nil, o.entries, in.Why); err != nil {
return seat.StartAnswer{}, err
}
@@ -125,12 +127,15 @@ func (v Verbs) startAtHead(caller string, in seat.StartInput, half Half, key str
entries := half.Entries
var group []string
var add []seat.Mover
passed := map[string]movedMover{}
for _, m := range movers {
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)...)
g, by := v.closedGroup(head, m.Module, half)
group = appendNew(group, g...)
maps.Copy(passed, by)
}
}
if len(group) == 0 && len(add) == 0 {
@@ -139,6 +144,7 @@ func (v Verbs) startAtHead(caller string, in seat.StartInput, half Half, key str
if err := v.record(seat.VerbStart, what, in.Why); err != nil {
return seat.StartAnswer{}, err
}
s.passMovedOn(head, half.Revision, passed)
if err := v.reopenGroup(caller, head, group, add, entries, in.Why); err != nil {
return seat.StartAnswer{}, err
}
@@ -151,6 +157,8 @@ type ownPipeline struct {
from seat.Pipeline
group []string
entries map[string]catalog.CatalogEntry
// passed are the movers of from a newer revision moved that the group passes (design 47 H2 H-A-594 (2), H-A-761).
passed map[string]movedMover
}
func olderModules(o []ownPipeline) []string {
@@ -163,7 +171,8 @@ func olderModules(o []ownPipeline) []string {
// ownFailedPipelines splits movers: those whose own required step failed in the newest pipeline of the branch other than the
// head's `key` that moves them, which ended (design 47 H2 H-A-643), with the closed group each such pipeline reopens for, and the movers left.
func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headEntries map[string]catalog.CatalogEntry) ([]ownPipeline, []seat.Mover, error) {
func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, half Half) ([]ownPipeline, []seat.Mover, error) {
headEntries := half.Entries
s := v.Starter
pkeys, err := branchKeys(s.Store, branch)
if err != nil {
@@ -193,8 +202,13 @@ func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headE
}
// Only the newest pipeline that moves the module counts: a newer one that passed it leaves the failure behind.
found = found && best.Ended != nil && len(failedSteps(best, m.Module)) > 0
// H-A-761: it reopens only at the fingerprint the head's entry holds; otherwise its key is dropped and said.
if bm, _ := MoverOf(best, m.Module); found && bm.Fingerprint != m.Fingerprint {
// H-A-761: it reopens only at the fingerprint the head's entry holds; otherwise its key is dropped and said. While the head
// is not newer than that pipeline's revision, a lagging view, it reopens nothing and its key is kept (H-A-770 (5), (6)).
if bm, _ := MoverOf(best, m.Module); found && bm.Fingerprint != m.Fingerprint && half.Revision <= best.Revision {
s.logf("start of %s reopens nothing of %s, which moves it at %s: the head's revision %d of %s holds it at %s and is not newer than %s's revision %d, so its key is kept and it is judged again when the view moves (H-A-770 (5), (6))",
m.Module, best.Pipeline, bm.Fingerprint, half.Revision, branch, m.Fingerprint, best.Pipeline, best.Revision)
found = false
} else if found && bm.Fingerprint != m.Fingerprint {
if k := UnfinishedKey(branch, m.Module); s.Unfinished != nil {
if _, ok, _ := s.Unfinished.Entry(k); ok {
s.Unfinished.dropMoved(k, m.Module, bm.Fingerprint, fmt.Sprintf("%s moved it at %s (revision %d); the head's revision of %s holds it at %s (H-A-761)", best.Pipeline, bm.Fingerprint, best.Revision, branch, m.Fingerprint))
@@ -210,10 +224,12 @@ func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headE
at := slices.IndexFunc(out, func(o ownPipeline) bool { return o.from.Pipeline == best.Pipeline })
if at < 0 {
// Its movers are read at the head's revision, whose entries are the newest (design 47 H2 H-A-763 (3)).
out = append(out, ownPipeline{from: best, entries: headEntries})
out = append(out, ownPipeline{from: best, entries: headEntries, passed: map[string]movedMover{}})
at = len(out) - 1
}
out[at].group = appendNew(out[at].group, v.closedGroup(best, m.Module, out[at].entries)...)
g, by := v.closedGroup(best, m.Module, half)
out[at].group = appendNew(out[at].group, g...)
maps.Copy(out[at].passed, by)
}
return out, rest, nil
}
@@ -244,10 +260,26 @@ func appendNew(into []string, add ...string) []string {
// 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)...)
// H-A-646). A passed mover is never in it. It is read over head, the head's revision, whose edges are the newest (H-A-763 (3)): a
// mover of p a newer revision moved, the head's entry holding another fingerprint than p's, counts as carried by that revision's
// pipeline and is in no group (H-A-594 (2), H-A-761, H-A-770 (5)); passed are those the group would hold otherwise, to be said and
// their keys dropped.
func (v Verbs) closedGroup(p seat.Pipeline, module string, head Half) (group []string, passed map[string]movedMover) {
entries := head.Entries
moved := movedOn(p, head)
delete(moved, module)
universe := appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...)
passed = map[string]movedMover{}
for _, m := range closeOver(p, module, universe, entries) {
if mv, ok := moved[m]; ok {
passed[m] = mv
}
}
return closeOver(p, module, without(universe, moved), entries), passed
}
// closeOver is module's group among universe, movers of p: closed under the tier edges and the awaited edges (closedGroup).
func closeOver(p seat.Pipeline, module string, universe []string, entries map[string]catalog.CatalogEntry) []string {
group := []string{module}
for changed := true; changed; {
changed = false
@@ -272,6 +304,23 @@ func (v Verbs) closedGroup(p seat.Pipeline, module string, entries map[string]ca
return group
}
// passMovedOn says each of moved, movers of p a newer revision moved, as carried by that revision's pipeline, naming both
// fingerprints and the revisions read (head, the head's revision), and drops its unfinished key where that names another
// fingerprint than the head's entry (design 47 H2 H-A-594 (2), H-A-761).
func (s *Starter) passMovedOn(p seat.Pipeline, head int64, moved map[string]movedMover) {
for _, m := range slices.Sorted(maps.Keys(moved)) {
why := movedWords(p, m, moved[m], head)
if s.Unfinished != nil {
k := UnfinishedKey(p.Branch, m)
if e, held, _ := s.Unfinished.Entry(k); held && e.Fingerprint != moved[m].Head {
s.Unfinished.dropMoved(k, m, e.Fingerprint, why)
continue
}
}
s.logf("%s", why)
}
}
// 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 {
@@ -364,6 +413,10 @@ type handPlan struct {
movers []seat.Mover
// entries are the entries a carry tiers its movers from.
entries map[string]catalog.CatalogEntry
// passed are the movers of from a newer revision moved that the group passes, read at the head's revision head (design 47 H2
// H-A-594 (2), H-A-761).
passed map[string]movedMover
head int64
}
// 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
@@ -399,6 +452,11 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) {
// the kept revision H-A-608 names stays the revision the record pins, and is only said.
kept := s.Unfinished.keptRevision(e, module)
head, hok := v.View(branch)
if he := head.Entries[module]; (!hok || he.Fp != e.Fingerprint) && head.Revision <= from.Revision {
// A lagging view: nothing is dropped and the key is judged again when the view moves (design 47 H2 H-A-770 (5), (6)).
return handPlan{}, fmt.Errorf("%s at fingerprint %s is not placed: the head's revision %d of %s holds it at %q and is not newer than the revision %d of its pipeline %s; its kept revision %d; nothing was dropped, it is judged again when the view moves (H-A-770 (5), (6))",
module, e.Fingerprint, head.Revision, branch, he.Fp, from.Revision, from.Pipeline, kept)
}
if he := head.Entries[module]; !hok || he.Fp != e.Fingerprint {
why := fmt.Sprintf("the head's revision %d of %s holds it at %q, not at the key's %q; its kept revision %d", head.Revision, branch, he.Fp, e.Fingerprint, kept)
s.Unfinished.dropMoved(key, module, e.Fingerprint, why)
@@ -408,9 +466,9 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) {
return handPlan{}, fmt.Errorf("%s at fingerprint %s is read at the head's revision %d of %s, which has no source", module, e.Fingerprint, head.Revision, branch)
}
half := head
group := v.closedGroup(from, module, half.Entries)
group, passed := v.closedGroup(from, module, half)
from.Movers = slices.Clone(from.Movers)
plan := handPlan{from: from, group: group, entries: half.Entries}
plan := handPlan{from: from, group: group, entries: half.Entries, passed: passed, head: half.Revision}
for _, g := range group {
adoptHead(&from, g, half.Entries) // a mover joins the head at the head's commit (design 47 H2 H-A-769 (1), H-A-768)
mv, _ := MoverOf(from, g)
@@ -517,6 +575,7 @@ func (v Verbs) PlaceUnfinished(caller string, in seat.PlaceUnfinishedInput) (sea
// 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
s.passMovedOn(plan.from, plan.head, plan.passed)
failed := false
for _, m := range plan.group {
failed = failed || len(failedSteps(plan.from, m)) > 0
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"strings"
"testing"
@@ -521,6 +522,7 @@ func TestAMoverReopenedIsAskedWithTheHeadsPins(t *testing.T) {
// design 47 H2 H-A-763 (3): the group a hand place or start's reopen closes is read over the head's entries, whose edges are the newest:
// an edge the head's entry of lib has and its kept revision's has not puts app, which lib waits for, in the group.
func TestAReopenedGroupIsClosedOverTheHeadsEdges(t *testing.T) {
t.Run("a predecessor a newer revision moved ties nothing", testAPredecessorANewerRevisionMovedTiesNothing)
reg, entries := placeFixture()
mk := func(module, fp string, edges []catalog.Edge) catalog.CatalogEntry {
return catalog.CatalogEntry{Module: module, Fp: fp, Commit: "c1", Repository: "o/" + module, Path: "modules/" + module, Edges: edges,
@@ -642,3 +644,268 @@ func TestAPlacedGroupJoinsTheHeadAtTheHeadsCommit(t *testing.T) {
t.Errorf("no build was asked of the joined mover (asks %d)", len(asks.asks))
}
}
// design 47 H2 H-A-594 (2), (3), (4), H-A-761 (issue 1984; main.530's mesh-delivery-builder, failed at src2:0da7a2b0 and built at
// src2:f28847e6 in main.531, refused start's reopen of main.530 whole and tied 21 movers at the carry of revision 537): a predecessor
// whose head entry holds another fingerprint than its pipeline's counts as carried by the newer revision. In every path that reads a
// closed group's ties or reopens a failed pipeline's group it ties nothing, leaves the group, its key dropped and said naming both
// fingerprints and the revisions read; the group goes on. One row per path.
// testAPredecessorANewerRevisionMovedTiesNothing is a row of TestAReopenedGroupIsClosedOverTheHeadsEdges (the module's tests are
// folded under its budget).
func testAPredecessorANewerRevisionMovedTiesNothing(t *testing.T) {
saidOf := func(said []string) string { return strings.Join(said, "\n") }
namesBoth := func(j, module, pipeline, at, head string, rev int64) bool {
return strings.Contains(j, module+" of "+pipeline+" counts as carried by a newer revision") && strings.Contains(j, at) &&
strings.Contains(j, fmt.Sprintf("head's revision %d", rev)) && strings.Contains(j, `at "`+head+`"`)
}
// The carries (Unfinished): main.5 ended failed, engine failed at f1, gitea left unfinished awaiting engine's package; stale left
// unfinished at f4. The head's revision 7 holds engine at f1b and stale at f4b, both moved by a newer revision.
failed := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, Outcome: seat.PipelineOutcomeFailed,
Movers: []seat.Mover{{Module: "engine", Fingerprint: "f1"}, {Module: "gitea", Fingerprint: "f2"}, {Module: "stale", Fingerprint: "f4"}},
Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed},
{Module: "gitea", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked},
{Module: "stale", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}}
edges := map[string]catalog.CatalogEntry{}
edgeInto(edges, "gitea", "engine", 1)
moved := map[string]catalog.CatalogEntry{"engine": {Commit: "c7", Fp: "f1b"}, "gitea": {Commit: "c7", Fp: "f2"}, "stale": {Commit: "c7", Fp: "f4b"}}
t.Run("the carry at a take-in", func(t *testing.T) {
for _, engine := range []string{"f1", "f1b"} {
var said []string
u := &Unfinished{Store: memUnfinished{"main.gitea": `{"fingerprint":"f2","revision":5,"pipeline":"main.5","outcome":"failed"}`},
Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) },
Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return edges, true },
Pipeline: func(string) (seat.Pipeline, bool) { return failed, true }}
head := maps.Clone(moved)
head["engine"] = catalog.CatalogEntry{Commit: "c7", Fp: engine}
got := u.Carry("main", 7, head, nil)
if engine == "f1" { // the head holds engine at its failed fingerprint: gitea stays tied
if len(got) != 0 || !strings.Contains(saidOf(said), "tied to [engine]") {
t.Errorf("with engine at f1 the carry = %+v (said %q), want gitea tied to engine", got, said)
}
continue
}
if len(got) != 1 || got[0].Module != "gitea" || got[0].Fingerprint != "f2" || !namesBoth(saidOf(said), "engine", "main.5", "f1", "f1b", 7) {
t.Errorf("with engine moved to f1b the carry = %+v (said %q), want gitea carried and engine said with both fingerprints", got, said)
}
}
})
t.Run("the carry at a pipeline's end", func(t *testing.T) {
var said []string
var added []string
st := memUnfinished{}
u := &Unfinished{Store: st, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) },
Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return edges, true },
Head: func(string) (Half, bool) { return Half{Revision: 7, Source: 9, Entries: moved}, true },
Add: func(_ seat.Pipeline, group []seat.Mover) (string, bool) {
added = append(added, moduleNames(group)...)
return "main.7", true
}}
u.Ended(failed)
if !slices.Equal(added, []string{"gitea"}) || st["main.stale"] != "" || !namesBoth(saidOf(said), "engine", "main.5", "f1", "f1b", 7) ||
!namesBoth(saidOf(said), "stale", "main.5", "f4", "f4b", 7) {
t.Errorf("at main.5's end added %v, state %v, said %q: want gitea carried, stale not kept, engine and stale said", added, st, said)
}
})
// H-A-770 (5): while the runner's view of the head is at main.5's revision or older, a head entry at another fingerprint counts
// for nothing: gitea stays tied to engine, stale stays unfinished, nothing is said moved; they are judged again when it moves.
t.Run("a lagging view drops and unties nothing", func(t *testing.T) {
for _, rev := range []int64{5, 4} {
var said, added []string
st := memUnfinished{}
u := &Unfinished{Store: st, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) },
Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return edges, true },
Head: func(string) (Half, bool) { return Half{Revision: rev, Source: 9, Entries: moved}, true },
Add: func(_ seat.Pipeline, group []seat.Mover) (string, bool) {
added = append(added, moduleNames(group)...)
return "main.7", true
}}
u.Ended(failed)
if !slices.Equal(added, []string{"stale"}) || st["main.gitea"] == "" || st["main.stale"] == "" || strings.Contains(saidOf(said), "counts as carried") {
t.Errorf("with the view at revision %d main.5's end added %v, state %v, said %q: want gitea tied and kept, stale kept and carried, nothing said moved", rev, added, st, said)
}
}
})
// H-A-770 (6): the same holds for H-A-761's drop of a key for its own mover: the carry at a take-in of revision 5 or older keeps
// gitea's key of main.5, said, and carries nothing (the place's row is in TestTakenInStartsOnlyItsEntries).
t.Run("a lagging view: the carry at a take-in keeps the key", func(t *testing.T) {
for _, rev := range []int64{5, 4} {
var said []string
st := memUnfinished{"main.gitea": `{"fingerprint":"f2","revision":5,"pipeline":"main.5","outcome":"failed"}`}
u := &Unfinished{Store: st, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }}
got := u.Carry("main", rev, map[string]catalog.CatalogEntry{"gitea": {Commit: "c7", Fp: "f2b"}}, nil)
if len(got) != 0 || st["main.gitea"] == "" || !strings.Contains(saidOf(said), "keeps its key") {
t.Errorf("a take-in of revision %d carried %+v, state %v, said %q: want the key kept and said, nothing carried", rev, got, st, said)
}
}
})
// H-A-770 (6): start with the view at revision 9, older than main.10, which failed app at src2:aa, while the view holds app at
// src2:a2: it reopens nothing, starts at the head as it does today, and keeps app's key, said.
t.Run("a lagging view: start keeps the key", func(t *testing.T) {
reg, entries := placeFixture()
e := entries["app"]
e.Fp, e.Commit = "src2:a2", "c2"
view := Half{Revision: 9, Source: 40, Entries: map[string]catalog.CatalogEntry{"app": e, "mesh-build-go": entries["mesh-build-go"]}}
store := &MoverStore{Raw: newMemRaw()}
end := time.Unix(50, 0)
old := seat.Pipeline{V: 1, Pipeline: Key("main", 10), Branch: "main", Revision: 10, Source: 41, Outcome: seat.PipelineOutcomeFailed, Ended: &end, EndCount: 1,
Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}},
Steps: []seat.StepResult{{Module: "app", Artifact: "app:program", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed, Ended: &end}}}
raw, _ := json.Marshal(old)
if err := store.Create(old.Pipeline, raw); err != nil {
t.Fatal(err)
}
u := memUnfinished{"main.app": `{"fingerprint":"src2:aa","revision":10,"pipeline":"` + old.Pipeline + `","outcome":"failed"}`}
var said []string
logf := func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }
s := &Starter{Pipelines: store, Store: store, Steps: &stepAsks{}, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil }, Logf: logf,
Revision: func(string, int64) (Half, error) { return view, nil },
Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }, Unfinished: &Unfinished{Store: u, Logf: logf}}
v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }},
View: func(string) (Half, bool) { return view, true }, Acts: &actLog{}}
a, err := v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "app", Why: "again"})
if err != nil || a.Pipeline != Key("main", 9) || u["main.app"] == "" || !strings.Contains(saidOf(said), "reopens nothing of main.10") {
t.Errorf("start = %+v (%v), app's key %q, said %q: want main.9 started at the head, the key kept and said", a, err, u["main.app"], said)
}
if p, _, _ := store.Get(old.Pipeline); p.Ended == nil {
t.Errorf("main.10 was reopened, want it left ended")
}
})
// The finding pipeline-failed's held-behind list (H-A-625 (2)) reads the head as the carry does: gitea awaits the failed engine's
// package and mate awaits gitea's; a mover a newer revision moved is held behind nothing and holds nothing behind it.
t.Run("the finding's held-behind list", func(t *testing.T) {
p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, Outcome: seat.PipelineOutcomeRunning,
Movers: []seat.Mover{{Module: "engine", Fingerprint: "f1"}, {Module: "gitea", Fingerprint: "f2"}, {Module: "mate", Fingerprint: "f3"}},
Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed},
{Module: "gitea", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked},
{Module: "mate", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}}
ties := maps.Clone(edges)
edgeInto(ties, "mate", "gitea", 1)
at := func(engine, gitea string) Half {
return Half{Revision: 7, Entries: map[string]catalog.CatalogEntry{"engine": {Fp: engine}, "gitea": {Fp: gitea}, "mate": {Fp: "f3"}}}
}
for _, c := range []struct {
head Half
want []string
}{{Half{}, []string{"gitea", "mate"}}, {at("f1", "f2"), []string{"gitea", "mate"}}, {at("f1b", "f2"), nil}, {at("f1", "f2b"), nil}} {
if got := HeldBehind(p, "engine", ties, c.head); !slices.Equal(got, c.want) {
t.Errorf("held behind engine with the head %v = %v, want %v", c.head, got, c.want)
}
}
})
// A rerun of a step that reads a test run reopens its ended pipeline as rerun does (H-A-594 (3)): lib, failed at src2:bb and
// moved by a newer revision to src2:b2, leaves its movers, said.
t.Run("rerun of a test run", func(t *testing.T) {
f := newRunFixture()
reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required",
Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass", Validate: "bypass"}}}
f.s.Registration = func(string) (catalog.Registration, bool) { return reg, true }
p := f.start(t, 4, 9)
e := f.store[p.Pipeline]
e.p.Steps[0].Outcome = seat.StepResultOutcomePassed // the build
f.store[p.Pipeline] = e
unit := stepNamed(p, "app:program", "unit")
ended := time.Now()
if _, err := f.h.OnStepEnded(stepSeatOf(t, "node-build-go"), "mesh.seat.node-build-go.event.step-ended.ace", StepEnded{ID: unit.Ask,
Pipeline: p.Pipeline, Module: "app", Commit: "c1", Fingerprint: "src2:aa", Step: "unit", Node: "ace", Outcome: "failed", Ended: &ended}); err != nil {
t.Fatal(err)
}
e = f.store[p.Pipeline]
if e.p.Outcome != seat.PipelineOutcomeFailed {
t.Fatalf("the pipeline is %s after the failing run, want failed", e.p.Outcome)
}
e.p.Movers = append(e.p.Movers, seat.Mover{Module: "lib", Commit: "c1", Fingerprint: "src2:bb"})
e.p.Steps = append(e.p.Steps, seat.StepResult{Module: "lib", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed, Ended: &ended})
f.store[p.Pipeline] = e
v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) {
return Half{Revision: 13, Entries: map[string]catalog.CatalogEntry{
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"lib": {Module: "lib", Fp: "src2:b2"},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true
}, Acts: &actLog{}}
if _, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Module: "app", Step: "unit", Artifact: "app:tools", Why: "flaky"}); err != nil {
t.Fatal(err)
}
f.mu.Lock()
j := saidOf(f.logged)
f.mu.Unlock()
if q := f.pipeline(p); Moves(q, "lib") || !Moves(q, "app") || !namesBoth(j, "lib", p.Pipeline, "src2:bb", "src2:b2", 13) {
t.Errorf("%s moves %+v and the journal says %q: want lib gone, said with both fingerprints", p.Pipeline, q.Movers, j)
}
})
// The reopens (Verbs): main.10 moves app and lib at revision 10; the head's revision 13 holds lib at src2:b2, which a newer
// revision moved, and app's entry there awaits lib's package.
reg, entries := placeFixture()
mk := func(module, fp string, edges []catalog.Edge) catalog.CatalogEntry {
return catalog.CatalogEntry{Module: module, Fp: fp, Commit: "c1", Repository: "o/" + module, Path: "modules/" + module, Edges: edges,
Artifacts: []catalog.Artifact{{Ref: catalog.ArtifactRef(module + ":program"), Language: "go"}}}
}
kept := Half{Revision: 10, Source: 41, Entries: map[string]catalog.CatalogEntry{"app": mk("app", "src2:aa", nil), "lib": mk("lib", "src2:bb", nil), "mesh-build-go": entries["mesh-build-go"]}}
head := Half{Revision: 13, Source: 42, Entries: map[string]catalog.CatalogEntry{"app": mk("app", "src2:aa", []catalog.Edge{{From: "lib:program", Kind: 1}}),
"lib": mk("lib", "src2:b2", nil), "mesh-build-go": entries["mesh-build-go"]}}
for _, how := range []string{"start", "place-unfinished", "rerun"} {
t.Run(how, func(t *testing.T) {
store := &MoverStore{Raw: newMemRaw()}
asks := &stepAsks{}
u := memUnfinished{}
var said []string
logf := func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }
s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil }, Logf: logf,
Revision: func(string, int64) (Half, error) { return kept, nil },
Registration: func(string) (catalog.Registration, bool) { return reg, true }, Unfinished: &Unfinished{Store: u, Logf: logf}}
key := Key("main", 10)
if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: kept.Entries, Movers: []seat.Mover{
{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}, {Module: "lib", Commit: "c1", Fingerprint: "src2:bb", Repository: "o/lib"}}}); !ok || err != nil {
t.Fatalf("start = %v, %v", ok, err)
}
p, rev, _ := store.Get(key)
end := time.Unix(50, 0)
for i := range p.Steps { // lib's lint failed; app's failed too, or for place-unfinished never ran
switch st := &p.Steps[i]; {
case how == "place-unfinished" && st.Module == "app":
st.Outcome, st.Ask = seat.StepResultOutcomeNotAsked, ""
case st.Step == seat.StepResultStepLint && st.Artifact != "":
st.Outcome, st.Ended = seat.StepResultOutcomeFailed, &end
}
}
p.Outcome, p.Ended, p.EndCount = seat.PipelineOutcomeFailed, &end, 1
if _, err := store.Update(key, p, rev); err != nil {
t.Fatal(err)
}
u["main.lib"] = `{"fingerprint":"src2:bb","revision":10,"pipeline":"` + key + `","outcome":"failed"}`
v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }}, View: func(string) (Half, bool) { return head, true }, Acts: &actLog{}}
before := len(asks.asks)
var err error
switch how {
case "start":
_, err = v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "app", Why: "again"})
case "place-unfinished":
u["main.app"] = `{"fingerprint":"src2:aa","revision":10,"pipeline":"` + key + `","outcome":"failed"}`
var a seat.PlaceUnfinishedAnswer
if a, err = v.PlaceUnfinished("op@shanks", seat.PlaceUnfinishedInput{Key: "main.app", Why: "again"}); err == nil &&
(len(a.Placed) != 1 || a.Placed[0] != (seat.PlaceUnfinishedAnswerPlacedItem{Key: "main.app", Pipeline: key})) {
t.Errorf("placed %+v, want main.app placed in %s", a, key)
}
default:
_, err = v.Rerun("op@shanks", seat.RerunInput{Pipeline: key, Module: "app", Step: seat.StepResultStepLint, Artifact: "app:program", Why: "again"})
}
if err != nil {
t.Fatalf("%s is refused (%v), want the group to go on without lib", how, err)
}
var modules []string
for _, a := range asks.asks[before:] {
if b, ok := a.(nodebuildgo.StepAsk); ok && b.Step != nil && !slices.Contains(modules, b.Step.Module) {
modules = append(modules, b.Step.Module)
}
}
if !slices.Equal(modules, []string{"app"}) {
t.Errorf("asked steps of %v, want app's alone", modules)
}
if cur, _, _ := store.Get(key); Moves(cur, "lib") || !Moves(cur, "app") {
t.Errorf("%s moves %+v, want app and lib gone", key, cur.Movers)
}
if j := saidOf(said); !namesBoth(j, "lib", key, "src2:bb", "src2:b2", 13) || u["main.lib"] != "" {
t.Errorf("said %q, lib's key %q: want lib said with both fingerprints and its key dropped", said, u["main.lib"])
}
})
}
}
@@ -555,7 +555,14 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
return Half{Revision: r, Source: 5, Entries: map[string]catalog.CatalogEntry{"batched": {Commit: "c0", Fp: "src2:o9"}}}, nil
}
u["main.batched"] = `{"fingerprint":"src2:o9","revision":9,"pipeline":"main.14","outcome":"failed"}`
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "older fingerprint"}); err == nil || !strings.Contains(err.Error(), "src2:o9") || !strings.Contains(err.Error(), "src2:bb") || !strings.Contains(err.Error(), "revision 9") || !strings.Contains(err.Error(), "revision 14") {
// H-A-770 (5), (6): with the view at main.14's own revision, a lagging view, the place is refused naming both revisions and
// nothing is dropped; at a newer head the key goes.
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "lagging view"}); err == nil || !strings.Contains(err.Error(), "is not placed") ||
!strings.Contains(err.Error(), "head's revision 14") || !strings.Contains(err.Error(), "revision 14 of its pipeline main.14") || u["main.batched"] == "" {
t.Errorf("place-unfinished with the view at the pipeline's revision = %v, key %q: want it refused naming both revisions and the key kept", err, u["main.batched"])
}
half.Revision = 15
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "older fingerprint"}); err == nil || !strings.Contains(err.Error(), "src2:o9") || !strings.Contains(err.Error(), "src2:bb") || !strings.Contains(err.Error(), "revision 9") || !strings.Contains(err.Error(), "revision 15") {
t.Errorf("place-unfinished of a key at an older fingerprint = %v, want it refused naming both fingerprints and the revisions", err)
}
if _, ok := u["main.batched"]; ok {
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"strconv"
"strings"
@@ -113,6 +114,50 @@ type Unfinished struct {
// Kept reads a pipeline's kept-revisions, the revision each re-pinned mover's entry comes from (H-A-285); nil, or a pipeline
// that keeps none, says the revision the key names (H-A-608).
Kept func(pipeline string) map[string]int64
// Head reads the head's revision of a branch, the newest its catalog view holds (H-A-759), whose entries say which movers a
// newer revision moved at a pipeline's end (design 47 H2 H-A-594 (2), H-A-761); nil reads none and passes no mover.
Head func(branch string) (Half, bool)
}
// movedMover is a mover a newer revision moved: its fingerprint in the pipeline read, and the one the head's entry holds ("" for
// none).
type movedMover struct{ At, Head string }
// movedOn are the movers of p it did not deliver, left unfinished or failed, whose module's entry at head, the head's revision,
// does not hold p's fingerprint of them: a predecessor a newer revision moved counts as carried by that revision's pipeline, so it
// ties nothing and goes in no group (design 47 H2 H-A-594 (2)), and it goes on only at the fingerprint the head's entry holds
// (H-A-761). None when head holds no entries, or while it is p's revision or older: a lagging view drops and unties nothing, and
// the mover is judged again when the view moves (H-A-770 (5)).
func movedOn(p seat.Pipeline, head Half) map[string]movedMover {
return movedAmong(p, appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...), head)
}
// movedAmong are the movers of p among names whose entry at head does not hold p's fingerprint of them (movedOn); none when head
// holds no entries or is not newer than p's revision (H-A-770 (5)).
func movedAmong(p seat.Pipeline, names []string, head Half) map[string]movedMover {
if head.Entries == nil || head.Revision <= p.Revision {
return nil
}
out := map[string]movedMover{}
for _, name := range names {
m, _ := MoverOf(p, name)
if e := head.Entries[name]; !slices.Contains(p.Superseded, name) && e.Fp != m.Fingerprint {
out[name] = movedMover{At: m.Fingerprint, Head: e.Fp}
}
}
return out
}
// without is modules less every one of moved.
func without(modules []string, moved map[string]movedMover) []string {
return slices.DeleteFunc(slices.Clone(modules), func(m string) bool { _, ok := moved[m]; return ok })
}
// movedWords says that module of p, which a newer revision moved, ties nothing, naming both fingerprints and the revisions read
// (design 47 H2 H-A-594 (2), H-A-761).
func movedWords(p seat.Pipeline, module string, mv movedMover, head int64) string {
return fmt.Sprintf("%s of %s counts as carried by a newer revision: %s holds it at %s (revision %d) and the head's revision %d of %s at %q, so it ties nothing and goes in no group (H-A-594 (2), H-A-761)",
module, p.Pipeline, p.Pipeline, mv.At, p.Revision, head, p.Branch, mv.Head)
}
func (u *Unfinished) logf(format string, args ...any) {
@@ -244,11 +289,29 @@ func (u *Unfinished) Ended(p seat.Pipeline) {
return
}
left := unfinishedOf(p)
// A mover a newer revision moved is not kept unfinished, and a failed one a newer revision moved ties nothing (design 47 H2
// H-A-594 (2), H-A-761).
var moved map[string]movedMover
var head Half
if len(left) > 0 && u.Head != nil {
if h, ok := u.Head(p.Branch); ok {
head, moved = h, movedOn(p, h)
}
}
for _, m := range p.Movers {
if slices.Contains(p.Superseded, m.Module) {
continue
}
key := UnfinishedKey(p.Branch, m.Module)
if mv, ok := moved[m.Module]; ok && slices.Contains(left, m.Module) {
why := movedWords(p, m.Module, mv, head.Revision)
if e, held, _ := u.read(key); held && e.Fingerprint != mv.Head {
u.dropMoved(key, m.Module, e.Fingerprint, why)
continue
}
u.logf("%s ended %s and does not keep %s unfinished: %s", p.Pipeline, p.Outcome, m.Module, why)
continue
}
if slices.Contains(left, m.Module) {
raw, _ := json.Marshal(UnfinishedEntry{Fingerprint: m.Fingerprint, Revision: p.Revision, Pipeline: p.Pipeline, Outcome: p.Outcome, Widens: m.Widens})
if err := u.Store.Put(key, raw); err != nil {
@@ -280,12 +343,14 @@ func (u *Unfinished) Ended(p seat.Pipeline) {
}
u.logf("%s ended %s: %s is no longer unfinished", p.Pipeline, p.Outcome, m.Module)
}
u.carryAtEnd(p, left)
u.carryAtEnd(p, left, moved, head.Revision)
}
// carryAtEnd adds each closed group of the movers left to the head's pipeline (H-A-594 (2), (3), H-A-607 (2)), and names that
// pipeline as the carrier of each of its movers' keys.
func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string) {
// pipeline as the carrier of each of its movers' keys. A mover of p a newer revision moved (moved, read at the head's revision
// head) goes in no group, and a failed one ties nothing, said (design 47 H2 H-A-594 (2), H-A-761).
func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string, moved map[string]movedMover, head int64) {
left = without(left, moved)
if len(left) == 0 || u.Add == nil || u.Entries == nil {
return
}
@@ -294,7 +359,20 @@ func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string) {
u.logf("%s: revision %d of %s is not read, so the movers it left are carried at the next take-in", p.Pipeline, p.Revision, p.Branch)
return
}
tied := tiedTo(p, left, failedMovers(p), entries)
failed := failedMovers(p)
tied := tiedTo(p, left, without(failed, moved), entries)
var passed []string
for _, by := range tiedTo(p, left, failed, entries) {
for _, f := range by {
if _, ok := moved[f]; ok && !slices.Contains(passed, f) {
passed = append(passed, f)
}
}
}
slices.Sort(passed)
for _, f := range passed {
u.logf("%s ended %s: %s", p.Pipeline, p.Outcome, movedWords(p, f, moved[f], head))
}
var free []string
for _, m := range left {
if len(tied[m]) == 0 {
@@ -333,57 +411,42 @@ func (u *Unfinished) markCarried(branch string, modules []string, carrier string
// heldBack are the failed modules a mover's key is tied to: the failed movers of its pipeline that the mover awaits at that
// pipeline's revision, directly or through others, and that are registered still (H-A-610, H-A-646). None when the hooks that
// read them are not set.
func (u *Unfinished) heldBack(branch, module string, e UnfinishedEntry) []string {
// read them are not set. With head, the head's revision, a mover of that pipeline a newer revision moved ties nothing (design 47
// H2 H-A-594 (2), H-A-761, H-A-770 (5)): the failed ones it passes for that are answered in passed, with the pipeline read.
func (u *Unfinished) heldBack(branch, module string, e UnfinishedEntry, head Half) (by []string, passed map[string]movedMover, from seat.Pipeline) {
if u.Pipeline == nil || u.Entries == nil {
return nil
return nil, nil, seat.Pipeline{}
}
p, ok := u.Pipeline(e.Pipeline)
if !ok {
return nil
return nil, nil, seat.Pipeline{}
}
entries, ok := u.Entries(branch, p.Revision)
if !ok {
return nil
return nil, nil, seat.Pipeline{}
}
moved := movedOn(p, head)
var left []string
for _, m := range p.Movers {
if _, held, _ := u.read(UnfinishedKey(branch, m.Module)); held && !slices.Contains(failedMovers(p), m.Module) {
left = append(left, m.Module)
}
}
var out []string
registered := func(f string) bool { return u.Registered == nil || u.Registered(f) }
for _, f := range tiedTo(p, without(left, moved), without(failedMovers(p), moved), entries)[module] {
if registered(f) {
by = append(by, f)
}
}
for _, f := range tiedTo(p, left, failedMovers(p), entries)[module] {
if u.Registered == nil || u.Registered(f) {
out = append(out, f)
if mv, ok := moved[f]; ok && registered(f) {
if passed == nil {
passed = map[string]movedMover{}
}
passed[f] = mv
}
}
return out
}
// HeldBehind are the modules whose unfinished key of branch is tied to module (H-A-625 (2)): the movers a failed module holds
// back, said by its finding pipeline-failed.
func (u *Unfinished) HeldBehind(branch, module string) []string {
if u == nil {
return nil
}
ukeys, err := u.Store.Keys(keys.EscapeName(branch) + ".*")
if err != nil {
return nil
}
slices.Sort(ukeys)
var out []string
for _, key := range ukeys {
_, name, _ := strings.Cut(key, ".")
m, err := keys.UnescapeName(name)
if err != nil {
continue
}
if e, held, _ := u.read(key); held && slices.Contains(u.heldBack(branch, m, e), module) {
out = append(out, m)
}
}
return out
return by, passed, p
}
// Carry adds to the movers of a catalog revision of branch each unfinished mover whose fingerprint is still its entry's in
@@ -391,7 +454,10 @@ func (u *Unfinished) HeldBehind(branch, module string) []string {
// moves at a newer fingerprint, or whose entry holds another fingerprint or none, has its key deleted; one it moves at its
// own fingerprint is carried by the revision already. A key whose carrier waits or runs is skipped (H-A-594 (4)); one tied to
// a failed mover the revision does not move is kept, tied, until that mover passes or leaves the registrations (H-A-594 (2),
// H-A-610). It answers movers with the added ones after them.
// H-A-610); a failed mover whose entry in entries holds another fingerprint than its pipeline's, which a newer revision moved,
// ties nothing, said (design 47 H2 H-A-594 (2), H-A-761). While revision is not newer than the revision of the pipeline a key
// names, a key whose entry holds another fingerprint is kept, said, not dropped (H-A-770 (5), (6)). It answers movers with the
// added ones after them.
func (u *Unfinished) Carry(branch string, revision int64, entries map[string]catalog.CatalogEntry, movers []seat.Mover) []seat.Mover {
if u == nil {
return movers
@@ -402,6 +468,7 @@ func (u *Unfinished) Carry(branch string, revision int64, entries map[string]cat
return movers
}
slices.Sort(ukeys)
var said []string
for _, key := range ukeys {
_, name, _ := strings.Cut(key, ".")
module, err := keys.UnescapeName(name)
@@ -425,11 +492,27 @@ func (u *Unfinished) Carry(branch string, revision int64, entries map[string]cat
continue
}
entry, why, ok := u.entryOf(branch, revision, entries, module, e)
if !ok && revision <= e.Revision {
// A head not newer than the key's pipeline is a lagging view: the key is kept and judged again when the view moves
// (design 47 H2 H-A-770 (5), (6)).
u.logf("revision %d of %s does not carry %s and keeps its key: %s, but revision %d is not newer than the revision %d of its pipeline %s, so it is judged again when the view moves (H-A-770 (5), (6))",
revision, branch, module, why, revision, e.Revision, e.Pipeline)
continue
}
if !ok {
u.dropMoved(key, module, e.Fingerprint, why)
continue
}
if by := u.heldBack(branch, module, e); len(by) > 0 && !slices.ContainsFunc(by, func(f string) bool {
// A failed predecessor a newer revision moved, the head's entry holding another fingerprint than its pipeline's, ties nothing,
// said once (design 47 H2 H-A-594 (2), H-A-761).
by, passed, from := u.heldBack(branch, module, e, Half{Revision: revision, Entries: entries})
for _, f := range slices.Sorted(maps.Keys(passed)) {
if w := movedWords(from, f, passed[f], revision); !slices.Contains(said, w) {
said = append(said, w)
u.logf("revision %d of %s: %s", revision, branch, w)
}
}
if len(by) > 0 && !slices.ContainsFunc(by, func(f string) bool {
return slices.ContainsFunc(movers, func(m seat.Mover) bool { return m.Module == f })
}) {
u.logf("revision %d of %s does not carry %s: it is tied to %v, which it does not move (H-A-594 (2))", revision, branch, module, by)
@@ -380,10 +380,12 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
var ask *Asked
var replaced string
var held []seat.StepResult
var moved map[string]movedMover
var head int64
p, _, err := v.change(in.Pipeline, seat.EventStepStarted, func() error {
return v.record(seat.VerbRerun, fmt.Sprintf("asked the %s step of %s again", in.Step, in.Pipeline), in.Why)
}, func(p *seat.Pipeline, now time.Time) (int, error) {
ask, replaced, held = nil, "", heldOf(*p)
ask, replaced, held, moved = nil, "", heldOf(*p), nil
switch p.Outcome {
case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded:
return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome)
@@ -406,6 +408,7 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
return -1, err
}
}
moved, head = v.leaveMovedOn(p, in.Module)
oldAsk := s.Ask
replaced = oldAsk
*s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat,
@@ -433,6 +436,9 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
if err != nil {
return seat.RerunAnswer{}, err
}
if v.Starter != nil {
v.Starter.passMovedOn(p, head, moved)
}
v.sayReopened(p, reopens)
v.Hearer.sayHeldEnded(p, held, allHow(waitHowReleased)) // the rerun of a held step releases its wait (H-A-599)
if ask == nil || replaced != ask.ID {
@@ -452,6 +458,24 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
return seat.RerunAnswer{Pipeline: in.Pipeline, Result: &r}, nil
}
// leaveMovedOn takes out of p, an ended delivering pipeline a rerun of keep's step reopens, each other mover a newer revision
// moved, the head's entry holding another fingerprint: it counts as carried by that revision's pipeline, so it ties nothing and
// none of the pipeline's later ends names it (design 47 H2 H-A-594 (2), (3), (4), H-A-761). It answers them, read at the head's
// revision head; none when p has not ended or the head is not held.
func (v Verbs) leaveMovedOn(p *seat.Pipeline, keep string) (moved map[string]movedMover, head int64) {
if p.Ended == nil || p.Run != "" || v.View == nil {
return nil, 0
}
h, ok := v.View(p.Branch)
if !ok {
return nil, 0
}
moved = movedOn(*p, h)
delete(moved, keep)
p.Movers = slices.DeleteFunc(slices.Clone(p.Movers), func(m seat.Mover) bool { _, ok := moved[m.Module]; return ok })
return moved, h.Revision
}
// rerunTest asks a test step of a test run again (design 47 G §727, A-469l): it joins its key's run while that runs, reads one
// that started after the step's last end, or else starts a new run under a new ask, replacing the ended key by compare-and-set
// and carrying its readers into the new value, so the new run's end moves every former reader that did not pass.
@@ -492,9 +516,12 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult,
if read {
event = seat.EventStepEnded
}
var moved map[string]movedMover
var head int64
p, _, err := v.change(in.Pipeline, event, func() error {
return v.record(seat.VerbRerun, fmt.Sprintf("asked the %s step of %s again", in.Step, in.Pipeline), in.Why)
}, func(p *seat.Pipeline, now time.Time) (int, error) {
moved = nil
switch p.Outcome {
case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded:
return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome)
@@ -503,6 +530,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult,
if err != nil {
return -1, err
}
moved, head = v.leaveMovedOn(p, in.Module) // as rerun does (design 47 H2 H-A-594 (3))
s := &p.Steps[i]
*s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat,
Outcome: seat.StepResultOutcomeRunning, By: caller, Rerun: true, Started: &now}
@@ -536,6 +564,9 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult,
if err != nil {
return seat.RerunAnswer{}, err
}
if v.Starter != nil {
v.Starter.passMovedOn(p, head, moved)
}
v.sayReopened(p, reopens)
switch {
case join || read: