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:
@@ -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