diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go index bd699591..0065aabd 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go @@ -173,9 +173,10 @@ func TestAToolchainEdgeIsNotAwaitedByTheBuildModulesOwnInputs(t *testing.T) { } } -// Design 47 H H-A-175 (G §270, A-326; H-A-101 (2)): a cycle among a pipeline's movers without steps ends the pipeline failed -// at its placing, its why `cycle` naming each artifact and edge kind, each of their steps ended not asked; a cycle through -// a build module's own inputs is broken (G §270) and placed; a mover waiting on a placed mover only waits. +// 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"}} @@ -183,22 +184,22 @@ func TestACycleAmongUnplacedMoversEndsThePipelineFailed(t *testing.T) { 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 - failed bool - placed []string + 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))}, false, []string{"mesh-sdk"}}, - {"a cycle no rule breaks ends the pipeline failed naming it", []catalog.CatalogEntry{ - entry("a", e("b:go", "a:go", 1)), - entry("b", e("a:go", "b:go", 1)), - entry("c")}, true, []string{"a", "b", "c"}}, + 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")}, false, []string{"b"}}, + 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} @@ -207,30 +208,32 @@ func TestACycleAmongUnplacedMoversEndsThePipelineFailed(t *testing.T) { p.Movers = append(p.Movers, seat.Mover{Module: en.Module, Commit: "c", Fingerprint: "src2:" + en.Module}) } s := &Starter{Name: "the-runner"} - asks, _, ended, _ := s.placeMovers(&p, func(string) (catalog.Registration, bool) { return reg, true }, entries, time.Unix(1, 0)) - var got []string - for _, m := range p.Movers { - if placed(p, m.Module) { - got = append(got, m.Module) + 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(got, c.placed) { - t.Errorf("%s: placed %v, want %v", c.name, got, c.placed) - } - if !c.failed { - if p.Outcome != seat.PipelineOutcomeRunning || len(ended) != 0 || len(asks) == 0 { - t.Errorf("%s: pipeline %s (%s), %d ended, %d asks; want running and asked", c.name, p.Outcome, p.Why, len(ended), len(asks)) - } - continue - } - if p.Outcome != seat.PipelineOutcomeFailed || !strings.HasPrefix(p.Why, "cycle: ") || !strings.Contains(p.Why, "a:go before b:go (kind 1)") || - !strings.Contains(p.Why, "b:go before a:go (kind 1)") || len(asks) != 0 || len(ended) == 0 { - t.Errorf("%s: pipeline %s why %q, %d asks, %d ended; want failed naming the cycle, nothing asked", c.name, p.Outcome, p.Why, len(asks), len(ended)) - } - for _, st := range p.Steps { - if st.Outcome != seat.StepResultOutcomeBypassed && (st.Outcome != seat.StepResultOutcomeNotAsked || st.Why != p.Why) { - t.Errorf("%s: %s's %s = %s (%s), want not asked naming the cycle", c.name, st.Module, st.Step, st.Outcome, st.Why) - } + 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 d585cedb..cfb8cc48 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -369,8 +369,10 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } } } - if ended := cycled(p, waits, unregistered, reg, entries, now, s.Name); len(ended) > 0 { - return nil, unregistered, ended, notAsked + 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) @@ -379,44 +381,70 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog return asks, unregistered, ended, notAsked } -// cycled ends p failed at its placing when every mover still without steps waits only on movers without steps (H-A-175; -// G §270 and A-326 break a build module's own inputs before this): a cycle no build can start, its why `cycle` naming each -// artifact and edge kind on it. The waiting movers' steps are placed ended not asked (as H-A-101 (2) does), and every other -// step still open ends not asked, the way a holderless pipeline ends at once (A-470g). It answers the steps it ended, -// none when there is no such cycle. -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 { +// 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 + return nil, false } - var on []string + after := map[string][]string{} + edges := map[string][]catalog.Edge{} for _, m := range waits { for _, x := range awaited(*p, m.Module, entries) { - if placed(*p, moduleOf(x.From)) { - return nil + 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)) } - 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 ended []int - for i := range p.Steps { - st := &p.Steps[i] - if st.Outcome == seat.StepResultOutcomeBypassed || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) { - continue + var approvals []int + for i, st := range p.Steps { + if st.Step == seat.StepResultStepApproval && st.Outcome == seat.StepResultOutcomeWaiting { + approvals = append(approvals, i) } - 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, i) } - p.Outcome, p.Why, p.Ended = seat.PipelineOutcomeFailed, why, &now - p.EndCount++ - return ended + 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