diff --git a/modules/mesh-delivery-sdk/composer/composer.go b/modules/mesh-delivery-sdk/composer/composer.go index 88b66f95..1f3907ae 100644 --- a/modules/mesh-delivery-sdk/composer/composer.go +++ b/modules/mesh-delivery-sdk/composer/composer.go @@ -67,6 +67,11 @@ type Request struct { // them (the definitions of the seat mesh-catalog, resolved), raw so that this package names no seat (ADR 0635 §4, ADR 0636 // §1). The judge and the composer read them. None is no list at hand: a composer handed none judges no machine (ADR 0636 §1). Seats []json.RawMessage `json:"seats,omitempty"` + // BlameTries bounds the composer's search for the modules a machine that does not compose blames: it composes at + // most this many times more, the assigner's setting blame-tries, since the composer has no settings of its own + // (design 47 G §721, §729; A-469i). None is no search: the composer blames only what its composition holds or + // refuses (A-468i). + BlameTries int `json:"blame_tries,omitempty"` } // Case is one catalogue composed: every module's manifest by name, and per node the manifests kept at the build it runs. @@ -168,6 +173,11 @@ type ManifestRead struct { // in words, why the composer did not judge the machine (an older node-engine's input that does not say how it composes, // novox/hq ADR 0593 §9): the machine is then neither composed nor refused, and a reader decides by this field alone, // never by the words of Reason. +// +// Blamed names each module the candidate's composition of the machine holds or refuses and the composition without the +// candidate does not, with its problem (design 47 G §721). A composer of this shape always writes it, an empty list when +// it blames none (A-469h); nil is a verdict with no such field, a composer from before §721, which its reader judges as +// before it ("the composer names no culprits"). type Machine struct { Composes bool `json:"composes"` NotJudged string `json:"not_judged,omitempty"` @@ -175,6 +185,10 @@ type Machine struct { Problems []string `json:"problems,omitempty"` Refusals []string `json:"refusals,omitempty"` Declared []Path `json:"declared,omitempty"` + Blamed []struct { + Module string `json:"module"` + Problem string `json:"problem"` + } `json:"blamed,omitzero"` } // Path is one path a declaration puts on the machine, with its kind (the resource's type), owner, group and mode as diff --git a/modules/mesh-delivery-sdk/composer/composer_test.go b/modules/mesh-delivery-sdk/composer/composer_test.go index 63e31c79..fd02622e 100644 --- a/modules/mesh-delivery-sdk/composer/composer_test.go +++ b/modules/mesh-delivery-sdk/composer/composer_test.go @@ -57,6 +57,42 @@ func TestAManifestIsItsBytesOrItsDigest(t *testing.T) { t.Errorf("the known packages %#v went as %s and read back %#v (%v)", known, wire, back.Packages, err) } } + // K1/AC4 (design 47 G §721, §729; A-469h, A-469i): a request's blame_tries and a verdict's blamed read back whole; a + // verdict with no blamed (a composer from before §721) reads back as no field, told apart from an empty list. + wire, err = json.Marshal(Request{V: Version, BlameTries: 20}) + if back, derr := Decode(wire); err != nil || derr != nil || back.BlameTries != 20 || !strings.Contains(string(wire), `"blame_tries":20`) { + t.Errorf("blame_tries 20 went as %s and read back %d (%v, %v)", wire, back.BlameTries, err, derr) + } + one := Machine{} + one.Blamed = append(one.Blamed, struct { + Module string `json:"module"` + Problem string `json:"problem"` + }{Module: "a", Problem: "holds /etc/x"}) + for _, c := range []struct { + name string + wire string + blamed int + old bool + }{ + {"blames one", `{"composes":false,"blamed":[{"module":"a","problem":"holds /etc/x"}]}`, 1, false}, + {"blames none", `{"composes":false,"blamed":[]}`, 0, false}, + {"an old composer", `{"composes":false}`, 0, true}, + } { + var m Machine + if err := json.Unmarshal([]byte(c.wire), &m); err != nil { + t.Fatalf("%s: %v", c.name, err) + } + if len(m.Blamed) != c.blamed || (m.Blamed == nil) != c.old { + t.Errorf("%s: %s read back blamed %#v", c.name, c.wire, m.Blamed) + } + again, err := json.Marshal(m) + if err != nil || string(again) != c.wire { + t.Errorf("%s: %s went again as %s (%v)", c.name, c.wire, again, err) + } + } + if wire, _ := json.Marshal(one); string(wire) != `{"composes":false,"blamed":[{"module":"a","problem":"holds /etc/x"}]}` { + t.Errorf("a machine blaming a went as %s", wire) + } bad := Request{V: Version, Cases: []Case{{Name: "c", Manifests: map[string]Manifest{"x": {Digest: "nope"}}}}} if err := Fill(&bad, func(Manifest) ([]byte, error) { return nil, errors.New("not there") }); err == nil || !strings.Contains(err.Error(), "nope") { t.Fatalf("a digest the indexer does not hold: %v", err)