composer: a machine's verdict names the modules it blames (G-24 H1)

The assigner fails only the composition steps of the modules a machine blames, so the composer names them: the modules
the change refuses that the node held neither in its read nor composing without the change, answered structured by
ComposeSent, and both owners of a path two modules own, from the resolution's pairs. Blamed is always written, so a
verdict blaming none is told from an old composer's. The two request-file tests are one, for the test budget.

Builds: design 47 G §721, §733; A-468h, A-468l, A-469h, A-469j
This commit is contained in:
2026-11-17 11:19:54 +01:00
parent d0b208b668
commit 06781d4dbc
6 changed files with 215 additions and 30 deletions
+5 -1
View File
@@ -152,7 +152,11 @@ func runWithSeats(req composer.Request) (composer.Verdict, error) {
for i := range v.Cases {
v.Cases[i].Machines = map[string]composer.Machine{}
for _, node := range machines {
v.Cases[i].Machines[node] = composer.Machine{NotJudged: NoSeatList}
// Blamed is always written, blaming none here (design 47 G §721, A-469h).
v.Cases[i].Machines[node] = composer.Machine{NotJudged: NoSeatList, Blamed: []struct {
Module string `json:"module"`
Problem string `json:"problem"`
}{}}
}
}
return v, nil
+79 -12
View File
@@ -161,9 +161,77 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
if m := resolverMachine(true); strings.Contains(m.Reason+strings.Join(m.Problems, " "), "both declare") || m.NotJudged != "" {
t.Errorf("with the seat list, the uplink's and the resolver's holders on one machine: %+v, want the uplink's stepping back", m)
}
if m := resolverMachine(false); m.Composes || m.NotJudged != NoSeatList || m.Reason != "" {
t.Errorf("without a seat list: %+v, want not judged, saying why", m)
if m := resolverMachine(false); m.Composes || m.NotJudged != NoSeatList || m.Reason != "" || m.Blamed == nil {
t.Errorf("without a seat list: %+v, want not judged, saying why, blaming none", m)
}
// Design 47 G §721, §733 (the node-engine's composer): a machine's verdict names the modules it blames, each with its
// problem, and always writes blamed (A-469h). On a node composed as its node-engine composes it (ComposedHow), blamed is
// the modules the change refuses that the node held neither in its read nor composing without the change (A-469j).
file := func(module, path, content string) string {
return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path +
`", "mode": "0600", "content": "` + content + `"}]}`
}
for _, row := range []struct {
name string
manifests map[string]string
assigned []string
how *compose.ComposedHow
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"}}},
// 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{}},
// 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{}},
[]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,
[]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"`}}},
} {
t.Run(row.name, func(t *testing.T) {
r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t),
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)}
}
r = withInput(t, r, compose.Input{Nodes: []compose.Node{{Name: "a", Assigned: row.assigned}}, ComposedHow: row.how})
var out, errOut bytes.Buffer
if code := run(nil, bytes.NewReader(encode(t, r)), &out, &errOut); code != 0 {
t.Fatalf("exit %d: %s", code, errOut.String())
}
if !strings.Contains(out.String(), `"blamed":`) {
t.Errorf("the verdict writes no blamed: %s", out.String())
}
var v composer.Verdict
if err := json.Unmarshal(out.Bytes(), &v); err != nil {
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 len(m.Blamed) != len(row.blamed) {
t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m)
}
for i, b := range row.blamed {
if m.Blamed[i].Module != b.Module || !strings.Contains(m.Blamed[i].Problem, b.Problem) {
t.Errorf("blamed %+v, want %+v", m.Blamed, row.blamed)
}
}
})
}
}
// blame is one module a machine's verdict blames (composer.Machine.Blamed).
type blame = struct {
Module string `json:"module"`
Problem string `json:"problem"`
}
// 1621/AC3: over the captured catalogue and a mesh of three machines, the command's verdict equals, machine for
@@ -211,6 +279,9 @@ func TestTheCommandAnswersWhatTheLinkedCompositionAnswers(t *testing.T) {
}
}
}
// G-24 H-AC3 (§721): a machine that does not compose and blames no module (ace: its own sealing key) fails on the
// node's own account, blamed written empty.
want.Blamed = []blame{}
if !reflect.DeepEqual(got, want) {
t.Errorf("%s: %s: command %+v, linked %+v", depth, node, got, want)
}
@@ -249,8 +320,8 @@ func TestACatalogueCheckoutIsComposedForANode(t *testing.T) {
}
}
// A run step hands the command no standard input: the request is read from the file -request names, and a file that is
// not there is a request it cannot read.
// A run step hands the command no standard input: the request is read from the file -request names, or from the one
// MESH_RUN_INPUT names, and a file that is not there is a request it cannot read.
func TestTheRequestIsReadFromAFile(t *testing.T) {
file := filepath.Join(t.TempDir(), "request.json")
r := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{
@@ -265,14 +336,10 @@ func TestTheRequestIsReadFromAFile(t *testing.T) {
if code, _, stderr := runJSON(t, []string{"-request", file + ".gone"}, nil); code != 1 || !strings.Contains(stderr, "cannot be read") {
t.Errorf("a request file that is not there: exit %d, %q", code, stderr)
}
}
// A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the last
// line of standard output (design 47 G A-167).
func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) {
file := filepath.Join(t.TempDir(), "input.json")
r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{
"demo": {Raw: json.RawMessage(`{"module":"demo","version":"1"}`)}}}}}
// A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the
// last line of standard output (design 47 G A-167).
r.Depth = composer.DepthCompose
if err := os.WriteFile(file, encode(t, r), 0o600); err != nil {
t.Fatal(err)
}
@@ -282,7 +349,7 @@ func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) {
t.Fatalf("exit %d: %s", code, errOut.String())
}
lines := strings.Split(strings.TrimRight(out.String(), "\n"), "\n")
var v composer.Verdict
v = composer.Verdict{}
if err := json.Unmarshal([]byte(lines[len(lines)-1]), &v); err != nil || len(v.Cases) != 1 || !v.Cases[0].Manifests["demo"].Accepted {
t.Fatalf("last line is no verdict: %v\n%s", err, out.String())
}