A10: the step validate, one run per take-in revision before the composition
The assigner takes the seat mesh-wants' step validate beside the composition step. Every mover's validate step of one take-in reads one run, the key <pipeline>.validate of composition-runs with no machine, taken up at the start like the composer's runs: a cycle the revision's entries make (graph.RefusedCycle) ends it at once; else the manifest validator built from the revision's entry of the module holding mesh-catalog runs on the Go build seat, its input kept and served on mesh-wants' input, over the revision's manifests and the branch's previous revision's. The step ends failed cycle, failed manifest-refused naming every problem the revision causes, or passed. Builds: design 47 H §745; H-A-34, H-A-51, H-A-108 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -370,6 +370,11 @@ func (c *compositionSteps) takeUp(ctx context.Context, r *compositionRuns) {
|
||||
if reader.Ended != nil {
|
||||
again = reader.ask
|
||||
}
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader.CompositionReader), c.resume, again)
|
||||
how := c.howOf(reader.Step, true)
|
||||
if how == nil {
|
||||
c.logf("the step %s of %s is not taken up again: it is no composition or validate step (%q)", reader.ID, reader.Module, reader.Step)
|
||||
continue
|
||||
}
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader.CompositionReader), how, again)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,11 @@ type joined struct {
|
||||
// written create-only (or replacing the ended key by compare-and-set), the reader its first, ask its run ask's id. At the
|
||||
// cap no run is started, an error naming the fill.
|
||||
func (r *compositionRuns) join(reader meshwants.CompositionReader, candidate, machine, ask string) (joined, error) {
|
||||
key := runKeyOf(candidate, machine)
|
||||
return r.joinAt(runKeyOf(candidate, machine), reader, candidate, machine, ask)
|
||||
}
|
||||
|
||||
// joinAt is join of the run under key: a machine's composition run, or a revision's validate run with no machine (H-A-108).
|
||||
func (r *compositionRuns) joinAt(key string, reader meshwants.CompositionReader, candidate, machine, ask string) (joined, error) {
|
||||
for {
|
||||
run, rev, ok, err := r.read(key)
|
||||
if err != nil {
|
||||
@@ -539,12 +543,7 @@ func (r *compositionRuns) clearBounds(key, ask string, prefixes ...string) error
|
||||
// stepEnded writes at as the `ended` of the reader asked under id in each run of its step's candidate naming it, by
|
||||
// compare-and-set (A-470m): the time its step said its end, carried with it into a rerun's run.
|
||||
func (r *compositionRuns) stepEnded(id string, step meshwants.StepRun, at time.Time) {
|
||||
candidate, err := candidateKeyOf(step)
|
||||
if err != nil {
|
||||
r.logf("the end of the composition step %s is not written on its runs: %v", id, err)
|
||||
return
|
||||
}
|
||||
keys, err := r.keysOf(candidate, id)
|
||||
keys, err := r.keysOfStep(step, id)
|
||||
if err != nil {
|
||||
r.logf("the end of the composition step %s is not written on its runs: %v", id, err)
|
||||
return
|
||||
@@ -564,6 +563,23 @@ func (r *compositionRuns) stepEnded(id string, step meshwants.StepRun, at time.T
|
||||
}
|
||||
}
|
||||
|
||||
// keysOfStep are the keys of the runs the step asked under id reads: its revision's validate run for a validate step, its
|
||||
// candidate's runs naming it for a composition step.
|
||||
func (r *compositionRuns) keysOfStep(step meshwants.StepRun, id string) ([]string, error) {
|
||||
if step.Step == meshwants.StepRunStepValidate {
|
||||
key, err := validateKeyOf(step)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []string{key}, nil
|
||||
}
|
||||
candidate, err := candidateKeyOf(step)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.keysOf(candidate, id)
|
||||
}
|
||||
|
||||
// hasReader is whether readers holds the step asked under id.
|
||||
func hasReader(readers []meshwants.CompositionReader, id string) bool {
|
||||
return slices.ContainsFunc(readers, func(c meshwants.CompositionReader) bool { return c.ID == id })
|
||||
@@ -672,6 +688,10 @@ func (r *compositionRuns) heardEnd(e buildstep.StepEnded, read func(buildstep.St
|
||||
said = fmt.Sprintf("%s: its run ask %s ended %s on %s: %s", node, e.Ask, e.Outcome, e.Node, e.Said)
|
||||
} else if answer, err := read(e); err != nil { // the program's last line of standard output (A-254)
|
||||
said = node + ": " + err.Error()
|
||||
} else if isValidateRun(run) {
|
||||
if verdict, said = validateRunVerdict(answer); said == "" {
|
||||
outcome = meshwants.CompositionRunOutcomePassed
|
||||
}
|
||||
} else if verdict, said = runVerdict(node, answer); said == "" {
|
||||
outcome = meshwants.CompositionRunOutcomePassed
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ type compositionSteps struct {
|
||||
// run runs one step and answers what it came to; resume judges a step taken up at the start from its runs (takeUp).
|
||||
run func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||
resume func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||
// validate runs one validate step and resumeValidate judges one taken up at the start (validatestep.go, design 47 H §745);
|
||||
// nil takes no validate step.
|
||||
validate func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||
resumeValidate func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||
// ended writes, once the step asked under id said its end, that time on its reader in each run naming it (A-470m); nil
|
||||
// writes none.
|
||||
ended func(id string, run meshwants.StepRun, at time.Time)
|
||||
@@ -88,18 +92,35 @@ func (p *stepPhase) get() string {
|
||||
return p.phase
|
||||
}
|
||||
|
||||
// take takes one ask of the accepted kind `step` by its id and body: a step that is no composition step, or an ask with no
|
||||
// id, is left with a log line; one taken is run in its own goroutine and its end said.
|
||||
// take takes one ask of the accepted kind `step` by its id and body: a step that is no composition or validate step, or an
|
||||
// ask with no id, is left with a log line; one taken is run in its own goroutine and its end said.
|
||||
func (c *compositionSteps) take(ctx context.Context, id string, data []byte) bool {
|
||||
var run meshwants.StepRun
|
||||
if err := json.Unmarshal(data, &run); err != nil || id == "" || run.Step != meshwants.StepRunStepComposition {
|
||||
c.logf("a step ask that is no composition step with an id is left: %v", err)
|
||||
err := json.Unmarshal(data, &run)
|
||||
how := c.howOf(run.Step, false)
|
||||
if err != nil || id == "" || how == nil {
|
||||
c.logf("a step ask that is no composition or validate step with an id is left: %v", err)
|
||||
return false
|
||||
}
|
||||
go c.say1(ctx, id, run, c.run, "")
|
||||
go c.say1(ctx, id, run, how, "")
|
||||
return true
|
||||
}
|
||||
|
||||
// howOf is what runs a step, or judges it once taken up at the start: by its step, composition or validate; nil for another.
|
||||
func (c *compositionSteps) howOf(step string, resumed bool) func(context.Context, string, meshwants.StepRun) stepOutcome {
|
||||
switch {
|
||||
case step == meshwants.StepRunStepComposition && resumed:
|
||||
return c.resume
|
||||
case step == meshwants.StepRunStepComposition:
|
||||
return c.run
|
||||
case step == meshwants.StepRunStepValidate && resumed:
|
||||
return c.resumeValidate
|
||||
case step == meshwants.StepRunStepValidate:
|
||||
return c.validate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// say1 runs one step with how and says its end, naming in `shared` the runs it read (§723); again is, for an end said again, the
|
||||
// ask of the run whose end makes it say again (sayEnd). A step whose wait was ended by its pipeline's supersede or cancel (leave)
|
||||
// says nothing: the runner ended it already.
|
||||
@@ -142,7 +163,11 @@ func (c *compositionSteps) sayEnd(id string, run meshwants.StepRun, started *tim
|
||||
if started == nil {
|
||||
started = &ended
|
||||
}
|
||||
end := meshwants.StepEnded{V: 1, ID: id, Pipeline: run.Pipeline, Step: meshwants.StepEndedStepComposition, Module: run.Module,
|
||||
step := meshwants.StepEndedStepComposition
|
||||
if run.Step == meshwants.StepRunStepValidate {
|
||||
step = meshwants.StepEndedStepValidate
|
||||
}
|
||||
end := meshwants.StepEnded{V: 1, ID: id, Pipeline: run.Pipeline, Step: step, Module: run.Module,
|
||||
Commit: run.Commit, Fingerprint: run.Fingerprint, Node: c.node, Outcome: o.Outcome, Said: o.Said, Warnings: o.Warnings,
|
||||
Rerun: run.Rerun, By: run.By, Started: started, Ended: &ended, Shared: o.Shared}
|
||||
msgID := id
|
||||
|
||||
@@ -662,7 +662,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil {
|
||||
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept,
|
||||
trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume, ended: runs.stepEnded, now: time.Now, logf: logger.Printf}
|
||||
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume,
|
||||
validate: run.validate, resumeValidate: run.resumeValidate, ended: runs.stepEnded, now: time.Now, logf: logger.Printf}
|
||||
move := steps.move(ctx) // the readers a rerun carried (§727, A-470d)
|
||||
runs.moved.Store(&move)
|
||||
// The state's watch wakes the steps waiting on a run and hears a bound's expiry; the runs standing at the start are taken up
|
||||
|
||||
@@ -0,0 +1,367 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
)
|
||||
|
||||
// The step validate (design 47 H §745; H-A-34, H-A-51, H-A-108): the assigner serves it as an accepted kind `step` of the seat
|
||||
// mesh-wants, asked by the runner for each mover before its composition step. One run per take-in revision, a key
|
||||
// `<pipeline>.validate` of the state composition-runs in the CompositionRun form with no machine, which every mover's step
|
||||
// reads: the cycle the revision's entries make (graph.RefusedCycle) ends it at once; else the manifest validator built from
|
||||
// the revision's own entry of the module holding the seat mesh-catalog, on the Go build seat as the composer is, runs in the
|
||||
// sandbox over the revision's manifests and the branch's previous revision's, its input kept and served on mesh-wants' input.
|
||||
// Every mover's step ends the same: failed `cycle` naming the cycle, failed `manifest-refused` naming every problem of a
|
||||
// manifest the revision alters or between manifests one it alters takes part in, or passed.
|
||||
|
||||
const (
|
||||
// validatorPackage is the manifest validator's import path in the module holding the seat mesh-catalog (the indexer's
|
||||
// cmd/mesh-judge, design 47 H-A-34).
|
||||
validatorPackage = "mesh-delivery-indexer/cmd/mesh-judge"
|
||||
// validateKeySuffix ends the key of a revision's validate run, `<pipeline>.validate` (H-A-108).
|
||||
validateKeySuffix = "." + meshwants.StepRunStepValidate
|
||||
// beforeCase is the validator's case of the branch's previous revision, beside changeCase (H-A-108 (3)).
|
||||
beforeCase = "before"
|
||||
// The reasons a validate step fails with, the first word of its said (§745).
|
||||
reasonManifestRefused = "manifest-refused"
|
||||
reasonCycle = "cycle"
|
||||
// betweenManifests is the validator's name for what it judges between manifests (the catalogue as a whole).
|
||||
betweenManifests = "(between manifests)"
|
||||
)
|
||||
|
||||
// validateKeyOf is the key of the validate run of the step's take-in revision.
|
||||
func validateKeyOf(step meshwants.StepRun) (string, error) {
|
||||
if step.Pipeline == "" {
|
||||
return "", errors.New("the step names no pipeline, so no validate run is named")
|
||||
}
|
||||
return step.Pipeline + validateKeySuffix, nil
|
||||
}
|
||||
|
||||
// isValidateRun says whether a run of the state is a revision's validate run: one with no machine.
|
||||
func isValidateRun(run meshwants.CompositionRun) bool { return run.Machine == "" }
|
||||
|
||||
// validate runs one mover's validate step: it joins or starts the revision's validate run and judges the step from its end.
|
||||
func (r *compositionRun) validate(ctx context.Context, id string, step meshwants.StepRun) stepOutcome {
|
||||
key, err := validateKeyOf(step)
|
||||
if err != nil {
|
||||
return couldNotRun(err.Error())
|
||||
}
|
||||
candidate, err := candidateKeyOf(step)
|
||||
if err != nil {
|
||||
return couldNotRun(err.Error())
|
||||
}
|
||||
j, err := r.runs.joinAt(key, readerOf(id, step), candidate, "", buildstep.NewID())
|
||||
if err != nil {
|
||||
return couldNotRun("the validate run " + key + " is not joined: " + err.Error())
|
||||
}
|
||||
if j.started {
|
||||
go r.startValidate(ctx, key, j.run, step)
|
||||
}
|
||||
return r.readValidate(ctx, key, step)
|
||||
}
|
||||
|
||||
// resumeValidate judges a validate step taken up at the assigner's start from its revision's run.
|
||||
func (r *compositionRun) resumeValidate(ctx context.Context, _ string, step meshwants.StepRun) stepOutcome {
|
||||
key, err := validateKeyOf(step)
|
||||
if err != nil {
|
||||
return couldNotRun(err.Error())
|
||||
}
|
||||
return r.readValidate(ctx, key, step)
|
||||
}
|
||||
|
||||
// readValidate waits for the end of the validate run of key and judges the step from it.
|
||||
func (r *compositionRun) readValidate(ctx context.Context, key string, step meshwants.StepRun) stepOutcome {
|
||||
setShared(ctx, r.runs.sharedOf([]string{key}, nil))
|
||||
setPhase(ctx, meshwants.StepProgressEventPhaseRun)
|
||||
run := r.runs.await(ctx, []string{key})[key]
|
||||
setPhase(ctx, meshwants.StepProgressEventPhaseReport)
|
||||
out := r.judgeValidate(ctx, step, run)
|
||||
out.Shared = r.runs.sharedOf([]string{key}, map[string]meshwants.CompositionRun{key: run})
|
||||
return out
|
||||
}
|
||||
|
||||
// judgeValidate is a step's end from its revision's validate run: could not run with the run's words; failed `cycle` naming
|
||||
// the cycle; failed `manifest-refused` naming every problem the revision causes; else passed.
|
||||
func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepRun, run meshwants.CompositionRun) stepOutcome {
|
||||
if run.Ended == nil {
|
||||
return couldNotRun("the step stopped before its validate run ended")
|
||||
}
|
||||
if run.Outcome != meshwants.CompositionRunOutcomePassed {
|
||||
return couldNotRun(run.Said)
|
||||
}
|
||||
var v validateVerdict
|
||||
if raw, err := json.Marshal(run.Verdict); err != nil || json.Unmarshal(raw, &v) != nil {
|
||||
return couldNotRun("the validate run's verdict does not read")
|
||||
}
|
||||
if len(v.Cycle) > 0 {
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomeFailed, Said: reasonCycle + ": " + cycleWords(v.Cycle)}
|
||||
}
|
||||
half, err := r.revision(ctx, step)
|
||||
if err != nil {
|
||||
return couldNotRun("the step's catalog revision is not read: " + err.Error())
|
||||
}
|
||||
before, err := r.before(ctx, step)
|
||||
if err != nil {
|
||||
return couldNotRun("the branch's previous catalog revision is not read: " + err.Error())
|
||||
}
|
||||
if problems := causedProblems(v.Change, v.Before, altered(half, before)); len(problems) > 0 {
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomeFailed, Said: reasonManifestRefused + ": " + strings.Join(problems, "; ")}
|
||||
}
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
|
||||
}
|
||||
|
||||
// validateVerdict is a validate run's verdict as the run keeps it: the cycle the revision makes, or the validator's two cases.
|
||||
type validateVerdict struct {
|
||||
Cycle []meshcatalog.ArtifactRef `json:"cycle,omitempty"`
|
||||
Change composer.CaseVerdict `json:"change"`
|
||||
Before composer.CaseVerdict `json:"before"`
|
||||
}
|
||||
|
||||
// asVerdict is v as a run's verdict.
|
||||
func (v validateVerdict) asVerdict() (map[string]any, error) {
|
||||
raw, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out map[string]any
|
||||
return out, json.Unmarshal(raw, &out)
|
||||
}
|
||||
|
||||
// cycleWords names a cycle as the artifacts it passes through.
|
||||
func cycleWords(cycle []meshcatalog.ArtifactRef) string {
|
||||
words := make([]string, len(cycle))
|
||||
for i, a := range cycle {
|
||||
words[i] = string(a)
|
||||
}
|
||||
return strings.Join(words, " → ")
|
||||
}
|
||||
|
||||
// before is the branch's catalog revision before the step's, read through the seat mesh-catalog's verb revision (H-A-108 (3));
|
||||
// none before the first.
|
||||
func (r *compositionRun) before(ctx context.Context, step meshwants.StepRun) (mcc.Half, error) {
|
||||
if step.Revision <= 1 {
|
||||
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{}}, nil
|
||||
}
|
||||
prev := step
|
||||
prev.Revision--
|
||||
return r.revision(ctx, prev)
|
||||
}
|
||||
|
||||
// altered are the modules whose manifest the revision adds or changes against the one before it.
|
||||
func altered(half, before mcc.Half) []string {
|
||||
var out []string
|
||||
for name, e := range half.Entries {
|
||||
if len(e.Manifest) == 0 {
|
||||
continue
|
||||
}
|
||||
b, ok := before.Entries[name]
|
||||
switch {
|
||||
case !ok || len(b.Manifest) == 0:
|
||||
out = append(out, name)
|
||||
case e.ManifestDigest != "" && b.ManifestDigest != "":
|
||||
if e.ManifestDigest != b.ManifestDigest {
|
||||
out = append(out, name)
|
||||
}
|
||||
default:
|
||||
x, _ := json.Marshal(e.Manifest)
|
||||
y, _ := json.Marshal(b.Manifest)
|
||||
if string(x) != string(y) {
|
||||
out = append(out, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// causedProblems are the problems the revision causes (ADR 0578 §2): every problem of a manifest it alters, and of any other
|
||||
// manifest, or between manifests, each problem the case before did not have.
|
||||
func causedProblems(change, before composer.CaseVerdict, touched []string) []string {
|
||||
var out []string
|
||||
for _, module := range slices.Sorted(maps.Keys(change.Manifests)) {
|
||||
read := change.Manifests[module]
|
||||
if read.Accepted || read.Refused == "" {
|
||||
continue
|
||||
}
|
||||
had := map[string]bool{}
|
||||
for _, p := range strings.Split(before.Manifests[module].Refused, "\n") {
|
||||
had[p] = true
|
||||
}
|
||||
var caused []string
|
||||
for _, p := range strings.Split(read.Refused, "\n") {
|
||||
if p != "" && (slices.Contains(touched, module) || !had[p]) {
|
||||
caused = append(caused, p)
|
||||
}
|
||||
}
|
||||
if len(caused) == 0 {
|
||||
continue
|
||||
}
|
||||
what := module
|
||||
if module == betweenManifests {
|
||||
what = "between manifests"
|
||||
}
|
||||
out = append(out, what+": "+strings.Join(caused, "; "))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// catalogEntry is the entry of the module that holds the seat mesh-catalog, or false.
|
||||
func catalogEntry(entries map[string]meshcatalog.CatalogEntry) (meshcatalog.CatalogEntry, bool) {
|
||||
for _, name := range slices.Sorted(maps.Keys(entries)) {
|
||||
for _, s := range entries[name].Serves {
|
||||
if strings.HasPrefix(strings.TrimPrefix(s, "seat:"), meshcatalog.Seat+".") {
|
||||
return entries[name], true
|
||||
}
|
||||
}
|
||||
}
|
||||
return meshcatalog.CatalogEntry{}, false
|
||||
}
|
||||
|
||||
// manifestsOf are the half's manifests whole, as the validator's case holds them.
|
||||
func manifestsOf(half mcc.Half) (map[string]composer.Manifest, error) {
|
||||
out := map[string]composer.Manifest{}
|
||||
for name, e := range half.Entries {
|
||||
if len(e.Manifest) == 0 {
|
||||
continue
|
||||
}
|
||||
raw, err := json.Marshal(e.Manifest)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the manifest of %s cannot be encoded: %w", name, err)
|
||||
}
|
||||
out[name] = composer.Manifest{Raw: raw}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// startValidate runs the validate run the step started: the revision's cycle ends it at once; else the validator's request
|
||||
// is kept once in `inputs`, its program and input recorded on the run, and one run ask put on the Go build seat. A fault ends
|
||||
// the run could not run.
|
||||
func (r *compositionRun) startValidate(ctx context.Context, key string, run meshwants.CompositionRun, step meshwants.StepRun) {
|
||||
ask := run.Ask
|
||||
end := func(outcome, said string, verdict map[string]any) {
|
||||
if _, err := r.runs.endRun(key, ask, outcome, said, verdict); err != nil {
|
||||
r.logf("the validate run %s is not ended: %v", key, err)
|
||||
}
|
||||
}
|
||||
couldNot := func(said string) { end(meshwants.CompositionRunOutcomeCouldNotRun, said, nil) }
|
||||
half, err := r.revision(ctx, step)
|
||||
if err != nil {
|
||||
couldNot("the step's catalog revision is not read: " + err.Error())
|
||||
return
|
||||
}
|
||||
if cycle := graph.RefusedCycle(half.Entries); cycle != nil {
|
||||
verdict, err := validateVerdict{Cycle: cycle}.asVerdict()
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
end(meshwants.CompositionRunOutcomePassed, "", verdict)
|
||||
return
|
||||
}
|
||||
before, err := r.before(ctx, step)
|
||||
if err != nil {
|
||||
couldNot("the branch's previous catalog revision is not read: " + err.Error())
|
||||
return
|
||||
}
|
||||
entry, ok := catalogEntry(half.Entries)
|
||||
if !ok {
|
||||
couldNot(fmt.Sprintf("the catalog revision %d holds no module claiming the seat %s, so no manifest validator is built", half.Revision.Revision, meshcatalog.Seat))
|
||||
return
|
||||
}
|
||||
program, err := programOfEntry(entry)
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
program.Package = validatorPackage
|
||||
seats, err := r.seats(ctx, half.Revision.Definitions)
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
change, err := manifestsOf(half)
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
prior, err := manifestsOf(before)
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
// No predefined key list and no known package names until a design line names the verb that gives them (H-A-108 (2)).
|
||||
req := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: changeCase, Manifests: change}, {Name: beforeCase, Manifests: prior}},
|
||||
Seats: seats}
|
||||
raw, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
couldNot("its request cannot be encoded: " + err.Error())
|
||||
return
|
||||
}
|
||||
digest, err := r.keeper.keep(ask, raw)
|
||||
if err != nil {
|
||||
couldNot("its request is not kept: " + err.Error())
|
||||
return
|
||||
}
|
||||
ref, err := buildstep.RunInputOf(inputVerbKey, raw)
|
||||
if err != nil {
|
||||
couldNot(err.Error())
|
||||
return
|
||||
}
|
||||
if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool {
|
||||
if c.Ask != ask || c.Ended != nil {
|
||||
return false
|
||||
}
|
||||
c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: entry.Fp}
|
||||
c.Input = digest
|
||||
return true
|
||||
}); err != nil {
|
||||
couldNot("the run's program and input are not written: " + err.Error())
|
||||
return
|
||||
}
|
||||
a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(),
|
||||
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the manifest validator of " + step.Pipeline + " at " + program.Commit}}
|
||||
if err := r.put(ctx, a); err != nil {
|
||||
couldNot("its run ask " + ask + " is not put: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// validateRunVerdict reads the validator's answer: its two cases as the run keeps them, or why it is none.
|
||||
func validateRunVerdict(answer []byte) (map[string]any, string) {
|
||||
var v composer.Verdict
|
||||
if err := json.Unmarshal(answer, &v); err != nil {
|
||||
return nil, "the manifest validator answered no verdict: " + err.Error()
|
||||
}
|
||||
if v.V != composer.Version {
|
||||
return nil, fmt.Sprintf("the manifest validator answered a verdict of version %d, the assigner reads %d", v.V, composer.Version)
|
||||
}
|
||||
var out validateVerdict
|
||||
found := 0
|
||||
for _, c := range v.Cases {
|
||||
switch c.Name {
|
||||
case changeCase:
|
||||
out.Change, found = c, found+1
|
||||
case beforeCase:
|
||||
out.Before, found = c, found+1
|
||||
}
|
||||
}
|
||||
if found != 2 {
|
||||
return nil, "the manifest validator's verdict does not hold both the cases " + changeCase + " and " + beforeCase
|
||||
}
|
||||
verdict, err := out.asVerdict()
|
||||
if err != nil {
|
||||
return nil, "the manifest validator's verdict cannot be kept: " + err.Error()
|
||||
}
|
||||
return verdict, ""
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
)
|
||||
|
||||
// A10/AC1, A10/AC2 (design 47 H §745; H-A-34, H-A-51, H-A-108): every mover's validate step of one take-in reads one validate
|
||||
// run, `<pipeline>.validate` of the state composition-runs; a manifest the revision alters that names an unknown field fails
|
||||
// it `manifest-refused` naming the problem, a problem of a manifest it leaves as it was does not, and the validator is the
|
||||
// revision's own entry of the module holding the seat mesh-catalog, on the Go build seat; a revision whose entries make a cycle
|
||||
// fails it `cycle` naming the cycle, with no validator asked.
|
||||
func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
indexer := meshcatalog.CatalogEntry{Module: "indexer", Repository: "novox/mesh-delivery", Commit: commitE3, Path: "modules/mesh-delivery-indexer",
|
||||
Fp: "src2:ix", Serves: []string{"seat:" + meshcatalog.Seat + ".revision"}, Manifest: map[string]any{"module": "indexer"}, ManifestDigest: "d-ix"}
|
||||
entry := func(module, digest string, edges ...meshcatalog.Edge) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: module, Manifest: map[string]any{"module": module, "d": digest}, ManifestDigest: digest, Edges: edges}
|
||||
}
|
||||
revisions := map[int64][]meshcatalog.CatalogEntry{
|
||||
6: {indexer, entry("web", "d-web-1"), entry("db", "d-db")},
|
||||
7: {indexer, entry("web", "d-web-2"), entry("db", "d-db")},
|
||||
9: {indexer, entry("a", "d-a", meshcatalog.Edge{From: "a:x", To: "b:y", Kind: 3}, meshcatalog.Edge{From: "b:y", To: "a:x", Kind: 3}), entry("b", "d-b")},
|
||||
}
|
||||
call := func(key string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
switch key {
|
||||
case mcc.RevisionVerb:
|
||||
var in meshcatalog.RevisionInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
entries, ok := revisions[in.Revision]
|
||||
if !ok || in.Branch != "main" {
|
||||
return nil, errors.New("asked another revision")
|
||||
}
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: in.Revision,
|
||||
Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: "sd"}}}, Entries: entries})
|
||||
case seatDefinitionsKey:
|
||||
return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Found: true, Entry: &meshcatalog.SeatDefinitionsAnswerEntry{Seat: "s1", Digest: "sd", Definition: map[string]any{"seat": "s1"}}})
|
||||
}
|
||||
return nil, errors.New("no such verb " + key)
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var asks []buildstep.StepAsk
|
||||
var requests []composer.Request
|
||||
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
||||
runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
|
||||
r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, now: time.Now, logf: t.Logf,
|
||||
put: func(_ context.Context, a buildstep.StepAsk) error {
|
||||
body, err := keeper.body(a.Run.Input.Digest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := composer.Decode(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mu.Lock()
|
||||
asks, requests = append(asks, a), append(requests, req)
|
||||
mu.Unlock()
|
||||
answer, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{
|
||||
{Name: changeCase, Manifests: map[string]composer.ManifestRead{"web": {Refused: `unknown field "colour"`}, "db": {Refused: "an old problem"}, "indexer": {Accepted: true}}},
|
||||
{Name: beforeCase, Manifests: map[string]composer.ManifestRead{"db": {Refused: "an old problem"}}}}})
|
||||
go func() {
|
||||
if err := runs.heardEnd(buildstep.StepEnded{Asker: runAsker, Ask: a.ID, Outcome: buildstep.OutcomePassed, Node: "novox"},
|
||||
func(buildstep.StepEnded) ([]byte, error) { return answer, nil }); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}}
|
||||
steps := &compositionSteps{validate: r.validate, run: r.run}
|
||||
if steps.howOf(meshwants.StepRunStepValidate, false) == nil || steps.howOf("check", false) != nil {
|
||||
t.Error("the validate step is not taken, or another step is")
|
||||
}
|
||||
step := func(module string, revision int64) meshwants.StepRun {
|
||||
return meshwants.StepRun{Step: meshwants.StepRunStepValidate, Pipeline: "main." + string(rune('0'+revision)), Branch: "main", Module: module,
|
||||
Revision: revision, Source: revision}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
outs := make([]stepOutcome, 2)
|
||||
var wg sync.WaitGroup
|
||||
for i, module := range []string{"web", "db"} {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); outs[i] = r.validate(ctx, "ask-"+module, step(module, 7)) }()
|
||||
}
|
||||
wg.Wait()
|
||||
for i, o := range outs {
|
||||
if o.Outcome != meshwants.StepEndedOutcomeFailed || !strings.HasPrefix(o.Said, reasonManifestRefused+": ") || !strings.Contains(o.Said, `web: unknown field "colour"`) ||
|
||||
strings.Contains(o.Said, "an old problem") {
|
||||
t.Errorf("mover %d's validate step ended %+v", i, o)
|
||||
}
|
||||
}
|
||||
if len(asks) != 1 {
|
||||
t.Fatalf("%d validator asks were put for one take-in, want 1", len(asks))
|
||||
}
|
||||
if p := asks[0].Run.Program; p.Commit != commitE3 || p.Dir != "modules/mesh-delivery-indexer" || p.Package != validatorPackage || len(asks[0].Run.Heads) != 0 {
|
||||
t.Errorf("the validator is built from %+v", asks[0].Run)
|
||||
}
|
||||
if c := requests[0].Cases; len(c) != 2 || c[0].Name != changeCase || c[1].Name != beforeCase || len(c[1].Manifests) != 3 || requests[0].Predefined != nil || requests[0].Packages != nil {
|
||||
t.Errorf("the validator's request is %+v", requests[0])
|
||||
}
|
||||
if _, _, ok, _ := runs.read("main.7" + validateKeySuffix); !ok {
|
||||
t.Error("the validate run is not the key <pipeline>.validate of composition-runs")
|
||||
}
|
||||
o := r.validate(ctx, "ask-a", step("a", 9))
|
||||
if o.Outcome != meshwants.StepEndedOutcomeFailed || o.Said != reasonCycle+": a:x → b:y → a:x" || len(asks) != 1 {
|
||||
t.Errorf("a revision making a cycle ended %+v (%d validator asks)", o, len(asks))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user