diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place.go b/modules/mesh-delivery-pipeline/internal/pipeline/place.go index 4110b3d1..d978de57 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place.go @@ -4,6 +4,8 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "maps" + "slices" "sort" "strconv" "strings" @@ -140,6 +142,13 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ steps = append(steps, s) continue } + // A Go step is asked only once every pin of its entry has a version (H-A-206): until then it waits on the + // publish, as the build does (H-A-165), and the publish re-pins the entry and moves the mover (H-A-204). + if path := unpinnedPackage(entry); path != "" && language == sdkstep.AskGo { + s.Seat, s.Outcome, s.Started, s.Why = bs, seat.StepResultOutcomeWaiting, &now, PinWait+path + steps = append(steps, s) + continue + } s.Seat, s.Outcome, s.Started = bs, seat.StepResultOutcomeRunning, &now s.Ask = AskID(startOf(p, now), p.Pipeline, m.Module, a.Ref, step) body := stepAsk(p, m, entry, a, language, step, s.Ask, asker, now) @@ -227,6 +236,45 @@ type Asked struct { Commit string } +// PinWait opens the why of a Go step held because its entry names a package with no version yet (H-A-206), the build's +// own wait form (H-A-165); the package's path follows. +const PinWait = "waits on the publish of " + +// unpinnedPackage is the first package, in path order, the entry names with no version, empty when every one has one. +func unpinnedPackage(e catalog.CatalogEntry) string { + for _, path := range slices.Sorted(maps.Keys(e.Packages)) { + if e.Packages[path] == "" { + return path + } + } + return "" +} + +// pinHeld says whether a step waits for its entry's pins (H-A-206). +func pinHeld(s seat.StepResult) bool { + return s.Outcome == seat.StepResultOutcomeWaiting && strings.HasPrefix(s.Why, PinWait) +} + +// endPinHeld ends, as the mover's build ended without passing, each of its steps waiting for its entry's pins (H-A-206): +// with the build's outcome and why, so no step waits on a publish the build no longer waits for. It answers the steps it +// ended; a build that passed ends none, the publish re-pinning the entry and moving the mover. +func endPinHeld(p *seat.Pipeline, build seat.StepResult, now time.Time) []int { + if stepPassed(build) { + return nil + } + var ended []int + for i := range p.Steps { + st := &p.Steps[i] + if st.Module != build.Module || !pinHeld(*st) { + continue + } + st.Outcome, st.Why, st.Ended = build.Outcome, "the build ended "+build.Outcome+" while this step waited: "+st.Why+"; "+build.Why, &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now)) + ended = append(ended, i) + } + return ended +} + func stepAsk(p seat.Pipeline, m seat.Mover, e catalog.CatalogEntry, a catalog.Artifact, language, step, id, asker string, now time.Time) nodebuildgo.StepAsk { // A step is for its module alone (principle 10, A-447): the fetch always names the module's directory, and the // artifact's named paths in it when the entry has them. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go index 21b3047e..0ffc885f 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go @@ -2,6 +2,7 @@ package pipeline import ( "encoding/json" + "fmt" "strconv" "strings" "testing" @@ -44,7 +45,7 @@ func placeFixture() (catalog.Registration, map[string]catalog.CatalogEntry) { Artifacts: map[string]catalog.StepStatuses{"tools": {Lint: "bypass"}}, }} return reg, map[string]catalog.CatalogEntry{ - "app": {Module: "app", Path: "modules/app", Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25", "git.novox.be/novox/x/go": ""}, Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}, + "app": {Module: "app", Path: "modules/app", Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25"}, Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}, {Ref: "app:web", Language: "rust"}}, Inputs: &catalog.EntryInputs{Paths: map[string][]string{"app:program": {"cmd/app"}}}}, "mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}, } @@ -104,13 +105,50 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { len(a.Step.Fetch.Paths) != 1 || a.Step.Fetch.Paths[0] != "cmd/app" { t.Errorf("the ask = %+v at %s", a, asks.at[1]) } - // Every step ask fetches with the entry's pins, as the builder gives them the build; a package with no pin yet is left - // out (H-A-203, H-A-192). + // Every step ask fetches with the entry's pins, as the builder gives them the build (H-A-203, H-A-192). for _, x := range asks.asks[1:] { if b, ok := x.(nodebuildgo.StepAsk); ok && b.Step != nil && (len(b.Step.Fetch.Packages) != 1 || b.Step.Fetch.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.25") { t.Errorf("the %s ask of %s fetches the pins %v, want the entry's", b.Step.Step, b.Step.Artifact, b.Step.Fetch.Packages) } } + // An entry naming a package with no version yet asks no Go step: each waits on its publish, as the build does, said in + // the journal (H-A-206); the build is still asked. + waiting := map[string]catalog.CatalogEntry{} + for k, e := range entries { + waiting[k] = e + } + held := waiting["app"] + held.Packages = map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25", "git.novox.be/novox/x/go": ""} + waiting["app"] = held + var journal []string + heldAsks := &stepAsks{} + hs := &Starter{Pipelines: store, Say: func(string, any) error { return nil }, Steps: heldAsks, Name: "the-runner", + Logf: func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }, + Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }} + if ok, err := hs.Start(Begin{Branch: "main", Source: 5, Entries: waiting, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:ab", Repository: "o/app"}}}); !ok || err != nil { + t.Fatalf("start = %v, %v", ok, err) + } + for _, x := range heldAsks.asks { + if b, ok := x.(nodebuildgo.StepAsk); ok { + t.Errorf("the %s of %s is asked with a package unpinned", b.Step.Step, b.Step.Artifact) + } + } + var hp seat.Pipeline + if err := json.Unmarshal(store["main.5"], &hp); err != nil { + t.Fatal(err) + } + if st := hp.Steps[1]; st.Step != "lint" || st.Outcome != seat.StepResultOutcomeWaiting || st.Ask != "" || st.Why != "waits on the publish of git.novox.be/novox/x/go" { + t.Errorf("the held lint step = %+v; want it waiting on the publish", st) + } + // The build ending without passing past its bound ends each held step as it ended (H-A-206). + failed := hp.Steps[0] + failed.Outcome, failed.Why = seat.StepResultOutcomeFailed, "package git.novox.be/novox/x/go has no released version" + if ended := endPinHeld(&hp, failed, time.Now()); len(ended) == 0 || hp.Steps[1].Outcome != seat.StepResultOutcomeFailed || hp.Steps[1].Ended == nil { + t.Errorf("after the build failed the held lint step = %+v (%d ended); want it failed", hp.Steps[1], len(ended)) + } + if !strings.Contains(strings.Join(journal, "\n"), "app's lint of app:program is not asked: it waits on the publish of git.novox.be/novox/x/go") { + t.Errorf("the journal says %q; want the held step named", journal) + } // An artifact that names no paths still fetches its module alone: the directory with no paths (principle 10, A-447). for _, x := range asks.asks[2:] { if b, ok := x.(nodebuildgo.StepAsk); ok && b.Step != nil && b.Step.Artifact == "app:tools" && (b.Step.Fetch.Dir != "modules/app" || len(b.Step.Fetch.Paths) != 0) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index cfb8cc48..cb039452 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -189,7 +189,7 @@ func (s *Starter) holderless(p *seat.Pipeline, asks []Asked, now time.Time) ([]A } var none []string for _, st := range p.Steps { - if !open(st) || !BoundSeat(st.Seat) || slices.Contains(none, st.Seat) { + if (!open(st) && !pinHeld(st)) || !BoundSeat(st.Seat) || slices.Contains(none, st.Seat) { continue } if holders, read := s.Holders(st.Seat); read && len(holders) == 0 { @@ -337,6 +337,11 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } steps, a := Place(*p, m, r, entries, now, s.Name) supersededWhy(*p, m.Module, entries, steps) + for _, st := range steps { + if pinHeld(st) { + s.logf("%s: %s's %s of %s is not asked: it %s, as its build does (H-A-206)", p.Pipeline, m.Module, st.Step, st.Artifact, st.Why) + } + } if failed != "" { why := "its dependency " + failed + " did not build" for k := range steps { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 9b39cf26..854af132 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -272,6 +272,9 @@ func (h *Hearer) OnStepEndedShared(bs StepSeat, subject string, ev StepEnded, sh // Every mover's validate reads the one run (ยง745, H-A-51); its end asks each mover's composition, or ends it not // asked when validate did not pass. var due []Asked + if s.Step == seat.StepResultStepBuild { + readers = append(readers, endPinHeld(&p, *s, now)...) + } if s.Step == seat.StepResultStepValidate { readers = append(readers, sameValidate(&p, i, now)...) var notAsked []int