diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/carry_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/carry_test.go index 79e225a63..63de02f3c 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/carry_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/carry_test.go @@ -1,120 +1,9 @@ package pipeline -import ( - "encoding/json" - "slices" - "strings" - "testing" - - 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" -) +import catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" func edgeInto(entries map[string]catalog.CatalogEntry, to, from string, kind int64) { e := entries[to] e.Edges = append(e.Edges, catalog.Edge{From: catalog.ArtifactRef(from + ":x"), Kind: kind}) entries[to] = e } - -// design 47 H2 H-A-594 (2), H-A-646 (AC-P3b): a mover awaiting a failed one's package (kind 1) or build step (kind 3), directly or -// through another, is tied; one with only a tier edge is not; the tied group is closed under the tier kinds. -func TestTiedMoversAreThoseAwaitingAFailedOne(t *testing.T) { - p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Outcome: seat.PipelineOutcomeFailed} - for _, m := range []string{"engine", "gitea", "far", "tieronly", "mate", "free"} { - p.Movers = append(p.Movers, seat.Mover{Module: m}) - } - entries := map[string]catalog.CatalogEntry{} - edgeInto(entries, "gitea", "engine", 1) // kind 1: awaits engine's package - edgeInto(entries, "far", "gitea", 3) // kind 3 through gitea - edgeInto(entries, "tieronly", "engine", 2) // delivery order only - edgeInto(entries, "mate", "far", 4) // tier edge to a tied mover: the group goes together - tied := tiedTo(p, []string{"gitea", "far", "tieronly", "mate", "free"}, []string{"engine"}, entries) - for _, m := range []string{"gitea", "far", "mate"} { - if !slices.Equal(tied[m], []string{"engine"}) { - t.Errorf("%s is tied to %v, want engine", m, tied[m]) - } - } - for _, m := range []string{"tieronly", "free"} { - if len(tied[m]) != 0 { - t.Errorf("%s is tied to %v, want none", m, tied[m]) - } - } - groups := tierGroups([]string{"tieronly", "free"}, entries) - if len(groups) != 2 { - t.Errorf("groups = %v, want each alone", groups) - } -} - -// design 47 H2 H-A-594 (3), (4), H-A-607 (2), H-A-609 (3): a group left joins the head's pipeline when that waits or runs, said by -// mover-added with from, its key naming the carrier and leaving the failed pipeline's movers; a take-in whose key is held adds -// its entries, one mover-added each with take-in; a carrier that ends otherwise leaves its key naming that pipeline. -func TestAClosedGroupJoinsTheHeadPipelineAndIsSaid(t *testing.T) { - mem := memStore{} - 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: "free", 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: "free", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}} - head := seat.Pipeline{Pipeline: "main.6", Branch: "main", Revision: 6, Outcome: seat.PipelineOutcomeRunning, Movers: []seat.Mover{{Module: "other", Fingerprint: "f9"}}} - mem["main.5"] = struct { - p seat.Pipeline - rev uint64 - }{failed, 1} - mem["main.6"] = struct { - p seat.Pipeline - rev uint64 - }{head, 1} - entries := map[string]catalog.CatalogEntry{} - edgeInto(entries, "gitea", "engine", 1) - type said struct { - subject string - ev seat.MoverAdded - } - var out []said - s := &Starter{Store: mem, Say: func(subject string, body any) error { - if ev, ok := body.(seat.MoverAdded); ok { - out = append(out, said{subject, ev}) - } - return nil - }} - st := memUnfinished{} - u := &Unfinished{Store: st, - Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return entries, true }, - Add: func(from seat.Pipeline, group []seat.Mover) (string, bool) { - return s.CarryToHead(from, group, entries, nil) - }} - u.Ended(failed) - if len(out) != 1 || out[0].ev.Module != "free" || out[0].ev.From != "main.5" || out[0].ev.Pipeline != "main.6" || !strings.HasSuffix(out[0].subject, ".main.6") { - t.Fatalf("mover-added = %+v, want free added to main.6 from main.5 alone: gitea is tied to engine", out) - } - if p, _, _ := mem.Get("main.6"); !Moves(p, "free") || !Moves(p, "other") { - t.Errorf("main.6 moves %+v, want other and free", p.Movers) - } - if p, _, _ := mem.Get("main.5"); Moves(p, "free") || !Moves(p, "gitea") { - t.Errorf("main.5 moves %+v, want free gone and the tied gitea kept", p.Movers) - } - var e UnfinishedEntry - _ = json.Unmarshal([]byte(st["main.free"]), &e) - if e.CarriedBy != "main.6" { - t.Errorf("free's key = %s, want carried by main.6", st["main.free"]) - } - // The carrier ends failed: the key stays, naming that pipeline, with no carrier. - ended := seat.Pipeline{Pipeline: "main.6", Branch: "main", Revision: 6, Outcome: seat.PipelineOutcomeFailed, - Movers: []seat.Mover{{Module: "free", Fingerprint: "f3"}}, - Steps: []seat.StepResult{{Module: "free", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed}}} - u.Ended(ended) - e = UnfinishedEntry{} - _ = json.Unmarshal([]byte(st["main.free"]), &e) - if e.CarriedBy != "" || e.Pipeline != "main.6" { - t.Errorf("free's key = %s, want pipeline main.6 and no carrier", st["main.free"]) - } - // A take-in whose key is held adds its entries, one mover-added each, with take-in. - out = nil - half := Half{Revision: 6, Source: 9, Entries: map[string]catalog.CatalogEntry{"late": {Commit: "c", Fp: "f7"}}} - s.Unfinished = u - n, err := s.TakenIn(catalog.TakeInTaken{Branch: "main", Source: 9, Revision: 6, Entries: []catalog.TakeInEntry{{Module: "late", Commit: "c", Fingerprint: "f7"}}}, - func(string) (Half, bool) { return half, true }) - if err != nil || n != 0 || len(out) != 1 || out[0].ev.TakeIn != 9 || out[0].ev.From != "" || out[0].ev.Module != "late" { - t.Errorf("a take-in of a held key = %d (%v), said %+v, want late added with take-in 9", n, err, out) - } -} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go index c96065593..760e7e857 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go @@ -157,30 +157,29 @@ func TestEachFailingMoverIsAFindingAndItsNextPassedPipelineClearsIt(t *testing.T if _, stands := f.held["delivery.app.main.pipeline-failed"]; !stands || len(f.held) != 1 { t.Fatalf("findings %v, want app's alone after lib's pipeline passed", f.held) } -} - -// design 47 H2 H-A-605 (2), H-A-625 (2) (AC-P7, AC-P7b): a module the registrations view no longer names has its finding -// pipeline-failed cleared, on any branch; the finding names the movers held behind the failed one and runner_unfinished_place. -func TestAFailedFindingNamesTheMoversHeldBehindAndGoesWithTheRegistration(t *testing.T) { - f := newHeld() - entries := map[string]catalog.CatalogEntry{} - edgeInto(entries, "gitea", "engine", 1) - p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, - 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.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") { - t.Fatalf("the finding says %q, want gitea held behind it and runner_unfinished_place", got.Explanation) - } - fl.Findings.(*heldFindings).held["delivery.engineer.main.pipeline-failed"] = condseat.Finding{Scope: "delivery", ID: "engineer.main", Kind: PipelineFailedKind} - fl.ModuleGone("engine") - if _, ok := f.held["delivery.engine.main.pipeline-failed"]; ok { - t.Errorf("engine left the registrations and its finding is held") - } - if _, ok := f.held["delivery.engineer.main.pipeline-failed"]; !ok { - t.Errorf("the finding of engineer, another module, was cleared") - } + // design 47 H2 H-A-605 (2), H-A-625 (2) (AC-P7, AC-P7b): a module the registrations view no longer names has its finding + // pipeline-failed cleared, on any branch; the finding names the movers held behind the failed one and runner_unfinished_place. + t.Run("TestAFailedFindingNamesTheMoversHeldBehindAndGoesWithTheRegistration", func(t *testing.T) { + f := newHeld() + entries := map[string]catalog.CatalogEntry{} + edgeInto(entries, "gitea", "engine", 1) + p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, + 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.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") { + t.Fatalf("the finding says %q, want gitea held behind it and runner_unfinished_place", got.Explanation) + } + fl.Findings.(*heldFindings).held["delivery.engineer.main.pipeline-failed"] = condseat.Finding{Scope: "delivery", ID: "engineer.main", Kind: PipelineFailedKind} + fl.ModuleGone("engine") + if _, ok := f.held["delivery.engine.main.pipeline-failed"]; ok { + t.Errorf("engine left the registrations and its finding is held") + } + if _, ok := f.held["delivery.engineer.main.pipeline-failed"]; !ok { + t.Errorf("the finding of engineer, another module, was cleared") + } + }) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go index fb2a9e81c..da7b49d37 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go @@ -304,6 +304,34 @@ func TestStandsAndStepStartedNameWhatAReadingStepWaitsOn(t *testing.T) { if len(f.said) == n { t.Error("resume said no step-started") } + // Design 47 H2 H-A-599, H-A-738 (2): a held step stands with the runner's stalled-bound and the time it was held, so the watchman's + // seed from stands times it as the wait-held did, also after a restart. + t.Run("TestStandsNamesTheBoundAndClockOfAHeldStep", func(t *testing.T) { + f := newRunFixture() + p := f.start(t, 4, 9) + held := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC) + pl := f.pipeline(p) + for i := range pl.Steps { + if pl.Steps[i].Step == "unit" && pl.Steps[i].Artifact == "app:program" { + pl.Steps[i].Outcome, pl.Steps[i].On, pl.Steps[i].Revision, pl.Steps[i].HeldAt = seat.StepResultOutcomeWaiting, seat.WaitOnRevisionView, 12, &held + } + } + pipes := memKept{} + put(t, pipes, p.Pipeline, pl) + a, err := Reads{Pipelines: pipes, Kept: memKept{}, StalledBound: time.Minute}.Stands() + if err != nil { + t.Fatal(err) + } + for _, w := range a.Stands { + if w.Artifact == "app:program" && w.Step == "unit" { + if w.Bound != "1m0s" || w.ClockFrom == nil || !w.ClockFrom.Equal(held) { + t.Errorf("the held step stands with bound %q and clock-from %v, want 1m0s and %v", w.Bound, w.ClockFrom, held) + } + return + } + } + t.Error("the held step does not stand") + }) } // TestAPipelineIsReadInParts holds show and runner_movers to design 47 H2 ยง789: one mover's steps of a record of 129 movers @@ -384,32 +412,3 @@ func TestAPipelineIsReadInParts(t *testing.T) { t.Fatalf("words %q", got) } } - -// Design 47 H2 H-A-599, H-A-738 (2): a held step stands with the runner's stalled-bound and the time it was held, so the watchman's -// seed from stands times it as the wait-held did, also after a restart. -func TestStandsNamesTheBoundAndClockOfAHeldStep(t *testing.T) { - f := newRunFixture() - p := f.start(t, 4, 9) - held := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC) - pl := f.pipeline(p) - for i := range pl.Steps { - if pl.Steps[i].Step == "unit" && pl.Steps[i].Artifact == "app:program" { - pl.Steps[i].Outcome, pl.Steps[i].On, pl.Steps[i].Revision, pl.Steps[i].HeldAt = seat.StepResultOutcomeWaiting, seat.WaitOnRevisionView, 12, &held - } - } - pipes := memKept{} - put(t, pipes, p.Pipeline, pl) - a, err := Reads{Pipelines: pipes, Kept: memKept{}, StalledBound: time.Minute}.Stands() - if err != nil { - t.Fatal(err) - } - for _, w := range a.Stands { - if w.Artifact == "app:program" && w.Step == "unit" { - if w.Bound != "1m0s" || w.ClockFrom == nil || !w.ClockFrom.Equal(held) { - t.Errorf("the held step stands with bound %q and clock-from %v, want 1m0s and %v", w.Bound, w.ClockFrom, held) - } - return - } - } - t.Error("the held step does not stand") -} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go index 4cfb2818d..444b6308f 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go @@ -549,6 +549,107 @@ func TestAPublishIsTakenIntoThePipelineOfItsRevision(t *testing.T) { if err := s.Published(ev, view); err != nil || len(published("main.8")) != 2 || len(published("main.7")) != 2 || len(published("main.9")) != 0 { t.Errorf("a publish at src2:a (%v): main.8 %v, main.7 %v, main.9 %v; want both pipelines moving it marked and revision 9's not", err, published("main.8"), published("main.7"), published("main.9")) } + // design 47 H2 H-A-594 (3), (4), H-A-607 (2), H-A-609 (3): a group left joins the head's pipeline when that waits or runs, said by + // mover-added with from, its key naming the carrier and leaving the failed pipeline's movers; a take-in whose key is held adds + // its entries, one mover-added each with take-in; a carrier that ends otherwise leaves its key naming that pipeline. + t.Run("TestAClosedGroupJoinsTheHeadPipelineAndIsSaid", func(t *testing.T) { + mem := memStore{} + 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: "free", 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: "free", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}} + head := seat.Pipeline{Pipeline: "main.6", Branch: "main", Revision: 6, Outcome: seat.PipelineOutcomeRunning, Movers: []seat.Mover{{Module: "other", Fingerprint: "f9"}}} + mem["main.5"] = struct { + p seat.Pipeline + rev uint64 + }{failed, 1} + mem["main.6"] = struct { + p seat.Pipeline + rev uint64 + }{head, 1} + entries := map[string]catalog.CatalogEntry{} + edgeInto(entries, "gitea", "engine", 1) + type said struct { + subject string + ev seat.MoverAdded + } + var out []said + s := &Starter{Store: mem, Say: func(subject string, body any) error { + if ev, ok := body.(seat.MoverAdded); ok { + out = append(out, said{subject, ev}) + } + return nil + }} + st := memUnfinished{} + u := &Unfinished{Store: st, + Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return entries, true }, + Add: func(from seat.Pipeline, group []seat.Mover) (string, bool) { + return s.CarryToHead(from, group, entries, nil) + }} + u.Ended(failed) + if len(out) != 1 || out[0].ev.Module != "free" || out[0].ev.From != "main.5" || out[0].ev.Pipeline != "main.6" || !strings.HasSuffix(out[0].subject, ".main.6") { + t.Fatalf("mover-added = %+v, want free added to main.6 from main.5 alone: gitea is tied to engine", out) + } + if p, _, _ := mem.Get("main.6"); !Moves(p, "free") || !Moves(p, "other") { + t.Errorf("main.6 moves %+v, want other and free", p.Movers) + } + if p, _, _ := mem.Get("main.5"); Moves(p, "free") || !Moves(p, "gitea") { + t.Errorf("main.5 moves %+v, want free gone and the tied gitea kept", p.Movers) + } + var e UnfinishedEntry + _ = json.Unmarshal([]byte(st["main.free"]), &e) + if e.CarriedBy != "main.6" { + t.Errorf("free's key = %s, want carried by main.6", st["main.free"]) + } + // The carrier ends failed: the key stays, naming that pipeline, with no carrier. + ended := seat.Pipeline{Pipeline: "main.6", Branch: "main", Revision: 6, Outcome: seat.PipelineOutcomeFailed, + Movers: []seat.Mover{{Module: "free", Fingerprint: "f3"}}, + Steps: []seat.StepResult{{Module: "free", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed}}} + u.Ended(ended) + e = UnfinishedEntry{} + _ = json.Unmarshal([]byte(st["main.free"]), &e) + if e.CarriedBy != "" || e.Pipeline != "main.6" { + t.Errorf("free's key = %s, want pipeline main.6 and no carrier", st["main.free"]) + } + // A take-in whose key is held adds its entries, one mover-added each, with take-in. + out = nil + half := Half{Revision: 6, Source: 9, Entries: map[string]catalog.CatalogEntry{"late": {Commit: "c", Fp: "f7"}}} + s.Unfinished = u + n, err := s.TakenIn(catalog.TakeInTaken{Branch: "main", Source: 9, Revision: 6, Entries: []catalog.TakeInEntry{{Module: "late", Commit: "c", Fingerprint: "f7"}}}, + func(string) (Half, bool) { return half, true }) + if err != nil || n != 0 || len(out) != 1 || out[0].ev.TakeIn != 9 || out[0].ev.From != "" || out[0].ev.Module != "late" { + t.Errorf("a take-in of a held key = %d (%v), said %+v, want late added with take-in 9", n, err, out) + } + // design 47 H2 H-A-594 (2), H-A-646 (AC-P3b): a mover awaiting a failed one's package (kind 1) or build step (kind 3), directly or + // through another, is tied; one with only a tier edge is not; the tied group is closed under the tier kinds. + t.Run("TestTiedMoversAreThoseAwaitingAFailedOne", func(t *testing.T) { + p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Outcome: seat.PipelineOutcomeFailed} + for _, m := range []string{"engine", "gitea", "far", "tieronly", "mate", "free"} { + p.Movers = append(p.Movers, seat.Mover{Module: m}) + } + entries := map[string]catalog.CatalogEntry{} + edgeInto(entries, "gitea", "engine", 1) // kind 1: awaits engine's package + edgeInto(entries, "far", "gitea", 3) // kind 3 through gitea + edgeInto(entries, "tieronly", "engine", 2) // delivery order only + edgeInto(entries, "mate", "far", 4) // tier edge to a tied mover: the group goes together + tied := tiedTo(p, []string{"gitea", "far", "tieronly", "mate", "free"}, []string{"engine"}, entries) + for _, m := range []string{"gitea", "far", "mate"} { + if !slices.Equal(tied[m], []string{"engine"}) { + t.Errorf("%s is tied to %v, want engine", m, tied[m]) + } + } + for _, m := range []string{"tieronly", "free"} { + if len(tied[m]) != 0 { + t.Errorf("%s is tied to %v, want none", m, tied[m]) + } + } + groups := tierGroups([]string{"tieronly", "free"}, entries) + if len(groups) != 2 { + t.Errorf("groups = %v, want each alone", groups) + } + }) + }) } // racingStore is memStore whose first Update is preceded by before, a write another part makes between a read and its write.