diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index f85db835..8c5ad01e 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -139,7 +139,7 @@ func (r *compositionRun) read(ctx context.Context, module string, keys []string, runs := r.runs.await(ctx, keys) setPhase(ctx, meshwants.StepProgressEventPhaseReport) for _, key := range keys { - ends = append(ends, judgeRun(module, runs[key], r.unlistedOn(runs[key].Machine))) + ends = append(ends, judgeRun(module, runs[key])) } out := outcomeOf(ends) out.Shared = r.runs.sharedOf(keys, runs) @@ -248,6 +248,21 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co r.logf("the composition run %s is not ended: %v", key, err) } } + // The one set of unlisted assignments, read once at the run's start and carried on the run to the leaving-out, the finding and + // every step's judgement, the resume's too (design 47 H-A-152, H-A-153). + unlisted := r.unlistedOn(node) + if len(unlisted) > 0 { + if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool { + if c.Ask != ask || c.Ended != nil { + return false + } + c.Unlisted = unlisted + return true + }); err != nil { + end(node + ": the run's unlisted assignments are not written: " + err.Error()) + return + } + } if err := prep.get(ctx); err != nil { end(node + ": " + err.Error()) return @@ -263,7 +278,7 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co return } cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none} - if left, err := r.leftOut(node, prep.manifests); err != nil { + if left, err := r.leftOut(node, unlisted); err != nil { end(node + ": " + err.Error()) return } else if left != nil { @@ -316,12 +331,13 @@ const notTried = "not tried: the search reached its bound" // it, on the node's own account; a verdict with no `blamed` (a composer before §721) is judged as before, with the warning "the // composer names no culprits"; otherwise the machine passes, with a warning for each other module blamed there. // -// unlisted are the modules the machine is assigned that none of their watched branches lists, left out of its composition: each is -// said on every path, in the machine's failed or could-not-run words where one is set, else as a warning, never the machine's -// failure and never dropped in silence (H-A-143, H-A-144, H-A-148). -func judgeRun(module string, run meshwants.CompositionRun, unlisted []string) machineEnd { +// The run's unlisted are the modules the machine is assigned that no watched branch's newest revision lists, left out of its +// composition, as the run's start read them (H-A-152, H-A-153): each is said on every path, in the machine's failed or +// could-not-run words where one is set, else as a warning, never the machine's failure and never dropped in silence (H-A-143, +// H-A-144, H-A-148). +func judgeRun(module string, run meshwants.CompositionRun) machineEnd { end := judgeVerdict(module, run) - for _, u := range unlisted { + for _, u := range run.Unlisted { said := run.Machine + " is assigned " + u + ", which no watched branch lists (H-A-143)" switch { case end.failed != "": @@ -594,16 +610,23 @@ func acrossBranches(step meshwants.StepRun, candidate mcc.Half, newest map[strin return out } -// unlistedOn is the modules the assignments place on node that the newest revision of none of their watched branches lists, a -// module with no watched branches among them (H-A-143, H-A-144), by name. +// unlistedOn is the one set of unlisted assignments of node (H-A-152): the modules the assignments place there that the newest +// revision of none of their watched branches lists, a module with no watched branches among them (H-A-143, H-A-144), by name. +// The candidate never enters it, so a module the change drops while still assigned stays in the composition and fails it as the +// change's own fault (ADR 0578 §2). Where the newest revisions are not followed yet nothing is unlisted: none while no branch's +// newest is held, and not a module one of whose watched branches' newest is not held yet. func (r *compositionRun) unlistedOn(node string) []string { if r.assigned == nil || r.newest == nil || r.watched == nil { return nil } newest := r.newest() + if len(newest) == 0 { + return nil + } var out []string for _, m := range r.assigned(node) { - if !listedOn(newest, r.watched(m), m) { + watched := r.watched(m) + if !listedOn(newest, watched, m) && !slices.ContainsFunc(watched, func(b string) bool { _, held := newest[b]; return !held }) { out = append(out, m) } } @@ -611,12 +634,12 @@ func (r *compositionRun) unlistedOn(node string) []string { return slices.Compact(out) } -// leftOut is the case's assignments of node with each module the case's manifests do not hold (none of its watched branches lists -// it) left out, or nil where none is (the case then composes the input's): a stale assignment is a fault of the assignments, not of -// the change judged, so it is left out of the composition, said in the journal and, at the judgement, as unlisted (design 47 -// H-A-148, H-A-143; ADR 0578 §2). -func (r *compositionRun) leftOut(node string, manifests map[string]composer.Manifest) (map[string]json.RawMessage, error) { - if r.assignment == nil { +// leftOut is the case's assignments of node with each module of the run's unlisted set left out, or nil where none is (the case +// then composes the input's): a stale assignment is a fault of the assignments, not of the change judged, so it is left out of the +// composition, said in the journal, raised as assignment-unlisted and, at the judgement, said as unlisted from the same set +// (design 47 H-A-148, H-A-149, H-A-152, H-A-143; ADR 0578 §2). +func (r *compositionRun) leftOut(node string, set []string) (map[string]json.RawMessage, error) { + if r.assignment == nil || len(set) == 0 { return nil, nil } a, ok := r.assignment(node) @@ -625,7 +648,7 @@ func (r *compositionRun) leftOut(node string, manifests map[string]composer.Mani } var unlisted []string for _, m := range a.Modules { - if _, held := manifests[m.Module]; !held { + if slices.Contains(set, m.Module) { unlisted = append(unlisted, m.Module) } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index d6c37833..9bf5111e 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -293,17 +293,32 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { } // A stale assignment is left out of the case's assignments as well, said, and the machine composes; a listed module stays in - // (H-A-148, ADR 0578 §2). + // (H-A-148, ADR 0578 §2). The one set is the watched branches' newest revisions', carried on the run (H-A-152, H-A-153): a module + // the candidate drops while the newest still lists it stays in, the change's own fault, and while no newest revision is followed + // nothing is left out. + dropsWeb := func() map[string]mcc.Half { + h := across.r.newest() + h["main"] = mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: "main", Revision: 6}, + Entries: map[string]meshcatalog.CatalogEntry{"m": {Module: "m", Manifest: map[string]any{"module": "m"}}, + "web": {Module: "web", Fp: "w1", Manifest: map[string]any{"module": "web"}}}} + return h + } for _, tc := range []struct { name string assigned []string - want []string // the case's modules of ace; nil: the input's assignments + newest func() map[string]mcc.Half // nil: across's + want []string // the case's modules of ace; nil: the input's assignments }{ - {"a stale assignment left out and said, the machine composes", []string{"m", "f1-circuits", "checker"}, []string{"m", "f1-circuits"}}, - {"listed modules alone: the input's assignments", []string{"m", "f1-circuits"}, nil}, + {"a stale assignment left out and said, the machine composes", []string{"m", "f1-circuits", "checker"}, nil, []string{"m", "f1-circuits"}}, + {"listed modules alone: the input's assignments", []string{"m", "f1-circuits"}, nil, nil}, + {"a module the candidate drops, the newest lists: kept", []string{"m", "f1-circuits", "web"}, dropsWeb, nil}, + {"no newest revision followed: nothing left out", []string{"m", "checker"}, func() map[string]mcc.Half { return map[string]mcc.Half{} }, nil}, } { left := newRunStand(t, "src2:e1", "src2:e1", "d1") left.r.newest, left.r.watched = across.r.newest, across.r.watched + if tc.newest != nil { + left.r.newest = tc.newest + } left.r.assigned = func(string) []string { return tc.assigned } left.r.assignment = func(node string) (mma.Assignments, bool) { a := mma.Assignments{Node: node} @@ -327,6 +342,10 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { if out.Outcome != meshwants.StepEndedOutcomePassed || (tc.want != nil) != slices.Contains(out.Warnings, said) { t.Errorf("%s: the step came to %+v", tc.name, out) } + if run, _, _, _ := left.runs.read(runKeyOf("main.7", "ace")); (tc.want != nil) != slices.Equal(run.Unlisted, []string{"checker"}) || + (tc.want == nil && run.Unlisted != nil) { + t.Errorf("%s: the run carries the unlisted %v", tc.name, run.Unlisted) + } raw, ok := left.requests["ace"].Cases[0].Assignments["ace"] if tc.want == nil { if ok { @@ -549,7 +568,9 @@ func TestAMachineIsJudgedByTheModulesItBlames(t *testing.T) { []string{"ace is assigned photos, which no watched branch lists (H-A-143)"}, []string{"photos"}}, } { t.Run(tc.name, func(t *testing.T) { - e := judgeRun(tc.module, tc.run, tc.unlisted) + run := tc.run + run.Unlisted = tc.unlisted // the set the run's start wrote (H-A-153) + e := judgeRun(tc.module, run) if e.failed != tc.failed || e.couldNot != tc.couldNo || !slices.Equal(e.warnings, tc.warnings) { t.Errorf("judged %+v, want failed %q, could not run %q, warnings %q", e, tc.failed, tc.couldNo, tc.warnings) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index f8844555..22d71366 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -818,7 +818,7 @@ func (r *compositionRuns) leave(pipeline string, stop func(ids []string)) ([]str // passedOn is whether the step of module passed on the machine of an ended run (§722): neither failed nor could not run there. func passedOn(module string, run meshwants.CompositionRun) bool { - e := judgeRun(module, run, nil) // the unlisted modules change only the words, never whether it passed + e := judgeVerdict(module, run) // the unlisted modules change only the words, never whether it passed return e.failed == "" && e.couldNot == "" } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go index d0be3c0d..7a0ccf15 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go @@ -416,7 +416,7 @@ func TestACompositionRunsBoundTimesOwedProgress(t *testing.T) { len(*drops) != 1 || !strings.HasPrefix((*drops)[0], "run-1: ") { t.Fatalf("past the bound: %+v, drops %v", run, *drops) } - if got := judgeRun("a", run, nil); got.couldNot != run.Said { + if got := judgeRun("a", run); got.couldNot != run.Said { t.Errorf("a reader of the run past its bound: %+v", got) } late := buildstep.StepEnded{Ask: "run-1", Asker: runAsker, Outcome: buildstep.OutcomePassed, Output: "{}"}