diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go index 80cfcaf55..a7d85938f 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go @@ -13,10 +13,13 @@ import ( "github.com/nats-io/nats.go" + "git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants" builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" + wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-sdk/go/seatlist" "mesh-delivery-pipeline/internal/pipeline" ) @@ -40,15 +43,35 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { if n == 0 { n = newest.Load() } - lib := "l1" + lib, goFp, base := "l1", "src2:go", n-1 if n == 2 { lib = "l2" } - return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n + 2}, + if n == 5 { // the build seat's holder moves with revision 5 (AC-P6b) + lib, goFp = "l5", "src2:go2" + } + return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n + 2, Base: base}, Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"}, {Module: "lib", Commit: lib, Fp: "src2:" + lib, Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go", Kind: "program"}}}, - {Module: "mesh-build-go", Commit: "c0", Fp: "src2:go", Acts: []catalog.ActingRule{{Step: "build", On: "go", Seat: nodebuildgo.Seat}}}}} + {Module: "mesh-build-go", Commit: "c0", Fp: goFp, Acts: []catalog.ActingRule{{Step: "build", On: "go", Seat: nodebuildgo.Seat}}}}} }) + // The seat holders and the grants part answer, so a widening is named only for what a revision alters against its base: the + // build seat's holder is the module mesh-build-go, every other seat's a module the catalog holds no entry of. + var held []any + for _, name := range []string{seat.Seat, catalog.Seat, pipeline.ComposerSeat, builds.Seat, nodebuildgo.Seat, wants.Seat} { + holder := "holder-" + name + if name == nodebuildgo.Seat { + holder = "mesh-build-go" + } + held = append(held, map[string]any{"seat": name, "holders": []any{map[string]any{"module": holder}}}) + } + for subject, body := range map[string]any{"mesh.seat." + seatlist.HolderSeat + ".call." + seatlist.HolderVerb + ".*": map[string]any{"seats": held}, + "mesh.seat." + meshgrants.Seat + ".call." + meshgrants.VerbGrantsFor + ".*": meshgrants.GrantsFor{}} { + raw, _ := json.Marshal(map[string]any{"result": body}) + if _, err := w.nc.Subscribe(subject, func(m *nats.Msg) { _ = m.Respond(raw) }); err != nil { + t.Fatal(err) + } + } ended := make(chan seat.PipelineEnded, 4) if _, err := w.nc.Subscribe("mesh.seat.mesh-pipeline-runner.event.pipeline-ended.>", func(m *nats.Msg) { var pe seat.PipelineEnded @@ -182,4 +205,36 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { if !readPipeline(ctx, w.pipelines, "main.3", &third) || third.EndCount != 2 || len(ended) != 0 { t.Errorf("main.3 ended %d times and %d ends wait, want its second end and no third", third.EndCount, len(ended)) } + + // design 47 H2 H-A-595 (AC-P6b), whole: lib fails in main.4 against a base that alters nothing for app, so app's first widens are + // empty and kept so in its key; main.5 carries app while the build seat's holder moves, and says app's widens as the first + // pipeline did, empty, while lib's own name the serving part. + newest.Store(4) + rev, _ = json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 4, Kind: "trunk", Branch: "main", Source: 6, CallKind: catalog.CatalogRevisionEventCallKindTakeIn}) + if _, err := w.js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil { + t.Fatal(err) + } + takeIn(6, 4, catalog.TakeInEntry{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, catalog.TakeInEntry{Module: "lib", Commit: "l1", Fingerprint: "src2:l1"}) + waitFor(t, ctx, w.logs, answer("main.4", true)) + if pe := endOf(); pe.Pipeline != "main.4" || !slices.Equal(pe.Unfinished, []string{"app"}) { + t.Fatalf("pipeline-ended = %s unfinished %v, want main.4 leaving app unfinished\n%s", pe.Pipeline, pe.Unfinished, w.logs.String()) + } + if e, err := unfinished.Get(ctx, "main.app"); err != nil || strings.Contains(string(e.Value()), `"widens"`) { + t.Fatalf("main.app's first widens are kept as %s (%v), want none named", e.Value(), err) + } + newest.Store(5) + rev, _ = json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 5, Kind: "trunk", Branch: "main", Source: 7, CallKind: catalog.CatalogRevisionEventCallKindTakeIn}) + if _, err := w.js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil { + t.Fatal(err) + } + takeIn(7, 5, catalog.TakeInEntry{Module: "lib", Commit: "l5", Fingerprint: "src2:l5"}) + waitFor(t, ctx, w.logs, answer("main.5", false)) + last := endOf() + widens := map[string][]seat.Widening{} + for _, m := range last.Movers { + widens[m.Module] = m.Widens + } + if last.Pipeline != "main.5" || len(widens["app"]) != 0 || len(widens["lib"]) != 1 || widens["lib"][0].Name != "mesh-build-go" { + t.Fatalf("%s ended with the widens %+v, want the carried app's empty as its first pipeline's and lib's naming the serving part mesh-build-go\n%s", last.Pipeline, widens, w.logs.String()) + } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 93921c095..c3b172bcf 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -1104,8 +1104,13 @@ func (h *Hearer) endPipeline(p *seat.Pipeline, now time.Time, wr func(seat.Pipel } if wr != nil { for i := range p.Movers { - // A carried or reopened mover says the widens its first pipeline computed and never computes it again (H-A-595). + // A carried or reopened mover says the widens its first pipeline computed and never computes it again (H-A-595): the + // key of the state unfinished keeps them, an empty first one too. if len(p.Movers[i].Widens) == 0 { + if kept, ok := h.keptWidens(*p, p.Movers[i]); ok { + p.Movers[i].Widens = kept + continue + } p.Movers[i].Widens = wr(*p, p.Movers[i].Module) } } @@ -1113,6 +1118,19 @@ func (h *Hearer) endPipeline(p *seat.Pipeline, now time.Time, wr func(seat.Pipel return true } +// keptWidens are the widens of m's first pipeline, kept in m's key of the state unfinished while the key names the fingerprint m +// is at (H-A-595); false when the key holds none for it, so the mover's first pipeline computes them. +func (h *Hearer) keptWidens(p seat.Pipeline, m seat.Mover) ([]seat.Widening, bool) { + if h.Unfinished == nil || h.Unfinished.Store == nil { + return nil, false + } + e, held, err := h.Unfinished.Entry(UnfinishedKey(p.Branch, m.Module)) + if err != nil || !held || e.Fingerprint != m.Fingerprint { + return nil, false + } + return e.Widens, true +} + // widensReads is the reader of one end's widens, made before its compare-and-set and kept for every retry (H-A-289). func (h *Hearer) widensReads() func(seat.Pipeline, string) []seat.Widening { if h.Widens == nil { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/widens.go b/modules/mesh-delivery-pipeline/internal/pipeline/widens.go index 7bf7a4725..30d151caf 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/widens.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/widens.go @@ -106,8 +106,9 @@ func (r *endReads) widens(p seat.Pipeline, module string) []seat.Widening { return could("mesh-catalog", fmt.Sprintf("the candidate's revision %d is not read: %v", p.Revision, err)) } // A change is what its movers alter against the revision's own base, never against a branch's newest (design 47 H2 H-A-582); - // the branch's first take-in has no base and alters nothing against it. - newest := cand + // a revision with no base (the branch's first) is computed against an empty one: it names every widening, all of it new + // (H-A-758). + var newest Half if cand.Base > 0 { if newest, err = r.revision(p.Branch, cand.Base); err != nil { return could("mesh-catalog", fmt.Sprintf("the base revision %d of revision %d is not read: %v", cand.Base, p.Revision, err)) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/widens_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/widens_test.go index b04caf628..81f206de8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/widens_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/widens_test.go @@ -87,6 +87,23 @@ func TestWidensIsTheCandidateAgainstItsBase(t *testing.T) { t.Errorf("%s: widens %q, want %q", c.name, got, c.want) } } + // H-A-758: a revision with no base is computed against an empty one, so it names every widening its mover holds. + first := &Widener{ + Revision: func(_ string, rev int64) (Half, error) { + if rev != 8 { + t.Errorf("a revision with no base asked revision %d, want only its own 8", rev) + } + return newest, nil + }, + Holder: func(s string) (string, error) { return holders[s], nil }, + } + var got []string + for _, x := range first.Widens(p, "app") { + got = append(got, x.What+" "+x.Name) + } + if want := "serving part build-go;serving part host;serving part indexer;serving part runner;acting rule app node-build-go.check;credential app token"; strings.Join(got, ";") != want { + t.Errorf("a revision with no base: widens %q, want every widening of its movers: %q", got, want) + } } // A pipeline's end keeps each mover's widens in its value, whether or not anything widens (design 47 G ยง71, A-207; H H-A-51). @@ -107,6 +124,16 @@ func TestAnEndKeepsEachMoversWidens(t *testing.T) { if !h.endPipeline(&c, time.Unix(1, 0), h.widensReads()) || len(c.Movers[0].Widens) != 1 || c.Movers[0].Widens[0].Name != "first" { t.Errorf("a carried mover's widens = %+v, want its first pipeline's", c.Movers[0].Widens) } + // H-A-595 (AC-P6b): a carried mover whose first pipeline's widens were empty keeps them empty, its key of the state unfinished + // holding them; one the key does not hold at its fingerprint is computed. + h.Unfinished = &Unfinished{Store: memUnfinished{"main.app": `{"fingerprint":"src2:aa","revision":3,"pipeline":"main.3","outcome":"failed"}`}} + e := seat.Pipeline{Branch: "main", Outcome: seat.PipelineOutcomeRunning, Movers: []seat.Mover{{Module: "app", Fingerprint: "src2:aa"}, {Module: "lib", Fingerprint: "src2:l1"}, {Module: "tool", Fingerprint: "src2:t1"}}, + Steps: []seat.StepResult{{Module: "app", Step: "build", Outcome: "passed"}, {Module: "lib", Step: "build", Outcome: "passed"}, {Module: "tool", Step: "build", Outcome: "passed"}}} + h.Unfinished.Store.Put("main.tool", []byte(`{"fingerprint":"src2:t0"}`)) + if !h.endPipeline(&e, time.Unix(1, 0), h.widensReads()) || len(e.Movers[0].Widens) != 0 || len(e.Movers[1].Widens) != 1 || len(e.Movers[2].Widens) != 1 { + t.Errorf("the ended movers' widens = %+v, want the carried app's empty and lib's and tool's (its key at another fingerprint) computed", e.Movers) + } + h.Unfinished = nil h.Widens = nil q := seat.Pipeline{Outcome: seat.PipelineOutcomeRunning, Movers: []seat.Mover{{Module: "app"}}, Steps: []seat.StepResult{{Module: "app", Step: "build", Outcome: "passed"}}} if !h.endPipeline(&q, time.Unix(1, 0), h.widensReads()) || len(q.Movers[0].Widens) != 0 {