diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go b/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go index 252e7db16..a4a45a733 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go @@ -310,6 +310,7 @@ func (v Verbs) reopenGroup(caller string, from seat.Pipeline, group []string, ad cur.Movers = Tiers(append(cur.Movers, add...), entries, s.logf) } for _, m := range group { + adoptHead(&cur, m, entries) // the group's movers take their commit from the head's entries (H-A-768) 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 its end count, which the @@ -408,8 +409,10 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) { } half := head group := v.closedGroup(from, module, half.Entries) + from.Movers = slices.Clone(from.Movers) plan := handPlan{from: from, group: group, entries: half.Entries} 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) plan.movers = append(plan.movers, mv) if k := UnfinishedKey(branch, g); slices.ContainsFunc(unfinishedOf(from), func(x string) bool { return x == g }) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go index fb9e1a7b4..ab1528795 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -432,6 +432,9 @@ func TestAMoverReopenedIsAskedWithTheHeadsPins(t *testing.T) { pin := func(v string) catalog.CatalogEntry { e := entries["app"] e.Fp, e.Packages, e.Commit, e.Repository = "src2:ab", map[string]string{sdk: v}, "c1", "o/app" + if v == "v0.1.27" { // design 47 H2 H-A-768: the head's entry holds the same fingerprint at a newer merge commit + e.Commit, e.Repository = "c2", "o/app-moved" + } return e } keptHalf := Half{Revision: 11, Source: 41, Entries: map[string]catalog.CatalogEntry{"app": pin("v0.1.26"), "mesh-build-go": entries["mesh-build-go"]}} @@ -489,16 +492,24 @@ func TestAMoverReopenedIsAskedWithTheHeadsPins(t *testing.T) { if len(asks.asks) == before { t.Fatalf("%s: nothing was asked", how) } - want := "v0.1.27" + want, wantCommit, wantRepo := "v0.1.27", "c2", "o/app-moved" if how != "start" && how != "place-unfinished" { - want = "v0.1.26" + want, wantCommit, wantRepo = "v0.1.26", "c1", "o/app" } seen := 0 for _, ask := range asks.asks[before:] { + if b, ok := ask.(builds.StepRun); ok { // the build ask names the entry's commit, as the builder's check of the entry needs + if len(b.Entries) != 1 || b.Entries[0].Commit != wantCommit { + t.Errorf("%s: the build asked %+v, want the entry's commit %s", how, b.Entries, wantCommit) + } + } if b, ok := ask.(nodebuildgo.StepAsk); ok && b.Step != nil && b.Step.Fetch.Packages != nil { if seen++; b.Step.Fetch.Packages[sdk] != want { t.Errorf("%s: asked %+v, want mesh-sdk pinned to %s", how, b.Step, want) } + if b.Step.Commit != wantCommit || b.Step.Fetch.Commit != wantCommit || b.Step.Fetch.Repository != wantRepo { + t.Errorf("%s: asked at commit %s (fetch %s of %s), want the commit %s of %s the entry holds", how, b.Step.Commit, b.Step.Fetch.Commit, b.Step.Fetch.Repository, wantCommit, wantRepo) + } } } if seen == 0 { @@ -581,3 +592,53 @@ func TestAReopenedGroupIsClosedOverTheHeadsEdges(t *testing.T) { } } } + +// design 47 H2 H-A-769 (1): runner_unfinished_place joins a group the head's running pipeline at the head's entry's commit: the head +// pipeline's mover is at c2 and its build ask names c2, whatever commit the ended pipeline's record held. +func TestAPlacedGroupJoinsTheHeadAtTheHeadsCommit(t *testing.T) { + reg, entries := placeFixture() + e := entries["app"] + e.Fp, e.Commit, e.Repository = "src2:ab", "c2", "o/app-moved" + head := Half{Revision: 13, Source: 42, 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:ab", Repository: "o/app"}}} + running := seat.Pipeline{V: 1, Pipeline: Key("main", 13), Branch: "main", Revision: 13, Source: 42, Outcome: seat.PipelineOutcomeRunning, + Movers: []seat.Mover{{Module: "lib", Commit: "c9", Fingerprint: "src2:lb"}}} + for _, p := range []seat.Pipeline{old, running} { + raw, _ := json.Marshal(p) + if err := store.Create(p.Pipeline, raw); err != nil { + t.Fatal(err) + } + } + u := memUnfinished{"main.app": `{"fingerprint":"src2:ab","revision":10,"pipeline":"` + old.Pipeline + `","outcome":"failed"}`} + asks := &stepAsks{} + s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil }, + Revision: func(_ string, r int64) (Half, error) { return head, nil }, + Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }} + s.Unfinished = &Unfinished{Store: u, Kept: func(string) map[string]int64 { return nil }} + acts := &actLog{} + 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: acts} + a, err := v.PlaceUnfinished("op@shanks", seat.PlaceUnfinishedInput{Key: "main.app", Why: "again"}) + if err != nil || a.Pipeline != running.Pipeline { + t.Fatalf("place-unfinished = %+v (%v), want it answering %s", a, err, running.Pipeline) + } + p, _, _ := store.Get(running.Pipeline) + if m, ok := MoverOf(p, "app"); !ok || m.Commit != "c2" || m.Repository != "o/app-moved" { + t.Errorf("the head pipeline's app mover = %+v, want it at the head entry's commit c2", m) + } + seen := false + for _, ask := range asks.asks { + if b, ok := ask.(builds.StepRun); ok { + seen = true + if len(b.Entries) != 1 || b.Entries[0].Module != "app" || b.Entries[0].Commit != "c2" { + t.Errorf("the build asked %+v, want app at c2", b.Entries) + } + } + } + if !seen { + t.Errorf("no build was asked of the joined mover (asks %d)", len(asks.asks)) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index f3644fb75..c632dd53b 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -130,6 +130,25 @@ func MoverOf(p seat.Pipeline, module string) (seat.Mover, bool) { return seat.Mover{}, false } +// adoptHead sets the commit and repository of p's mover of module, when its entry in entries holds the mover's fingerprint, to +// that entry's, so a mover that goes on is asked, and its step ends are matched, at the commit the head's entry names: a same +// fingerprint at a newer commit is the same build (design 47 H2 H-A-768, H-A-530). A mover whose entry holds another fingerprint +// is left as it is. +func adoptHead(p *seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) { + e, ok := entries[module] + for i, m := range p.Movers { + if m.Module != module || !ok || e.Fp != m.Fingerprint { + continue + } + if e.Commit != "" { + p.Movers[i].Commit = e.Commit + } + if e.Repository != "" { + p.Movers[i].Repository = e.Repository + } + } +} + // Moves says whether p moves module. func Moves(p seat.Pipeline, module string) bool { _, ok := MoverOf(p, module) @@ -511,6 +530,10 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } // A mover a same-source re-pin kept is placed from the revision it is kept at, its ids its own (H-A-286). entries := all + if p.EndCount > 0 { // a mover of an ended pipeline that goes on takes its commit from the head's entry (H-A-768) + adoptHead(p, m.Module, all) + m = p.Movers[i] + } // A mover of a pipeline that ended and goes on again reads the head's entry when it holds the mover at its fingerprint // (design 47 H2 H-A-764 (1), H-A-763 (3)); its ids still mix in the kept revision. if rev := kept[m.Module]; rev > 0 && !(p.EndCount > 0 && all[m.Module].Fp == m.Fingerprint) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index c3b172bcf..8289f460d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -306,6 +306,7 @@ func (h *Hearer) OnStepEndedRevised(bs StepSeat, subject string, ev StepEnded, s return seat.Pipeline{}, fmt.Errorf("%w: ask %s names pipeline %q, which the runner cannot read: %v", ErrRefused, ev.ID, ev.Pipeline, err) } i := stepOfAsk(p, ev.ID) + // A step's end is matched by its ask, module and fingerprint, never by the commit (design 47 H2 H-A-769 (2), H-A-530). // The validate ask is the pipeline's one, naming no mover (H-A-51): its end, naming the mover whose body the holder // took, is matched by its ask alone and ends every mover's validate step under it (H-A-252). oneValidate := i >= 0 && p.Steps[i].Step == seat.StepResultStepValidate && p.Steps[i].Seat == wants.Seat @@ -321,7 +322,7 @@ func (h *Hearer) OnStepEndedRevised(bs StepSeat, subject string, ev StepEnded, s return p, fmt.Errorf("%w: pipeline %s asked no step under ask %s", ErrRefused, ev.Pipeline, ev.ID) case p.Steps[i].Seat != bs.Seat: return p, fmt.Errorf("%w: ask %s was asked of %s, not %s", ErrRefused, ev.ID, p.Steps[i].Seat, bs.Seat) - case ev.Step != p.Steps[i].Step || (!oneValidate && (ev.Commit != m.Commit || ev.Fingerprint != m.Fingerprint || ev.Module != m.Module)): + case ev.Step != p.Steps[i].Step || (!oneValidate && (ev.Fingerprint != m.Fingerprint || ev.Module != m.Module)): return p, fmt.Errorf("%w: ask %s ended %s of %s at %s (%s), asked as %s of %s at %s (%s)", ErrRefused, ev.ID, ev.Step, ev.Module, ev.Commit, ev.Fingerprint, p.Steps[i].Step, p.Steps[i].Module, m.Commit, m.Fingerprint) case !open(p.Steps[i]): diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps_test.go index 2925bd337..c846cbe98 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps_test.go @@ -592,3 +592,18 @@ func TestEachStepEndWritesItsLineOnce(t *testing.T) { } } } + +// design 47 H2 H-A-769 (2): a step's end is matched by its ask, module and fingerprint, not by the mover's commit: a mover adopted at c2 +// while its step asked at c1 runs has that end taken. +func TestAStepEndAtTheAskedCommitIsTakenAfterTheMoverAdoptedANewOne(t *testing.T) { + h, store, _, _, _ := fixture() + e := store[pkey] + e.p.Movers = []seat.Mover{{Module: "app", Commit: "c2", Fingerprint: "src2:aa"}} + store[pkey] = e + if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a1", "lint", "passed")); err != nil { + t.Fatalf("the end at c1 of a step asked at c1 = %v, want it taken", err) + } + if store[pkey].p.Steps[0].Outcome != seat.StepResultOutcomePassed { + t.Errorf("the step = %s, want passed", store[pkey].p.Steps[0].Outcome) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index b1e84f8f3..89b49c5d1 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -397,6 +397,11 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru return -1, fmt.Errorf("the %s step of %s is running: it is not asked again", in.Step, p.Pipeline) } if s.Seat != "" { + if p.Run == "" && v.View != nil { // the record's commit becomes the head entry's before the ask is made (H-A-768) + if h, ok := v.View(p.Branch); ok { + adoptHead(p, s.Module, h.Entries) + } + } if ask, err = v.askOf(*p, *s, caller, now); err != nil { return -1, err } @@ -676,6 +681,12 @@ func (v Verbs) placedAsk(p seat.Pipeline, s seat.StepResult, id string, now time if v.Starter == nil || v.Starter.Registration == nil || v.Starter.Steps == nil || (v.View == nil && p.Run == "") { return nil, errors.New("the runner cannot ask a step: it holds no registration or no ask") } + if atHead && p.Run == "" && v.View != nil { + if h, ok := v.View(p.Branch); ok { // its commit and repository are the head's entry's too (design 47 H2 H-A-768) + p.Movers = slices.Clone(p.Movers) + adoptHead(&p, s.Module, h.Entries) + } + } m, ok := MoverOf(p, s.Module) if !ok { return nil, fmt.Errorf("%s moves no module %q", p.Pipeline, s.Module)