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:
@@ -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
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func Answer(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]st
|
||||
return refuse(fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err))
|
||||
}
|
||||
}
|
||||
composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps))
|
||||
composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), nil)
|
||||
if err != nil {
|
||||
// Not one module's: the node's own (a value served elsewhere, the mesh's network), said once as the node's.
|
||||
if len(failed) == 0 {
|
||||
@@ -331,8 +331,11 @@ func standsInFor(x, node string) (string, string) {
|
||||
// else the manifest it is composed from. Only the part of the offer that cannot compose is left out, by provision
|
||||
// (culprit): de-spiegel's routes, its names unset, leave route-proxy without them while mailu keeps its smtp account,
|
||||
// and the hold says so.
|
||||
//
|
||||
// owned, where not nil, is told each culprit held for a refusal that names paths two modules both own, with those pairs
|
||||
// (resolution.Refusal.OwnedTwice): a composer blames both owners with the path (design 47 G §721; A-468l).
|
||||
func composeEach(in compose.Input, node string, fps map[string]string, applied bool, running []compositions.Composed, failed map[string]string,
|
||||
ran func(module string) (catalogue.Manifest, bool)) (out map[string]compositions.Composed, skipped, stood []string, err error) {
|
||||
ran func(module string) (catalogue.Manifest, bool), owned func(culprit string, twice []resolution.OwnedTwice)) (out map[string]compositions.Composed, skipped, stood []string, err error) {
|
||||
mode := compose.Foreseeing
|
||||
if applied {
|
||||
mode = compose.Reading
|
||||
@@ -383,6 +386,9 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b
|
||||
if module == "" {
|
||||
return nil, nil, nil, firstReason(err, failed)
|
||||
}
|
||||
if refusal := (*resolution.Refusal)(nil); owned != nil && errors.As(err, &refusal) && len(refusal.OwnedTwice) > 0 {
|
||||
owned(module, refusal.OwnedTwice)
|
||||
}
|
||||
hold(module, err.Error(), leave)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -703,7 +703,7 @@ func Compose(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]s
|
||||
return nil, nil, held, fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err)
|
||||
}
|
||||
}
|
||||
out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps))
|
||||
out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), nil)
|
||||
return out, skipped, held, err
|
||||
}
|
||||
|
||||
@@ -730,7 +730,7 @@ func ComposingInput(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[s
|
||||
|
||||
// ComposeSent composes node from an input ComposingInput read, through the path Compose takes (composeEach, the read's holds
|
||||
// first): what a check's sandbox runs. False when the input says no way of composing node (an input from a node-engine
|
||||
// before ComposedHow): the caller cannot compose it as the node does.
|
||||
// before ComposedHow): the caller cannot compose it as the node does. A node the change refuses is a *Refuses.
|
||||
func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bool, error) {
|
||||
c := in.ComposedHow
|
||||
if c == nil || c.Node != node {
|
||||
@@ -740,7 +740,14 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil)
|
||||
twice := map[string][]resolution.OwnedTwice{}
|
||||
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, func(culprit string, pairs []resolution.OwnedTwice) {
|
||||
for _, p := range pairs {
|
||||
if p.Modules[0] == culprit || p.Modules[1] == culprit {
|
||||
twice[culprit] = append(twice[culprit], p)
|
||||
}
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
@@ -748,18 +755,57 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo
|
||||
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
|
||||
// review of the sandbox input).
|
||||
var refused []string
|
||||
for _, m := range sortedKeys(held) {
|
||||
blamed := map[string]string{}
|
||||
ours := func(m string) bool {
|
||||
_, was := c.Held[m]
|
||||
if _, before := c.HeldBefore[m]; !was && !before {
|
||||
_, before := c.HeldBefore[m]
|
||||
return !was && !before
|
||||
}
|
||||
for _, m := range sortedKeys(held) {
|
||||
if ours(m) {
|
||||
refused = append(refused, m+": "+held[m])
|
||||
blamed[m] = held[m]
|
||||
}
|
||||
}
|
||||
if len(refused) > 0 {
|
||||
return nil, true, fmt.Errorf("on %s the change refuses %s", node, strings.Join(refused, "; "))
|
||||
if len(refused) == 0 {
|
||||
return out, true, nil
|
||||
}
|
||||
return out, true, nil
|
||||
// Two modules owning one path are each blamed, with that path, the one held for it and the one it was held beside
|
||||
// (design 47 G §721; A-468l).
|
||||
for _, m := range sortedKeys(blamed) {
|
||||
for _, p := range twice[m] {
|
||||
words := fmt.Sprintf("%s and %s both declare the path %q", p.Modules[0], p.Modules[1], p.Path)
|
||||
for _, owner := range p.Modules {
|
||||
if ours(owner) {
|
||||
blamed[owner] = words
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
e := &Refuses{Node: node, words: strings.Join(refused, "; ")}
|
||||
for _, m := range sortedKeys(blamed) {
|
||||
e.Blamed = append(e.Blamed, Blamed{Module: m, Problem: blamed[m]})
|
||||
}
|
||||
return nil, true, e
|
||||
}
|
||||
|
||||
// Refuses is ComposeSent's refusal of a node by the change, answered structured (design 47 G §721; A-469j): each module
|
||||
// the sandbox held that its node-engine held neither in the read nor composing without the change (HeldBefore), and
|
||||
// each other owner of a path one of them was held for, with its problem.
|
||||
type Refuses struct {
|
||||
Node string
|
||||
Blamed []Blamed
|
||||
words string
|
||||
}
|
||||
|
||||
// Blamed is one module a refusal of the change blames, with its problem.
|
||||
type Blamed struct {
|
||||
Module string
|
||||
Problem string
|
||||
}
|
||||
|
||||
func (e *Refuses) Error() string { return fmt.Sprintf("on %s the change refuses %s", e.Node, e.words) }
|
||||
|
||||
// Plans is the provisioning plan of each module handed to the provisioner on the scope's node, composed from the bus
|
||||
// alone (novox/hq ADR 0570 clause 2): the controller's handedPlans over the same input (mesh-control
|
||||
// cmd/mesh-controller/compose_sdk.go), its rendering in the Foreseeing mode with the mesh's generators. A plan names
|
||||
|
||||
@@ -20,7 +20,19 @@ func heldKey(claim, kind string) string {
|
||||
//
|
||||
// Every reason at once rather than the first, and each says what to do about it. A person
|
||||
// resolving these fixes them in one pass or in four.
|
||||
type Refusal struct{ Problems []string }
|
||||
type Refusal struct {
|
||||
Problems []string
|
||||
// OwnedTwice is each path two modules both own among Problems, as a pair: a composer blames both owners with the
|
||||
// path, never by the words (design 47 G §721; A-468l).
|
||||
OwnedTwice []OwnedTwice
|
||||
}
|
||||
|
||||
// OwnedTwice is one path two modules both declare as their own (checkResources), the module that declared it first
|
||||
// first.
|
||||
type OwnedTwice struct {
|
||||
Path string
|
||||
Modules [2]string
|
||||
}
|
||||
|
||||
func (r *Refusal) Error() string {
|
||||
return "these assignments cannot be applied:\n - " + strings.Join(r.Problems, "\n - ")
|
||||
@@ -616,7 +628,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
// Listed after the holding: an optional consumer of a requirement nothing answers is left absent there (ADR 0330 §3, §7).
|
||||
resolution.Absent = absentOf(absent, order, catalogue)
|
||||
problems = append(problems, unheld...)
|
||||
problems = append(problems, checkResources(resolution.Modules)...)
|
||||
owned, twice := resourceProblems(resolution.Modules)
|
||||
problems = append(problems, owned...)
|
||||
resolution.Claims = claims
|
||||
|
||||
// Judged over the closure — what this node will actually run — so a holder pulled in by a
|
||||
@@ -641,7 +654,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
problems = append(problems, why)
|
||||
}
|
||||
sort.Strings(problems)
|
||||
return mcat.Resolution{}, nil, &Refusal{Problems: problems}
|
||||
return mcat.Resolution{}, nil, &Refusal{Problems: problems, OwnedTwice: twice}
|
||||
}
|
||||
return resolution, held, nil
|
||||
}
|
||||
@@ -910,6 +923,13 @@ func canonicalSeat(name string) string {
|
||||
// resolves with no refusal. What is refused is the contradiction — a path one module owns and
|
||||
// another merely accesses — because shared data is the operator's and nobody's to own.
|
||||
func checkResources(modules []mcat.Manifest) []string {
|
||||
problems, _ := resourceProblems(modules)
|
||||
return problems
|
||||
}
|
||||
|
||||
// resourceProblems is checkResources' problems, with each path two modules both own as a pair beside its words.
|
||||
func resourceProblems(modules []mcat.Manifest) ([]string, []OwnedTwice) {
|
||||
var twice []OwnedTwice
|
||||
// Judged as the machine composes them: where the node-resolver holder writes the resolver file, the
|
||||
// uplink holder's rendering of it is not composed, so it is not a second owner (novox/hq ADR 0247).
|
||||
modules = steppedBack(modules)
|
||||
@@ -987,6 +1007,9 @@ func checkResources(modules []mcat.Manifest) []string {
|
||||
if other, taken := owner[key]; taken && other != m.Module {
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"%s and %s both declare the %s %q", other, m.Module, field, value))
|
||||
if field == "path" {
|
||||
twice = append(twice, OwnedTwice{Path: value, Modules: [2]string{other, m.Module}})
|
||||
}
|
||||
}
|
||||
owner[key] = m.Module
|
||||
if field == "path" {
|
||||
@@ -1007,6 +1030,7 @@ func checkResources(modules []mcat.Manifest) []string {
|
||||
if other, taken := owner[key]; taken && other != m.Module {
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"%s and %s both declare the path %q", other, m.Module, fact.Path))
|
||||
twice = append(twice, OwnedTwice{Path: fact.Path, Modules: [2]string{other, m.Module}})
|
||||
}
|
||||
owner[key] = m.Module
|
||||
ownedPath[fact.Path] = m.Module
|
||||
@@ -1042,7 +1066,7 @@ func checkResources(modules []mcat.Manifest) []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems
|
||||
return problems, twice
|
||||
}
|
||||
|
||||
// meshNetwork is what to assign to a machine that needs to reach another one.
|
||||
|
||||
@@ -9,6 +9,7 @@ package composer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
@@ -27,6 +28,7 @@ import (
|
||||
|
||||
"github.com/novox/mesh-host/internal/compose"
|
||||
"github.com/novox/mesh-host/internal/compose/frombus"
|
||||
"github.com/novox/mesh-host/internal/compose/resolution"
|
||||
)
|
||||
|
||||
// The shapes of mesh-sdk's composer package, by the names this package's code was written with.
|
||||
@@ -261,6 +263,9 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
|
||||
m.Reason += "; " + words
|
||||
}
|
||||
}
|
||||
if m.Blamed == nil {
|
||||
m.Blamed = []blame{} // always written, so a verdict blaming none is told from an old composer's (A-469h)
|
||||
}
|
||||
cv.Machines[node] = m
|
||||
}
|
||||
return cv, nil
|
||||
@@ -455,7 +460,7 @@ func HoldingsOf(shelf map[string]catalogue.Manifest, nodes []compose.Node) []cat
|
||||
func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
||||
if depth == DepthResolve {
|
||||
if _, err := compose.Resolve(in, node); err != nil {
|
||||
return Machine{Reason: err.Error()}
|
||||
return Machine{Reason: err.Error(), Blamed: ownedTwice(err)}
|
||||
}
|
||||
return Machine{Composes: true}
|
||||
}
|
||||
@@ -464,7 +469,14 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
||||
if !declarations {
|
||||
if _, how, err := frombus.ComposeSent(in, node); how {
|
||||
if err != nil {
|
||||
return Machine{Reason: err.Error()}
|
||||
m := Machine{Reason: err.Error()}
|
||||
var refuses *frombus.Refuses
|
||||
if errors.As(err, &refuses) {
|
||||
for _, b := range refuses.Blamed {
|
||||
m.Blamed = append(m.Blamed, blame{Module: b.Module, Problem: b.Problem})
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
return Machine{Composes: true}
|
||||
}
|
||||
@@ -478,7 +490,7 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
||||
return Machine{NotJudged: NotJudged + strings.Join(folded, ", ") +
|
||||
" (its own composition carries them as they run, and the sandbox cannot): " + err.Error()}
|
||||
}
|
||||
return Machine{Reason: err.Error()}
|
||||
return Machine{Reason: err.Error(), Blamed: ownedTwice(err)}
|
||||
}
|
||||
m := Machine{Composes: len(problems) == 0, Problems: problems, Refusals: d.Refusals()}
|
||||
if len(problems) > 0 {
|
||||
@@ -490,6 +502,32 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
||||
return m
|
||||
}
|
||||
|
||||
// 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"`
|
||||
Problem string `json:"problem"`
|
||||
}
|
||||
|
||||
// ownedTwice blames both owners of each path a refusal names two modules owning, with that path (design 47 G §721;
|
||||
// A-468l), where nothing held either: a composition that holds no module.
|
||||
func ownedTwice(err error) []blame {
|
||||
var refusal *resolution.Refusal
|
||||
if !errors.As(err, &refusal) {
|
||||
return nil
|
||||
}
|
||||
problem := map[string]string{}
|
||||
for _, p := range refusal.OwnedTwice {
|
||||
for _, owner := range p.Modules {
|
||||
problem[owner] = fmt.Sprintf("%s and %s both declare the path %q", p.Modules[0], p.Modules[1], p.Path)
|
||||
}
|
||||
}
|
||||
var out []blame
|
||||
for _, m := range slices.Sorted(maps.Keys(problem)) {
|
||||
out = append(out, blame{Module: m, Problem: problem[m]})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// NotJudged opens the words of a machine the sandbox does not judge (Machine.NotJudged, the contract's field, ADR 0593 §9):
|
||||
// its node-engine sent an input that does not say how it composes (compose.Input.ComposedHow), and the node runs modules
|
||||
// folded in its own composition. The machine is then neither composed nor refused; a reader decides by the field.
|
||||
|
||||
Reference in New Issue
Block a user