diff --git a/modules/mesh-delivery-contracts/go/seats/nodebuildgo/contract.go b/modules/mesh-delivery-contracts/go/seats/nodebuildgo/contract.go index 047c71bef..038451d87 100644 --- a/modules/mesh-delivery-contracts/go/seats/nodebuildgo/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/nodebuildgo/contract.go @@ -73,7 +73,7 @@ func VerbDescription(verb string) string { case VerbKeptArtifact: return "The one build this node keeps instead of storing it through the seat oci-artifact-registry: the new build of that seat's holder, when the running holder refused or did not answer the store (design 47 *The artifact store's holder takes its own new build even when its seat is the one broken*). Answers where the bytes are, as an object by their digest on the bus (the old objects form, ADR 0619 §2), never in the answer; the node-engine checks what it fetched against the digest and applies nothing that differs. A module that claims no oci-artifact-registry is refused by name, so a store outage never becomes a delivery from build nodes; so is a build this node no longer keeps, or keeps under another digest." case VerbSteps: - return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint always, unit and integration tests where its packages hold them. Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." + return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint where the artifact holds what its language's lint reads (a Go artifact always, a TypeScript artifact only where one of its packages holds a TypeScript file; design 47 H2 H-A-515 second addendum), unit and integration tests where its packages hold them. A kind it answers none for is never asked: the pipeline runner ends it nothing to run at placement (H-A-515 addendum). Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." case VerbAnswer: return "A step's answer by its ask, when the step's key or a run's step-ended names it as `answer-object` because the answer is over what the steps state's value or the event carries (design 47 H2 H-A-412): the kept end's bytes in chunks of at most 512 KiB on the chunk subject of the call, each acknowledged by the caller on the ack subject within 30 seconds; the answer is of any size. An answer inline in the key or the event is never asked here; a run's test output is the verb output's." case VerbOutput: diff --git a/modules/mesh-delivery-contracts/go/seats/nodebuildimage/contract.go b/modules/mesh-delivery-contracts/go/seats/nodebuildimage/contract.go index efce6a6d9..77dc64f16 100644 --- a/modules/mesh-delivery-contracts/go/seats/nodebuildimage/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/nodebuildimage/contract.go @@ -72,7 +72,7 @@ func VerbDescription(verb string) string { case VerbKeptArtifact: return "The one build this node keeps instead of storing it through the seat oci-artifact-registry: the new build of that seat's holder, when the running holder refused or did not answer the store (design 47 *The artifact store's holder takes its own new build even when its seat is the one broken*). Answers where the bytes are, as an object by their digest on the bus (the old objects form, ADR 0619 §2), never in the answer; the node-engine checks what it fetched against the digest and applies nothing that differs. A module that claims no oci-artifact-registry is refused by name, so a store outage never becomes a delivery from build nodes; so is a build this node no longer keeps, or keeps under another digest." case VerbSteps: - return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint always, unit and integration tests where its packages hold them. Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." + return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint where the artifact holds what its language's lint reads (a Go artifact always, a TypeScript artifact only where one of its packages holds a TypeScript file; design 47 H2 H-A-515 second addendum), unit and integration tests where its packages hold them. A kind it answers none for is never asked: the pipeline runner ends it nothing to run at placement (H-A-515 addendum). Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." case VerbAnswer: return "A step's answer by its ask, when the step's key or a run's step-ended names it as `answer-object` because the answer is over what the steps state's value or the event carries (design 47 H2 H-A-412): the kept end's bytes in chunks of at most 512 KiB on the chunk subject of the call, each acknowledged by the caller on the ack subject within 30 seconds; the answer is of any size. An answer inline in the key or the event is never asked here; a run's test output is the verb output's." case VerbOutput: diff --git a/modules/mesh-delivery-contracts/go/seats/nodebuildnode/contract.go b/modules/mesh-delivery-contracts/go/seats/nodebuildnode/contract.go index 1460a4cc9..ce3d01670 100644 --- a/modules/mesh-delivery-contracts/go/seats/nodebuildnode/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/nodebuildnode/contract.go @@ -73,7 +73,7 @@ func VerbDescription(verb string) string { case VerbKeptArtifact: return "The one build this node keeps instead of storing it through the seat oci-artifact-registry: the new build of that seat's holder, when the running holder refused or did not answer the store (design 47 *The artifact store's holder takes its own new build even when its seat is the one broken*). Answers where the bytes are, as an object by their digest on the bus (the old objects form, ADR 0619 §2), never in the answer; the node-engine checks what it fetched against the digest and applies nothing that differs. A module that claims no oci-artifact-registry is refused by name, so a store outage never becomes a delivery from build nodes; so is a build this node no longer keeps, or keeps under another digest." case VerbSteps: - return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint always, unit and integration tests where its packages hold them. Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." + return "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint where the artifact holds what its language's lint reads (a Go artifact always, a TypeScript artifact only where one of its packages holds a TypeScript file; design 47 H2 H-A-515 second addendum), unit and integration tests where its packages hold them. A kind it answers none for is never asked: the pipeline runner ends it nothing to run at placement (H-A-515 addendum). Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480)." case VerbAnswer: return "A step's answer by its ask, when the step's key or a run's step-ended names it as `answer-object` because the answer is over what the steps state's value or the event carries (design 47 H2 H-A-412): the kept end's bytes in chunks of at most 512 KiB on the chunk subject of the call, each acknowledged by the caller on the ack subject within 30 seconds; the answer is of any size. An answer inline in the key or the event is never asked here; a run's test output is the verb output's." case VerbOutput: diff --git a/modules/mesh-delivery-contracts/parts/build-step.json b/modules/mesh-delivery-contracts/parts/build-step.json index 49f33cfcd..97d1c763b 100644 --- a/modules/mesh-delivery-contracts/parts/build-step.json +++ b/modules/mesh-delivery-contracts/parts/build-step.json @@ -194,7 +194,7 @@ }, { "name": "steps", - "description": "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint always, unit and integration tests where its packages hold them. Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480).", + "description": "Which pipeline steps an artifact can run, found by its language's convention (design 47 *Pipeline steps and the policy*): lint where the artifact holds what its language's lint reads (a Go artifact always, a TypeScript artifact only where one of its packages holds a TypeScript file; design 47 H2 H-A-515 second addendum), unit and integration tests where its packages hold them. A kind it answers none for is never asked: the pipeline runner ends it nothing to run at placement (H-A-515 addendum). Kept by the artifact's fingerprint; again finds them anew. With drop and why it deletes the artifact's kept key instead, writes the act in the hand-act log of the seat mesh-hand-acts first (a log that refuses deletes nothing and answers error), and answers dropped (design 47 G section 463, section 480).", "input": { "type": "object", "properties": { diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/detect.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/detect.go new file mode 100644 index 000000000..21462cc77 --- /dev/null +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/detect.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "fmt" + + nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-sdk/go/buscalls" + + "mesh-delivery-pipeline/internal/pipeline" +) + +// stepsOf calls a build seat's verb steps at placement, once (design 47 H2 H-A-515 addendum): the seat answers from its kept +// answer by the artifact's fingerprint, in seconds, never through a build node's queue. A call that fails or is not +// answered within the call's bound is the runner's to say, and the artifact's steps are asked as before. The three build +// seats' steps take one input and answer one form (nodebuildgo's contract; the manifest invokes each). +func stepsOf(call func(key string, body any) (json.RawMessage, error)) pipeline.StepsCaller { + return func(buildSeat string, in nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) { + key := "seat:" + buildSeat + "." + nodebuildgo.VerbSteps + raw, err := call(key, in) + if err != nil { + return nodebuildgo.StepsAnswer{}, err + } + answer, said, ok := buscalls.Unwrap(raw) + if !ok { + return nodebuildgo.StepsAnswer{}, fmt.Errorf("%s answered: %s", key, said) + } + var a nodebuildgo.StepsAnswer + if err := json.Unmarshal(answer, &a); err != nil { + return a, fmt.Errorf("the answer of %s is not its steps: %w", key, err) + } + return a, nil + } +} diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index 94bdb3d73..33105faee 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -180,7 +180,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains), Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing, Findings: rv.Findings, Observer: cred.Module, // a mover waiting on its registration is registration-missing (H-A-262) - Unfinished: unfinished, RootTree: rootTree(calls)} + Unfinished: unfinished, RootTree: rootTree(calls), + Detect: stepsOf(calls.Call)} // a step kind an artifact's build seat answers none for is never asked (H-A-515) hearer.Unfinished = unfinished hearer.AskSteps = starter.AskSteps hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4)) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/detected.go b/modules/mesh-delivery-pipeline/internal/pipeline/detected.go new file mode 100644 index 000000000..da3def416 --- /dev/null +++ b/modules/mesh-delivery-pipeline/internal/pipeline/detected.go @@ -0,0 +1,122 @@ +package pipeline + +import ( + "fmt" + "slices" + "strings" + "time" + + 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" + nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" + "git.novox.be/novox/mesh-sdk/go/seatdef" +) + +// **A step with nothing to run is never asked** (design 47 H2 H-A-515 and its addendum): at placement the runner calls +// the verb steps of each artifact's build seat (design 47 G §22, §326), which answers, kept by the artifact's fingerprint, +// which pipeline steps the artifact can run; every lint, unit or integration step of a kind it answers none for ends +// nothing to run at once, asked of no build node. The other steps are asked as before, beside the build step. A steps call +// that fails or is not answered asks the artifact's steps as before, said in one journal line. + +// StepsCaller calls the verb steps of the build seat buildSeat (the three build seats' verbs have one form, so nodebuildgo's +// contract reads each seat's). +type StepsCaller func(buildSeat string, in nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) + +// detected is one artifact's answer of its build seat's steps: the seat and the step kinds it answered. +type detected struct { + Seat string + Kinds []string +} + +// detectedSteps is each artifact's answer by its reference; an artifact it names nothing of is asked as before. +type detectedSteps map[string]detected + +// detect calls the verb steps of each artifact of mover m whose lint, unit or integration step the policy does not bypass +// and a build seat builds, at the fingerprint and with the fetch its steps would be asked with (H-A-515 addendum). An +// artifact whose call fails, or whose answer says an error, is left out, and its steps are asked as before: said once +// per artifact in the journal. Nil without a caller. +func (s *Starter) detect(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[string]catalog.CatalogEntry) detectedSteps { + if s.Detect == nil { + return nil + } + entry := entries[m.Module] + out := detectedSteps{} + for _, a := range entry.Artifacts { + if sdkstep.PackedOrFetched(a.Language, a.Kind) { + continue + } + name := a.Ref + if _, after, ok := strings.Cut(a.Ref, ":"); ok { + name = after + } + if !slices.ContainsFunc(buildSteps, func(step string) bool { return Status(reg, name, step) != seat.StepResultStatusBypass }) { + continue + } + on := a.Language + if on == "" && a.Kind == "image" { + on = seatdef.OnKindImage + } + bs, err := BuildSeat(entries, on) + if err != nil { + continue // place ends its steps could not run, naming the missing seat + } + fetch := stepFetch(m, entry, a) + in := nodebuildgo.StepsInput{Module: m.Module, Artifact: nodebuildgo.DetectedStepsByModuleArtifactKey(m.Module, name), + Fingerprint: m.Fingerprint, Fetch: &fetch} + ans, err := s.Detect(bs, in) + if err == nil && ans.Error != "" { + err = fmt.Errorf("it answered %s", ans.Error) + } + if err != nil { + s.logf("%s: the steps of %s are not read from %s (%v): its lint, unit and integration steps are asked as before (H-A-515)", p.Pipeline, a.Ref, bs, err) + continue + } + d := detected{Seat: bs} + for _, st := range ans.Steps { + d.Kinds = append(d.Kinds, st.Step) + } + out[a.Ref] = d + } + return out +} + +// placedNothing are the steps of steps, appended to p at base, that placing ended nothing to run (H-A-515 addendum): each +// written in the step log, and answered by its index in p, for its step-ended to be said once p is written. +func placedNothing(p *seat.Pipeline, steps []seat.StepResult, base int, now time.Time) []int { + var out []int + for k, st := range steps { + if placedNothingToRun(st) { + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, st, now)) + out = append(out, base+k) + } + } + return out +} + +// placedNothingToRun says a lint, unit or integration step was ended nothing to run at its placing, asked of no one. +func placedNothingToRun(st seat.StepResult) bool { + return st.Outcome == seat.StepResultOutcomeNothingToRun && st.Ask == "" && len(st.Shared) == 0 && slices.Contains(buildSteps, st.Step) +} + +// knownOf is what placing knew of mover module's artifacts, read back from p's own steps: each artifact with a step ended +// nothing to run at its placing knows every kind but those. A step placed again from it (asked again after a restart) +// finds the same asks and the same test runs as its first placing. +func knownOf(p seat.Pipeline, module string) detectedSteps { + var out detectedSteps + for _, st := range p.Steps { + if st.Module != module || !placedNothingToRun(st) { + continue + } + if out == nil { + out = detectedSteps{} + } + d, read := out[st.Artifact] + if !read { + d = detected{Seat: st.Seat, Kinds: slices.Clone(buildSteps)} + } + d.Kinds = slices.DeleteFunc(d.Kinds, func(k string) bool { return k == st.Step }) + out[st.Artifact] = d + } + return out +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place.go b/modules/mesh-delivery-pipeline/internal/pipeline/place.go index d093ffa2f..6d8002604 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place.go @@ -93,7 +93,7 @@ func startOf(p seat.Pipeline, now time.Time) time.Time { // could not run naming the missing seat; the module's steps wait. It returns the steps and the asks to put on the seats' // work queues, one per running step. func Place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[string]catalog.CatalogEntry, now time.Time, asker string) ([]seat.StepResult, []Asked) { - return place(p, m, reg, entries, now, asker, true, 0) + return place(p, m, reg, entries, now, asker, true, 0, nil) } // place is Place; share false places each build step its own ask, as a step asked before the test runs is (§730, A-468k). @@ -101,8 +101,10 @@ func Place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ // reference order, asks the run and names it in Shared; every other step of the key reads it, keeping no ask of its own and // naming the run's ask and the step that asked it (A-469m, A-469q). // kept is the catalog revision a same-source re-pin kept m at, 0 for a mover not kept: its every ask id mixes it in -// (H-A-286). -func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[string]catalog.CatalogEntry, now time.Time, asker string, share bool, kept int64) ([]seat.StepResult, []Asked) { +// (H-A-286). known is what each artifact's build seat answered its verb steps (Starter.detect, design 47 H2 H-A-515 +// addendum): a lint, unit or integration step of a kind it answered none for is placed ended nothing to run, asked of no +// one; an artifact known names nothing of is asked as before. +func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[string]catalog.CatalogEntry, now time.Time, asker string, share bool, kept int64, known detectedSteps) ([]seat.StepResult, []Asked) { entry := entries[m.Module] candidate, named := CandidateOf(p) share = share && named @@ -114,7 +116,8 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ // The build step is every mover's first, required whatever the policy names, asked of the seat mesh-builds for the // mover's own entry only (A-99, A-97): each mover is built by its own step (§746). build := seat.StepResult{Step: seat.StepResultStepBuild, Module: m.Module, Status: seat.StepResultStatusRequired, Fingerprint: m.Fingerprint, - Seat: builds.Seat, Outcome: seat.StepResultOutcomeRunning, Started: &now, Ask: keptAskID(startOf(p, now), p.Pipeline, m.Module, "", seat.StepResultStepBuild, kept)} + Seat: builds.Seat, Outcome: seat.StepResultOutcomeRunning, Started: &now, AskedAt: &now, // asked-at, as a test step's (§778, H-A-516) + Ask: keptAskID(startOf(p, now), p.Pipeline, m.Module, "", seat.StepResultStepBuild, kept)} steps = append(steps, build) asks = append(asks, buildAsk(p, m, build.Ask)) for _, a := range arts { @@ -134,6 +137,14 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ steps = append(steps, s) continue } + if d, read := known[a.Ref]; read && !slices.Contains(d.Kinds, step) { + // The build seat's steps answers no step of this kind for the artifact: it ends nothing to run at once, and no + // build node is asked (design 47 H2 H-A-515 addendum). + s.Seat, s.Outcome, s.Started, s.Ended = d.Seat, seat.StepResultOutcomeNothingToRun, &now, &now + s.Why = fmt.Sprintf("the seat %s's steps answers no %s step for %s: nothing to run, asked of no build node (H-A-515)", d.Seat, step, a.Ref) + steps = append(steps, s) + continue + } on := a.Language if on == "" && a.Kind == "image" { on = seatdef.OnKindImage @@ -425,6 +436,19 @@ func (s *Starter) keptEntries(branch string, rev int64) (map[string]catalog.Cata } func stepAsk(p seat.Pipeline, m seat.Mover, e catalog.CatalogEntry, a catalog.Artifact, language, step, id, asker string, now time.Time) nodebuildgo.StepAsk { + fetch := stepFetch(m, e, a) + ask := nodebuildgo.StepAsk{V: 1, ID: id, Asker: asker, Kind: "step", Language: language, At: &now, + Step: &nodebuildgo.StepRun{Artifact: a.Ref, Branch: p.Branch, Commit: m.Commit, Fetch: fetch, Fingerprint: m.Fingerprint, + Module: m.Module, Pipeline: p.Pipeline, Revision: p.Revision, Source: p.Source, Step: step}} + if step == seat.StepResultStepIntegration { + ask.Needs = checkNeedsOf(e, a.Ref) + } + return ask +} + +// stepFetch is what a step of artifact a of mover m fetches, and what its build seat's steps is asked to look at (H-A-515 +// addendum), so the steps answered are those the step would run. +func stepFetch(m seat.Mover, e catalog.CatalogEntry, a catalog.Artifact) nodebuildgo.Fetch { // 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. fetch := nodebuildgo.Fetch{Repository: m.Repository, Commit: m.Commit, Dir: e.Path} @@ -443,13 +467,7 @@ func stepAsk(p seat.Pipeline, m seat.Mover, e catalog.CatalogEntry, a catalog.Ar } fetch.Packages[path] = version } - ask := nodebuildgo.StepAsk{V: 1, ID: id, Asker: asker, Kind: "step", Language: language, At: &now, - Step: &nodebuildgo.StepRun{Artifact: a.Ref, Branch: p.Branch, Commit: m.Commit, Fetch: fetch, Fingerprint: m.Fingerprint, - Module: m.Module, Pipeline: p.Pipeline, Revision: p.Revision, Source: p.Source, Step: step}} - if step == seat.StepResultStepIntegration { - ask.Needs = checkNeedsOf(e, a.Ref) - } - return ask + return fetch } // checkNeedsOf are the seats artifact ref's integration tests need the node to hold, read from its check-needs in the diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go index 40f37d233..af5316902 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" + "errors" "fmt" "reflect" "slices" @@ -59,6 +60,7 @@ func placeFixture() (catalog.Registration, map[string]catalog.CatalogEntry) { func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { t.Run("an artifact without a language is placed by its kind", testAnArtifactWithoutALanguageIsPlacedByItsKind) t.Run("the build holds the approval whatever the policy names", testTheBuildHoldsTheApprovalWhateverThePolicyNames) + t.Run("a kind its build seat's steps answers none for is asked of no one", testAKindStepsAnswersNoneForIsAskedOfNoOne) reg, entries := placeFixture() store := created{} asks := &stepAsks{} @@ -95,6 +97,10 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { t.Errorf("ask %d's id %q is not the usual form opened by the pipeline's start: %v", i, id, err) } } + // H-A-516: the build step's record carries its asked-at, as a test step's does. + if p.Steps[0].AskedAt == nil || !p.Steps[0].AskedAt.Equal(*p.Steps[0].Started) { + t.Errorf("the build step's asked-at = %v, want the time it was asked", p.Steps[0].AskedAt) + } // A-99: the build is every pipeline's first step, required whatever the policy names, asked of mesh-builds for the // module's own entry only. b, ok := asks.asks[0].(builds.StepRun) @@ -242,6 +248,78 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { } } +// Design 47 H2 H-A-515 addendum: at placement the runner calls each artifact's build seat's steps, with the fetch and the +// fingerprint its steps are asked with; a kind it answers none for ends nothing to run at once, logged and said, asked of +// no build node; a call that fails asks the artifact's steps as before, said once in the journal. An artifact whose every +// build step the policy bypasses, or that no seat builds, is not called. +// testAKindStepsAnswersNoneForIsAskedOfNoOne is a row of TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat. +func testAKindStepsAnswersNoneForIsAskedOfNoOne(t *testing.T) { + reg, entries := placeFixture() + store := created{} + asks := &stepAsks{} + var journal []string + var called []nodebuildgo.StepsInput + s := &Starter{Pipelines: store, Say: func(string, any) error { return nil }, Steps: asks, 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" }, + Detect: func(buildSeat string, in nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) { + called = append(called, in) + if buildSeat != "node-build-go" { + t.Errorf("steps asked of %s, want the artifact's build seat", buildSeat) + } + if in.Artifact == "app.tools" { + return nodebuildgo.StepsAnswer{}, errors.New("no responders") + } + return nodebuildgo.StepsAnswer{Artifact: in.Artifact, Steps: []nodebuildgo.DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"./cmd/app"}}}}, nil + }} + if ok, err := s.Start(Begin{Branch: "main", Source: 4, Entries: entries, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}}}); !ok || err != nil { + t.Fatalf("start = %v, %v", ok, err) + } + var p seat.Pipeline + if err := json.Unmarshal(store["main.4"], &p); err != nil { + t.Fatal(err) + } + var got []string + for _, st := range p.Steps[:10] { + got = append(got, st.Artifact+" "+st.Step+" "+st.Outcome) + } + want := []string{" build running", "app:program lint running", "app:program unit running", "app:program integration nothing to run", + "app:tools lint bypassed", "app:tools unit running", "app:tools integration running", + "app:web lint could not run", "app:web unit could not run", "app:web integration could not run"} + if strings.Join(got, "|") != strings.Join(want, "|") { + t.Errorf("steps = %q, want %q", got, want) + } + if st := p.Steps[3]; st.Ask != "" || st.Ended == nil || st.Seat != "node-build-go" || !strings.Contains(st.Why, "no integration step") { + t.Errorf("the integration step with nothing to run = %+v; want it ended at once, asked of no one, saying why", st) + } + for _, x := range asks.asks { + if b, ok := x.(nodebuildgo.StepAsk); ok && b.Step.Artifact == "app:program" && b.Step.Step == "integration" { + t.Error("the integration step steps answers none for was asked") + } + } + if len(asks.asks) != 6 { + t.Errorf("asked %d steps, want the build, the four running build steps and the composition", len(asks.asks)) + } + if len(called) != 2 || called[0].Module != "app" || called[0].Artifact != "app.program" || called[0].Fingerprint != "src2:aa" || + called[0].Fetch == nil || called[0].Fetch.Repository != "o/app" || called[0].Fetch.Commit != "c1" || called[0].Fetch.Dir != "modules/app" || + len(called[0].Fetch.Paths) != 1 || called[0].Fetch.Paths[0] != "cmd/app" { + t.Errorf("steps was called with %+v; want program and tools, each with the fetch its steps are asked with", called) + } + all := strings.Join(journal, "\n") + if !strings.Contains(all, "the steps of app:tools are not read from node-build-go (no responders)") || !strings.Contains(all, "step ended main.4 app integration nothing to run") { + t.Errorf("the journal says %q; want the failed call and the step's end", journal) + } + if len(p.Unlogged) == 0 || !slices.ContainsFunc(p.Unlogged, func(e seat.LogEntry) bool { + return e.Step == "integration" && e.Outcome == seat.StepResultOutcomeNothingToRun + }) { + t.Errorf("the step log holds %+v; want the end of the step with nothing to run", p.Unlogged) + } + // Placed again (asked again after a restart), the same steps are asked and the one with nothing to run is not. + if known := knownOf(p, "app"); len(known) != 1 || strings.Join(known["app:program"].Kinds, ",") != "lint,unit" { + t.Errorf("knownOf = %+v; want program's lint and unit", known) + } +} + // A pipeline whose other steps are all bypassed still has its build, required whatever the policy names, so its approval is // not due at its start (A-99, §26). // testTheBuildHoldsTheApprovalWhateverThePolicyNames is a row of TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat (design 47 H2 §819: the module's tests are folded under its budget). diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go index 2e7bc6a0f..75f28495e 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go @@ -209,7 +209,11 @@ func (s *Starter) placeAgain(p *seat.Pipeline, m seat.Mover, half Half, now time s.logf("%s: %s waits for %s before its build", p.Pipeline, m.Module, strings.Join(waiting, ", ")) return nil, nil, false } - steps, asks := place(*p, m, r, half.Entries, now, s.Name, true, half.Revision) + var known detectedSteps + if failed == "" { // a mover whose steps end not asked calls no steps + known = s.detect(*p, m, r, half.Entries) + } + steps, asks := place(*p, m, r, half.Entries, now, s.Name, true, half.Revision, known) supersededWhy(*p, m.Module, half.Entries, steps) var notAsked []int if failed != "" { @@ -224,6 +228,8 @@ func (s *Starter) placeAgain(p *seat.Pipeline, m seat.Mover, half Half, now time notAsked = append(notAsked, len(p.Steps)+k) } asks = nil + } else { + notAsked = placedNothing(p, steps, len(p.Steps), now) } p.Steps = append(p.Steps, steps...) return asks, notAsked, false diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index 1082dbc0d..e2429dd7d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -174,6 +174,9 @@ type Starter struct { // Registration is a module's registration, whose policy names the steps of its pipeline (§21, §23); with none, a // pipeline starts with no step and says so. Registration func(module string) (catalog.Registration, bool) + // Detect calls an artifact's build seat's verb steps at placement, so a step kind it answers none for ends nothing to + // run, asked of no build node (design 47 H2 H-A-515 addendum); nil calls none, and every step is asked. + Detect StepsCaller // RegistrationsRead says whether the registrations view's first read is in (design 47 H2 §788): before it no // registration-missing is judged and "registrations not yet read" is said once; nil reads as read. RegistrationsRead func() bool @@ -531,7 +534,11 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog waits = append(waits, m) continue } - steps, a := place(*p, m, r, entries, now, s.Name, true, kept[m.Module]) + var known detectedSteps + if failed == "" { // a mover whose steps end not asked calls no steps + known = s.detect(*p, m, r, entries) + } + steps, a := place(*p, m, r, entries, now, s.Name, true, kept[m.Module], known) supersededWhy(*p, m.Module, entries, steps) for _, st := range steps { if pinHeld(st) { @@ -563,6 +570,7 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } } } + notAsked = append(notAsked, placedNothing(p, steps, len(p.Steps), now)...) p.Steps = append(p.Steps, steps...) for _, x := range a { if !slices.ContainsFunc(asks, func(y Asked) bool { return y.ID == x.ID }) { @@ -823,8 +831,9 @@ func (s *Starter) Resume(store Updater, branch string, half Half) (int, error) { continue } } - _, shared := place(p, m, reg, entries, now, s.Name, true, rev) - _, unshared := place(p, m, reg, entries, now, s.Name, false, rev) + // Placed again with what its first placing knew, so a kind ended nothing to run moves no test run's asker (H-A-515). + _, shared := place(p, m, reg, entries, now, s.Name, true, rev, knownOf(p, m.Module)) + _, unshared := place(p, m, reg, entries, now, s.Name, false, rev, knownOf(p, m.Module)) for _, a := range shared { if running[a.ID] && !own[a.ID] { due = append(due, a) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 4eb168431..fcc689246 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -702,7 +702,7 @@ func (v Verbs) placedAsk(p seat.Pipeline, s seat.StepResult, id string, now time return nil, fmt.Errorf("revision %d of %s, which %s is kept at, is not read (%v): the step is asked when it is", rev, p.Branch, m.Module, err) } } - _, placed := place(p, m, reg, entries, now, v.Starter.Name, false, rev) + _, placed := place(p, m, reg, entries, now, v.Starter.Name, false, rev, nil) base := keptAskID(startOf(p, now), p.Pipeline, m.Module, s.Artifact, s.Step, rev) for _, a := range placed { if a.ID != base { diff --git a/modules/mesh-delivery-pipeline/manifest_test.go b/modules/mesh-delivery-pipeline/manifest_test.go index 05dd24838..b8b2d835f 100644 --- a/modules/mesh-delivery-pipeline/manifest_test.go +++ b/modules/mesh-delivery-pipeline/manifest_test.go @@ -132,7 +132,9 @@ func TestManifest(t *testing.T) { "seat:node-build-go.accept.check", "seat:node-build-go.accept.delivery", "seat:node-build-node.accept.check", "seat:node-build-node.accept.delivery", "seat:node-build-image.accept.check", "seat:node-build-image.accept.delivery", // design 47 H2 §791: runner_step_output reads a step's output where its build seat's holder keeps it. - "seat:node-build-go.output", "seat:node-build-node.output", "seat:node-build-image.output"})}, + "seat:node-build-go.output", "seat:node-build-node.output", "seat:node-build-image.output", + // design 47 H2 H-A-515 addendum: an artifact's steps read at placement, so a kind it has none of is never asked. + "seat:node-build-go.steps", "seat:node-build-node.steps", "seat:node-build-image.steps"})}, {"uses operator-channel", equalSets(m.Uses, []string{"operator-channel"})}, // RN25 (§539): the runner's tools carry the prefix runner_. {"first-view tools", equalSets(m.Tools, []string{"runner_first_views", "runner_first_view_again", "runner_health", "runner_unlogged", "runner_unlogged_append", diff --git a/modules/mesh-delivery-pipeline/module.json b/modules/mesh-delivery-pipeline/module.json index 6e7b82b38..5a1801ced 100644 --- a/modules/mesh-delivery-pipeline/module.json +++ b/modules/mesh-delivery-pipeline/module.json @@ -111,7 +111,10 @@ "seat:node-build-image.accept.delivery", "seat:node-build-go.output", "seat:node-build-node.output", - "seat:node-build-image.output" + "seat:node-build-image.output", + "seat:node-build-go.steps", + "seat:node-build-node.steps", + "seat:node-build-image.steps" ], "uses": [ "operator-channel"