From 8700aabba3b3710da2f73c9c70d0c3afc1679480 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 11:21:49 +0100 Subject: [PATCH] composer: a machine that fails with no module held is searched for its culprit, bounded by blame_tries (G-24 H2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composer program has no settings, so the assigner bounds the search through the request: only the candidate's changed modules placed on the machine are held, one at a time, the search ending at the first whose hold ends the problem; past the bound the untried are named. A request with no blame_tries gets no search. Builds: design 47 G §721, §733; A-468h, A-468i, A-469i, A-469j, A-469k --- cmd/mesh-compose/main_test.go | 42 +++++++++++++++---- internal/composer/composer.go | 77 +++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 10 deletions(-) diff --git a/cmd/mesh-compose/main_test.go b/cmd/mesh-compose/main_test.go index 04efce78..24a58563 100644 --- a/cmd/mesh-compose/main_test.go +++ b/cmd/mesh-compose/main_test.go @@ -172,30 +172,48 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path + `", "mode": "0600", "content": "` + content + `"}]}` } + plain := func(module string) string { return `{"module": "` + module + `", "version": "1"}` } + secret := `N=${secret:repository}\\n` + search := map[string]string{"m1": plain("m1"), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")} for _, row := range []struct { name string manifests map[string]string assigned []string how *compose.ComposedHow + tries int // the request's blame_tries blamed []blame // each module blamed, its problem holding the words given }{ // G-24 H-AC1: a fixture module whose manifest is refused on the machine is blamed by name. {"a module the change refuses is blamed by name", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)}, - []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, []blame{{Module: "app", Problem: "repository"}}}, + []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "app", Problem: "repository"}}}, // Held composing without the change (HeldBefore): left out of blamed. {"a module held before the change is not blamed", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)}, - []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, []blame{}}, + []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, 0, []blame{}}, // G-24 H-AC2 (A-468l): two modules owning one path are both blamed, with that path. {"two modules owning one path are both blamed", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, - []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, + []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, // The same, on a node whose input says not how it composes: nothing is held, both owners are blamed from the refusal. {"two path owners, composed without how the node composes", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, - []string{"one", "two"}, nil, + []string{"one", "two"}, nil, 20, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, + // G-24 H-AC5: a machine that fails with no module held is searched over the changed modules placed on it (here every + // one, the input naming no manifest its builds were made of, A-469k), in assignment order; the search ends at the + // first whose hold ends the problem, so m3 is never tried. + {"the search ends at the first module whose hold ends the problem", search, []string{"m1", "m2", "m3"}, nil, 20, + []blame{{Module: "m2", Problem: "repository"}}}, + // A module whose case manifest is the one its build was made of is not changed (A-469k), so never held: m2's + // problem is then no changed module's, and none is blamed. + {"a module its build was made of is not tried", search, []string{"m1", "m2", "m3"}, + &compose.ComposedHow{Node: "b", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}}, + // G-24 H-AC4: past the request's blame_tries the modules not yet tried are named so. + {"past blame_tries the untried are named", search, []string{"m1", "m2", "m3"}, nil, 1, + []blame{{Module: "m2", Problem: composer.NotTried}, {Module: "m3", Problem: composer.NotTried}}}, + // A-468i: a request with no blame_tries gets no search; the machine fails on the node's own account (H-AC3). + {"a request with no blame_tries is not searched", search, []string{"m1", "m2", "m3"}, nil, 0, []blame{}}, } { t.Run(row.name, func(t *testing.T) { - r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), + r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), BlameTries: row.tries, Cases: []composer.Case{{Name: "change", Manifests: map[string]composer.Manifest{}}}} for name, raw := range row.manifests { r.Cases[0].Manifests[name] = composer.Manifest{Raw: json.RawMessage(raw)} @@ -213,8 +231,8 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { t.Fatal(err) } m := v.Cases[0].Machines["a"] - if len(row.blamed) > 0 && m.Composes { - t.Errorf("a machine that blames a module composes: %+v", m) + if held := row.how != nil && row.how.HeldBefore != nil; m.Composes != held { + t.Errorf("composes = %v, want %v: %+v", m.Composes, held, m) } if len(m.Blamed) != len(row.blamed) { t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m) @@ -228,6 +246,16 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { } } +// digest is the content digest of a manifest (compose.ContentDigest). +func digest(t *testing.T, raw string) string { + t.Helper() + d, err := compose.ContentDigest([]byte(raw)) + if err != nil { + t.Fatal(err) + } + return d +} + // blame is one module a machine's verdict blames (composer.Machine.Blamed). type blame = struct { Module string `json:"module"` diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 1bf54522..3a470ece 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -238,7 +238,9 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { } cv.Machines = map[string]Machine{} for _, node := range r.Machines { - m := machine(in, node, depth, r.Declarations) + at := in // the input m is composed from + m := machine(at, node, depth, r.Declarations) + problem := problemOf(m) // what the search for culprits holds a module against, before any words are added if words := awaitedOn(in, node, awaited); words != "" { // Composed without the build it runs at: named per node and module, never a silent pass (issue 1921). The // machine is then not judged, as for a node whose running state its engine does not send (ADR 0593 §9). Where @@ -249,11 +251,12 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { // shanks). how := "composed from the change's manifest without its build: " if !m.Composes && m.NotJudged == "" { - switch again := machine(heldAgain(in, held, awaited), node, depth, r.Declarations); { + lifted := heldAgain(in, held, awaited) + switch again := machine(lifted, node, depth, r.Declarations); { case again.Composes: m, how = again, "composed with it held as its node-engine holds it, since it does not compose without its build: " case again.NotJudged == "": - m, how = again, "refused with it held as its node-engine holds it, since it does not compose without its build: " + m, how, at, problem = again, "refused with it held as its node-engine holds it, since it does not compose without its build: ", lifted, problemOf(again) } } words = how + words @@ -263,6 +266,11 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { m.Reason += "; " + words } } + // A machine that does not compose with no module held is searched for the module whose hold ends its problem, bounded + // by the request's blame_tries; a request with none gets no search (design 47 G §721; A-468i, A-469j). + if !m.Composes && m.NotJudged == "" && len(m.Blamed) == 0 && r.BlameTries > 0 { + m.Blamed = culprits(at, held, node, depth, r.Declarations, changedOn(at, node, c, held.ComposedHow), r.BlameTries, problem) + } if m.Blamed == nil { m.Blamed = []blame{} // always written, so a verdict blaming none is told from an old composer's (A-469h) } @@ -502,6 +510,69 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine { return m } +// NotTried is the problem of a changed module the search for culprits did not hold, its bound reached (design 47 G §721). +const NotTried = "not tried: the search reached its bound" + +// triedHeld is the words a module is held with while the search for culprits tries it. +const triedHeld = "held by the composer's search for the module the machine's problem is of" + +// culprits holds each of changed on node, one at a time, as its node-engine holds a module (heldAgain), each try +// composing once more, and blames the first whose hold ends problem: the try composes, or fails otherwise, as culprit +// blames a stub (frombus). At most tries tries; past them each module not yet tried is named NotTried (design 47 G §721). +// None ends it: no module is blamed, and the machine fails on the node's own account. +func culprits(in, held compose.Input, node, depth string, declarations bool, changed []string, tries int, problem string) []blame { + for i, mod := range changed { + if i == tries { + var out []blame + for _, untried := range changed[i:] { + out = append(out, blame{Module: untried, Problem: NotTried}) + } + return out + } + try := machine(heldAgain(in, held, map[string]string{mod: triedHeld}), node, depth, declarations) + if try.NotJudged == "" && (try.Composes || problemOf(try) != problem) { + return []blame{{Module: mod, Problem: problem}} + } + } + return nil +} + +// problemOf is a machine's problem in words: why it does not compose, with what the validator refuses. +func problemOf(m Machine) string { + if len(m.Problems) == 0 { + return m.Reason + } + return m.Reason + ": " + strings.Join(m.Problems, "; ") +} + +// changedOn is each module placed on node, in assignment order, whose case manifest's content digest differs from the +// manifest its build was made of as the input names it (ComposedHow.Manifests), or that the input names none for: the +// candidate's changed modules (design 47 G §721; A-469k). A module the case carries no manifest of is not changed. +func changedOn(in compose.Input, node string, c Case, how *compose.ComposedHow) []string { + var out []string + for _, mod := range assignedOn(in, node) { + man, carried := c.Manifests[mod] + if !carried || len(man.Raw) == 0 { + continue + } + if digest, err := compose.ContentDigest(man.Raw); err == nil && digest == manifestOf(how, mod) { + continue + } + out = append(out, mod) + } + return out +} + +// assignedOn is the modules placed on node, in assignment order. +func assignedOn(in compose.Input, node string) []string { + for _, n := range in.Nodes { + if n.Name == node { + return n.Assigned + } + } + return nil +} + // blame is one module a machine's verdict blames, with its problem (Machine.Blamed, design 47 G §721). type blame = struct { Module string `json:"module"`