diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/order.go b/modules/mesh-delivery-pipeline/internal/pipeline/order.go index cf0000b6..59838981 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/order.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/order.go @@ -137,7 +137,9 @@ func components(movers []seat.Mover, after map[string][]string) map[string]int { var buildKinds = []int64{3, 1} // awaited are the artifact references mover m's steps wait for in p (§746, H-A-51): the From of each edge of a build kind -// into m from another mover of p, toolchain edges first, each once. +// into m from another mover of p, toolchain edges first, each once. A toolchain edge (kind 3) from a build module whose +// own new version is built from m is not awaited: what a build module's new version is built from is built by its +// running version, never waited for (G §270, A-326), so the running build module builds m and the new one the rest. func awaited(p seat.Pipeline, m string, entries map[string]catalog.CatalogEntry) []catalog.Edge { var out []catalog.Edge for _, kind := range buildKinds { @@ -146,12 +148,35 @@ func awaited(p seat.Pipeline, m string, entries map[string]catalog.CatalogEntry) if x.Kind != kind || from == m || !Moves(p, from) || slices.ContainsFunc(out, func(e catalog.Edge) bool { return e.From == x.From }) { continue } + if kind == 3 && builtFrom(p, from, entries)[m] { + continue + } out = append(out, x) } } return out } +// builtFrom are the movers of p that module's new version is built from (G §270): the From mover of each edge of a build +// kind into it, and what those are built from in turn. +func builtFrom(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) map[string]bool { + seen := map[string]bool{} + next := []string{module} + for len(next) > 0 { + cur := next[0] + next = next[1:] + for _, x := range entries[cur].Edges { + from := moduleOf(x.From) + if !slices.Contains(buildKinds, x.Kind) || from == cur || seen[from] || !Moves(p, from) { + continue + } + seen[from] = true + next = append(next, from) + } + } + return seen +} + // ready says whether mover m of p may be placed (§746, H-A-84): every artifact it awaits is in its From mover's published. // It answers the references still awaited, and the first From mover whose build ended without passing, so m never builds. func ready(p seat.Pipeline, m string, entries map[string]catalog.CatalogEntry) (bool, []string, string) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go index a5dff3bb..0065aabd 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go @@ -4,6 +4,7 @@ import ( "slices" "strings" "testing" + "time" 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" @@ -124,3 +125,115 @@ func TestAMoversBuildWaitsForItsDependenciesInThePipeline(t *testing.T) { } } } + +// Design 47 G §270, A-326 (H §746, H-A-83 (2)): what a build module's new version is built from is built by its running +// version, never waited for: a mover the moving build module imports, directly or through another mover, does not await +// that build module's toolchain edge, so a pipeline moving mesh-sdk or the contracts with the Go build module places them +// at once (main.28, main.30 of 2026-11-20 waited on each other forever); every other mover still awaits the new one. +func TestAToolchainEdgeIsNotAwaitedByTheBuildModulesOwnInputs(t *testing.T) { + e := func(from, to string, kind int64) catalog.Edge { return catalog.Edge{From: from, To: to, Kind: kind} } + entries := map[string]catalog.CatalogEntry{ + "mesh-sdk": {Edges: []catalog.Edge{e("mesh-build-go:files", "mesh-sdk:go", 3)}}, + "contracts": {Edges: []catalog.Edge{e("mesh-build-go:files", "contracts:go-a", 3), e("mesh-build-go:files", "contracts:go-b", 3)}}, + "delivery-sdk": {Edges: []catalog.Edge{e("mesh-build-go:files", "delivery-sdk:go", 3), e("mesh-sdk:go", "delivery-sdk:go", 1)}}, + "mesh-build-go": {Edges: []catalog.Edge{e("contracts:go-a", "mesh-build-go:tools", 1), e("delivery-sdk:go", "mesh-build-go:tools", 1), e("nats:tools", "mesh-build-go:files", 4)}}, + "zfs": {Edges: []catalog.Edge{e("mesh-build-go:files", "zfs:tools", 3), e("contracts:go-a", "zfs:tools", 1)}}, + "tool": {Edges: []catalog.Edge{e("builder:program", "tool:program", 3)}}, + "builder": {}, + } + pipe := func(modules ...string) seat.Pipeline { + var p seat.Pipeline + for _, m := range modules { + p.Movers = append(p.Movers, seat.Mover{Module: m}) + } + return p + } + all := pipe("mesh-sdk", "contracts", "delivery-sdk", "mesh-build-go", "zfs") + for _, c := range []struct { + name string + p seat.Pipeline + mover string + want []string + }{ + {"the build module's own package input awaits no toolchain edge", all, "contracts", nil}, + {"an input through another mover awaits no toolchain edge", all, "mesh-sdk", nil}, + {"an input that imports another input awaits only that package", all, "delivery-sdk", []string{"mesh-sdk:go"}}, + {"the build module awaits its inputs' packages", all, "mesh-build-go", []string{"contracts:go-a", "delivery-sdk:go"}}, + {"any other mover awaits the new build module first", all, "zfs", []string{"mesh-build-go:files", "contracts:go-a"}}, + {"a build module that is not built from the mover is awaited", pipe("tool", "builder"), "tool", []string{"builder:program"}}, + {"a build module that does not move is not awaited", pipe("tool"), "tool", nil}, + } { + var got []string + for _, x := range awaited(c.p, c.mover, entries) { + got = append(got, x.From) + } + if !slices.Equal(got, c.want) { + t.Errorf("%s: %s awaits %v, want %v", c.name, c.mover, got, c.want) + } + } +} + +// Design 47 H H-A-175, H-A-176 (G §270, A-326; H-A-101 (2), H-A-163): when every mover without steps waits only on movers +// without steps, their steps are placed ended not asked, the why `cycle` naming the edges inside the cycle alone; a step +// of another mover is asked as ever, and the pipeline ends by the end judgement, at once when no required step is open; a +// cycle through a build module's own inputs is broken (G §270) and placed; a mover waiting on a placed mover only waits. +func TestACycleAmongUnplacedMoversEndsThePipelineFailed(t *testing.T) { + reg, base := placeFixture() + reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Integration: "bypass", Validate: "bypass", Composition: "bypass"}} + entry := func(m string, edges ...catalog.Edge) catalog.CatalogEntry { + return catalog.CatalogEntry{Module: m, Artifacts: []catalog.Artifact{{Ref: m + ":go", Language: "go"}}, Edges: edges} + } + e := func(from, to string, kind int64) catalog.Edge { return catalog.Edge{From: from, To: to, Kind: kind} } + cycle := []catalog.CatalogEntry{entry("a", e("b:go", "a:go", 1)), entry("b", e("a:go", "b:go", 1))} + for _, c := range []struct { + name string + entries []catalog.CatalogEntry + outcome string + asked []string + notAsked []string + }{ + {"a cycle G §270 breaks is placed", []catalog.CatalogEntry{ + entry("mesh-sdk", e("mesh-build-go:files", "mesh-sdk:go", 3)), + entry("mesh-build-go", e("mesh-sdk:go", "mesh-build-go:go", 1))}, seat.PipelineOutcomeRunning, []string{"mesh-sdk"}, nil}, + {"a cycle beside a free mover ends its own steps and the free one is asked", + append(slices.Clone(cycle), entry("c"), entry("d", e("a:go", "d:go", 1))), seat.PipelineOutcomeRunning, []string{"c"}, []string{"a", "b", "d"}}, + {"a cycle alone ends the pipeline failed at once", cycle, seat.PipelineOutcomeFailed, nil, []string{"a", "b"}}, + {"a mover waiting on a placed mover waits", []catalog.CatalogEntry{ + entry("a", e("b:go", "a:go", 1)), entry("b")}, seat.PipelineOutcomeRunning, []string{"b"}, nil}, + } { + entries := map[string]catalog.CatalogEntry{"mesh-build-go": base["mesh-build-go"]} + p := seat.Pipeline{Pipeline: "main.4", Branch: "main", Source: 4, Outcome: seat.PipelineOutcomeRunning} + for _, en := range c.entries { + entries[en.Module] = en + p.Movers = append(p.Movers, seat.Mover{Module: en.Module, Commit: "c", Fingerprint: "src2:" + en.Module}) + } + s := &Starter{Name: "the-runner"} + asks, _, ended, notAsked := s.placeMovers(&p, func(string) (catalog.Registration, bool) { return reg, true }, entries, time.Unix(1, 0)) + if p.Outcome != c.outcome || (c.outcome == seat.PipelineOutcomeFailed) != (len(ended) > 0) || (len(c.asked) > 0) != (len(asks) > 0) { + t.Errorf("%s: pipeline %s (%s), %d asks, %d ended; want %s", c.name, p.Outcome, p.Why, len(asks), len(ended), c.outcome) + } + said := map[int]bool{} + for _, i := range append(ended, notAsked...) { + said[i] = true + } + var asked, ends []string + for i, st := range p.Steps { + switch { + case st.Outcome == seat.StepResultOutcomeNotAsked && strings.HasPrefix(st.Why, "cycle: ") && said[i]: + if !slices.Contains(ends, st.Module) { + ends = append(ends, st.Module) + } + if st.Why != "cycle: a:go before b:go (kind 1); b:go before a:go (kind 1)" { + t.Errorf("%s: %s's %s why %q, want the cycle's two edges alone", c.name, st.Module, st.Step, st.Why) + } + case open(st) || st.Outcome == seat.StepResultOutcomeWaiting: + if !slices.Contains(asked, st.Module) { + asked = append(asked, st.Module) + } + } + } + if !slices.Equal(asked, c.asked) || !slices.Equal(ends, c.notAsked) { + t.Errorf("%s: open %v, ended not asked %v; want %v and %v", c.name, asked, ends, c.asked, c.notAsked) + } + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index 27174963..cfb8cc48 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -317,6 +317,7 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog var asks []Asked var unregistered []string var notAsked []int + var waits []seat.Mover for _, m := range p.Movers { if placed(*p, m.Module) { continue @@ -331,6 +332,7 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog due, waiting, failed := ready(*p, m.Module, entries) if !due && failed == "" { s.logf("%s: %s waits for %s before its build", p.Pipeline, m.Module, strings.Join(waiting, ", ")) + waits = append(waits, m) continue } steps, a := Place(*p, m, r, entries, now, s.Name) @@ -367,6 +369,11 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } } } + if steps, ended := cycled(p, waits, unregistered, reg, entries, now, s.Name); ended { + return nil, unregistered, steps, notAsked + } else { + notAsked = append(notAsked, steps...) + } // A mover placed after the validate ended has its composition asked, or not asked, at once (§745). more, _ := releaseCompositions(p, now) asks = append(asks, more...) @@ -374,6 +381,72 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog return asks, unregistered, ended, notAsked } +// cycled ends not asked, at p's placing, the steps of every mover still without steps when each waits only on movers +// without steps (H-A-175, H-A-176; G §270 and A-326 break a build module's own inputs before this): a cycle no build can +// start, and the movers that wait only on it. Their steps are placed ended not asked (as H-A-101 (2) does), the why +// `cycle` naming each artifact and edge kind whose two movers share a strongly connected group; no step already asked is +// touched. The pipeline then ends by the end judgement of H-A-163 (endPipeline), failed once no required step is open, +// its running steps running to their own end. It answers the steps it ended not asked, or, when the pipeline ended, every +// step it ended, and whether the pipeline ended. +func cycled(p *seat.Pipeline, waits []seat.Mover, unregistered []string, reg func(module string) (catalog.Registration, bool), entries map[string]catalog.CatalogEntry, now time.Time, name string) ([]int, bool) { + if len(waits) == 0 || len(unregistered) > 0 { + return nil, false + } + after := map[string][]string{} + edges := map[string][]catalog.Edge{} + for _, m := range waits { + for _, x := range awaited(*p, m.Module, entries) { + from := moduleOf(x.From) + if placed(*p, from) { + return nil, false + } + after[m.Module] = append(after[m.Module], from) + edges[m.Module] = append(edges[m.Module], x) + } + } + comp := components(waits, after) + var on []string + for _, m := range waits { + for _, x := range edges[m.Module] { + if comp[moduleOf(x.From)] == comp[m.Module] { + on = append(on, fmt.Sprintf("%s before %s (kind %d)", x.From, x.To, x.Kind)) + } + } + } + sort.Strings(on) + why := "cycle: " + strings.Join(on, "; ") + var ended []int + for _, m := range waits { + r, _ := reg(m.Module) + steps, _ := Place(*p, m, r, entries, now, name) + for k := range steps { + st := &steps[k] + if st.Outcome == seat.StepResultOutcomeBypassed { + continue + } + st.Outcome, st.Why, st.Ask, st.Shared, st.Ended = seat.StepResultOutcomeNotAsked, why, "", nil, &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now)) + ended = append(ended, len(p.Steps)+k) + } + p.Steps = append(p.Steps, steps...) + } + var approvals []int + for i, st := range p.Steps { + if st.Step == seat.StepResultStepApproval && st.Outcome == seat.StepResultOutcomeWaiting { + approvals = append(approvals, i) + } + } + if !endPipeline(p, now, nil) { + return ended, false + } + for _, i := range approvals { + if p.Steps[i].Outcome == seat.StepResultOutcomeNotAsked { + ended = append(ended, i) + } + } + return ended, true +} + // sayNotAsked says the step-ended of each step of p placed not asked because its mover's dependency did not build, naming // the dependency in its why, so no step ends silently (H-A-101 (2)). func (s *Starter) sayNotAsked(p seat.Pipeline, steps []int) {