From dca2545eb71d7100b0d423c8941f12d9e36e6d42 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 16:29:24 +0100 Subject: [PATCH] H-A-479 third addendum: a reopening never builds beside an open pipeline A rerun that would reopen an ended pipeline while another open delivering pipeline carries one of its movers at the same revision is refused with "its pipeline is running", nothing asked, so one entry is never built side by side. Tests now cover the two paths review round 2 found untested: the indexer keeps a revision's gathering while another pipeline's reservation is left and removes it with the last, and a test step's rerun reopening an ended pipeline says pipeline-started before its run is started again. Builds: design 47 H2 H-A-479 third addendum, H-A-479 second addendum, H-A-479 addendum (2); review round 2 --- .../internal/index/repin_test.go | 28 ++++++++++++ .../internal/pipeline/testruns_test.go | 44 +++++++++++++++++++ .../internal/pipeline/verbs.go | 35 +++++++++++++++ .../internal/pipeline/verbs_test.go | 15 +++++++ 4 files changed, 122 insertions(+) diff --git a/modules/mesh-delivery-indexer/internal/index/repin_test.go b/modules/mesh-delivery-indexer/internal/index/repin_test.go index 6621d5c25..52c8256c7 100644 --- a/modules/mesh-delivery-indexer/internal/index/repin_test.go +++ b/modules/mesh-delivery-indexer/internal/index/repin_test.go @@ -2,6 +2,7 @@ package index import ( "context" + "encoding/json" "fmt" "slices" "strings" @@ -167,4 +168,31 @@ func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) { if _, _, kept, _ := heard.Get(ctx, ReservedKey(next, "mesh-sdk")); kept { t.Errorf("the withdrawn reservation is still kept") } + // H-A-479 second addendum: two pipelines' movers reserve at one revision while its gathering is open; withdrawing one + // pipeline's mover keeps the gathering and the other's reservation, withdrawing the last removes the gathering too. + six := BranchObject("main", 6) + for _, m := range []string{"one", "two"} { + raw, _ := json.Marshal(Reserved{V: 1, Revision: six, Module: m}) + if err := heard.Create(ctx, ReservedKey(six, m), raw); err != nil { + t.Fatal(err) + } + } + if err := heard.Create(ctx, SettlingKey(six), []byte(`{}`)); err != nil { + t.Fatal(err) + } + if err := ix.Withdraw(ctx, "main", 6, []string{"one"}); err != nil { + t.Fatal(err) + } + _, _, gathering, _ := heard.Get(ctx, SettlingKey(six)) + _, _, one, _ := heard.Get(ctx, ReservedKey(six, "one")) + _, _, two, _ := heard.Get(ctx, ReservedKey(six, "two")) + if !gathering || one || !two { + t.Fatalf("withdrawing one: gathering %v, one kept %v, two kept %v; want the gathering and two kept, one gone", gathering, one, two) + } + if err := ix.Withdraw(ctx, "main", 6, []string{"two"}); err != nil { + t.Fatal(err) + } + if _, _, gathering, _ := heard.Get(ctx, SettlingKey(six)); gathering { + t.Error("withdrawing the last reservation kept the revision's gathering") + } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index 4b882b0ca..0e8337406 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -655,6 +655,50 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) { t.Error("the step's finding was written before its run's end") } }) + // H-A-479 addendum (2): a test step's rerun reopening an ended pipeline says its pipeline-started before its run is + // started again, so its revision is pinned before the step is asked. + t.Run("a test step's rerun reopening an ended pipeline pins its revision first", func(t *testing.T) { + f := newRunFixture() + p := f.start(t, 4, 9) + unit := stepNamed(p, "app:program", "unit") + run := unit.Shared[0].Run + 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) + } + q, rev, _ := f.store.Get(p.Pipeline) + q.Outcome, q.Ended = seat.PipelineOutcomeFailed, &ended + if _, err := f.store.Update(p.Pipeline, q, rev); err != nil { + t.Fatal(err) + } + before, _, _ := f.runs.Get(run) + var started []string + f.s.Say = func(_ string, body any) error { + if ps, ok := body.(seat.PipelineStarted); ok { + if r, _, _ := f.runs.Get(run); r.Ask != before.Ask || r.Ended == nil { + t.Errorf("pipeline-started said after the run was started again (ask %s, was %s)", r.Ask, before.Ask) + } + started = append(started, ps.Pipeline) + } + return nil + } + v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) { + return Half{Entries: map[string]catalog.CatalogEntry{ + "app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}}, + "mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true + }, Acts: &actLog{}, RevisionHeld: func(string, int64) error { return nil }} + a, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:program", Why: "fixed"}) + if err != nil { + t.Fatal(err) + } + if len(started) != 1 || started[0] != p.Pipeline { + t.Errorf("pipeline-started at the reopening = %v, want %s once", started, p.Pipeline) + } + if r, _, _ := f.runs.Get(run); r.Ask != a.Result.Ask || r.Ended != nil { + t.Errorf("the rerun's run = %+v; want the new ask running", r) + } + }) // A rerun whose read of the key is changed before its write (a step joining the ended run) writes from the latest read, // carrying that reader, never answering the change as an error nor putting back the earlier readers. t.Run("a rerun writes its run from the latest read", func(t *testing.T) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 691121f45..be2870482 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -316,6 +316,13 @@ func (v Verbs) reopening(key string) (bool, error) { p.Outcome == seat.PipelineOutcomeCancelled || p.Outcome == seat.PipelineOutcomeSuperseded { return false, nil } + // A reopening never builds beside an open pipeline carrying one of its movers at the same revision (H-A-479 third + // addendum). + if open, err := v.openBeside(p); err != nil { + return false, err + } else if open != "" { + return false, fmt.Errorf("the pipeline %s ended and is not reopened: its pipeline %s is running: nothing was asked", key, open) + } if v.RevisionHeld != nil { if err := v.RevisionHeld(p.Branch, p.Revision); errors.Is(err, ErrRevisionGone) { return false, fmt.Errorf("the pipeline %s ended and its revision %d is gone; start the mover again at the head: nothing was asked (%v)", key, p.Revision, err) @@ -326,6 +333,34 @@ func (v Verbs) reopening(key string) (bool, error) { return true, nil } +// openBeside is the key of another delivering pipeline of p's branch and revision, not ended, carrying one of p's movers it +// did not leave; empty when none (H-A-479 third addendum). +func (v Verbs) openBeside(p seat.Pipeline) (string, error) { + pkeys, err := branchKeys(v.Hearer.Store, p.Branch) + if err != nil { + return "", fmt.Errorf("the pipelines of %s are not listed, so %s is not reopened: nothing was asked: %w", p.Branch, p.Pipeline, err) + } + for _, key := range pkeys { + if key == p.Pipeline { + continue + } + o, _, err := v.Hearer.Store.Get(key) + if err != nil { + return "", fmt.Errorf("the pipeline %s is not read, so %s is not reopened: nothing was asked: %w", key, p.Pipeline, err) + } + if o.Run != "" || o.Ended != nil || o.Revision != p.Revision || + (o.Outcome != seat.PipelineOutcomeRunning && o.Outcome != seat.PipelineOutcomeWaiting) { + continue + } + for _, m := range p.Movers { + if Moves(o, m.Module) && !slices.Contains(o.Superseded, m.Module) { + return key, nil + } + } + } + return "", nil +} + // rerun asks one step again (Rerun). func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.RerunAnswer, error) { if p, _, err := v.Hearer.Store.Get(in.Pipeline); err == nil { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go index 519532b4c..0a29c03b1 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go @@ -552,6 +552,21 @@ func TestARerunOfAnEndedPipelinePinsItsRevisionAgainOrIsRefusedWhenItIsGone(t *t return nil } in := seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"} + // H-A-479 third addendum: another open pipeline carrying app at the same revision refuses the reopening. + store["main.5.again.1"] = struct { + p seat.Pipeline + rev uint64 + }{seat.Pipeline{Pipeline: "main.5.again.1", Branch: "main", Source: 5, Revision: 5, Outcome: seat.PipelineOutcomeRunning, + Movers: []seat.Mover{{Module: "app", Fingerprint: "src2:aa"}}}, 1} + gone = false + if _, err := v.Rerun("operator", in); err == nil || !strings.Contains(err.Error(), "its pipeline main.5.again.1 is running") { + t.Fatalf("a reopening beside main.5.again.1 = %v; want refused naming it", err) + } + if len(asks.asks) != 0 || store[pkey].p.Outcome != seat.PipelineOutcomeFailed { + t.Fatalf("a refused reopening asked %d, left the pipeline %s", len(asks.asks), store[pkey].p.Outcome) + } + delete(store, "main.5.again.1") + gone = true if _, err := v.Rerun("operator", in); err == nil || !strings.Contains(err.Error(), "its revision 5 is gone; start the mover again at the head") { t.Fatalf("a rerun of an ended pipeline whose revision is gone = %v; want refused by name", err) }