Compare commits
75
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85d1707e82 | ||
|
|
cb6cd9d996 | ||
|
|
2057c9d304 | ||
|
|
6ac8952541 | ||
|
|
6e89a5defd | ||
|
|
4b11f66b4b | ||
|
|
0439af3649 | ||
|
|
5cc26e2659 | ||
|
|
91dc064f92 | ||
|
|
7b6468e2bb | ||
|
|
0cc1728a04 | ||
|
|
d1768241dc | ||
|
|
cdd8bd3cba | ||
|
|
121a8090b3 | ||
|
|
ba9d4787f9 | ||
|
|
87cfae48b2 | ||
|
|
179a4a6402 | ||
|
|
7bfeb466bf | ||
|
|
e7803f8943 | ||
|
|
baeb87d195 | ||
|
|
9172eccbc4 | ||
|
|
07ea73bd64 | ||
|
|
d57e2325f6 | ||
|
|
43c812e98e | ||
|
|
e3d994fde1 | ||
|
|
eb89cb7da3 | ||
|
|
ed7cefb5d8 | ||
|
|
f21b8c202d | ||
|
|
b4bf772de4 | ||
|
|
c5f76cb974 | ||
|
|
8700aabba3 | ||
|
|
06781d4dbc | ||
|
|
d0b208b668 | ||
|
|
85ad1eef74 | ||
|
|
51b89964c5 | ||
|
|
1a6a380507 | ||
|
|
0612916af0 | ||
|
|
10a6824abe | ||
|
|
bb285f9c1b | ||
|
|
cbed32524a | ||
|
|
b132653fc0 | ||
|
|
523ad97e28 | ||
|
|
5b4484efd8 | ||
|
|
0a43489a74 | ||
|
|
dbb77efab1 | ||
|
|
1b9f9355b5 | ||
|
|
72385fd84a | ||
|
|
3bb895152f | ||
|
|
c6d893e141 | ||
|
|
310ff0cabc | ||
|
|
13fcfae051 | ||
|
|
f8f33e54a7 | ||
|
|
869d15e6d3 | ||
|
|
292aa54bbb | ||
|
|
f539cdb7ec | ||
|
|
3b365ba7cc | ||
|
|
6eb41a17e1 | ||
|
|
a1cd4a1a2f | ||
|
|
7a30c0d54c | ||
|
|
a9eb4372d9 | ||
|
|
c025bb5f1e | ||
|
|
5a3510b115 | ||
|
|
7f892a757c | ||
|
|
40ed0633e0 | ||
|
|
5bbde5db40 | ||
|
|
21e452df28 | ||
|
|
dc32afdd7e | ||
|
|
8a0c39280d | ||
|
|
a00cccfe0d | ||
|
|
592b4002bd | ||
|
|
0adc5ab4e6 | ||
|
|
6079f634d6 | ||
|
|
eaf011e971 | ||
|
|
1c3b2597ba | ||
|
|
fd023f7473 |
@@ -152,7 +152,11 @@ func runWithSeats(req composer.Request) (composer.Verdict, error) {
|
|||||||
for i := range v.Cases {
|
for i := range v.Cases {
|
||||||
v.Cases[i].Machines = map[string]composer.Machine{}
|
v.Cases[i].Machines = map[string]composer.Machine{}
|
||||||
for _, node := range machines {
|
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
|
return v, nil
|
||||||
|
|||||||
+114
-12
@@ -161,9 +161,112 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
|
|||||||
if m := resolverMachine(true); strings.Contains(m.Reason+strings.Join(m.Problems, " "), "both declare") || m.NotJudged != "" {
|
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)
|
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 != "" {
|
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", m)
|
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 + `"}]}`
|
||||||
|
}
|
||||||
|
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{}}, 20, []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"}}, 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{}}, 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, 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"}, &compose.ComposedHow{Node: "a"}, 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: "a", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}},
|
||||||
|
// A-470v: a hold that changes the problem but leaves the machine not composing keeps that module held and blamed,
|
||||||
|
// and the search goes on against the retry's problem: both modules the change refuses are blamed.
|
||||||
|
{"every module the change refuses is blamed", map[string]string{"m1": file("m1", "/var/lib/m1/env", secret), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")},
|
||||||
|
[]string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 20, []blame{{Module: "m1", Problem: "repository"}, {Module: "m2", Problem: "repository"}}},
|
||||||
|
// 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"}, &compose.ComposedHow{Node: "a"}, 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"}, &compose.ComposedHow{Node: "a"}, 0, []blame{}},
|
||||||
|
// A-469j: one search, the composer's, inside the node-engine's composition (ComposeSent): an input that says not how
|
||||||
|
// its node composes is composed without one, so its failure is the node's own.
|
||||||
|
{"a node that says not how it composes is not searched", search, []string{"m1", "m2", "m3"}, nil, 20, []blame{}},
|
||||||
|
} {
|
||||||
|
t.Run(row.name, func(t *testing.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)}
|
||||||
|
}
|
||||||
|
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 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)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
Problem string `json:"problem"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1621/AC3: over the captured catalogue and a mesh of three machines, the command's verdict equals, machine for
|
// 1621/AC3: over the captured catalogue and a mesh of three machines, the command's verdict equals, machine for
|
||||||
@@ -211,6 +314,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) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("%s: %s: command %+v, linked %+v", depth, node, got, want)
|
t.Errorf("%s: %s: command %+v, linked %+v", depth, node, got, want)
|
||||||
}
|
}
|
||||||
@@ -249,8 +355,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
|
// A run step hands the command no standard input: the request is read from the file -request names, or from the one
|
||||||
// not there is a request it cannot read.
|
// MESH_RUN_INPUT names, and a file that is not there is a request it cannot read.
|
||||||
func TestTheRequestIsReadFromAFile(t *testing.T) {
|
func TestTheRequestIsReadFromAFile(t *testing.T) {
|
||||||
file := filepath.Join(t.TempDir(), "request.json")
|
file := filepath.Join(t.TempDir(), "request.json")
|
||||||
r := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{
|
r := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{
|
||||||
@@ -265,14 +371,10 @@ func TestTheRequestIsReadFromAFile(t *testing.T) {
|
|||||||
if code, _, stderr := runJSON(t, []string{"-request", file + ".gone"}, nil); code != 1 || !strings.Contains(stderr, "cannot be read") {
|
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)
|
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
|
// A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the
|
||||||
// line of standard output (design 47 G A-167).
|
// last line of standard output (design 47 G A-167).
|
||||||
func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) {
|
r.Depth = composer.DepthCompose
|
||||||
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"}`)}}}}}
|
|
||||||
if err := os.WriteFile(file, encode(t, r), 0o600); err != nil {
|
if err := os.WriteFile(file, encode(t, r), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -282,7 +384,7 @@ func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) {
|
|||||||
t.Fatalf("exit %d: %s", code, errOut.String())
|
t.Fatalf("exit %d: %s", code, errOut.String())
|
||||||
}
|
}
|
||||||
lines := strings.Split(strings.TrimRight(out.String(), "\n"), "\n")
|
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 {
|
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())
|
t.Fatalf("last line is no verdict: %v\n%s", err, out.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,6 +18,7 @@ import (
|
|||||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
"github.com/novox/mesh-host/internal/accounts"
|
"github.com/novox/mesh-host/internal/accounts"
|
||||||
"github.com/novox/mesh-host/internal/agent"
|
"github.com/novox/mesh-host/internal/agent"
|
||||||
"github.com/novox/mesh-host/internal/apply"
|
"github.com/novox/mesh-host/internal/apply"
|
||||||
@@ -378,9 +380,9 @@ func packagesFrom(node string, session *link.Session, composer *atomic.Pointer[s
|
|||||||
// nec.AnswerBound, selfcompose candidateWithin). The answer is
|
// nec.AnswerBound, selfcompose candidateWithin). The answer is
|
||||||
// the seat's shape (nodeengine.ComposeCandidateAnswer), checked as it is encoded; a node whose shadow does not run yet
|
// the seat's shape (nodeengine.ComposeCandidateAnswer), checked as it is encoded; a node whose shadow does not run yet
|
||||||
// answers unready, which the checker takes as no answer.
|
// answers unready, which the checker takes as no answer.
|
||||||
func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow]) func(candidate string, input bool) (any, error) {
|
func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow]) func(candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) {
|
||||||
return func(candidate string, input bool) (any, error) {
|
return func(candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) {
|
||||||
ask := nodeengine.ComposeCandidateInput{Candidate: candidate, Input: input}
|
ask := nodeengine.ComposeCandidateInput{Candidate: candidate, Input: input, Call: call}
|
||||||
if _, err := nec.EncodeAsk(ask); err != nil {
|
if _, err := nec.EncodeAsk(ask); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -394,11 +396,7 @@ func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
a = s.ComposeCandidate(ctx, ask)
|
a = s.ComposeCandidate(ctx, ask)
|
||||||
}
|
}
|
||||||
raw, err := nec.EncodeAnswer(a)
|
return answerComposeCandidate(a, candidate, input, call, line)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("this node's answer to %s does not fit the seat's shape: %w", candidate, err)
|
|
||||||
}
|
|
||||||
return json.RawMessage(raw), nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,3 +423,35 @@ func entryAgainFrom(composer *atomic.Pointer[selfcompose.Composer]) func(ctx con
|
|||||||
return c.EntryAgain(ctx, fingerprint)
|
return c.EntryAgain(ctx, fingerprint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// answerComposeCandidate encodes the answer of compose-candidate. The verb is marked chunks (A-237b, A-237c): asked with input and a
|
||||||
|
// call token, the composition input goes in chunks over the link's connection, whatever its size, and the answer names them;
|
||||||
|
// asked with no token (the checker's, until G removes it, G-6 §321, A-237c) it stays inline in the answer.
|
||||||
|
func answerComposeCandidate(a nodeengine.ComposeCandidateAnswer, candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) {
|
||||||
|
var chunked []byte
|
||||||
|
if input && call != "" && a.Input != nil {
|
||||||
|
if line == nil {
|
||||||
|
return nil, errors.New("this engine has no bus connection to send the composition input on")
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(a.Input)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the composition input of %s cannot be encoded: %w", candidate, err)
|
||||||
|
}
|
||||||
|
chunked, a.Input = body, nil
|
||||||
|
a.Chunks = int64((len(body) + buscalls.SeatChunkBytes - 1) / buscalls.SeatChunkBytes)
|
||||||
|
}
|
||||||
|
raw, err := nec.EncodeAnswer(a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("this node's answer to %s does not fit the seat's shape: %w", candidate, err)
|
||||||
|
}
|
||||||
|
if chunked != nil {
|
||||||
|
send := buscalls.SeatChunks{Seat: nodeengine.Seat, Verb: nodeengine.VerbComposeCandidate, Call: call}
|
||||||
|
// The answer names the chunks first; the send runs after it and ends at a chunk the caller does not acknowledge.
|
||||||
|
go func() {
|
||||||
|
if err := send.Send(line, chunked, buscalls.SeatAckWithin, log.Printf); err != nil {
|
||||||
|
log.Printf("the send %s of the composition input of %s: %v", call, candidate, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
return json.RawMessage(raw), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -992,6 +992,11 @@ func runLink(ctx context.Context, opts options) error {
|
|||||||
// The engine's own module, first from its applied record of the build whose fingerprint is its own (design 47 G §527,
|
// The engine's own module, first from its applied record of the build whose fingerprint is its own (design 47 G §527,
|
||||||
// §634, A-149); on a first start with no such record, from its first composing.
|
// §634, A-149); on a first start with no such record, from its first composing.
|
||||||
own.Set(ownModuleApplied(appliedStoreFor(opts.state), os.Getenv(compositions.FingerprintVar)))
|
own.Set(ownModuleApplied(appliedStoreFor(opts.state), os.Getenv(compositions.FingerprintVar)))
|
||||||
|
// The live start's recovery (A-404): a first start whose composing never ends is named by its unit's environment, so it
|
||||||
|
// serves its seat (root-free); the name the assignments place on this node. Ended by the lookup from the bus after G.
|
||||||
|
if own.Get() == "" {
|
||||||
|
own.Set(os.Getenv("MESH_ENGINE_OWN_MODULE"))
|
||||||
|
}
|
||||||
queue := &link.Session{
|
queue := &link.Session{
|
||||||
Own: own,
|
Own: own,
|
||||||
Membership: membership,
|
Membership: membership,
|
||||||
@@ -1257,6 +1262,7 @@ const (
|
|||||||
// anyway. A statement the bus did not take is said at the next look. It reads; it never acts (ADR 0240
|
// anyway. A statement the bus did not take is said at the next look. It reads; it never acts (ADR 0240
|
||||||
// rule 6) — but for going on with a take act stopped at its bound (ADR 0328 §7), which runs beside it.
|
// rule 6) — but for going on with a take act stopped at its bound (ADR 0328 §7), which runs beside it.
|
||||||
func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session, say link.Announce, reapply, reconcile func(modules ...string)) {
|
func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session, say link.Announce, reapply, reconcile func(modules ...string)) {
|
||||||
|
say("the looks of what runs and of the accounts start (A-405)")
|
||||||
var missingBefore, inactiveBefore map[string]bool
|
var missingBefore, inactiveBefore map[string]bool
|
||||||
ticker := time.NewTicker(liveness.LookEvery)
|
ticker := time.NewTicker(liveness.LookEvery)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
@@ -1279,8 +1285,16 @@ func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session,
|
|||||||
case <-nudged:
|
case <-nudged:
|
||||||
owed = true
|
owed = true
|
||||||
}
|
}
|
||||||
|
first := lastAccounts.Load() == nil
|
||||||
|
began := time.Now()
|
||||||
|
if first {
|
||||||
|
say("the first look of what runs begins (A-405)")
|
||||||
|
}
|
||||||
st, changed := j.Look(ctx)
|
st, changed := j.Look(ctx)
|
||||||
owed = owed || changed
|
owed = owed || changed
|
||||||
|
if first {
|
||||||
|
say(fmt.Sprintf("the first look of what runs took %s; units and accounts next (A-405)", time.Since(began).Round(time.Millisecond)))
|
||||||
|
}
|
||||||
var unitSt *units.Statement
|
var unitSt *units.Statement
|
||||||
if u := unitJudge; u != nil {
|
if u := unitJudge; u != nil {
|
||||||
us, unitsChanged := u.Look(ctx)
|
us, unitsChanged := u.Look(ctx)
|
||||||
@@ -1294,9 +1308,15 @@ func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session,
|
|||||||
}
|
}
|
||||||
var accountSt *accounts.Statement
|
var accountSt *accounts.Statement
|
||||||
if a := accountJudge; a != nil {
|
if a := accountJudge; a != nil {
|
||||||
|
if first {
|
||||||
|
say(fmt.Sprintf("the first look of the accounts begins at %s (A-405)", time.Since(began).Round(time.Millisecond)))
|
||||||
|
}
|
||||||
as, accountsChanged := a.Look(ctx)
|
as, accountsChanged := a.Look(ctx)
|
||||||
accountSt = &as
|
accountSt = &as
|
||||||
lastAccounts.Store(&as)
|
lastAccounts.Store(&as)
|
||||||
|
if first {
|
||||||
|
say(fmt.Sprintf("the first look of the accounts ended at %s: %d accounts (A-405)", time.Since(began).Round(time.Millisecond), len(as.Accounts)))
|
||||||
|
}
|
||||||
owed = owed || accountsChanged
|
owed = owed || accountsChanged
|
||||||
if accountsChanged {
|
if accountsChanged {
|
||||||
for _, v := range as.Accounts {
|
for _, v := range as.Accounts {
|
||||||
|
|||||||
@@ -699,7 +699,7 @@ func nodeAgent(ctx context.Context, opts options, signer ed25519.PublicKey, trus
|
|||||||
apply.UseEngineModule(composer.EngineModule) // the guard of the engine's own trees fixes no name (§527)
|
apply.UseEngineModule(composer.EngineModule) // the guard of the engine's own trees fixes no name (§527)
|
||||||
env.Composed, env.SelfComposed, env.Policy, env.ComposedToday = composer, true, composer.Policy, composer.ComposedToday
|
env.Composed, env.SelfComposed, env.Policy, env.ComposedToday = composer, true, composer.Policy, composer.ComposedToday
|
||||||
env.Recovery = recoveryEnv(session, composer)
|
env.Recovery = recoveryEnv(session, composer)
|
||||||
env.WhyUnmade, env.Waiting = composer.WhyUnmade, composer.Waiting
|
env.WhyUnmade, env.Waiting, env.RunningManifest = composer.WhyUnmade, composer.Waiting, composer.RunningManifest
|
||||||
keptFetchFn := keptArtifactFetch(composer.KeptBuildOf, session.AskSeatOn, session.KeptObject)
|
keptFetchFn := keptArtifactFetch(composer.KeptBuildOf, session.AskSeatOn, session.KeptObject)
|
||||||
keptFetch.Store(&keptFetchFn)
|
keptFetch.Store(&keptFetchFn)
|
||||||
env.HoldsData = composer.HoldsData // what runs from the kept declaration says Data as its manifest does
|
env.HoldsData = composer.HoldsData // what runs from the kept declaration says Data as its manifest does
|
||||||
@@ -1200,6 +1200,8 @@ func composerEnv(session *link.Session, node string, say func(string), hooks com
|
|||||||
// And the shadow too: the catalog half read by the fingerprints its wants and runnings name, over its own calls of the seat mesh-catalog's
|
// And the shadow too: the catalog half read by the fingerprints its wants and runnings name, over its own calls of the seat mesh-catalog's
|
||||||
// verb entry on its link session (design 47 G §421): neither the indexer's nor the builder's states are read.
|
// verb entry on its link session (design 47 G §421): neither the indexer's nor the builder's states are read.
|
||||||
env.Entry = selfcompose.EntryCall(session.AskMeshSeat)
|
env.Entry = selfcompose.EntryCall(session.AskMeshSeat)
|
||||||
|
// And the registry seats' verb versions, to resolve a want that names its version to its artifacts' digests (A-430a).
|
||||||
|
env.Registry = selfcompose.EntryCall(session.AskMeshSeat)
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
"git.novox.be/novox/mesh-sdk/go/buscompose"
|
"git.novox.be/novox/mesh-sdk/go/buscompose"
|
||||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||||
@@ -702,7 +703,10 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
path := filepath.Join(b.dir, "web.conf")
|
path := filepath.Join(b.dir, "web.conf")
|
||||||
man := `{"module":"web","version":"2","config":{"greeting":{"type":"string","description":"what the file says","default":"hello"}},` +
|
// A description past what one answer carries (900 KiB, and under the bus's 1 MiB for one value), so the composition input this
|
||||||
|
// node sends is over the inline bound (A-237b, A-237c).
|
||||||
|
pad := strings.Repeat("x", 930_000)
|
||||||
|
man := `{"module":"web","version":"2","config":{"greeting":{"type":"string","description":"what the file says ` + pad + `","default":"hello"}},` +
|
||||||
`"resources":[{"id":"conf","type":"file","path":"` + path + `","mode":"0640","content":"greeting=${config:greeting}\n"},` +
|
`"resources":[{"id":"conf","type":"file","path":"` + path + `","mode":"0640","content":"greeting=${config:greeting}\n"},` +
|
||||||
`{"id":"tools","type":"package","package":"web-tools"}]}`
|
`{"id":"tools","type":"package","package":"web-tools"}]}`
|
||||||
digest := meshcatalogclient.ManifestDigest([]byte(man))
|
digest := meshcatalogclient.ManifestDigest([]byte(man))
|
||||||
@@ -728,7 +732,43 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
before, _ := b.composed.Status()
|
before, _ := b.composed.Status()
|
||||||
got, err := composeCandidateFrom(itNode, &shadowNow)(key, false)
|
// A-237c: asked with input and no call token (the checker's, until G removes it, G-6 §321) an input past what one answer carries
|
||||||
|
// is refused; asked with a token it is sent in chunks through the engine's call, whatever its size (A-237b).
|
||||||
|
if over, err := composeCandidateFrom(itNode, &shadowNow)(key, true, "", nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if a, err := nec.DecodeAnswer(over.(json.RawMessage)); err != nil || a.Verdict != nec.Refused || !strings.Contains(a.Refused, "an answer on the bus carries") || a.Input != nil {
|
||||||
|
t.Errorf("an input over the inline bound asked with no token answered %+v (%v)", a, err)
|
||||||
|
}
|
||||||
|
line := &ackingLine{chunks: map[string][]byte{}, done: make(chan struct{})}
|
||||||
|
const call = "0123456789abcdef0123456789abcdef"
|
||||||
|
acts := &link.HandActs{Node: itNode, ComposeCandidate: composeCandidateFrom(itNode, &shadowNow)}
|
||||||
|
chunked, err := acts.Call(link.EngineCall{Verb: link.ActComposeCandidate, Line: line,
|
||||||
|
Args: map[string]any{"candidate": key, "input": true, "call": call}})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ca, err := nec.DecodeAnswer(chunked.(json.RawMessage))
|
||||||
|
if err != nil || ca.Verdict != nec.Composed || ca.Chunks < 2 || ca.Input != nil {
|
||||||
|
t.Fatalf("the input asked with a token answered %+v (%v), want the chunks and no inline input", ca, err)
|
||||||
|
}
|
||||||
|
line.want = int(ca.Chunks)
|
||||||
|
select {
|
||||||
|
case <-line.done:
|
||||||
|
case <-time.After(10 * time.Second):
|
||||||
|
t.Fatalf("%d of %d chunks were sent", line.sent(), ca.Chunks)
|
||||||
|
}
|
||||||
|
var file []byte
|
||||||
|
for n := int64(1); n <= ca.Chunks; n++ {
|
||||||
|
var c buscalls.SeatChunk
|
||||||
|
if err := json.Unmarshal(line.chunks[buscalls.SeatChunks{Seat: nodeengine.Seat, Verb: nodeengine.VerbComposeCandidate, Call: call}.Chunk(n)], &c); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
file = append(file, c.Data...)
|
||||||
|
}
|
||||||
|
if len(file) <= 900<<10 || !json.Valid(file) {
|
||||||
|
t.Errorf("the chunks held %d bytes, want a JSON input over 900 KiB", len(file))
|
||||||
|
}
|
||||||
|
got, err := composeCandidateFrom(itNode, &shadowNow)(key, false, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1237,3 +1277,35 @@ func TestNatsTheFirstReadOfTheSeatListEndsTheNodesWait(t *testing.T) {
|
|||||||
t.Error("the list was read by the reader of a run begun since, not by the one that met no responders")
|
t.Error("the list was read by the reader of a run begun since, not by the one that met no responders")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ackingLine is a bus connection that acknowledges every chunk published on it, as a caller does, and keeps the chunks.
|
||||||
|
type ackingLine struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
onAck nats.MsgHandler
|
||||||
|
chunks map[string][]byte
|
||||||
|
done chan struct{}
|
||||||
|
want int
|
||||||
|
closed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ackingLine) Subscribe(_ string, cb nats.MsgHandler) (*nats.Subscription, error) {
|
||||||
|
l.mu.Lock()
|
||||||
|
l.onAck = cb
|
||||||
|
l.mu.Unlock()
|
||||||
|
return &nats.Subscription{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ackingLine) sent() int { l.mu.Lock(); defer l.mu.Unlock(); return len(l.chunks) }
|
||||||
|
|
||||||
|
func (l *ackingLine) Publish(subject string, data []byte) error {
|
||||||
|
l.mu.Lock()
|
||||||
|
l.chunks[subject] = data
|
||||||
|
cb := l.onAck
|
||||||
|
if l.want > 0 && len(l.chunks) >= l.want && !l.closed {
|
||||||
|
l.closed = true
|
||||||
|
close(l.done)
|
||||||
|
}
|
||||||
|
l.mu.Unlock()
|
||||||
|
go cb(&nats.Msg{Subject: strings.Replace(subject, ".chunk.", ".ack.", 1)})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
+24
-6
@@ -132,6 +132,10 @@ type Env struct {
|
|||||||
// a fingerprint it holds none of, so a composer that believes it handed it hands it again. Nil tells nobody.
|
// a fingerprint it holds none of, so a composer that believes it handed it hands it again. Nil tells nobody.
|
||||||
WhyUnmade func(module string) string
|
WhyUnmade func(module string) string
|
||||||
Waiting func(module, fp string)
|
Waiting func(module, fp string)
|
||||||
|
// RunningManifest is the one place that answers the manifest of the build a module runs here (design 47 G A-484): the source
|
||||||
|
// that answered with its build, or, where none did, the words naming the three it tried. The tool composition says it. Nil
|
||||||
|
// says nothing.
|
||||||
|
RunningManifest func(module string) (source, fp, words string)
|
||||||
// Apply applies one module's composition (scope NodeModule for the node's own), given the compositions the node's
|
// Apply applies one module's composition (scope NodeModule for the node's own), given the compositions the node's
|
||||||
// other modules run so a path, unit or group they hold is not removed or taken. It is called with one module at a
|
// other modules run so a path, unit or group they hold is not removed or taken. It is called with one module at a
|
||||||
// time.
|
// time.
|
||||||
@@ -660,16 +664,25 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
|
|||||||
a.notComposed[module] = mark
|
a.notComposed[module] = mark
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
phase, detail := string(nodeengineclient.PhaseFailed), NotComposedDetail+why
|
phase, detail := string(nodeengineclient.PhaseFailed), NotComposedDetail+why
|
||||||
|
var wait *nodeengine.Wait
|
||||||
if heldForEntry(why) {
|
if heldForEntry(why) {
|
||||||
// The entry its want names is not held: the phase held, its detail opening entry-asked: or entry-missing: and
|
// The entry its want names is not held: the phase held, its detail opening entry-asked: or entry-missing: and
|
||||||
// naming the fingerprint (design 47 G section 421).
|
// naming the fingerprint (design 47 G section 421).
|
||||||
phase, detail = string(nodeengineclient.PhaseHeld), why
|
phase, detail = string(nodeengineclient.PhaseHeld), why
|
||||||
|
// The hold says what it waits on, as every hold but a failed backup does (design 47 G A-453, section 541).
|
||||||
|
wait = a.composeWait(strings.TrimSuffix(heldReason(why), ":"), why)
|
||||||
}
|
}
|
||||||
a.writeHave(ctx, Have{Module: module, FP: mark.prior.FP, Composed: mark.prior.Composed, Sealed: mark.prior.Sealed,
|
a.writeHave(ctx, Have{Module: module, FP: mark.prior.FP, Composed: mark.prior.Composed, Sealed: mark.prior.Sealed,
|
||||||
Phase: phase, Detail: detail})
|
Phase: phase, Detail: detail, Wait: wait})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// composeWait is the wait a hold of the composition carries in its have: step compose, with its reason and its words (design 47 G
|
||||||
|
// A-453, section 541). Only a hold for a failed backup carries none.
|
||||||
|
func (a *Agent) composeWait(reason, words string) *nodeengine.Wait {
|
||||||
|
return &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: reason, Since: a.now(), Words: words}
|
||||||
|
}
|
||||||
|
|
||||||
// writeHave writes a module's have (the node's own key for NodeModule); on a node composing its own, with the sealed
|
// writeHave writes a module's have (the node's own key for NodeModule); on a node composing its own, with the sealed
|
||||||
// values of the composition it names when the caller gave none (Have.Sealed): those of the composition the agent applied or holds at that digest, else
|
// values of the composition it names when the caller gave none (Have.Sealed): those of the composition the agent applied or holds at that digest, else
|
||||||
// those the module's last have said at that digest.
|
// those the module's last have said at that digest.
|
||||||
@@ -1530,7 +1543,7 @@ func (a *Agent) baseline(ctx context.Context, module string, w wantNow, comp com
|
|||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if h.Phase == string(nodeengineclient.PhaseHeld) {
|
if h.Phase == string(nodeengineclient.PhaseHeld) && !judgedAgain(h) {
|
||||||
// Held for a failed backup, and the operator's answer is still to come: the hold is kept, nothing is
|
// Held for a failed backup, and the operator's answer is still to come: the hold is kept, nothing is
|
||||||
// backed up again or applied, and the next revision of the want is the answer (ADR 0568 §4). Said, so
|
// backed up again or applied, and the next revision of the want is the answer (ADR 0568 §4). Said, so
|
||||||
// why it holds is read from the journal and not guessed (issue 1585: this branch was silent).
|
// why it holds is read from the journal and not guessed (issue 1585: this branch was silent).
|
||||||
@@ -1622,7 +1635,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
|
|||||||
|
|
||||||
// A want with parts is applied only when they and the digests its composition fetches agree (design 47 G §524): the
|
// A want with parts is applied only when they and the digests its composition fetches agree (design 47 G §524): the
|
||||||
// module keeps running what it has, and the have says which digest differs.
|
// module keeps running what it has, and the have says which digest differs.
|
||||||
if words := partsDifference(w.Want.Parts, comp.C.Resources); words != "" {
|
if words := partsDifference(w.Want.Parts, comp.C.Resources, comp.C.Templates); words != "" {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
prev, runs := a.running[module]
|
prev, runs := a.running[module]
|
||||||
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
|
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
|
||||||
@@ -1634,7 +1647,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
|
|||||||
}
|
}
|
||||||
a.env.Say(fmt.Sprintf("%s is held: %s", module, words))
|
a.env.Say(fmt.Sprintf("%s is held: %s", module, words))
|
||||||
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
|
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
|
||||||
Detail: words})
|
Detail: words, Wait: a.composeWait(strings.TrimSuffix(PartsDiffer, ":"), words)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1671,9 +1684,14 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
|
|||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
|
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
// It keeps running what it has: the have says what it holds and why it waits.
|
// It keeps running what it has: the have says what it holds and why it waits. A backup interrupted is no failure of it, so
|
||||||
|
// its hold waits as kept.go's do, with the words as the reason; only a failed backup carries no wait (A-453).
|
||||||
|
var wait *nodeengine.Wait
|
||||||
|
if words == BackupInterrupted {
|
||||||
|
wait = a.composeWait(words, words)
|
||||||
|
}
|
||||||
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
|
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
|
||||||
Detail: words})
|
Detail: words, Wait: wait})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,15 +357,53 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) {
|
|||||||
if got := len(b.appliedList()) - before; (got == 1) != row.applies {
|
if got := len(b.appliedList()) - before; (got == 1) != row.applies {
|
||||||
t.Fatalf("parts %q: applied %d times, want applies=%v", row.name, got, row.applies)
|
t.Fatalf("parts %q: applied %d times, want applies=%v", row.name, got, row.applies)
|
||||||
}
|
}
|
||||||
if h := b.haves.last("web"); !row.applies && (h.Phase != string(nodeengineclient.PhaseHeld) || h.Detail != row.detail) {
|
if h := b.haves.last("web"); !row.applies && (h.Phase != string(nodeengineclient.PhaseHeld) || h.Detail != row.detail ||
|
||||||
t.Fatalf("parts %q: the have is %s %q, want held %q", row.name, h.Phase, h.Detail, row.detail)
|
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != "parts-differ" || h.Wait.Words != row.detail) {
|
||||||
|
t.Fatalf("parts %q: the have is %s %q wait %+v, want held %q waiting on parts-differ (A-453)", row.name, h.Phase, h.Detail, h.Wait, row.detail)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// A container's digest is the one after its image's @.
|
// A container's digest is the one after its image's @.
|
||||||
container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","module":"web"}`)
|
container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","image-seat":"mesh-artifact-store","image-holder":"n1","module":"web"}`)
|
||||||
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}); got != "" {
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, nil); got != "" {
|
||||||
t.Fatalf("a container whose digest is in the parts differs: %q", got)
|
t.Fatalf("a container whose digest is in the parts differs: %q", got)
|
||||||
}
|
}
|
||||||
|
// A-454: an image the manifest pins from outside, by its digest, is no part of the want's parts, and a mesh-built one still is.
|
||||||
|
upstream := json.RawMessage(`{"id":"web.u","type":"container","name":"web-u","image":"registry@` + d2 + `","module":"web"}`)
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}, nil); got != "" {
|
||||||
|
t.Fatalf("an upstream image pinned by its digest is a part: %q", got)
|
||||||
|
}
|
||||||
|
// And neither is the registry seat's copy of an upstream image, though it is routed through the seat.
|
||||||
|
mirrored := json.RawMessage(`{"id":"web.m","type":"container","name":"web-m","image":"store:5000/upstream/docker.io/library/registry@` + d1 + `","image-seat":"container-image-registry","image-holder":"n1","module":"web"}`)
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}, nil); got != "" {
|
||||||
|
t.Fatalf("an upstream copy served through the registry seat is a part: %q", got)
|
||||||
|
}
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) {
|
||||||
|
t.Fatalf("with only an upstream image the mesh-built one is not missing, or the upstream one is named: %q", got)
|
||||||
|
}
|
||||||
|
// A-454a: a mesh-built image whose seat holder is not on record carries no image-seat; its digest is in the parts, so it is fetched.
|
||||||
|
noSeat := json.RawMessage(`{"id":"web.n","type":"container","name":"web-n","image":"store/web@` + d3 + `","module":"web"}`)
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}, nil); got != "" {
|
||||||
|
t.Fatalf("a mesh-built image with no image-seat, named by the parts, is not fetched: %q", got)
|
||||||
|
}
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}, nil); got != "" {
|
||||||
|
t.Fatalf("an upstream image beside it is a part: %q", got)
|
||||||
|
}
|
||||||
|
// A-481: a templates archive the composition was rendered from is fetched, one the want's parts do not name is a part
|
||||||
|
// the composition lacks, and the want's digest nothing read stays not fetched.
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, []string{d1}); got != "" {
|
||||||
|
t.Fatalf("a templates archive named by the parts and rendered from is fetched: %q", got)
|
||||||
|
}
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d1) {
|
||||||
|
t.Fatalf("a templates archive nothing read stays not fetched: %q", got)
|
||||||
|
}
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, []string{d1}); !strings.Contains(got, "fetched and not in the want's parts: "+d1) {
|
||||||
|
t.Fatalf("a templates archive outside the parts differs: %q", got)
|
||||||
|
}
|
||||||
|
// A-432: a runtime of its own runs the tool runner's program, which the module's parts do not name.
|
||||||
|
ownRuntime := json.RawMessage(`{"id":"web.own-runtime","type":"process","name":"web-runtime","source":"store/node-tools","digest":"` + d1 + `","run":["./node-tools"],"module":"web"}`)
|
||||||
|
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}, nil); got != "" {
|
||||||
|
t.Fatalf("a runtime of its own differs from the module's parts: %q", got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// R6-A AC2: given a kept declaration and wants and compositions equal to it, when the agent starts, nothing is applied
|
// R6-A AC2: given a kept declaration and wants and compositions equal to it, when the agent starts, nothing is applied
|
||||||
@@ -749,7 +787,8 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
|
|||||||
})
|
})
|
||||||
eventually(t, "the have does not say held", func() bool {
|
eventually(t, "the have does not say held", func() bool {
|
||||||
h := b.haves.last("db")
|
h := b.haves.last("db")
|
||||||
return h.Phase == string(nodeengineclient.PhaseHeld) && strings.Contains(h.Detail, "repository is locked") && h.FP == fp1
|
// A hold for a failed backup carries no wait: the operator is asked about it (A-453).
|
||||||
|
return h.Phase == string(nodeengineclient.PhaseHeld) && strings.Contains(h.Detail, "repository is locked") && h.FP == fp1 && h.Wait == nil
|
||||||
})
|
})
|
||||||
if got := b.appliedList(); len(got) != 0 {
|
if got := b.appliedList(); len(got) != 0 {
|
||||||
t.Fatalf("something was applied behind a failed backup: %v", got)
|
t.Fatalf("something was applied behind a failed backup: %v", got)
|
||||||
@@ -808,8 +847,9 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
|
|||||||
stopI := ib.run()
|
stopI := ib.run()
|
||||||
<-began
|
<-began
|
||||||
stopI()
|
stopI()
|
||||||
if h := ib.haves.last("db"); h.Phase != string(nodeengineclient.PhaseHeld) || h.FP != fp1 || h.Composed != dig1 || h.Detail != BackupInterrupted {
|
if h := ib.haves.last("db"); h.Phase != string(nodeengineclient.PhaseHeld) || h.FP != fp1 || h.Composed != dig1 || h.Detail != BackupInterrupted ||
|
||||||
t.Errorf("held after an interrupted backup: %+v", h)
|
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != BackupInterrupted {
|
||||||
|
t.Errorf("held after an interrupted backup, with its wait (A-453): %+v", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// At a start: a backup the node agent's own stop interrupted (postgres on novox, 2026-10-31) is no failure, so it is
|
// At a start: a backup the node agent's own stop interrupted (postgres on novox, 2026-10-31) is no failure, so it is
|
||||||
@@ -819,16 +859,28 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
|
|||||||
detail, backup string
|
detail, backup string
|
||||||
backups, applied int
|
backups, applied int
|
||||||
phase string
|
phase string
|
||||||
namesNothing bool // the have names no fp and no composition
|
namesNothing bool // the have names no fp and no composition
|
||||||
|
reason string // the reason of the wait the have carries; empty: it carries none
|
||||||
}{
|
}{
|
||||||
{BackupInterrupted, meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false},
|
{BackupInterrupted, meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false, ""},
|
||||||
// novox's postgres: its held have, written before mesh-host #189, names nothing it runs.
|
// novox's postgres: its held have, written before mesh-host #189, names nothing it runs.
|
||||||
{BackupInterrupted, "", 1, 1, nodeengineclient.PhaseRunning, true},
|
{BackupInterrupted, "", 1, 1, nodeengineclient.PhaseRunning, true, ""},
|
||||||
// A backup that failed, and the want carries the operator's answer, written before this start (nats on novox,
|
// A backup that failed, and the want carries the operator's answer, written before this start (nats on novox,
|
||||||
// 2026-11-04, issue 1585): again backs it up and applies, skip applies without one; no answer keeps the hold.
|
// 2026-11-04, issue 1585): again backs it up and applies, skip applies without one; no answer keeps the hold.
|
||||||
{"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false},
|
{"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false, ""},
|
||||||
{"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, 1, nodeengineclient.PhaseRunning, false},
|
{"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, 1, nodeengineclient.PhaseRunning, false, ""},
|
||||||
{"restic: the repository is locked", "", 0, 0, nodeengineclient.PhaseHeld, false},
|
{"restic: the repository is locked", "", 0, 0, nodeengineclient.PhaseHeld, false, ""},
|
||||||
|
// A hold the node-engine judges again (novox's indexer, 2026-11-16): its parts differed or its entry was not
|
||||||
|
// held, which no answer of the operator's releases; at a start it is judged again, here backed up and applied.
|
||||||
|
{PartsDiffer + " fetched and not in the want's parts: sha256:a03131c6", "", 1, 1, nodeengineclient.PhaseRunning, false, "parts-differ"},
|
||||||
|
{EntryMissing + " the catalog half holds no entry of the build", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-missing"},
|
||||||
|
// g14's feh, 2026-11-18: the kept step's hold opens "whether ..." and says its reason in its wait; the words decide nothing.
|
||||||
|
{"whether feh's kept data changes form is not known", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-missing"},
|
||||||
|
{EntryAsked + " the entry is asked", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-asked"},
|
||||||
|
// Opening words alone are no reason: a failed backup's detail that opens with them waits for the answer.
|
||||||
|
{PartsDiffer + " as the words of a failed backup", "", 0, 0, nodeengineclient.PhaseHeld, false, ""},
|
||||||
|
// A restore point not taken waits for the answer, its reason being its words.
|
||||||
|
{"the restore point of db's data was not taken", "", 0, 0, nodeengineclient.PhaseHeld, false, "the restore point of db's data was not taken"},
|
||||||
} {
|
} {
|
||||||
r := newBed(t)
|
r := newBed(t)
|
||||||
r.comps.before(ck1, craw1)
|
r.comps.before(ck1, craw1)
|
||||||
@@ -836,6 +888,9 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
|
|||||||
wk, wraw := wantFor(t, "db", fp2, dig2, row.backup)
|
wk, wraw := wantFor(t, "db", fp2, dig2, row.backup)
|
||||||
r.wants.before(wk, wraw)
|
r.wants.before(wk, wraw)
|
||||||
held := Have{Module: "db", FP: fp1, Composed: dig1, Phase: string(nodeengineclient.PhaseHeld), Detail: row.detail}
|
held := Have{Module: "db", FP: fp1, Composed: dig1, Phase: string(nodeengineclient.PhaseHeld), Detail: row.detail}
|
||||||
|
if row.reason != "" {
|
||||||
|
held.Wait = &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: row.reason, Words: row.detail}
|
||||||
|
}
|
||||||
if row.namesNothing {
|
if row.namesNothing {
|
||||||
held.FP, held.Composed = "", ""
|
held.FP, held.Composed = "", ""
|
||||||
}
|
}
|
||||||
@@ -1663,6 +1718,16 @@ func TestTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes(
|
|||||||
if _, err := b.ag.Composition(context.Background(), "ghost", "", false); err == nil || !strings.Contains(err.Error(), "waits for the composer: no manifest in the composer's picture") {
|
if _, err := b.ag.Composition(context.Background(), "ghost", "", false); err == nil || !strings.Contains(err.Error(), "waits for the composer: no manifest in the composer's picture") {
|
||||||
t.Errorf("the composition read of ghost says %v, want why the composer made none", err)
|
t.Errorf("the composition read of ghost says %v, want why the composer made none", err)
|
||||||
}
|
}
|
||||||
|
// Where the one place says what runs of it (A-484), the tool answers it though the want's build has no composition.
|
||||||
|
b.ag.env.RunningManifest = func(string) (string, string, string) {
|
||||||
|
_ = b.ag.Running() // the one place reads what the agent runs: the tool must not hold the agent's lock while it does
|
||||||
|
return "the module's trunk manifest in the catalog", "src2:t", "the manifest of the build ghost runs here is read from the module's trunk manifest in the catalog"
|
||||||
|
}
|
||||||
|
if view, err := b.ag.Composition(context.Background(), "ghost", "", false); err != nil || view.RunsManifest == nil ||
|
||||||
|
view.RunsManifest.Source != "the module's trunk manifest in the catalog" || !strings.Contains(view.Composition.Refused, "waits for the composer") {
|
||||||
|
t.Errorf("the composition read of ghost says %+v, %v, want what runs of it and why the composer made none", view.RunsManifest, err)
|
||||||
|
}
|
||||||
|
b.ag.env.RunningManifest = nil
|
||||||
toldMu.Lock()
|
toldMu.Lock()
|
||||||
if n := slices.Index(told, "ghost@"+fpOf("9")); saidCount() != 1 || n < 0 || slices.Contains(told[n+1:], "ghost@"+fpOf("9")) {
|
if n := slices.Index(told, "ghost@"+fpOf("9")); saidCount() != 1 || n < 0 || slices.Contains(told[n+1:], "ghost@"+fpOf("9")) {
|
||||||
t.Errorf("said %d times, told %q; want once and ghost told once", saidCount(), told)
|
t.Errorf("said %d times, told %q; want once and ghost told once", saidCount(), told)
|
||||||
@@ -1775,9 +1840,14 @@ func TestTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes(
|
|||||||
}
|
}
|
||||||
// Design 47 G §421: a module whose want's entry the catalog half holds none of is the phase held, its detail opening
|
// Design 47 G §421: a module whose want's entry the catalog half holds none of is the phase held, its detail opening
|
||||||
// entry-missing: and naming the fingerprint; composed again, its have is what it runs.
|
// entry-missing: and naming the fingerprint; composed again, its have is what it runs.
|
||||||
b.ag.NotComposedEach(context.Background(), "", map[string]string{"idle": EntryMissing + " the catalog half holds no entry of the build src2:x"})
|
// A-453: the hold carries its wait, step compose with the reason, as every hold but a failed backup does.
|
||||||
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseHeld) || h.Composed != idleDig || h.Detail != EntryMissing+" the catalog half holds no entry of the build src2:x" {
|
for _, row := range []struct{ opening, reason string }{{EntryMissing, "entry-missing"}, {EntryAsked, "entry-asked"}} {
|
||||||
t.Errorf("idle's have while its entry is missing: %+v", h)
|
words := row.opening + " the catalog half holds no entry of the build src2:x"
|
||||||
|
b.ag.NotComposedEach(context.Background(), "", map[string]string{"idle": words})
|
||||||
|
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseHeld) || h.Composed != idleDig || h.Detail != words ||
|
||||||
|
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != row.reason || h.Wait.Words != words || h.Wait.Since.IsZero() {
|
||||||
|
t.Errorf("idle's have while its entry is %s: %+v", row.reason, h)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.ag.NotComposedEach(context.Background(), "", nil)
|
b.ag.NotComposedEach(context.Background(), "", nil)
|
||||||
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseRunning) || h.Composed != idleDig {
|
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseRunning) || h.Composed != idleDig {
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ type CompositionView struct {
|
|||||||
Revisions []RevisionView `json:"revisions,omitempty"`
|
Revisions []RevisionView `json:"revisions,omitempty"`
|
||||||
// Runs is what runs of the module, and where that is known from; nil when nothing of it runs.
|
// Runs is what runs of the module, and where that is known from; nil when nothing of it runs.
|
||||||
Runs *RunsView `json:"runs,omitempty"`
|
Runs *RunsView `json:"runs,omitempty"`
|
||||||
|
// RunsManifest is the manifest of the build that runs of the module, as the one place reads it (design 47 G A-484): which
|
||||||
|
// source answered, or the words naming the three it tried. Said also where the want's build has no composition.
|
||||||
|
RunsManifest *RunsManifestView `json:"runs-manifest,omitempty"`
|
||||||
// Judged is the move from what runs to the composition read, as the agent judges it before an apply.
|
// Judged is the move from what runs to the composition read, as the agent judges it before an apply.
|
||||||
Judged JudgedView `json:"judged"`
|
Judged JudgedView `json:"judged"`
|
||||||
// Diff is every resource that differs from what runs, when asked.
|
// Diff is every resource that differs from what runs, when asked.
|
||||||
@@ -136,6 +139,14 @@ type RunsView struct {
|
|||||||
Resources int `json:"resources"`
|
Resources int `json:"resources"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunsManifestView is what the one place answers of the build a module runs here.
|
||||||
|
type RunsManifestView struct {
|
||||||
|
// Source is the source that answered; empty when none did.
|
||||||
|
Source string `json:"source,omitempty"`
|
||||||
|
FP string `json:"fp,omitempty"`
|
||||||
|
Words string `json:"words"`
|
||||||
|
}
|
||||||
|
|
||||||
// JudgedView is a move's judgement.
|
// JudgedView is a move's judgement.
|
||||||
type JudgedView struct {
|
type JudgedView struct {
|
||||||
Judgement string `json:"judgement"`
|
Judgement string `json:"judgement"`
|
||||||
@@ -190,6 +201,11 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
|
// Read outside the lock: the one place reads what the agent runs (Agent.Running takes it), and nothing it does is asked of the bus.
|
||||||
|
if a.env.RunningManifest != nil && module != NodeModule {
|
||||||
|
src, rfp, words := a.env.RunningManifest(module)
|
||||||
|
view.RunsManifest = &RunsManifestView{Source: src, FP: rfp, Words: words}
|
||||||
|
}
|
||||||
if module != NodeModule && fp == "" {
|
if module != NodeModule && fp == "" {
|
||||||
return view, fmt.Errorf("%s has no want and no have on %s, so no build of it is composed here", module, a.env.Node)
|
return view, fmt.Errorf("%s has no want and no have on %s, so no build of it is composed here", module, a.env.Node)
|
||||||
}
|
}
|
||||||
@@ -220,12 +236,19 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo
|
|||||||
case digest != "" && read == nil:
|
case digest != "" && read == nil:
|
||||||
return view, fmt.Errorf("no revision of %s the bucket keeps has the digest %s; revisions lists those it keeps", key, digest)
|
return view, fmt.Errorf("no revision of %s the bucket keeps has the digest %s; revisions lists those it keeps", key, digest)
|
||||||
case read == nil && !haveLatest:
|
case read == nil && !haveLatest:
|
||||||
|
// What runs of the module is still said, through the one place (A-484): the composition read is the want's build, and a
|
||||||
|
// module held at another build has none of it.
|
||||||
|
words := fmt.Sprintf("the bucket holds no composition of %s at %s", module, fp)
|
||||||
if a.env.SelfComposed && a.env.WhyUnmade != nil && module != NodeModule {
|
if a.env.SelfComposed && a.env.WhyUnmade != nil && module != NodeModule {
|
||||||
if why := a.env.WhyUnmade(module); why != "" {
|
if why := a.env.WhyUnmade(module); why != "" {
|
||||||
return view, fmt.Errorf("the bucket holds no composition of %s at %s; the agent waits for the composer: %s", module, fp, why)
|
words = fmt.Sprintf("the bucket holds no composition of %s at %s; the agent waits for the composer: %s", module, fp, why)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return view, fmt.Errorf("the bucket holds no composition of %s at %s", module, fp)
|
if view.RunsManifest == nil {
|
||||||
|
return view, errors.New(words)
|
||||||
|
}
|
||||||
|
view.Composition = RevisionView{Key: key, Refused: words}
|
||||||
|
return view, nil
|
||||||
case read == nil:
|
case read == nil:
|
||||||
read = &latest
|
read = &latest
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,9 +239,9 @@ func (a *Agent) keptStep(ctx context.Context, module string, w wantNow, comp com
|
|||||||
since := r.now()
|
since := r.now()
|
||||||
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld), Detail: words,
|
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld), Detail: words,
|
||||||
Wait: &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: "entry-missing", Since: since, Words: words}})
|
Wait: &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: "entry-missing", Since: since, Words: words}})
|
||||||
if a.env.Waiting != nil {
|
// The composition of the want is held: the wait is for an entry, not for a composition, so the composer is not told it
|
||||||
a.env.Waiting(module, fp)
|
// is waited for (that handed the same composition again every pass, and the move failed the same way again); it
|
||||||
}
|
// hands the composition again when the entry answers (Composer.entryChanged).
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
take, restore := keptMoves(changes, prev.Fp, fp)
|
take, restore := keptMoves(changes, prev.Fp, fp)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type recoveryFake struct {
|
|||||||
catchUp []meshrecovery.CatchUp
|
catchUp []meshrecovery.CatchUp
|
||||||
expired chan struct{}
|
expired chan struct{}
|
||||||
unknown error // FormChanges answers it
|
unknown error // FormChanges answers it
|
||||||
|
waited int // times the agent told the composer it waits for a composition
|
||||||
}
|
}
|
||||||
|
|
||||||
type fakeAnswer struct {
|
type fakeAnswer struct {
|
||||||
@@ -110,6 +111,7 @@ func moveDB(t *testing.T, f *recoveryFake, ranFrom, to string, settle func(b *be
|
|||||||
}
|
}
|
||||||
f.events, f.expired = make(chan Ending, 16), make(chan struct{})
|
f.events, f.expired = make(chan Ending, 16), make(chan struct{})
|
||||||
b.env.Recovery = f.env()
|
b.env.Recovery = f.env()
|
||||||
|
b.env.Waiting = func(string, string) { f.mu.Lock(); f.waited++; f.mu.Unlock() }
|
||||||
b.env.Stop = func(context.Context, string) Result {
|
b.env.Stop = func(context.Context, string) Result {
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
f.calls = append(f.calls, "stop")
|
f.calls = append(f.calls, "stop")
|
||||||
@@ -289,6 +291,11 @@ func testAMoveAcrossAFormChange(t *testing.T) {
|
|||||||
t.Run("a form change not known moves nothing and waits for the entries (A-113)", func(t *testing.T) {
|
t.Run("a form change not known moves nothing and waits for the entries (A-113)", func(t *testing.T) {
|
||||||
f := &recoveryFake{unknown: fmt.Errorf("the entry is asked")}
|
f := &recoveryFake{unknown: fmt.Errorf("the entry is asked")}
|
||||||
b := moveDB(t, f, "a", "b", heldHave)
|
b := moveDB(t, f, "a", "b", heldHave)
|
||||||
|
f.mu.Lock()
|
||||||
|
if f.waited != 0 {
|
||||||
|
t.Errorf("the composer was told the agent waits for a composition %d times; it waits for an entry and holds the composition", f.waited)
|
||||||
|
}
|
||||||
|
f.mu.Unlock()
|
||||||
if h := b.haves.last("db"); h.FP != fp("a") || !contains(h.Detail, "is not known") || h.Wait == nil || h.Wait.Reason != "entry-missing" {
|
if h := b.haves.last("db"); h.FP != fp("a") || !contains(h.Detail, "is not known") || h.Wait == nil || h.Wait.Reason != "entry-missing" {
|
||||||
t.Fatalf("the have %+v", h)
|
t.Fatalf("the have %+v", h)
|
||||||
}
|
}
|
||||||
|
|||||||
+63
-5
@@ -6,6 +6,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,21 +23,65 @@ const (
|
|||||||
EntryMissing = "entry-missing:"
|
EntryMissing = "entry-missing:"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// judgedAgain says a held have is a hold the node-engine judges again at a start, not one that waits for the operator's answer:
|
||||||
|
// its wait's reason (the structured field the have carries) is that its want's parts differ from its composition (§524) or its
|
||||||
|
// entry is not held (§421), whatever words its detail opens with. Only a failed backup or restore point waits for an answer (ADR
|
||||||
|
// 0568 §4); novox, 2026-11-16: the indexer held "parts-differ" was kept at a start as "held for a failed backup"; g14, 2026-11-18:
|
||||||
|
// feh held "whether ..." with the reason entry-missing was kept the same way.
|
||||||
|
func judgedAgain(h Have) bool {
|
||||||
|
if h.Wait == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch h.Wait.Reason {
|
||||||
|
case strings.TrimSuffix(PartsDiffer, ":"), strings.TrimSuffix(EntryAsked, ":"), strings.TrimSuffix(EntryMissing, ":"):
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// heldReason is the opening of a detail held for an entry: EntryAsked or EntryMissing.
|
||||||
|
func heldReason(why string) string {
|
||||||
|
if strings.HasPrefix(why, EntryAsked) {
|
||||||
|
return EntryAsked
|
||||||
|
}
|
||||||
|
return EntryMissing
|
||||||
|
}
|
||||||
|
|
||||||
// heldForEntry says whether why is a hold for the entry a want names.
|
// heldForEntry says whether why is a hold for the entry a want names.
|
||||||
func heldForEntry(why string) bool {
|
func heldForEntry(why string) bool {
|
||||||
return strings.HasPrefix(why, EntryAsked) || strings.HasPrefix(why, EntryMissing)
|
return strings.HasPrefix(why, EntryAsked) || strings.HasPrefix(why, EntryMissing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// upstreamCopy is whether a routed image is the registry seat's copy of an upstream image, `<address>/upstream/<host>/<image>@<digest>`:
|
||||||
|
// the mesh mirrors it, but it built nothing, so it is no part of a want (design 47 G A-454).
|
||||||
|
func upstreamCopy(image string) bool {
|
||||||
|
_, path, ok := strings.Cut(image, "/")
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, _, upstream := reference.InUpstream(path)
|
||||||
|
return upstream
|
||||||
|
}
|
||||||
|
|
||||||
// partsDifference checks a want's `parts` against the digests of the archive, process and container resources of the
|
// partsDifference checks a want's `parts` against the digests of the archive, process and container resources of the
|
||||||
// composition, which are the digests the apply fetches and checks (design 47 G section 524). A want with no `parts` (an
|
// composition, which are the digests the apply fetches and checks (design 47 G section 524). A want with no `parts` (an
|
||||||
// assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With
|
// assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With
|
||||||
// `parts`, the want is applied only when the digest of every resource fetched is among the values of `parts` and every
|
// `parts`, the want is applied only when the digest of every resource fetched is among the values of `parts` and every
|
||||||
// value of `parts` is the digest of a resource fetched; otherwise it returns the detail naming each digest.
|
// value of `parts` is the digest of a resource fetched; otherwise it returns the detail naming each digest.
|
||||||
func partsDifference(parts map[string]string, resources []json.RawMessage) string {
|
func partsDifference(parts map[string]string, resources []json.RawMessage, templates []string) string {
|
||||||
if len(parts) == 0 {
|
if len(parts) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
inParts := map[string]bool{}
|
||||||
|
for _, d := range parts {
|
||||||
|
inParts[d] = true
|
||||||
|
}
|
||||||
fetched := map[string]bool{}
|
fetched := map[string]bool{}
|
||||||
|
// A templates archive the composition was rendered from was read from the artifact store and checked by its digest:
|
||||||
|
// a part fetched (design 47 G A-481, A-481a).
|
||||||
|
for _, d := range templates {
|
||||||
|
fetched[d] = true
|
||||||
|
}
|
||||||
for _, raw := range resources {
|
for _, raw := range resources {
|
||||||
r, err := declaration.ParseResource(raw)
|
r, err := declaration.ParseResource(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,15 +93,27 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin
|
|||||||
fetched[res.Digest] = true
|
fetched[res.Digest] = true
|
||||||
}
|
}
|
||||||
case *declaration.Process:
|
case *declaration.Process:
|
||||||
if res.Source != "" {
|
// A runtime of its own runs the tool runner's program, which the tool runner's want checks (A-432).
|
||||||
|
if res.Source != "" && !strings.HasSuffix(res.ID, "."+catalogue.OwnRuntimeID()) {
|
||||||
fetched[res.Digest] = true
|
fetched[res.Digest] = true
|
||||||
}
|
}
|
||||||
case *declaration.Container:
|
case *declaration.Container:
|
||||||
|
// A digest the want's parts name always counts as fetched, whatever marks the resource carries; one they do not
|
||||||
|
// name counts only when it is the mesh's own: an image the manifest pins from outside, or the registry seat's
|
||||||
|
// copy of an upstream image, is no part (design 47 G A-454, A-454a).
|
||||||
|
digest := ""
|
||||||
if strings.HasPrefix(res.Image, "sha256:") {
|
if strings.HasPrefix(res.Image, "sha256:") {
|
||||||
fetched[res.Image] = true
|
digest = res.Image
|
||||||
} else if _, digest, ok := strings.Cut(res.Image, "@"); ok {
|
} else if _, d, ok := strings.Cut(res.Image, "@"); ok {
|
||||||
fetched[digest] = true
|
digest = d
|
||||||
}
|
}
|
||||||
|
if digest == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !inParts[digest] && (res.ImageSeat == "" || upstreamCopy(res.Image)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fetched[digest] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
named := map[string]bool{}
|
named := map[string]bool{}
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
|
|||||||
}
|
}
|
||||||
kept := make(map[string]catalogue.Manifest, len(n.Kept))
|
kept := make(map[string]catalogue.Manifest, len(n.Kept))
|
||||||
for m, man := range n.Kept {
|
for m, man := range n.Kept {
|
||||||
if man.Stubbed && man.RunsAs == "" {
|
if man.Stubbed && man.RunsAs == "" && !keepsProgram(man) {
|
||||||
man.Bundles = runningBundles(n.RunsTools[m], reading.Catalogue[m])
|
man.Bundles = runningBundles(n.RunsTools[m], reading.Catalogue[m])
|
||||||
}
|
}
|
||||||
kept[m] = man
|
kept[m] = man
|
||||||
@@ -297,6 +297,10 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
|
|||||||
}
|
}
|
||||||
if m, ok := in.Catalogue[c.Module]; ok && c.Module != "" {
|
if m, ok := in.Catalogue[c.Module]; ok && c.Module != "" {
|
||||||
c.Data = len(m.DataItems()) > 0
|
c.Data = len(m.DataItems()) > 0
|
||||||
|
// The archive its files were rendered from, which the parts check counts as fetched (design 47 G A-481a).
|
||||||
|
if m.TemplatesDigest != "" {
|
||||||
|
c.Templates = []string{m.TemplatesDigest}
|
||||||
|
}
|
||||||
out[key] = c
|
out[key] = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,6 +493,56 @@ func Stub(m catalogue.Manifest) catalogue.Manifest {
|
|||||||
// run). What it provides, requires, listens on and grants is its manifest's. A module whose resources runs holds none
|
// run). What it provides, requires, listens on and grants is its manifest's. A module whose resources runs holds none
|
||||||
// of is its Stub, as before.
|
// of is its Stub, as before.
|
||||||
func Carried(m catalogue.Manifest, module string, runs *engcomp.Composed) catalogue.Manifest {
|
func Carried(m catalogue.Manifest, module string, runs *engcomp.Composed) catalogue.Manifest {
|
||||||
|
stub := carried(m, module, runs)
|
||||||
|
if catalogue.IsToolRunner(m) && (len(stub.Bundles) != 1 || stub.Bundles[0].Binary == "") {
|
||||||
|
if b, ok := runningProgram(module, runs); ok {
|
||||||
|
stub.Bundles = []catalogue.Bundle{b}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stub
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepsProgram says a held tool runner carries the program it runs (Carried, runningProgram): its one bundle is that
|
||||||
|
// program, which the tools bundles it serves never replace, or the modules of their own account it runs are held for
|
||||||
|
// want of it (lead-47 2026-11-16: 40ed063 kept novox's, and the loop over what the runtime serves dropped it again).
|
||||||
|
func keepsProgram(m catalogue.Manifest) bool {
|
||||||
|
return catalogue.IsToolRunner(m) && len(m.Bundles) == 1 && m.Bundles[0].Binary != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// runningProgram is the program bundle of the tool runner as it runs on the node: its process's source, digest and binary.
|
||||||
|
// A held tool runner keeps it, so a module of its own account is run by the same program the node runs (novox/hq ADR 0259
|
||||||
|
// §8) and is not held for want of a runtime that runs (lead-47 2026-11-16: novox's tool runner was held for a build the
|
||||||
|
// catalog half held no entry of, and held the new indexer with it).
|
||||||
|
func runningProgram(module string, runs *engcomp.Composed) (catalogue.Bundle, bool) {
|
||||||
|
if runs == nil {
|
||||||
|
return catalogue.Bundle{}, false
|
||||||
|
}
|
||||||
|
for _, raw := range runs.Resources {
|
||||||
|
var r struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Module string `json:"module"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Source string `json:"source"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
Run []string `json:"run"`
|
||||||
|
}
|
||||||
|
if json.Unmarshal(raw, &r) != nil || r.Type != "process" || r.Source == "" || r.Digest == "" || len(r.Run) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
owner := r.Module
|
||||||
|
if owner == "" {
|
||||||
|
owner, _ = declaration.ModuleGuess(r.ID)
|
||||||
|
}
|
||||||
|
binary, ok := strings.CutPrefix(r.Run[0], "./")
|
||||||
|
if owner != module || !ok || binary == "" || strings.Contains(binary, "/") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return catalogue.Bundle{Name: "program", Source: registryforms.Forms.Recorded(r.Source), Digest: r.Digest, Binary: binary}, true
|
||||||
|
}
|
||||||
|
return catalogue.Bundle{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func carried(m catalogue.Manifest, module string, runs *engcomp.Composed) catalogue.Manifest {
|
||||||
if runs == nil {
|
if runs == nil {
|
||||||
return Stub(m)
|
return Stub(m)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -19,6 +20,7 @@ func fpFor(c byte) string { return meshcatalogclient.SourcePrefix2 + strings.Rep
|
|||||||
// to: every resource once, each in its module's composition at the fingerprint given, the module's ownership said on
|
// to: every resource once, each in its module's composition at the fingerprint given, the module's ownership said on
|
||||||
// it; a module given no fingerprint is named as skipped and composed nowhere.
|
// it; a module given no fingerprint is named as skipped and composed nowhere.
|
||||||
func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
||||||
|
t.Run("a held tool runner keeps its program for the modules of their own account", aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount)
|
||||||
in := aSmallMesh(t)
|
in := aSmallMesh(t)
|
||||||
d, _, err := Compose(in, "laptop")
|
d, _, err := Compose(in, "laptop")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -31,10 +33,19 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
|||||||
sort.Strings(want)
|
sort.Strings(want)
|
||||||
|
|
||||||
fps := map[string]string{"mesh-wireguard": fpFor('a'), "files": fpFor('b')}
|
fps := map[string]string{"mesh-wireguard": fpFor('a'), "files": fpFor('b')}
|
||||||
|
// A-481a: the composition names the digest of the templates archive its module was rendered from.
|
||||||
|
templated := in.Catalogue["files"]
|
||||||
|
templated.TemplatesDigest = "sha256:" + strings.Repeat("e", 64)
|
||||||
|
in.Catalogue["files"] = templated
|
||||||
out, skipped, err := Compositions(in, "laptop", fps, Foreseeing)
|
out, skipped, err := Compositions(in, "laptop", fps, Foreseeing)
|
||||||
if err != nil || len(skipped) != 0 {
|
if err != nil || len(skipped) != 0 {
|
||||||
t.Fatalf("Compositions = %v, skipped %v", err, skipped)
|
t.Fatalf("Compositions = %v, skipped %v", err, skipped)
|
||||||
}
|
}
|
||||||
|
for _, c := range out {
|
||||||
|
if want := map[string][]string{"files": {templated.TemplatesDigest}}[c.Module]; !slices.Equal(c.Templates, want) {
|
||||||
|
t.Errorf("%s names the templates %v, want %v", c.Module, c.Templates, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
var got []string
|
var got []string
|
||||||
for key, c := range out {
|
for key, c := range out {
|
||||||
node, module, fp, isNode, err := engcomp.ParseKey(key)
|
node, module, fp, isNode, err := engcomp.ParseKey(key)
|
||||||
@@ -191,3 +202,54 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lead-47 2026-11-16: a held tool runner keeps the program it runs (Carried, runningProgram) after what the runtime serves
|
||||||
|
// is laid on the stubs (Node.RunsTools), so a module of its own account on its node is run by that program, not held
|
||||||
|
// "the tool runner is not here to run it from" (novox, the new indexer).
|
||||||
|
func aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount(t *testing.T) {
|
||||||
|
dg := "sha256:" + strings.Repeat("d", 64)
|
||||||
|
source := catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg
|
||||||
|
runtime := catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||||
|
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/node-tools/broker"}}}
|
||||||
|
own := catalogue.Manifest{Module: "mesh-self-check", Version: "1", RunsAs: "mesh-self-check",
|
||||||
|
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/mesh-self-check/broker", Taken: catalogue.TakenAtStart}},
|
||||||
|
Bundles: []catalogue.Bundle{{Name: "tools", Source: catalogue.ArtifactStoreScheme + "mesh-self-check/tools/blobs/" + dg,
|
||||||
|
Digest: dg, Language: "go", Loads: []string{"mesh-self-check-tools"}}}}
|
||||||
|
store := catalogue.Manifest{Module: "artifacts", Version: "1",
|
||||||
|
Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}},
|
||||||
|
Listens: []catalogue.Listening{{Name: "registry", Port: 5100, From: catalogue.FromMesh}}}
|
||||||
|
runs := engcomp.Composed{Node: "anchor", Module: "node-tools", Resources: []json.RawMessage{json.RawMessage(
|
||||||
|
`{"id":"node-tools.runtime","module":"node-tools","type":"process","name":"node-tools","source":"` + source +
|
||||||
|
`","digest":"` + dg + `","run":["./node-tools"],"env":{"MESH_TOOL_MODULES":""}}`)}}
|
||||||
|
in := aMesh(t)
|
||||||
|
in.Catalogue["node-tools"], in.Catalogue["artifacts"], in.Catalogue["mesh-self-check"] = runtime, store, own
|
||||||
|
anchor := nodeOf(t, &in, "anchor")
|
||||||
|
anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "mesh-self-check")
|
||||||
|
in.BusMinted = []string{"anchor.node-tools", "anchor.mesh-self-check"}
|
||||||
|
anchor.SealingKey = keyOf(t, "anchor")
|
||||||
|
anchor.Held = map[string]bool{"node-tools": true}
|
||||||
|
anchor.Kept = map[string]catalogue.Manifest{"node-tools": Carried(runtime, "node-tools", &runs)}
|
||||||
|
anchor.RunsTools = ToolsRunning([]engcomp.Composed{runs})
|
||||||
|
fps := map[string]string{overlay.Name: fpFor('a'), "artifacts": fpFor('5'), "node-tools": fpFor('e'), "mesh-self-check": fpFor('6')}
|
||||||
|
out, _, _, err := CompositionsIn(in, "anchor", fps, Foreseeing)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("a module of its own account beside a held tool runner: %v", err)
|
||||||
|
}
|
||||||
|
ran := false
|
||||||
|
for _, c := range out {
|
||||||
|
for _, raw := range c.Resources {
|
||||||
|
var r struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
Run []string `json:"run"`
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
if json.Unmarshal(raw, &r) == nil && r.Type == "process" && r.User == "mesh-self-check" {
|
||||||
|
ran = r.Digest == dg && len(r.Run) == 1 && r.Run[0] == "./node-tools"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !ran {
|
||||||
|
t.Errorf("mesh-self-check is not run by the program node-tools runs: %v", out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -201,7 +201,9 @@ func TestAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// A consumer whose set does not resolve is skipped, not fatal.
|
// A consumer whose set does not resolve is skipped, not fatal.
|
||||||
nodeOf(t, &in, "laptop").Assigned = append(nodeOf(t, &in, "laptop").Assigned, "files")
|
nodeOf(t, &in, "laptop").Assigned = append(nodeOf(t, &in, "laptop").Assigned, "files")
|
||||||
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "nothing-gives-this"}}
|
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "two-give-this"}}
|
||||||
|
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||||
|
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||||
if got, err := Render(in, "anchor", Foreseeing); err != nil || len(got.Rendering.Grants) != 0 {
|
if got, err := Render(in, "anchor", Foreseeing); err != nil || len(got.Rendering.Grants) != 0 {
|
||||||
t.Errorf("a consumer that does not resolve: %v %+v", err, got.Rendering.Grants)
|
t.Errorf("a consumer that does not resolve: %v %+v", err, got.Rendering.Grants)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
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, s.RunningManifest, true)
|
||||||
if err != 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.
|
// 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 {
|
if len(failed) == 0 {
|
||||||
@@ -141,6 +141,45 @@ func Answer(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]st
|
|||||||
a.Differs = slices.DeleteFunc(cmp.Differs, func(d nodeengine.CandidateDiffers) bool { return !notFailed(d.Module) })
|
a.Differs = slices.DeleteFunc(cmp.Differs, func(d nodeengine.CandidateDiffers) bool { return !notFailed(d.Module) })
|
||||||
cmp.Added = slices.DeleteFunc(cmp.Added, func(d nodeengine.CandidateAdded) bool { return !notFailed(d.Module) })
|
cmp.Added = slices.DeleteFunc(cmp.Added, func(d nodeengine.CandidateAdded) bool { return !notFailed(d.Module) })
|
||||||
skipped = slices.DeleteFunc(skipped, func(m string) bool { return !notFailed(m) })
|
skipped = slices.DeleteFunc(skipped, func(m string) bool { return !notFailed(m) })
|
||||||
|
// A module the node runs and an assignment names, but that no build can be given to compose at (what runs of it carries
|
||||||
|
// no fingerprint, it having started before the node-engine wrote them, and the declaration gives none), is held: kept as
|
||||||
|
// it runs, said as held with why, never removed and never stopped for it. Only a module no assignment names is removed
|
||||||
|
// (A-410).
|
||||||
|
for _, m := range skipped {
|
||||||
|
if !runs[m] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
a.Removed = slices.DeleteFunc(a.Removed, func(x string) bool { return x == m })
|
||||||
|
a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: m,
|
||||||
|
Why: "what runs of " + m + " has no fingerprint and none is given to compose it at, so it is kept as it runs",
|
||||||
|
Today: "running, kept as it runs"})
|
||||||
|
}
|
||||||
|
skipped = slices.DeleteFunc(skipped, func(m string) bool { return runs[m] })
|
||||||
|
// And whatever the candidate's assignment of this node names that runs and was composed to nothing for any other reason
|
||||||
|
// (the module is in no catalogue the composition reads, so it has no resources and is not even skipped): held the same
|
||||||
|
// way. Only a module no assignment names is removed (A-410).
|
||||||
|
placedHere := map[string]bool{}
|
||||||
|
if p, given := s.Assignments[s.Node]; given && p != nil {
|
||||||
|
for _, m := range p.Modules {
|
||||||
|
placedHere[m.Module] = true
|
||||||
|
}
|
||||||
|
} else if !given {
|
||||||
|
for _, m := range trunk[s.Node].Modules {
|
||||||
|
placedHere[m.Module] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.Removed = slices.DeleteFunc(a.Removed, func(m string) bool {
|
||||||
|
if !placedHere[m] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: m,
|
||||||
|
Why: "the assignment names " + m + " on this node, and the composition made nothing of it, so it is kept as it runs",
|
||||||
|
Today: "running, kept as it runs"})
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if len(a.Removed) == 0 {
|
||||||
|
a.Removed = nil
|
||||||
|
}
|
||||||
|
|
||||||
// What the proposal adds, by node and module: placed by a candidate and not by the trunk on that node.
|
// What the proposal adds, by node and module: placed by a candidate and not by the trunk on that node.
|
||||||
added := map[string]bool{}
|
added := map[string]bool{}
|
||||||
@@ -292,8 +331,12 @@ 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
|
// 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,
|
// (culprit): de-spiegel's routes, its names unset, leave route-proxy without them while mailu keeps its smtp account,
|
||||||
// and the hold says so.
|
// and the hold says so.
|
||||||
|
//
|
||||||
|
// search says a refusal is laid on a culprit (culprit). The node composing itself always searches; a composer's sandbox
|
||||||
|
// (ComposeSent) does not, since it runs the one search for culprits itself, bounded by its request (design 47 G §721;
|
||||||
|
// A-469j): there the first refusal no hold of the read answers is the node's (err).
|
||||||
func composeEach(in compose.Input, node string, fps map[string]string, applied bool, running []compositions.Composed, failed map[string]string,
|
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), search bool) (out map[string]compositions.Composed, skipped, stood []string, err error) {
|
||||||
mode := compose.Foreseeing
|
mode := compose.Foreseeing
|
||||||
if applied {
|
if applied {
|
||||||
mode = compose.Reading
|
mode = compose.Reading
|
||||||
@@ -317,7 +360,9 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b
|
|||||||
}
|
}
|
||||||
if ran != nil {
|
if ran != nil {
|
||||||
if was, ok := ran(m); ok {
|
if was, ok := ran(m); ok {
|
||||||
man.Contributes, man.ContributesMany, man.Listens = was.Contributes, was.ContributesMany, was.Listens
|
// A held module keeps running what it runs, so it keeps offering what that build offers, whatever its version and
|
||||||
|
// whether the catalog lists the build: the module that requires it is no "nothing provides" (A-480, A-484).
|
||||||
|
man.Contributes, man.ContributesMany, man.Listens, man.Provides = was.Contributes, was.ContributesMany, was.Listens, was.Provides
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
src[m] = man
|
src[m] = man
|
||||||
@@ -340,6 +385,9 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b
|
|||||||
var leftOut map[string]string
|
var leftOut map[string]string
|
||||||
out, skipped, stood, leftOut, err = compose.CompositionsHolding(in, node, fps, mode)
|
out, skipped, stood, leftOut, err = compose.CompositionsHolding(in, node, fps, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !search {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
module, leave := culprit(in, node, fps, mode, failed, err)
|
module, leave := culprit(in, node, fps, mode, failed, err)
|
||||||
if module == "" {
|
if module == "" {
|
||||||
return nil, nil, nil, firstReason(err, failed)
|
return nil, nil, nil, firstReason(err, failed)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -193,6 +194,47 @@ func answerNamesEveryRefusalAndLeavesAnOldBuildToTheNode(t *testing.T) {
|
|||||||
if a = Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given(b), InOwn: []string{"spiegel"}}, fps, withMembership, "p-h1", 3); a.Verdict != nodeengine.CandidateAnswerVerdictSame {
|
if a = Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given(b), InOwn: []string{"spiegel"}}, fps, withMembership, "p-h1", 3); a.Verdict != nodeengine.CandidateAnswerVerdictSame {
|
||||||
t.Errorf("the node's own with its bus membership is answered %+v, want the same", a)
|
t.Errorf("the node's own with its bus membership is answered %+v, want the same", a)
|
||||||
}
|
}
|
||||||
|
// (C) A module the node runs and an assignment names, given no fingerprint to compose at (it started before the node
|
||||||
|
// wrote them): held as it runs, never removed (A-410). One no assignment names is removed.
|
||||||
|
noFp := maps.Clone(fps)
|
||||||
|
delete(noFp, "lemurs")
|
||||||
|
unmarked := make([]engcomp.Composed, 0, len(running))
|
||||||
|
for _, c := range running {
|
||||||
|
if c.Module == "lemurs" {
|
||||||
|
c.FP = ""
|
||||||
|
}
|
||||||
|
unmarked = append(unmarked, c)
|
||||||
|
}
|
||||||
|
unmarked = append(unmarked, engcomp.Composed{Node: "n1", Module: "gone", FP: fp("1")})
|
||||||
|
a = Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given(b), InOwn: []string{"spiegel"}}, noFp, unmarked, "p-h1", 3)
|
||||||
|
if !reflect.DeepEqual(a.Removed, []string{"gone"}) {
|
||||||
|
t.Errorf("removed %v, want only the module no assignment names", a.Removed)
|
||||||
|
}
|
||||||
|
heldIt := false
|
||||||
|
for _, h := range a.Held {
|
||||||
|
heldIt = heldIt || h.Module == "lemurs" && h.Why != ""
|
||||||
|
}
|
||||||
|
if !heldIt || len(a.Added) != 0 {
|
||||||
|
t.Errorf("a running module with no fingerprint is answered held %+v added %+v, want held with why and not added", a.Held, a.Added)
|
||||||
|
}
|
||||||
|
// (D) One the assignment names whose manifest says its name alone (no resources: what stands in for a module whose entry
|
||||||
|
// is not held) composes to nothing, and is not even skipped: held too, not removed (A-410).
|
||||||
|
nameOnly := []byte(`{"module":"ghost","version":"0"}`)
|
||||||
|
ghostDigest := meshcatalogclient.ManifestDigest(nameOnly)
|
||||||
|
b.manifests[ghostDigest] = nameOnly
|
||||||
|
b.modules["ghost"] = meshcatalog.ModulesByModuleValue{Manifest: ghostDigest}
|
||||||
|
pGhost := b.assignments["n1"]
|
||||||
|
trunkMods := pGhost.Modules
|
||||||
|
pGhost.Modules = append(append([]meshmoduleassigner.PlacedModule{}, trunkMods...), meshmoduleassigner.PlacedModule{Module: "ghost"})
|
||||||
|
b.assignments["n1"] = pGhost
|
||||||
|
ghostRuns := append(append([]engcomp.Composed{}, unmarked...), engcomp.Composed{Node: "n1", Module: "ghost", FP: fp("2")})
|
||||||
|
a = Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given(b), InOwn: []string{"spiegel"}}, noFp, ghostRuns, "p-h1", 3)
|
||||||
|
if !reflect.DeepEqual(a.Removed, []string{"gone"}) || !slices.ContainsFunc(a.Held, func(h nodeengine.CandidateRefusal) bool { return h.Module == "ghost" }) {
|
||||||
|
t.Errorf("a named module the composition made nothing of: removed %v held %+v, want it held and only gone removed (%.600s)", a.Removed, a.Held, fmt.Sprintf("%+v", a))
|
||||||
|
}
|
||||||
|
pGhost.Modules = trunkMods
|
||||||
|
b.assignments["n1"] = pGhost
|
||||||
|
delete(b.modules, "ghost")
|
||||||
// Without what runs, the fold composes spiegel from its manifest, as before, and the composition refuses it.
|
// Without what runs, the fold composes spiegel from its manifest, as before, and the composition refuses it.
|
||||||
if _, _, held, err := Compose(ctx, b, Mesh{}, Scope{Node: "n1", InOwn: []string{"spiegel"}}, fps); err != nil ||
|
if _, _, held, err := Compose(ctx, b, Mesh{}, Scope{Node: "n1", InOwn: []string{"spiegel"}}, fps); err != nil ||
|
||||||
!strings.Contains(held["spiegel"], "spiegel has not been built for this mesh") {
|
!strings.Contains(held["spiegel"], "spiegel has not been built for this mesh") {
|
||||||
@@ -596,7 +638,10 @@ func answerNamesEveryRefusalAndLeavesAnOldBuildToTheNode(t *testing.T) {
|
|||||||
siteRuns.FP = fp("7")
|
siteRuns.FP = fp("7")
|
||||||
b.manifests[meshcatalogclient.ManifestDigest(site)] = site
|
b.manifests[meshcatalogclient.ManifestDigest(site)] = site
|
||||||
b.builds["site "+fp("7")] = &builds.BuilderBuild{State: builds.BuildDone, Manifest: meshcatalogclient.ManifestDigest(site)}
|
b.builds["site "+fp("7")] = &builds.BuilderBuild{State: builds.BuildDone, Manifest: meshcatalogclient.ManifestDigest(site)}
|
||||||
got, _, held, err = Compose(ctx, b, Mesh{}, Scope{Node: "n1", Running: []engcomp.Composed{siteRuns}}, fps)
|
// The manifest of the build that runs is read in the one place (A-484), here the manifest of the build 7.
|
||||||
|
ranSite, _ := catalogue.Decode(site)
|
||||||
|
got, _, held, err = Compose(ctx, b, Mesh{}, Scope{Node: "n1", Running: []engcomp.Composed{siteRuns},
|
||||||
|
RunningManifest: func(module string) (catalogue.Manifest, bool) { return ranSite, module == "site" }}, fps)
|
||||||
if err != nil || held["site"] == "" || held["nft"] != "" {
|
if err != nil || held["site"] == "" || held["nft"] != "" {
|
||||||
t.Errorf("site moved to 9090 in its new manifest: %v, held %v; want site held alone", err, held)
|
t.Errorf("site moved to 9090 in its new manifest: %v, held %v; want site held alone", err, held)
|
||||||
}
|
}
|
||||||
@@ -633,7 +678,9 @@ func otherNodeNotResolvedIsNamed(t *testing.T) {
|
|||||||
given[n] = &p
|
given[n] = &p
|
||||||
}
|
}
|
||||||
a := Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given}, map[string]string{"cons": "src2:" + strings.Repeat("1", 64)}, nil, "p-h1", 1)
|
a := Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given}, map[string]string{"cons": "src2:" + strings.Repeat("1", 64)}, nil, "p-h1", 1)
|
||||||
if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || !strings.Contains(a.Refused, "prov on n2 lacks container-runtime") {
|
// cons is held for the requirement nothing answers (A-452) and its why names n2's provider.
|
||||||
|
if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || len(a.Refusals) != 1 || a.Refusals[0].Module != "cons" ||
|
||||||
|
!strings.Contains(a.Refusals[0].Why, "prov on n2 lacks container-runtime") {
|
||||||
t.Errorf("a refusal for want of n2's provider = %+v", a)
|
t.Errorf("a refusal for want of n2's provider = %+v", a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,11 @@ type Scope struct {
|
|||||||
// the seat list, novox/hq ADR 0636 §1): each is held as it runs, as a module refused alone is, so no take-in or
|
// the seat list, novox/hq ADR 0636 §1): each is held as it runs, as a module refused alone is, so no take-in or
|
||||||
// artifact reference of it can refuse the node (issue 1966). Nil holds none.
|
// artifact reference of it can refuse the node (issue 1966). Nil holds none.
|
||||||
Held map[string]string
|
Held map[string]string
|
||||||
|
// RunningManifest answers the manifest of the build a module runs on the composing node, from the one place that reads it
|
||||||
|
// (design 47 G A-484: its entry, else the composition the node runs of it, else the trunk's manifest): what a held module
|
||||||
|
// keeps offering the others (what it provides, contributes and listens on), since it keeps running what it runs. False
|
||||||
|
// where nothing is read; the manifest it is composed from is its offer then. Nil: none is read.
|
||||||
|
RunningManifest func(module string) (catalogue.Manifest, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InOwn is, of the modules p places on its node, those whose resources the node's own composition it runs
|
// InOwn is, of the modules p places on its node, those whose resources the node's own composition it runs
|
||||||
@@ -271,6 +276,11 @@ func taken(name string, raw []byte, m meshcatalog.ModulesByModuleValue) (man cat
|
|||||||
func input(ctx context.Context, r Reader, mesh Mesh, s Scope, refuse func(module string, err error), wanted map[string]string) (compose.Input, error) {
|
func input(ctx context.Context, r Reader, mesh Mesh, s Scope, refuse func(module string, err error), wanted map[string]string) (compose.Input, error) {
|
||||||
b, err := readBase(ctx, r, mesh, s)
|
b, err := readBase(ctx, r, mesh, s)
|
||||||
b.refuseOwn(refuse)
|
b.refuseOwn(refuse)
|
||||||
|
// The engine is named from the catalogue the base read, before the rest of the input, so a node whose input fails
|
||||||
|
// still serves its seat (root-free): live on novox 2026-11-14 no pass ended, so the seat was never served (A-403).
|
||||||
|
if s.Engine != nil && len(b.in.Catalogue) > 0 {
|
||||||
|
s.Engine(EngineModule(b.in, s.Node, s.OwnFingerprint))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return compose.Input{}, err
|
return compose.Input{}, err
|
||||||
}
|
}
|
||||||
@@ -698,7 +708,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)
|
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, s.RunningManifest, true)
|
||||||
return out, skipped, held, err
|
return out, skipped, held, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -725,36 +735,146 @@ 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
|
// 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
|
// 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) {
|
//
|
||||||
|
// It runs the one search for culprits (design 47 G §721; A-469j, A-468i): where the composition fails with no module held
|
||||||
|
// that the node held neither in the read nor before the change, and no path owned twice names its owners, each of
|
||||||
|
// s.Changed is held in turn, one composition each, and the first whose hold ends the problem (the try composes or fails
|
||||||
|
// otherwise) is blamed with it; one that leaves the machine not composing stays held, and the search goes on (A-470v). At most s.Tries tries; past them each module not yet tried is blamed NotTried. With no
|
||||||
|
// tries there is no search: the failure is the node's own (err).
|
||||||
|
func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Composed, bool, error) {
|
||||||
c := in.ComposedHow
|
c := in.ComposedHow
|
||||||
if c == nil || c.Node != node {
|
if c == nil || c.Node != node {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
held := maps.Clone(c.Held)
|
compose1 := func(also ...string) (map[string]engcomp.Composed, map[string]string, error) {
|
||||||
if held == nil {
|
held := maps.Clone(c.Held)
|
||||||
held = map[string]string{}
|
if held == nil {
|
||||||
|
held = map[string]string{}
|
||||||
|
}
|
||||||
|
// A module the node holds composing without the change is held as there: the candidate keeps it as the node does,
|
||||||
|
// which is no change and no search (issue 1126; design 47 G §721, HeldBefore left out of blamed).
|
||||||
|
for m, why := range c.HeldBefore {
|
||||||
|
if _, was := held[m]; !was {
|
||||||
|
held[m] = why
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, m := range also {
|
||||||
|
held[m] = triedHeld
|
||||||
|
}
|
||||||
|
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, false)
|
||||||
|
return out, held, err
|
||||||
}
|
}
|
||||||
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil)
|
ours := func(m string) bool {
|
||||||
if err != nil {
|
_, was := c.Held[m]
|
||||||
return nil, true, err
|
_, before := c.HeldBefore[m]
|
||||||
|
return !was && !before
|
||||||
}
|
}
|
||||||
|
out, held, err := compose1()
|
||||||
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
|
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
|
||||||
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
|
// 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).
|
// review of the sandbox input).
|
||||||
var refused []string
|
var refused []string
|
||||||
|
blamed := map[string]string{}
|
||||||
for _, m := range sortedKeys(held) {
|
for _, m := range sortedKeys(held) {
|
||||||
_, was := c.Held[m]
|
if ours(m) {
|
||||||
if _, before := c.HeldBefore[m]; !was && !before {
|
|
||||||
refused = append(refused, m+": "+held[m])
|
refused = append(refused, m+": "+held[m])
|
||||||
|
blamed[m] = held[m]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(refused) > 0 {
|
// Two modules owning one path are each blamed, with that path, outside the search (design 47 G §721; A-468l).
|
||||||
return nil, true, fmt.Errorf("on %s the change refuses %s", node, strings.Join(refused, "; "))
|
var refusal *resolution.Refusal
|
||||||
|
if err != nil && errors.As(err, &refusal) {
|
||||||
|
for _, p := range refusal.OwnedTwice {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out, true, nil
|
// A hold that changes the problem but leaves the machine not composing keeps that module held and blamed, and the
|
||||||
|
// search goes on against the retry's problem, from the first changed module not held, within the same tries, until the
|
||||||
|
// machine composes or no hold changes it (A-470v): every module the change refuses is blamed, never only the first.
|
||||||
|
if err != nil && len(blamed) == 0 && s.Tries > 0 {
|
||||||
|
problem, tries := err.Error(), 0
|
||||||
|
var kept []string
|
||||||
|
search:
|
||||||
|
for {
|
||||||
|
tried := map[string]bool{} // against the problem of now
|
||||||
|
for _, mod := range s.Changed {
|
||||||
|
if slices.Contains(kept, mod) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if tries == s.Tries {
|
||||||
|
for _, untried := range s.Changed {
|
||||||
|
if _, done := blamed[untried]; !done && !tried[untried] {
|
||||||
|
blamed[untried] = NotTried
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break search
|
||||||
|
}
|
||||||
|
tries++
|
||||||
|
tried[mod] = true
|
||||||
|
_, _, again := compose1(append(slices.Clone(kept), mod)...)
|
||||||
|
if again == nil {
|
||||||
|
blamed[mod] = problem
|
||||||
|
break search
|
||||||
|
}
|
||||||
|
if again.Error() != problem {
|
||||||
|
blamed[mod], problem = problem, again.Error()
|
||||||
|
kept = append(kept, mod)
|
||||||
|
continue search
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break // no hold changes the problem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(blamed) == 0 {
|
||||||
|
return out, true, err
|
||||||
|
}
|
||||||
|
words := strings.Join(refused, "; ")
|
||||||
|
if err != nil {
|
||||||
|
words = err.Error()
|
||||||
|
}
|
||||||
|
e := &Refuses{Node: node, words: words}
|
||||||
|
for _, m := range sortedKeys(blamed) {
|
||||||
|
e.Blamed = append(e.Blamed, Blamed{Module: m, Problem: blamed[m]})
|
||||||
|
}
|
||||||
|
return nil, true, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search is the composer's one search for culprits in ComposeSent (design 47 G §721): the candidate's changed modules
|
||||||
|
// placed on the node, in assignment order, and the request's blame_tries.
|
||||||
|
type Search struct {
|
||||||
|
Changed []string
|
||||||
|
Tries int
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
// 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
|
// 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
|
// 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
|
// cmd/mesh-controller/compose_sdk.go), its rendering in the Foreseeing mode with the mesh's generators. A plan names
|
||||||
@@ -876,33 +996,6 @@ func parser(Mesh) func([]byte) (catalogue.Manifest, error) {
|
|||||||
return catalogue.Decode
|
return catalogue.Decode
|
||||||
}
|
}
|
||||||
|
|
||||||
// ranOf is what a module last offered the others, read when it is held (composeEach, issue 1960): its manifest at the
|
|
||||||
// build its own composition runs at (running), where that is another build than the one it is composed at (fps) and
|
|
||||||
// the builder holds it done. False where nothing is known of it (it runs no composition of its own, it runs the build
|
|
||||||
// it is composed at, or its build is unread): the manifest it is composed from is its offer then. Only what it says to
|
|
||||||
// others is taken of it, which needs no take-in of its artifacts.
|
|
||||||
func ranOf(ctx context.Context, r Reader, mesh Mesh, running []engcomp.Composed, fps map[string]string) func(string) (catalogue.Manifest, bool) {
|
|
||||||
parse := parser(mesh)
|
|
||||||
return func(module string) (catalogue.Manifest, bool) {
|
|
||||||
for _, c := range running {
|
|
||||||
if c.Module != module || c.FP == "" || c.FP == fps[module] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
b, err := r.Build(ctx, module, c.FP)
|
|
||||||
if err != nil || b == nil || b.State != builds.BuildDone || b.Manifest == "" {
|
|
||||||
return catalogue.Manifest{}, false
|
|
||||||
}
|
|
||||||
raw, err := r.Manifest(ctx, b.Manifest)
|
|
||||||
if err != nil {
|
|
||||||
return catalogue.Manifest{}, false
|
|
||||||
}
|
|
||||||
man, err := parse(raw)
|
|
||||||
return man, err == nil
|
|
||||||
}
|
|
||||||
return catalogue.Manifest{}, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fromBuilds puts in the built manifest of each module placed on the composing node, at the trunk's FP2, and of each
|
// fromBuilds puts in the built manifest of each module placed on the composing node, at the trunk's FP2, and of each
|
||||||
// module it keeps at another build (Scope.KeptAt, into its node's Kept), read from the builder's done key and resolved
|
// module it keeps at another build (Scope.KeptAt, into its node's Kept), read from the builder's done key and resolved
|
||||||
// by the one take-in rule (takein.Manifest), a templates archive read in the artifact store as the node reaches it
|
// by the one take-in rule (takein.Manifest), a templates archive read in the artifact store as the node reaches it
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
"github.com/novox/mesh-host/internal/compose"
|
"github.com/novox/mesh-host/internal/compose"
|
||||||
"github.com/novox/mesh-host/internal/compose/resolution"
|
"github.com/novox/mesh-host/internal/compose/resolution"
|
||||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
@@ -39,11 +40,17 @@ func aNode(t *testing.T, manifests ...string) (*bus, map[string]string) {
|
|||||||
// refusal can be of the held module's stub (node-tools held, then "its build produced 0 bundle(s)", its own why unsaid).
|
// refusal can be of the held module's stub (node-tools held, then "its build produced 0 bundle(s)", its own why unsaid).
|
||||||
func aNodeRefusedWholeSaysWhatItHeld(t *testing.T) {
|
func aNodeRefusedWholeSaysWhatItHeld(t *testing.T) {
|
||||||
refused := `{"module":"power","version":"1","items":[{"collection":"contribution:node-bar:block","attributes":{"shows":"state"},"template":"files/a"}]}`
|
refused := `{"module":"power","version":"1","items":[{"collection":"contribution:node-bar:block","attributes":{"shows":"state"},"template":"files/a"}]}`
|
||||||
needs := `{"module":"lamp","version":"1","requires":["nothing-provides-this"]}`
|
needs := `{"module":"lamp","version":"1","requires":["two-provide-this"]}`
|
||||||
b, fps := aNode(t, refused, needs)
|
giverA := `{"module":"giver-a","version":"1","provides":[{"name":"two-provide-this"}]}`
|
||||||
|
giverB := `{"module":"giver-b","version":"1","provides":[{"name":"two-provide-this"}]}`
|
||||||
|
b, fps := aNode(t, refused, needs, giverA, giverB)
|
||||||
|
// The two givers are in the catalogue and placed on no node, so lamp's requirement has two answers and nobody chose.
|
||||||
|
placed := b.assignments["n1"]
|
||||||
|
placed.Modules = placed.Modules[:2]
|
||||||
|
b.assignments["n1"] = placed
|
||||||
refuse(b, "power", `"shows" is none of them`)
|
refuse(b, "power", `"shows" is none of them`)
|
||||||
_, _, held, err := Compose(context.Background(), b, Mesh{}, Scope{Node: "n1"}, fps)
|
_, _, held, err := Compose(context.Background(), b, Mesh{}, Scope{Node: "n1"}, fps)
|
||||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") || !strings.Contains(err.Error(), `held before: power: `) ||
|
if err == nil || !strings.Contains(err.Error(), "choose one") || !strings.Contains(err.Error(), `held before: power: `) ||
|
||||||
!strings.Contains(err.Error(), `"shows" is none of them`) {
|
!strings.Contains(err.Error(), `"shows" is none of them`) {
|
||||||
t.Errorf("the node refused whole with %v (held %v), want lamp's refusal and power held before, with its why", err, held)
|
t.Errorf("the node refused whole with %v (held %v), want lamp's refusal and power held before, with its why", err, held)
|
||||||
}
|
}
|
||||||
@@ -331,4 +338,44 @@ func TestASecondClaimantOfASeatIsHeldAndTheNodeComposesTheRest(t *testing.T) {
|
|||||||
t.Errorf("running %v: the answer is %+v, want beta refused with the claim's words", running, ans)
|
t.Errorf("running %v: the answer is %+v, want beta refused with the claim's words", running, ans)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A-480 rows, in this test to keep the module's count:
|
||||||
|
// A-480 (design 47 G): a module the node holds keeps running what it runs, and so keeps providing what its running build provides,
|
||||||
|
// whatever its catalogue entry: the module that requires it is not held for "nothing provides" (live, 2026-11-17 22:52: feh on g14
|
||||||
|
// held for "x11-display" while xorg runs there, held only for want of an entry of its wanted build). The offer is the running
|
||||||
|
// manifest of the build it runs, from the one place that reads it (A-484); a module neither running nor composable still gives
|
||||||
|
// "nothing provides".
|
||||||
|
const xorgRunning = `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}`
|
||||||
|
feh := `{"module":"feh","version":"1","requires":["x11-display"]}`
|
||||||
|
nameOnly := `{"module":"xorg","version":"0"}`
|
||||||
|
for _, row := range []struct {
|
||||||
|
name string
|
||||||
|
scope func(fps map[string]string, b *bus) Scope
|
||||||
|
provided bool
|
||||||
|
}{
|
||||||
|
{"the one place answers the manifest of the build it runs (A-484)", func(fps map[string]string, b *bus) Scope {
|
||||||
|
man, _ := catalogue.Decode([]byte(xorgRunning))
|
||||||
|
return Scope{RunningManifest: func(module string) (catalogue.Manifest, bool) { return man, module == "xorg" }}
|
||||||
|
}, true},
|
||||||
|
{"the one place reads none", func(map[string]string, *bus) Scope {
|
||||||
|
return Scope{RunningManifest: func(string) (catalogue.Manifest, bool) { return catalogue.Manifest{}, false }}
|
||||||
|
}, false},
|
||||||
|
{"nothing of it runs", func(map[string]string, *bus) Scope { return Scope{} }, false},
|
||||||
|
} {
|
||||||
|
b, fps := aNode(t, nameOnly, feh)
|
||||||
|
scope := row.scope(fps, b)
|
||||||
|
scope.Node = "n1"
|
||||||
|
scope.Held = map[string]string{"xorg": "entry-missing: the catalog half holds no entry of the build"}
|
||||||
|
_, _, held, err := Compose(context.Background(), b, Mesh{}, scope, fps)
|
||||||
|
why, fehHeld := held["feh"]
|
||||||
|
if row.provided && (err != nil || fehHeld) {
|
||||||
|
t.Errorf("%s: err %v, feh held %q; want feh composed with xorg held as what runs", row.name, err, why)
|
||||||
|
}
|
||||||
|
if !row.provided && !(fehHeld && strings.Contains(why, `nothing provides "x11-display"`)) && (err == nil || !strings.Contains(err.Error(), "nothing provides")) {
|
||||||
|
t.Errorf("%s: err %v, held %v; want nothing provides", row.name, err, held)
|
||||||
|
}
|
||||||
|
if !strings.Contains(held["xorg"], "entry-missing") {
|
||||||
|
t.Errorf("%s: xorg's own hold is %q, want it said", row.name, held["xorg"])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package compose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -171,6 +172,34 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) {
|
|||||||
return d, validate.Declaration(body), nil
|
return d, validate.Declaration(body), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// composeWithoutStoreFetchers (it answers the modules it left out, and why) is resolution.Compose where a module that fetches from the artifact store while the node reaches
|
||||||
|
// none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates
|
||||||
|
// archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it
|
||||||
|
// (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read.
|
||||||
|
func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, map[string]string, error) {
|
||||||
|
var held map[string]string
|
||||||
|
for {
|
||||||
|
composed, err := resolution.Compose(plan, with)
|
||||||
|
var none *resolution.NoStoreError
|
||||||
|
if !errors.As(err, &none) {
|
||||||
|
return composed, with, held, err
|
||||||
|
}
|
||||||
|
if _, already := with.NotPlaced[none.Module]; already {
|
||||||
|
return catalogue.Composed{}, with, nil, err
|
||||||
|
}
|
||||||
|
left := make(map[string]string, len(with.NotPlaced)+1)
|
||||||
|
for m, why := range with.NotPlaced {
|
||||||
|
left[m] = why
|
||||||
|
}
|
||||||
|
left[none.Module] = none.Error()
|
||||||
|
with.NotPlaced = left
|
||||||
|
if held == nil {
|
||||||
|
held = map[string]string{}
|
||||||
|
}
|
||||||
|
held[none.Module] = none.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// declaration is the controller's declarationWith over the plain Input.
|
// declaration is the controller's declarationWith over the plain Input.
|
||||||
func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
||||||
resolved, err := c.planFor(nodeName)
|
resolved, err := c.planFor(nodeName)
|
||||||
@@ -188,7 +217,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
|||||||
with := rendered.Rendering
|
with := rendered.Rendering
|
||||||
with.Generators = gens
|
with.Generators = gens
|
||||||
plan := resolved.Plan
|
plan := resolved.Plan
|
||||||
composed, err := resolution.Compose(plan, with)
|
composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Declared{}, err
|
return Declared{}, err
|
||||||
}
|
}
|
||||||
@@ -202,7 +231,21 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Declared{}, err
|
return Declared{}, err
|
||||||
}
|
}
|
||||||
out := Declared{Held: resolved.Held, Resources: composed.Resources, Adoption: adoptionFor(plan, node, composed),
|
// A module that fetches from a store no node reaches is held with its words, as a module whose claim cannot be held is: it
|
||||||
|
// stays on the build it runs, its composition kept (A-452, A-461).
|
||||||
|
held := resolved.Held
|
||||||
|
if len(storeHeld) > 0 {
|
||||||
|
held = make(map[string]string, len(resolved.Held)+len(storeHeld))
|
||||||
|
for m, why := range resolved.Held {
|
||||||
|
held[m] = why
|
||||||
|
}
|
||||||
|
for m, why := range storeHeld {
|
||||||
|
if _, said := held[m]; !said {
|
||||||
|
held[m] = why
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := Declared{Held: held, Resources: composed.Resources, Adoption: adoptionFor(plan, node, composed),
|
||||||
Received: composed.Received, Mesh: with.Mesh, BusUsers: with.BusUsers,
|
Received: composed.Received, Mesh: with.Mesh, BusUsers: with.BusUsers,
|
||||||
LeftOut: sortedKeysOf(composed.LeftOut), LeftOutWhy: composed.LeftOut,
|
LeftOut: sortedKeysOf(composed.LeftOut), LeftOutWhy: composed.LeftOut,
|
||||||
Withheld: rendered.Withheld, Unbound: rendered.Unbound,
|
Withheld: rendered.Withheld, Unbound: rendered.Unbound,
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import (
|
|||||||
|
|
||||||
// fourOnTheNetwork is aMesh and two more machines on the private network at the site `there`: `ace`, dialled at
|
// fourOnTheNetwork is aMesh and two more machines on the private network at the site `there`: `ace`, dialled at
|
||||||
// ace.example:51820, at 10.77.0.3, and `box`, behind no endpoint, at 10.77.0.4. A module `office` requires
|
// ace.example:51820, at 10.77.0.3, and `box`, behind no endpoint, at 10.77.0.4. A module `office` requires
|
||||||
// `document-server`, which nothing in the catalogue provides: the shape of issue 1833 (nextcloud on the hub wanting a
|
// `document-server`, which two modules of the catalogue provide and nobody chose: a refusal of the node's own set, as
|
||||||
// document server nobody offered).
|
// issue 1833 was (nextcloud on the hub wanting a document server; an unanswered requirement now costs only its consumer, A-452).
|
||||||
func fourOnTheNetwork(t *testing.T) Input {
|
func fourOnTheNetwork(t *testing.T) Input {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
in := aMesh(t)
|
in := aMesh(t)
|
||||||
in.Catalogue["office"] = catalogue.Manifest{Module: "office", Version: "1", Requires: []string{"document-server"}}
|
in.Catalogue["office"] = catalogue.Manifest{Module: "office", Version: "1", Requires: []string{"document-server"}}
|
||||||
|
in.Catalogue["docs-a"] = catalogue.Manifest{Module: "docs-a", Version: "1", Provides: catalogue.Offers("document-server")}
|
||||||
|
in.Catalogue["docs-b"] = catalogue.Manifest{Module: "docs-b", Version: "1", Provides: catalogue.Offers("document-server")}
|
||||||
caps := map[string]bool{"container-runtime": true, "wireguard": true, "systemd": true}
|
caps := map[string]bool{"container-runtime": true, "wireguard": true, "systemd": true}
|
||||||
in.Nodes = append(in.Nodes,
|
in.Nodes = append(in.Nodes,
|
||||||
Node{Name: "ace", Place: Place{Key: keyOf(t, "ace"), Endpoint: "ace.example:51820", Site: "there", Address: "10.77.0.3"},
|
Node{Name: "ace", Place: Place{Key: keyOf(t, "ace"), Endpoint: "ace.example:51820", Site: "there", Address: "10.77.0.3"},
|
||||||
@@ -26,7 +28,7 @@ func fourOnTheNetwork(t *testing.T) Input {
|
|||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement nothing provides.
|
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement two modules provide.
|
||||||
func unresolvableBy(t *testing.T, in *Input, name string) {
|
func unresolvableBy(t *testing.T, in *Input, name string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
n := nodeOf(t, in, name)
|
n := nodeOf(t, in, name)
|
||||||
@@ -70,7 +72,7 @@ func TestOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
|
|||||||
if err == nil || !IsUnresolvable(err) {
|
if err == nil || !IsUnresolvable(err) {
|
||||||
t.Fatalf("the machine that does not resolve is not refused as its own set failing: %v", err)
|
t.Fatalf("the machine that does not resolve is not refused as its own set failing: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), `nothing provides "document-server", wanted by office`) {
|
if !strings.Contains(err.Error(), `"document-server" is wanted by office and 2 modules provide it`) {
|
||||||
t.Errorf("the refusal does not name what could not be resolved: %v", err)
|
t.Errorf("the refusal does not name what could not be resolved: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,15 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) {
|
|||||||
r.MeshRange = c.overlayRange()
|
r.MeshRange = c.overlayRange()
|
||||||
|
|
||||||
// The artifact store as this node reaches it now, with what the mesh has built.
|
// The artifact store as this node reaches it now, with what the mesh has built.
|
||||||
|
// No address for any reason read without error (no holder, a holder laid by its name alone, a holder not on the private
|
||||||
|
// network, a holder opening no listen to the mesh, or two) holds only the modules that fetch from the store: they wait,
|
||||||
|
// with the words of an unanswered requirement, and the node composes the rest (design 47 G A-461, A-461e, A-452). A fault
|
||||||
|
// reading the inputs still refuses the node (A-461b).
|
||||||
store, err := c.artifactStoreAddress(nodeName)
|
store, err := c.artifactStoreAddress(nodeName)
|
||||||
|
var noAddress *storeListenError
|
||||||
|
if errors.As(err, &noAddress) {
|
||||||
|
store, err = "", nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
@@ -363,6 +371,11 @@ func (c *composer) storeHolders() map[string]catalogue.Manifest {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// storeListenError is the refusal of a holder that opens no listen to the mesh, or two: the store has no address (A-461).
|
||||||
|
type storeListenError struct{ said string }
|
||||||
|
|
||||||
|
func (e *storeListenError) Error() string { return e.said }
|
||||||
|
|
||||||
// storeListen is the store holder's listen every machine pulls from: its one listen open to the mesh. A holder opening
|
// storeListen is the store holder's listen every machine pulls from: its one listen open to the mesh. A holder opening
|
||||||
// none, or more than one, says no address, by name: which of two ports is the store is no guess the composer makes.
|
// none, or more than one, says no address, by name: which of two ports is the store is no guess the composer makes.
|
||||||
func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
|
func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
|
||||||
@@ -376,15 +389,15 @@ func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
|
|||||||
case 1:
|
case 1:
|
||||||
return open[0], nil
|
return open[0], nil
|
||||||
case 0:
|
case 0:
|
||||||
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
|
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
|
||||||
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)
|
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)}
|
||||||
}
|
}
|
||||||
var said []string
|
var said []string
|
||||||
for _, l := range open {
|
for _, l := range open {
|
||||||
said = append(said, fmt.Sprintf("%s (%d)", l.Name, l.Port))
|
said = append(said, fmt.Sprintf("%s (%d)", l.Name, l.Port))
|
||||||
}
|
}
|
||||||
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
|
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
|
||||||
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))
|
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))}
|
||||||
}
|
}
|
||||||
|
|
||||||
// artifactStoreOnNetwork is the machine on this network that holds the store's seat, and the port that machine put the
|
// artifactStoreOnNetwork is the machine on this network that holds the store's seat, and the port that machine put the
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package compose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -351,8 +352,58 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) {
|
|||||||
m := in.Catalogue["registry"]
|
m := in.Catalogue["registry"]
|
||||||
m.Listens = append(m.Listens, catalogue.Listening{Name: "other", Port: 5300, From: catalogue.FromMesh})
|
m.Listens = append(m.Listens, catalogue.Listening{Name: "other", Port: 5300, From: catalogue.FromMesh})
|
||||||
in.Catalogue["registry"] = m
|
in.Catalogue["registry"] = m
|
||||||
if _, err := Places(in, "laptop"); err == nil || !strings.Contains(err.Error(), "opens registry (5000), other (5300) to the mesh") {
|
// A-461, A-452: a node that reaches no store address (a holder opening two listens to the mesh, so none is a guess, or a holder
|
||||||
t.Errorf("a holder opening two listens to the mesh: %v", err)
|
// laid name-only, found by nobody) costs the modules that fetch from it, whatever the shape of the fetch (an image, a tools
|
||||||
|
// bundle of the runtime), and never the node: they wait with the words of an unanswered requirement, and the rest composes.
|
||||||
|
dg := "sha256:" + strings.Repeat("a", 64)
|
||||||
|
in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1",
|
||||||
|
Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@" + dg}}}
|
||||||
|
in.Catalogue["node-tools"] = catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||||
|
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/node-tools/broker"}},
|
||||||
|
Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg,
|
||||||
|
Digest: dg, Language: "go", Binary: "node-tools"}}}
|
||||||
|
in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1",
|
||||||
|
Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/plain", "mode": "0700"}}}
|
||||||
|
laptop := nodeOf(t, &in, "laptop")
|
||||||
|
laptop.Assigned = append(laptop.Assigned, "app", "node-tools", "plain")
|
||||||
|
laptop.SealingKey = keyOf(t, "laptop")
|
||||||
|
in.BusMinted = []string{"laptop.node-tools"}
|
||||||
|
got, err := Render(in, "laptop", Reading)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("a holder opening two listens to the mesh refuses the whole node: %v", err)
|
||||||
|
}
|
||||||
|
if got.Rendering.ArtifactStore != "" {
|
||||||
|
t.Errorf("the store has an address: %q", got.Rendering.ArtifactStore)
|
||||||
|
}
|
||||||
|
d, _, err := Compose(in, "laptop")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("a node that reaches no store address is refused whole: %v", err)
|
||||||
|
}
|
||||||
|
for _, m := range []string{"app", "node-tools"} {
|
||||||
|
if why := d.LeftOutWhy[m]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "no artifact store") {
|
||||||
|
t.Errorf("%s, which fetches from the store, waits with %q", m, why)
|
||||||
|
}
|
||||||
|
// Held, not only left out: it stays on the build it runs and its handed composition is kept (A-452).
|
||||||
|
if why := d.Held[m]; !strings.Contains(why, "nothing provides") {
|
||||||
|
t.Errorf("%s, which fetches from the store, is held with %q", m, why)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, held := d.Held["plain"]; held {
|
||||||
|
t.Errorf("a module that fetches nothing from the store is held")
|
||||||
|
}
|
||||||
|
if why, held := d.LeftOutWhy["plain"]; held {
|
||||||
|
t.Errorf("a module that fetches nothing from the store waits: %q", why)
|
||||||
|
}
|
||||||
|
if !slices.ContainsFunc(d.Resources, func(r map[string]any) bool { return r["id"] == "plain.state" }) {
|
||||||
|
t.Errorf("the rest of the node was not composed: %v", d.Resources)
|
||||||
|
}
|
||||||
|
// A-461b: only the listen refusal holds the store's fetchers; any other fault of finding the store (here the holder's machine is
|
||||||
|
// on the network as first read but unknown when its assignment is read) still refuses the node.
|
||||||
|
broken := newComposer(in)
|
||||||
|
broken.onTheNetwork()
|
||||||
|
broken.in.Nodes = []Node{*nodeOf(t, &in, "laptop")}
|
||||||
|
if _, err := broken.places("laptop", Resolved{}); err == nil || !strings.Contains(err.Error(), "reading what anchor is assigned") {
|
||||||
|
t.Errorf("a fault of finding the store other than its listen refusal did not refuse the node: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ import (
|
|||||||
"github.com/novox/mesh-host/internal/registryforms"
|
"github.com/novox/mesh-host/internal/registryforms"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NoStoreError is a module that fetches from the artifact store while this node reaches none: it costs that module, never the
|
||||||
|
// node. The caller leaves the module out of the declaration, with these words (design 47 G A-461, A-452; ADR 0163 rule 6).
|
||||||
|
type NoStoreError struct {
|
||||||
|
Module string
|
||||||
|
said string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NoStoreError) Error() string {
|
||||||
|
return fmt.Sprintf("nothing provides %q, wanted by %s: %s", "the artifact store's address", e.Module, e.said)
|
||||||
|
}
|
||||||
|
|
||||||
// artifactsInto composes the artifact store's address into a resource's `image` and `source`.
|
// artifactsInto composes the artifact store's address into a resource's `image` and `source`.
|
||||||
//
|
//
|
||||||
// **Composed here, at the last moment before a machine, and stored nowhere.** A kept reference is
|
// **Composed here, at the last moment before a machine, and stored nowhere.** A kept reference is
|
||||||
@@ -35,11 +46,11 @@ func artifactsInto(resource map[string]any, module string, with mcat.Rendering)
|
|||||||
}
|
}
|
||||||
if _, kept := registryforms.Forms.InArtifactStore(written); kept {
|
if _, kept := registryforms.Forms.InArtifactStore(written); kept {
|
||||||
if with.ArtifactStore == "" {
|
if with.ArtifactStore == "" {
|
||||||
return fmt.Errorf(
|
return &NoStoreError{Module: module, said: fmt.Sprintf(
|
||||||
"%s's %v names %s, which is in the mesh's artifact store, and this mesh has no "+
|
"%s's %v names %s, which is in the mesh's artifact store, and this mesh has no "+
|
||||||
"artifact store on its network to fetch it from — nothing assigned holds the seat "+
|
"artifact store on its network to fetch it from — nothing assigned holds the seat "+
|
||||||
"container-image-registry, or the machine holding it is not on the private network",
|
"container-image-registry, or the machine holding it is not on the private network",
|
||||||
module, resource["id"], written)
|
module, resource["id"], written)}
|
||||||
}
|
}
|
||||||
resource[key] = registryforms.Forms.Routed(written, with.ArtifactStore)
|
resource[key] = registryforms.Forms.Routed(written, with.ArtifactStore)
|
||||||
imageSeatInto(resource, key, written, with)
|
imageSeatInto(resource, key, written, with)
|
||||||
|
|||||||
@@ -27,45 +27,53 @@ func mailSenderManifest(t *testing.T, own string) mcat.Manifest {
|
|||||||
// 1170/AC1: a family owned by the module's own account lands at 0600, owned by that account — and a module's
|
// 1170/AC1: a family owned by the module's own account lands at 0600, owned by that account — and a module's
|
||||||
// other own secrets (no per-secret owner declared) keep secrets-owner, unchanged.
|
// other own secrets (no per-secret owner declared) keep secrets-owner, unchanged.
|
||||||
func TestAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
|
func TestAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
|
||||||
m := mailSenderManifest(t, "mesh-mail-send")
|
// ADR 0680 §1, §4: the owner is the account the manifest names: one the module makes, the operator account
|
||||||
m.OwnSecrets["smtp-relay-key"] = mcat.OwnSecret{Path: "/var/lib/mesh-mail/smtp-relay-key", Taken: mcat.TakenAtStart}
|
// (`${machine:account}`, filled with the machine's account) or root.
|
||||||
r := mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{m}}
|
for _, c := range []struct{ name, owner, account, want string }{
|
||||||
out, err := Declaration(r, mcat.Rendering{
|
{"an account the module makes", "mesh-mail-send", "", "mesh-mail-send"},
|
||||||
Needed: map[string]map[string]string{"mesh-mail": {"mail-credential-smtp": "sealed-credential", "smtp-relay-key": "sealed-relay"}},
|
{"the operator account", "${machine:account}", "ops", "ops"},
|
||||||
})
|
{"root", "root", "ops", "root"},
|
||||||
if err != nil {
|
} {
|
||||||
t.Fatalf("composing the declaration: %v", err)
|
t.Run(c.name, func(t *testing.T) {
|
||||||
}
|
m := mailSenderManifest(t, c.owner)
|
||||||
var family, plain map[string]any
|
m.OwnSecrets["smtp-relay-key"] = mcat.OwnSecret{Path: "/var/lib/mesh-mail/smtp-relay-key", Taken: mcat.TakenAtStart}
|
||||||
for _, res := range out {
|
r := mcat.Resolution{Node: "novox", Account: c.account, Modules: []mcat.Manifest{m}}
|
||||||
if res["type"] != "file" {
|
out, err := Declaration(r, mcat.Rendering{
|
||||||
continue
|
Needed: map[string]map[string]string{"mesh-mail": {"mail-credential-smtp": "sealed-credential", "smtp-relay-key": "sealed-relay"}},
|
||||||
}
|
})
|
||||||
switch res["path"] {
|
if err != nil {
|
||||||
case "/var/lib/mesh-mail/mail-credential-smtp.secret":
|
t.Fatalf("composing the declaration: %v", err)
|
||||||
family = res
|
}
|
||||||
case "/var/lib/mesh-mail/smtp-relay-key":
|
var family, plain map[string]any
|
||||||
plain = res
|
for _, res := range out {
|
||||||
}
|
if res["type"] != "file" {
|
||||||
}
|
continue
|
||||||
if family == nil {
|
}
|
||||||
t.Fatalf("the family member was not composed at all: %v", out)
|
switch res["path"] {
|
||||||
}
|
case "/var/lib/mesh-mail/mail-credential-smtp.secret":
|
||||||
if got := family["owner"]; got != "mesh-mail-send" {
|
family = res
|
||||||
t.Fatalf("the family member's owner: %v; want mesh-mail-send", got)
|
case "/var/lib/mesh-mail/smtp-relay-key":
|
||||||
}
|
plain = res
|
||||||
// review round 1, finding 7: asserted, not merely logged. ownedBy never sets "mode", so a sealed secret
|
}
|
||||||
// file carries none here either — the host applies 0600 to every one regardless (novox/hq ADR 0086) —
|
}
|
||||||
// and the owner clause must not have added one of its own that could override that.
|
if family == nil {
|
||||||
if _, has := family["mode"]; has {
|
t.Fatalf("the family member was not composed at all: %v", out)
|
||||||
t.Fatalf("the family member carries its own mode %v; the owner clause must not set one, so the "+
|
}
|
||||||
"host's 0600 for every sealed secret file stands", family["mode"])
|
if got := family["owner"]; got != c.want {
|
||||||
}
|
t.Fatalf("the family member's owner: %v; want %s", got, c.want)
|
||||||
if plain == nil {
|
}
|
||||||
t.Fatalf("the module's other own secret was not composed at all: %v", out)
|
// ownedBy never sets "mode", so a sealed secret file carries none here either: the host applies
|
||||||
}
|
// 0600 to every one regardless (novox/hq ADR 0086), and the owner clause must not override it.
|
||||||
if got := plain["owner"]; got != "mesh-mail" {
|
if _, has := family["mode"]; has {
|
||||||
t.Fatalf("a secret with no per-secret owner kept %v; want the module's secrets-owner %q", got, "mesh-mail")
|
t.Fatalf("the family member carries its own mode %v; the host's 0600 must stand", family["mode"])
|
||||||
|
}
|
||||||
|
if plain == nil {
|
||||||
|
t.Fatalf("the module's other own secret was not composed at all: %v", out)
|
||||||
|
}
|
||||||
|
if got := plain["owner"]; got != "mesh-mail" {
|
||||||
|
t.Fatalf("a secret with no per-secret owner kept %v; want the module's secrets-owner %q", got, "mesh-mail")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// 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.
|
// 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 {
|
func (r *Refusal) Error() string {
|
||||||
return "these assignments cannot be applied:\n - " + strings.Join(r.Problems, "\n - ")
|
return "these assignments cannot be applied:\n - " + strings.Join(r.Problems, "\n - ")
|
||||||
@@ -181,6 +193,22 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
|||||||
absent[want] = true
|
absent[want] = true
|
||||||
reported[want] = true
|
reported[want] = true
|
||||||
}
|
}
|
||||||
|
// A requirement nothing answers costs the modules that want it, not the machine (A-452, ADR 0636 §3): said once per name,
|
||||||
|
// each consumer is held after the walk, when the set is known.
|
||||||
|
// The value is the remedy the mesh-wide refusal adds, empty for a requirement nothing on the node answers.
|
||||||
|
unanswered := map[string]string{}
|
||||||
|
var unansweredOrder []string
|
||||||
|
holdWhenUnanswered := func(want, remedy string) {
|
||||||
|
if !wantedHard(want) && wantedOptionally(want) {
|
||||||
|
// Only optional consumers: left absent, never held (ADR 0330 §3).
|
||||||
|
leaveAbsent(want)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, ok := unanswered[want]; !ok {
|
||||||
|
unansweredOrder = append(unansweredOrder, want)
|
||||||
|
}
|
||||||
|
unanswered[want] = remedy
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if len(queue) == 0 {
|
if len(queue) == 0 {
|
||||||
@@ -373,9 +401,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
|||||||
} else if len(answers) > 1 {
|
} else if len(answers) > 1 {
|
||||||
remedy = "— assign one of these to a node: " + strings.Join(answers, ", ")
|
remedy = "— assign one of these to a node: " + strings.Join(answers, ", ")
|
||||||
}
|
}
|
||||||
problems = append(problems, fmt.Sprintf(
|
// Not answered on the node nor in the rest of the mesh: costs its consumers only (A-452).
|
||||||
"nothing in this mesh provides %q, wanted by %s %s",
|
holdWhenUnanswered(want, remedy)
|
||||||
want, because[want], remedy))
|
|
||||||
case len(where) == 1:
|
case len(where) == 1:
|
||||||
if c, pinned := world.Pinned[want]; pinned && !chosenMatches(c, where[0]) {
|
if c, pinned := world.Pinned[want]; pinned && !chosenMatches(c, where[0]) {
|
||||||
// One provider, and it is not the one this machine was told to use. Silently
|
// One provider, and it is not the one this machine was told to use. Silently
|
||||||
@@ -483,8 +510,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
reported[want] = true
|
reported[want] = true
|
||||||
problems = append(problems, fmt.Sprintf(
|
holdWhenUnanswered(want, "")
|
||||||
"nothing provides %q, wanted by %s", want, because[want]))
|
|
||||||
continue
|
continue
|
||||||
case 1:
|
case 1:
|
||||||
// No choice to make, so none is made. This is the case that lets `install i3` bring
|
// No choice to make, so none is made. This is the case that lets `install i3` bring
|
||||||
@@ -591,15 +617,19 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
|||||||
resolution := mcat.Resolution{Node: node.Name, At: node.At, PublicDomain: node.PublicDomain,
|
resolution := mcat.Resolution{Node: node.Name, At: node.At, PublicDomain: node.PublicDomain,
|
||||||
Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount,
|
Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount,
|
||||||
AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities,
|
AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities,
|
||||||
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept,
|
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept}
|
||||||
Absent: absentOf(absent, order, catalogue)}
|
|
||||||
for _, n := range providersFirst(order, catalogue) {
|
for _, n := range providersFirst(order, catalogue) {
|
||||||
resolution.Modules = append(resolution.Modules, catalogue[n])
|
resolution.Modules = append(resolution.Modules, catalogue[n])
|
||||||
}
|
}
|
||||||
|
|
||||||
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
||||||
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
||||||
problems = append(problems, checkResources(resolution.Modules)...)
|
held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held, absent)
|
||||||
|
// 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...)
|
||||||
|
owned, twice := resourceProblems(resolution.Modules)
|
||||||
|
problems = append(problems, owned...)
|
||||||
resolution.Claims = claims
|
resolution.Claims = claims
|
||||||
|
|
||||||
// Judged over the closure — what this node will actually run — so a holder pulled in by a
|
// Judged over the closure — what this node will actually run — so a holder pulled in by a
|
||||||
@@ -624,7 +654,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
|||||||
problems = append(problems, why)
|
problems = append(problems, why)
|
||||||
}
|
}
|
||||||
sort.Strings(problems)
|
sort.Strings(problems)
|
||||||
return mcat.Resolution{}, nil, &Refusal{Problems: problems}
|
return mcat.Resolution{}, nil, &Refusal{Problems: problems, OwnedTwice: twice}
|
||||||
}
|
}
|
||||||
return resolution, held, nil
|
return resolution, held, nil
|
||||||
}
|
}
|
||||||
@@ -680,6 +710,58 @@ func checkCapabilities(modules []mcat.Manifest, node mcat.Node) []string {
|
|||||||
return problems
|
return problems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unansweredWords is why a consumer is held for a requirement nothing answers, naming the provision.
|
||||||
|
func unansweredWords(want, consumer, remedy string) string {
|
||||||
|
if remedy == "" {
|
||||||
|
return fmt.Sprintf("nothing provides %q, wanted by %s", want, consumer)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("nothing in this mesh provides %q, wanted by %s %s", want, consumer, remedy)
|
||||||
|
}
|
||||||
|
|
||||||
|
// holdUnanswered holds each module of the set that wants a requirement nothing answers, with the words "nothing provides" naming the
|
||||||
|
// provision (A-452): it stays in the set, so what it provides still counts for the others. A requirement none of the set's modules
|
||||||
|
// wants (an assigned name the catalogue does not know) has no consumer to hold and comes back as a problem of the node; so does a
|
||||||
|
// set whose every module is held, since then nothing could be composed.
|
||||||
|
func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[string]string, because map[string]string, held map[string]string, absent map[string]bool) (map[string]string, []string) {
|
||||||
|
var problems []string
|
||||||
|
for _, want := range unanswered {
|
||||||
|
found := false
|
||||||
|
for _, m := range modules {
|
||||||
|
wants := false
|
||||||
|
for _, w := range m.Wants() {
|
||||||
|
if w == want {
|
||||||
|
wants = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !wants {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
found = true
|
||||||
|
if m.IsOptional(want) {
|
||||||
|
// Optional for this module: not held, left absent and listed (ADR 0330 §3, §7).
|
||||||
|
absent[want] = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if held == nil {
|
||||||
|
held = map[string]string{}
|
||||||
|
}
|
||||||
|
why := unansweredWords(want, m.Module, remedies[want])
|
||||||
|
if prior, ok := held[m.Module]; ok {
|
||||||
|
why = prior + "; " + why
|
||||||
|
}
|
||||||
|
held[m.Module] = why
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
problems = append(problems, unansweredWords(want, because[want], remedies[want]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(unanswered) > 0 && len(held) >= len(modules) {
|
||||||
|
problems = append(problems, "no module of the node could be composed: every one is held")
|
||||||
|
}
|
||||||
|
return held, problems
|
||||||
|
}
|
||||||
|
|
||||||
// holdClaims refuses two modules holding one singular thing, within this node's own set and against what is held elsewhere for
|
// holdClaims refuses two modules holding one singular thing, within this node's own set and against what is held elsewhere for
|
||||||
// the wider scopes: the claims that hold, and for each module that cannot hold what it claims, why (every reason, joined).
|
// the wider scopes: the claims that hold, and for each module that cannot hold what it claims, why (every reason, joined).
|
||||||
func holdClaims(modules []mcat.Manifest, node mcat.Node, elsewhere []mcat.Held, holdings []mcat.Held) ([]mcat.Held, map[string]string) {
|
func holdClaims(modules []mcat.Manifest, node mcat.Node, elsewhere []mcat.Held, holdings []mcat.Held) ([]mcat.Held, map[string]string) {
|
||||||
@@ -841,6 +923,13 @@ func canonicalSeat(name string) string {
|
|||||||
// resolves with no refusal. What is refused is the contradiction — a path one module owns and
|
// 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.
|
// another merely accesses — because shared data is the operator's and nobody's to own.
|
||||||
func checkResources(modules []mcat.Manifest) []string {
|
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
|
// 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).
|
// uplink holder's rendering of it is not composed, so it is not a second owner (novox/hq ADR 0247).
|
||||||
modules = steppedBack(modules)
|
modules = steppedBack(modules)
|
||||||
@@ -918,6 +1007,9 @@ func checkResources(modules []mcat.Manifest) []string {
|
|||||||
if other, taken := owner[key]; taken && other != m.Module {
|
if other, taken := owner[key]; taken && other != m.Module {
|
||||||
problems = append(problems, fmt.Sprintf(
|
problems = append(problems, fmt.Sprintf(
|
||||||
"%s and %s both declare the %s %q", other, m.Module, field, value))
|
"%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
|
owner[key] = m.Module
|
||||||
if field == "path" {
|
if field == "path" {
|
||||||
@@ -938,6 +1030,7 @@ func checkResources(modules []mcat.Manifest) []string {
|
|||||||
if other, taken := owner[key]; taken && other != m.Module {
|
if other, taken := owner[key]; taken && other != m.Module {
|
||||||
problems = append(problems, fmt.Sprintf(
|
problems = append(problems, fmt.Sprintf(
|
||||||
"%s and %s both declare the path %q", other, m.Module, fact.Path))
|
"%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
|
owner[key] = m.Module
|
||||||
ownedPath[fact.Path] = m.Module
|
ownedPath[fact.Path] = m.Module
|
||||||
@@ -973,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.
|
// meshNetwork is what to assign to a machine that needs to reach another one.
|
||||||
|
|||||||
@@ -53,31 +53,75 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestARequirementWithSeveralAnswersIsRefusedAndNamed(t *testing.T) {
|
// A requirement nothing answers costs the modules that want it, not the machine (A-452; ace, 2026-11-16 23:11: ten unanswered
|
||||||
// The mesh does not pick. A default would be a choice made for somebody who finds out later,
|
// requirements refused the whole composition), whether nothing on the node or nothing in the whole mesh answers it; one that
|
||||||
// and naming the candidates is the whole remedy.
|
// only optional consumers want is left absent (ADR 0330 §3); several answers are still the node's refusal, naming them (the
|
||||||
_, err := Resolve(shelf(
|
// mesh does not pick: a default would be a choice made for somebody who finds out later); and a node whose every module is held,
|
||||||
mod("editor", nil, []string{"shell"}, nil),
|
// or an assigned name nobody wants, is still refused.
|
||||||
mod("bash", []string{"shell"}, nil, nil),
|
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
||||||
mod("zsh", []string{"shell"}, nil, nil),
|
optional := mod("viewer", nil, []string{"codec"}, nil)
|
||||||
mod("fish", []string{"shell"}, nil, nil),
|
optional.OptionalRequires = map[string]bool{"codec": true}
|
||||||
), []string{"editor"}, workstation(), mcat.World{})
|
hard := mod("player", nil, []string{"codec"}, nil)
|
||||||
|
meshDB := mcat.Manifest{Module: "postgres", Provides: []mcat.Offer{{Name: "postgres-database", Scope: mcat.ScopeMesh}}}
|
||||||
if err == nil {
|
for _, c := range []struct {
|
||||||
t.Fatal("a requirement with three answers was resolved without asking")
|
name string
|
||||||
}
|
shelf map[string]mcat.Manifest
|
||||||
for _, want := range []string{"bash", "fish", "zsh", "choose one"} {
|
assigned []string
|
||||||
if !strings.Contains(err.Error(), want) {
|
held map[string]string // module -> words in its why
|
||||||
t.Errorf("the refusal does not mention %q: %v", want, err)
|
refused []string // words of the node's refusal
|
||||||
}
|
absent bool
|
||||||
}
|
}{
|
||||||
}
|
{name: "on the node", assigned: []string{"ca-trust", "baserow", "sheet-viewer", "editor"},
|
||||||
|
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil),
|
||||||
func TestARequirementWithNoAnswerIsRefused(t *testing.T) {
|
mod("baserow", []string{"spreadsheet"}, []string{"route"}, nil),
|
||||||
_, err := Resolve(shelf(mod("i3", nil, []string{"xorg"}, nil)), []string{"i3"}, workstation(), mcat.World{})
|
mod("sheet-viewer", nil, []string{"spreadsheet"}, nil), mod("editor", nil, nil, nil)),
|
||||||
|
held: map[string]string{"ca-trust": `nothing provides "internal-acme-ca"`, "baserow": `nothing provides "route"`}},
|
||||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") {
|
{name: "in the whole mesh", assigned: []string{"baserow", "editor"},
|
||||||
t.Fatalf("a requirement nothing satisfies gave %v", err)
|
shelf: shelf(meshDB, mod("baserow", nil, []string{"postgres-database"}, nil), mod("editor", nil, nil, nil)),
|
||||||
|
held: map[string]string{"baserow": `nothing in this mesh provides "postgres-database", wanted by baserow`}},
|
||||||
|
{name: "wanted hard by one and optionally by another", assigned: []string{"player", "viewer"},
|
||||||
|
shelf: shelf(hard, optional), held: map[string]string{"player": `nothing provides "codec"`}, absent: true},
|
||||||
|
{name: "every module held", assigned: []string{"ca-trust"},
|
||||||
|
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
|
||||||
|
refused: []string{"nothing provides", "every one is held"}},
|
||||||
|
{name: "nobody wants it", assigned: []string{"ghost"}, shelf: shelf(mod("editor", nil, nil, nil)),
|
||||||
|
refused: []string{"nothing provides"}},
|
||||||
|
{name: "several answers", assigned: []string{"editor"},
|
||||||
|
shelf: shelf(mod("editor", nil, []string{"shell"}, nil), mod("bash", []string{"shell"}, nil, nil),
|
||||||
|
mod("zsh", []string{"shell"}, nil, nil), mod("fish", []string{"shell"}, nil, nil)),
|
||||||
|
refused: []string{"bash", "fish", "zsh", "choose one"}},
|
||||||
|
} {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
got, held, err := ResolveHolding(c.shelf, c.assigned, workstation(), mcat.World{})
|
||||||
|
if c.refused != nil {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("the node was composed, not refused")
|
||||||
|
}
|
||||||
|
for _, w := range c.refused {
|
||||||
|
if !strings.Contains(err.Error(), w) {
|
||||||
|
t.Errorf("the refusal does not mention %q: %v", w, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("the node was refused whole: %v", err)
|
||||||
|
}
|
||||||
|
if len(held) != len(c.held) {
|
||||||
|
t.Errorf("held %v, want modules %v", held, c.held)
|
||||||
|
}
|
||||||
|
for m, w := range c.held {
|
||||||
|
if !strings.Contains(held[m], w) {
|
||||||
|
t.Errorf("%s is held with %q, want %q", m, held[m], w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, heldToo := held["viewer"]; c.absent && (heldToo || len(got.Absent) != 1 || got.Absent[0] != (mcat.Absent{Consumer: "viewer", Requirement: "codec"})) {
|
||||||
|
t.Errorf("the optional consumer was held or not listed absent: held %v absent %v", held, got.Absent)
|
||||||
|
}
|
||||||
|
if len(got.Modules) != len(c.assigned) {
|
||||||
|
t.Errorf("the node does not keep every module of its set: %v", names(got))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -291,22 +291,31 @@ func (c *composer) resolutionHolding(nodeName string) (catalogue.Resolution, map
|
|||||||
At: onNetwork[nodeName], PublicDomain: node.PublicDomain,
|
At: onNetwork[nodeName], PublicDomain: node.PublicDomain,
|
||||||
Account: node.Account, AccountHome: node.AccountHome,
|
Account: node.Account, AccountHome: node.AccountHome,
|
||||||
AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome}, world)
|
AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome}, world)
|
||||||
if err != nil {
|
// What another node's set would have offered is missing when that set does not resolve here: said with the refusal, and with
|
||||||
// What another node's set would have offered is missing when that set does not resolve here: said with the
|
// each module held for a requirement nothing answers, so "nothing provides" is read beside why (issue 1126, probe #532).
|
||||||
// refusal, so "nothing provides" is read beside why (issue 1126, probe #532).
|
why := func() string {
|
||||||
|
var out string
|
||||||
if len(left) > 0 {
|
if len(left) > 0 {
|
||||||
var why []string
|
var parts []string
|
||||||
for _, l := range left {
|
for _, l := range left {
|
||||||
why = append(why, l.String())
|
parts = append(parts, l.String())
|
||||||
}
|
}
|
||||||
err = fmt.Errorf("%w\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", err, len(left), strings.Join(why, "; "))
|
out += fmt.Sprintf("\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", len(left), strings.Join(parts, "; "))
|
||||||
}
|
}
|
||||||
if len(c.unhostable) > 0 {
|
if len(c.unhostable) > 0 {
|
||||||
err = fmt.Errorf("%w\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s",
|
out += fmt.Sprintf("\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s",
|
||||||
err, strings.Join(c.unhostable, "; "))
|
strings.Join(c.unhostable, "; "))
|
||||||
}
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
// The node's own set does not compose: the only failure a mesh-wide gatherer may pass over.
|
// The node's own set does not compose: the only failure a mesh-wide gatherer may pass over.
|
||||||
return catalogue.Resolution{}, nil, notResolvable{err}
|
return catalogue.Resolution{}, nil, notResolvable{fmt.Errorf("%w%s", err, why())}
|
||||||
|
}
|
||||||
|
for m, w := range held {
|
||||||
|
if strings.Contains(w, "nothing provides") || strings.Contains(w, "nothing in this mesh provides") {
|
||||||
|
held[m] = w + why()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resolved, held, nil
|
return resolved, held, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,9 @@ func TestARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
|
|||||||
// 1362/AC5: a node whose own set does not compose returns an error callers can tell from an unreadable Input.
|
// 1362/AC5: a node whose own set does not compose returns an error callers can tell from an unreadable Input.
|
||||||
func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
|
func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
|
||||||
in := aMesh(t)
|
in := aMesh(t)
|
||||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"nothing-gives-this"}}
|
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"two-give-this"}}
|
||||||
|
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||||
|
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||||
laptop := nodeOf(t, &in, "laptop")
|
laptop := nodeOf(t, &in, "laptop")
|
||||||
laptop.Assigned = append(laptop.Assigned, "rival-one")
|
laptop.Assigned = append(laptop.Assigned, "rival-one")
|
||||||
if _, err := Resolve(in, "laptop"); err == nil || !IsUnresolvable(err) {
|
if _, err := Resolve(in, "laptop"); err == nil || !IsUnresolvable(err) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package composer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
"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"
|
||||||
"github.com/novox/mesh-host/internal/compose/frombus"
|
"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.
|
// The shapes of mesh-sdk's composer package, by the names this package's code was written with.
|
||||||
@@ -236,8 +238,21 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
|
|||||||
}
|
}
|
||||||
cv.Machines = map[string]Machine{}
|
cv.Machines = map[string]Machine{}
|
||||||
for _, node := range r.Machines {
|
for _, node := range r.Machines {
|
||||||
m := machine(in, node, depth, r.Declarations)
|
// A module awaited on node whose build can never be made, the revision giving it no fingerprint (Case.None), does
|
||||||
if words := awaitedOn(in, node, awaited); words != "" {
|
// not leave the machine not judged: it is held as its node-engine holds it, the machine judged from that
|
||||||
|
// composition, and the module blamed with the revision's none words (design 47 G A-470j, A-470k). Each other
|
||||||
|
// awaited build keeps the machine not judged, as below.
|
||||||
|
never, pending := neverOn(in, node, awaited, c.None)
|
||||||
|
at := in // the input m is composed from
|
||||||
|
if len(never) > 0 {
|
||||||
|
at = heldAgain(in, held, never)
|
||||||
|
}
|
||||||
|
// The one search for culprits runs inside the node-engine's composition (frombus.ComposeSent), over the case's
|
||||||
|
// changed modules on node, bounded by the request's blame_tries; a request with none gets no search (design 47 G
|
||||||
|
// §721; A-468i, A-469j, A-469k).
|
||||||
|
search := frombus.Search{Changed: changedOn(in, node, c, held.ComposedHow), Tries: r.BlameTries}
|
||||||
|
m := machine(at, node, depth, r.Declarations, search)
|
||||||
|
if words := awaitedOn(at, node, pending); words != "" {
|
||||||
// Composed without the build it runs at: named per node and module, never a silent pass (issue 1921). The
|
// 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
|
// machine is then not judged, as for a node whose running state its engine does not send (ADR 0593 §9). Where
|
||||||
// it does not compose without that build (a tool runner's bundle), it is composed with the module held as its
|
// it does not compose without that build (a tool runner's bundle), it is composed with the module held as its
|
||||||
@@ -247,7 +262,8 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
|
|||||||
// shanks).
|
// shanks).
|
||||||
how := "composed from the change's manifest without its build: "
|
how := "composed from the change's manifest without its build: "
|
||||||
if !m.Composes && m.NotJudged == "" {
|
if !m.Composes && m.NotJudged == "" {
|
||||||
switch again := machine(heldAgain(in, held, awaited), node, depth, r.Declarations); {
|
lifted := heldAgain(at, held, pending)
|
||||||
|
switch again := machine(lifted, node, depth, r.Declarations, search); {
|
||||||
case again.Composes:
|
case again.Composes:
|
||||||
m, how = again, "composed with it held as its node-engine holds it, since it does not compose without its build: "
|
m, how = again, "composed with it held as its node-engine holds it, since it does not compose without its build: "
|
||||||
case again.NotJudged == "":
|
case again.NotJudged == "":
|
||||||
@@ -261,6 +277,12 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
|
|||||||
m.Reason += "; " + words
|
m.Reason += "; " + words
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(never) > 0 && m.NotJudged == "" {
|
||||||
|
m = blameNever(m, never, c.None) // after the held composition is judged, its search and the awaited words included
|
||||||
|
}
|
||||||
|
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
|
cv.Machines[node] = m
|
||||||
}
|
}
|
||||||
return cv, nil
|
return cv, nil
|
||||||
@@ -415,6 +437,54 @@ func heldAgain(in, held compose.Input, awaited map[string]string) compose.Input
|
|||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// neverOn splits the modules overrule lifted with their build awaited: never is each placed on node whose build can never
|
||||||
|
// be made, the case naming it in None (the revision gives it no fingerprint), with its awaited words; pending is awaited
|
||||||
|
// without them (design 47 G A-470j, A-470k).
|
||||||
|
func neverOn(in compose.Input, node string, awaited, none map[string]string) (never, pending map[string]string) {
|
||||||
|
pending = awaited
|
||||||
|
for _, mod := range assignedOn(in, node) {
|
||||||
|
if _, unbuildable := none[mod]; !unbuildable || awaited[mod] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if never == nil {
|
||||||
|
never, pending = map[string]string{}, maps.Clone(awaited)
|
||||||
|
}
|
||||||
|
never[mod] = awaited[mod]
|
||||||
|
delete(pending, mod)
|
||||||
|
}
|
||||||
|
return never, pending
|
||||||
|
}
|
||||||
|
|
||||||
|
// blameNever is m, judged with each of never held (its blames and the search already in it), with each of never blamed
|
||||||
|
// with the revision's none words, in place of any problem its composition gave it: the machine composes with none of
|
||||||
|
// them, so it does not compose, and says why (design 47 G §721, A-470j). A held composition that still fails and blames
|
||||||
|
// nobody stays on the node's own account (§722): none of never is blamed in its place.
|
||||||
|
func blameNever(m Machine, never, none map[string]string) Machine {
|
||||||
|
mods := slices.Sorted(maps.Keys(never))
|
||||||
|
var said []string
|
||||||
|
for _, mod := range mods {
|
||||||
|
said = append(said, mod+" ("+none[mod]+")")
|
||||||
|
}
|
||||||
|
words := "composed with it held as its node-engine holds it, since its build can never be made: " + strings.Join(said, ", ")
|
||||||
|
if !m.Composes && len(m.Blamed) == 0 {
|
||||||
|
m.Reason += "; " + words
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
if m.Composes {
|
||||||
|
m.Composes, m.Reason = false, words
|
||||||
|
} else {
|
||||||
|
m.Reason += "; " + words
|
||||||
|
}
|
||||||
|
for _, mod := range mods {
|
||||||
|
if i := slices.IndexFunc(m.Blamed, func(b blame) bool { return b.Module == mod }); i >= 0 {
|
||||||
|
m.Blamed[i].Problem = none[mod]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m.Blamed = append(m.Blamed, blame{Module: mod, Problem: none[mod]})
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
// awaitedOn is the words of each module placed on node that is composed without its build (overrule), joined, sorted.
|
// awaitedOn is the words of each module placed on node that is composed without its build (overrule), joined, sorted.
|
||||||
func awaitedOn(in compose.Input, node string, awaited map[string]string) string {
|
func awaitedOn(in compose.Input, node string, awaited map[string]string) string {
|
||||||
var out []string
|
var out []string
|
||||||
@@ -452,19 +522,26 @@ func HoldingsOf(shelf map[string]catalogue.Manifest, nodes []compose.Node) []cat
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
func machine(in compose.Input, node, depth string, declarations bool, search frombus.Search) Machine {
|
||||||
if depth == DepthResolve {
|
if depth == DepthResolve {
|
||||||
if _, err := compose.Resolve(in, node); err != nil {
|
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}
|
return Machine{Composes: true}
|
||||||
}
|
}
|
||||||
// Composed as the node-engine composes it, when its input says how (compose.Input.ComposedHow, issue 774): the same
|
// Composed as the node-engine composes it, when its input says how (compose.Input.ComposedHow, issue 774): the same
|
||||||
// path, at the same builds, a module folded in its own composition kept as it runs.
|
// path, at the same builds, a module folded in its own composition kept as it runs.
|
||||||
if !declarations {
|
if !declarations {
|
||||||
if _, how, err := frombus.ComposeSent(in, node); how {
|
if _, how, err := frombus.ComposeSent(in, node, search); how {
|
||||||
if err != nil {
|
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}
|
return Machine{Composes: true}
|
||||||
}
|
}
|
||||||
@@ -478,7 +555,7 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
|||||||
return Machine{NotJudged: NotJudged + strings.Join(folded, ", ") +
|
return Machine{NotJudged: NotJudged + strings.Join(folded, ", ") +
|
||||||
" (its own composition carries them as they run, and the sandbox cannot): " + err.Error()}
|
" (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()}
|
m := Machine{Composes: len(problems) == 0, Problems: problems, Refusals: d.Refusals()}
|
||||||
if len(problems) > 0 {
|
if len(problems) > 0 {
|
||||||
@@ -490,6 +567,71 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
|
|||||||
return m
|
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 = frombus.NotTried
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
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):
|
// 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
|
// 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.
|
// folded in its own composition. The machine is then neither composed nor refused; a reader decides by the field.
|
||||||
@@ -601,6 +743,7 @@ func manifestOf(how *compose.ComposedHow, module string) string {
|
|||||||
func sameContract(built, carried catalogue.Manifest) bool {
|
func sameContract(built, carried catalogue.Manifest) bool {
|
||||||
contract := func(m catalogue.Manifest) string {
|
contract := func(m catalogue.Manifest) string {
|
||||||
m.Handed, m.Build, m.Templates, m.Resources, m.Bundles, m.Items = nil, nil, "", nil, nil, nil
|
m.Handed, m.Build, m.Templates, m.Resources, m.Bundles, m.Items = nil, nil, "", nil, nil, nil
|
||||||
|
m.TemplatesDigest = "" // written by a take-in (A-481a)
|
||||||
raw, err := json.Marshal(m)
|
raw, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -164,7 +165,7 @@ func TestARequestItCannotRunIsRefused(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if m := refused.Cases[0].Machines["a"]; m.Composes || !strings.Contains(m.Reason, "app: ") || !strings.Contains(m.Reason, "repository") {
|
if m := refused.Cases[0].Machines["a"]; m.Composes || !strings.Contains(m.Reason, "app has a file") || !strings.Contains(m.Reason, "repository") {
|
||||||
t.Errorf("a module the change refuses on a node composed as its node-engine does: %+v", m)
|
t.Errorf("a module the change refuses on a node composed as its node-engine does: %+v", m)
|
||||||
}
|
}
|
||||||
// Held composing without the change, blamed for a refusal beyond the read (issue 1960's unset names): no refusal of
|
// Held composing without the change, blamed for a refusal beyond the read (issue 1960's unset names): no refusal of
|
||||||
@@ -320,24 +321,39 @@ func TestARequestItCannotRunIsRefused(t *testing.T) {
|
|||||||
}
|
}
|
||||||
runner := `{"module": "app", "version": "1", "tool-runner": true, ` +
|
runner := `{"module": "app", "version": "1", "tool-runner": true, ` +
|
||||||
`"build": {"artifacts": [{"name": "runtime", "kind": "bundle", "language": "go", "from": "cmd/runner", "binary": "runner"}]}}`
|
`"build": {"artifacts": [{"name": "runtime", "kind": "bundle", "language": "go", "from": "cmd/runner", "binary": "runner"}]}}`
|
||||||
|
office := `{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}`
|
||||||
for _, row := range []struct {
|
for _, row := range []struct {
|
||||||
name, raw, digest string
|
name, raw, digest string
|
||||||
words string // in NotJudged, its build's paths not declared; "" composes at its build
|
words string // in NotJudged, its build's paths not declared; "" composes at its build
|
||||||
beside string // a module the change refuses on the same node: words are then in the refusal
|
beside string // a module the change refuses on the same node: words are then in the refusal
|
||||||
|
none string // the revision's none words for app (Case.None): judged held, app blamed with them
|
||||||
|
tries int // the request's blame_tries
|
||||||
}{
|
}{
|
||||||
{"the digest of the case's manifest", plain, same, "", ""},
|
{"the digest of the case's manifest", plain, same, "", "", "", 20},
|
||||||
{"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), ""},
|
{"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), "", "", 20},
|
||||||
{"no digest, the same contract", plain, "", "", ""},
|
{"no digest, the same contract", plain, "", "", "", "", 20},
|
||||||
{"no digest, another contract", strings.Replace(plain, `"version": "1"`, `"version": "2"`, 1), "",
|
{"no digest, another contract", strings.Replace(plain, `"version": "1"`, `"version": "2"`, 1), "",
|
||||||
"app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", ""},
|
"app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", "", "", 20},
|
||||||
{"a tool runner, its bundle awaited", runner, "",
|
{"a tool runner, its bundle awaited", runner, "",
|
||||||
"composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", ""},
|
"composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", "", "", 20},
|
||||||
// The group check of c5d32074c945, shanks: the change refused lab there, and the words were those of the
|
// The group check of c5d32074c945, shanks: the change refused lab there, and the words were those of the
|
||||||
// composition from the change's manifests unbuilt ("mesh-build-go runs as its own account and its build
|
// composition from the change's manifests unbuilt ("mesh-build-go runs as its own account and its build
|
||||||
// produced no bundle to serve"), not of the one with them held, so the lift's own refusals failed the node.
|
// produced no bundle to serve"), not of the one with them held, so the lift's own refusals failed the node.
|
||||||
{"a tool runner awaited beside a module the change refuses", runner, "",
|
{"a tool runner awaited beside a module the change refuses", runner, "",
|
||||||
"refused with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1",
|
"refused with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1",
|
||||||
`{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}`},
|
office, "", 20},
|
||||||
|
// G-24 H3 (A-470j, A-470k; live at revision 449, lidarr, radarr and gitea): a build the revision gives no
|
||||||
|
// fingerprint can never be made, so it does not leave the machine not judged: the machine is judged held, and
|
||||||
|
// app is blamed with the revision's none words. An awaited build the case does not name so stays not judged
|
||||||
|
// (the rows above).
|
||||||
|
{"a build that can never be made, its machine judged held", plain, strings.Repeat("b", 64), "", "", "builders disagree: node 22 and node 24", 20},
|
||||||
|
{"a tool runner whose bundle can never be made", runner, "", "", "", "no build module", 20},
|
||||||
|
// The held composition is judged first, the search included, and the build that can never be made is blamed
|
||||||
|
// beside what it blames (review round 1: office refused beside it went unblamed).
|
||||||
|
{"a build that can never be made beside a module the change refuses", runner, "", "", office, "no build module", 20},
|
||||||
|
// A held composition that still fails and blames nobody else (no search asked) fails on the node's own
|
||||||
|
// account: the build that can never be made is not blamed in its place (§722).
|
||||||
|
{"a build that can never be made beside a refusal nobody is blamed for", runner, "", "", office, "no build module", 0},
|
||||||
} {
|
} {
|
||||||
in := compose.Input{Catalogue: map[string]catalogue.Manifest{"app": built}, Nodes: []compose.Node{{Name: "a", Assigned: []string{"app"}}},
|
in := compose.Input{Catalogue: map[string]catalogue.Manifest{"app": built}, Nodes: []compose.Node{{Name: "a", Assigned: []string{"app"}}},
|
||||||
ComposedHow: &compose.ComposedHow{Node: "a", Builds: map[string]string{"app": "fp1"}}}
|
ComposedHow: &compose.ComposedHow{Node: "a", Builds: map[string]string{"app": "fp1"}}}
|
||||||
@@ -345,16 +361,41 @@ func TestARequestItCannotRunIsRefused(t *testing.T) {
|
|||||||
in.ComposedHow.Manifests = map[string]string{"app": row.digest}
|
in.ComposedHow.Manifests = map[string]string{"app": row.digest}
|
||||||
}
|
}
|
||||||
manifests := map[string]Manifest{"app": {Raw: json.RawMessage(row.raw)}}
|
manifests := map[string]Manifest{"app": {Raw: json.RawMessage(row.raw)}}
|
||||||
|
var none map[string]string
|
||||||
|
if row.none != "" {
|
||||||
|
none = map[string]string{"app": row.none}
|
||||||
|
}
|
||||||
if row.beside != "" {
|
if row.beside != "" {
|
||||||
manifests["office"] = Manifest{Raw: json.RawMessage(row.beside)}
|
manifests["office"] = Manifest{Raw: json.RawMessage(row.beside)}
|
||||||
in.Nodes[0].Assigned = append(in.Nodes[0].Assigned, "office")
|
in.Nodes[0].Assigned = append(in.Nodes[0].Assigned, "office")
|
||||||
}
|
}
|
||||||
v, err := Run(withInput(t, Request{V: Version, Machines: []string{"a"}, Depth: DepthCompose, Declarations: true,
|
// A row with a build that can never be made beside a refused module is composed as its node-engine composes it
|
||||||
Cases: []Case{{Name: "change", Manifests: manifests}}}, in))
|
// (no declarations), where the search for culprits runs (frombus.ComposeSent).
|
||||||
|
v, err := Run(withInput(t, Request{V: Version, Machines: []string{"a"}, Depth: DepthCompose, Declarations: row.none == "" || row.beside == "", BlameTries: row.tries,
|
||||||
|
Cases: []Case{{Name: "change", Manifests: manifests, None: none}}}, in))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
m := v.Cases[0].Machines["a"]
|
m := v.Cases[0].Machines["a"]
|
||||||
|
if row.none != "" {
|
||||||
|
want, problem := []string{"app"}, map[string]string{}
|
||||||
|
switch {
|
||||||
|
case row.beside != "" && row.tries == 0:
|
||||||
|
want = nil
|
||||||
|
case row.beside != "":
|
||||||
|
want = append(want, "office")
|
||||||
|
}
|
||||||
|
var got []string
|
||||||
|
for _, b := range m.Blamed {
|
||||||
|
got, problem[b.Module] = append(got, b.Module), b.Problem
|
||||||
|
}
|
||||||
|
slices.Sort(got)
|
||||||
|
if m.NotJudged != "" || m.Composes || !slices.Equal(got, want) || (want != nil && problem["app"] != row.none) ||
|
||||||
|
!strings.Contains(m.Reason, "its build can never be made") {
|
||||||
|
t.Errorf("%s: machine %+v, want it judged with app held and blamed with %q, and %v blamed", row.name, m, row.none, want)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
if row.beside != "" {
|
if row.beside != "" {
|
||||||
said := fmt.Sprint(m.Reason, m.Problems, m.Refusals)
|
said := fmt.Sprint(m.Reason, m.Problems, m.Refusals)
|
||||||
if m.Composes || m.NotJudged != "" || !strings.Contains(said, "office") || strings.Contains(said, "bundle") || !strings.Contains(m.Reason, row.words) {
|
if m.Composes || m.NotJudged != "" || !strings.Contains(said, "office") || strings.Contains(said, "bundle") || !strings.Contains(m.Reason, row.words) {
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ type Composed struct {
|
|||||||
Own NodeOwn
|
Own NodeOwn
|
||||||
Plan *catalogue.Plan
|
Plan *catalogue.Plan
|
||||||
Refused string
|
Refused string
|
||||||
|
// Templates are the digests of the templates archives the module's files were rendered from, sorted (A-481a).
|
||||||
|
Templates []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucket constants of a node's compositions (the state composed is one bucket per node).
|
// Bucket constants of a node's compositions (the state composed is one bucket per node).
|
||||||
@@ -65,7 +67,7 @@ func BucketFor(node string) (string, error) {
|
|||||||
|
|
||||||
func toClient(c Composed) (nodeengineclient.Composition, error) {
|
func toClient(c Composed) (nodeengineclient.Composition, error) {
|
||||||
out := nodeengineclient.Composition{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data,
|
out := nodeengineclient.Composition{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data,
|
||||||
Resources: c.Resources, Filled: c.Filled, Refused: c.Refused}
|
Resources: c.Resources, Filled: c.Filled, Refused: c.Refused, Templates: c.Templates}
|
||||||
raw, err := json.Marshal(c.Own)
|
raw, err := json.Marshal(c.Own)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return out, err
|
return out, err
|
||||||
@@ -83,7 +85,7 @@ func toClient(c Composed) (nodeengineclient.Composition, error) {
|
|||||||
|
|
||||||
func fromClient(c nodeengineclient.Composition) (Composed, error) {
|
func fromClient(c nodeengineclient.Composition) (Composed, error) {
|
||||||
out := Composed{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, Resources: c.Resources,
|
out := Composed{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, Resources: c.Resources,
|
||||||
Filled: c.Filled, Refused: c.Refused}
|
Filled: c.Filled, Refused: c.Refused, Templates: c.Templates}
|
||||||
raw, err := json.Marshal(c.Own)
|
raw, err := json.Marshal(c.Own)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return out, err
|
return out, err
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ func compareOne(module string, composed, running Composed, sameValue func(a, b s
|
|||||||
switch {
|
switch {
|
||||||
case !jsonEqual(a.Filled, b.Filled):
|
case !jsonEqual(a.Filled, b.Filled):
|
||||||
return differs("", "the files the provisioner fills differ")
|
return differs("", "the files the provisioner fills differ")
|
||||||
|
case !jsonEqual(a.Templates, b.Templates):
|
||||||
|
return differs("", "the templates archives it was rendered from differ")
|
||||||
case a.Data != b.Data:
|
case a.Data != b.Data:
|
||||||
return differs("", "whether it declares data differs")
|
return differs("", "whether it declares data differs")
|
||||||
case !jsonEqual(a.Own, b.Own):
|
case !jsonEqual(a.Own, b.Own):
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,6 +15,7 @@ import (
|
|||||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||||
@@ -52,6 +54,9 @@ type EngineCall struct {
|
|||||||
Verb string
|
Verb string
|
||||||
Caller string
|
Caller string
|
||||||
Args map[string]any
|
Args map[string]any
|
||||||
|
// Line is the link's bus connection, which a verb marked chunks sends its answer's file on (buscalls.SeatChunks.Send); nil
|
||||||
|
// where the call did not come over a live link.
|
||||||
|
Line buscalls.ChunkLine
|
||||||
}
|
}
|
||||||
|
|
||||||
// EngineFunc answers one call: its result, or why it is refused.
|
// EngineFunc answers one call: its result, or why it is refused.
|
||||||
@@ -157,12 +162,17 @@ func (l *natsLink) serveEngineSeat(handle EngineFunc, module string) {
|
|||||||
Description: "the node seat node-engine of " + l.node + " (novox/hq ADR 0563)", QueueGroupDisabled: true,
|
Description: "the node seat node-engine of " + l.node + " (novox/hq ADR 0563)", QueueGroupDisabled: true,
|
||||||
Metadata: map[string]string{"seat": EngineSeat, "scope": "node", "node": l.node}})
|
Metadata: map[string]string{"seat": EngineSeat, "scope": "node", "node": l.node}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("the node seat %s of %s is not served: %v (A-405)", EngineSeat, l.node, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apart := make(chan struct{}, apartAtOnce)
|
apart := make(chan struct{}, apartAtOnce)
|
||||||
|
withLine := func(c EngineCall) (any, error) {
|
||||||
|
c.Line = l.conn // a verb marked chunks sends its file on the link's own connection
|
||||||
|
return handle(c)
|
||||||
|
}
|
||||||
for _, v := range ServedEngineSeat().Serves {
|
for _, v := range ServedEngineSeat().Serves {
|
||||||
verb := v.Name
|
verb := v.Name
|
||||||
answer := EngineAnswer(handle, verb, l.node, apart)
|
answer := EngineAnswer(withLine, verb, l.node, apart)
|
||||||
meta := EngineEndpointMetadata(v, l.node, module)
|
meta := EngineEndpointMetadata(v, l.node, module)
|
||||||
_ = svc.AddEndpoint(verb, answer, micro.WithEndpointSubject(EngineToolSubject(verb, l.node)),
|
_ = svc.AddEndpoint(verb, answer, micro.WithEndpointSubject(EngineToolSubject(verb, l.node)),
|
||||||
micro.WithEndpointMetadata(meta))
|
micro.WithEndpointMetadata(meta))
|
||||||
@@ -172,6 +182,7 @@ func (l *natsLink) serveEngineSeat(handle EngineFunc, module string) {
|
|||||||
l.engineMu.Lock()
|
l.engineMu.Lock()
|
||||||
l.engine = svc
|
l.engine = svc
|
||||||
l.engineMu.Unlock()
|
l.engineMu.Unlock()
|
||||||
|
log.Printf("the node seat %s of %s is served as %s (A-405)", EngineSeat, l.node, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
// answeredApart are the verbs answered off the subscription that delivered them: each endpoint's subscription hands its
|
// answeredApart are the verbs answered off the subscription that delivered them: each endpoint's subscription hands its
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
sdkkeys "git.novox.be/novox/mesh-sdk/go/keys"
|
sdkkeys "git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -175,7 +176,8 @@ type HandActs struct {
|
|||||||
// ComposeCandidate composes a check's candidate (the indexer's candidate key) on this node in shadow and answers per
|
// ComposeCandidate composes a check's candidate (the indexer's candidate key) on this node in shadow and answers per
|
||||||
// module, applying and writing nothing; with input, also the composition input it composed from (the verb
|
// module, applying and writing nothing; with input, also the composition input it composed from (the verb
|
||||||
// compose-candidate, ADR 0593 §7).
|
// compose-candidate, ADR 0593 §7).
|
||||||
ComposeCandidate func(candidate string, input bool) (any, error)
|
// call is the caller's token for the chunks the input is sent in (A-237b) and line the connection they go on; with no token the input is inline.
|
||||||
|
ComposeCandidate func(candidate string, input bool, call string, line buscalls.ChunkLine) (any, error)
|
||||||
// ManifestReads is what this engine states it reads of a manifest and when its record last carried them (the verb
|
// ManifestReads is what this engine states it reads of a manifest and when its record last carried them (the verb
|
||||||
// manifest-reads, novox/hq ADR 0618 §3).
|
// manifest-reads, novox/hq ADR 0618 §3).
|
||||||
ManifestReads func() ([]string, time.Time)
|
ManifestReads func() ([]string, time.Time)
|
||||||
@@ -289,7 +291,7 @@ func (h *HandActs) Call(c EngineCall) (any, error) {
|
|||||||
if b, ok := c.Args["input"].(bool); ok {
|
if b, ok := c.Args["input"].(bool); ok {
|
||||||
input = b
|
input = b
|
||||||
}
|
}
|
||||||
return h.ComposeCandidate(arg("candidate"), input)
|
return h.ComposeCandidate(arg("candidate"), input, arg("call"), c.Line)
|
||||||
case ActManifestReads:
|
case ActManifestReads:
|
||||||
if h.ManifestReads == nil {
|
if h.ManifestReads == nil {
|
||||||
return nil, errors.New("this engine states no manifest reads yet: its node agent has not started")
|
return nil, errors.New("this engine states no manifest reads yet: its node agent has not started")
|
||||||
|
|||||||
+9
@@ -116,6 +116,15 @@
|
|||||||
"$SRV.PING.node-tools.NODE",
|
"$SRV.PING.node-tools.NODE",
|
||||||
"mesh.control.NODE.>",
|
"mesh.control.NODE.>",
|
||||||
"mesh.seat.mesh-catalog.call.entry.node~NODE",
|
"mesh.seat.mesh-catalog.call.entry.node~NODE",
|
||||||
|
"mesh.seat.mesh-catalog.call.module.node~NODE",
|
||||||
|
"mesh.seat.container-image-registry.call.versions.node~NODE",
|
||||||
|
"mesh.seat.mesh-catalog.call.revision.node~NODE",
|
||||||
|
"mesh.seat.mesh-grants.call.withheld.node~NODE",
|
||||||
|
"mesh.seat.mesh-module-assigner.call.assignments.node~NODE",
|
||||||
|
"mesh.seat.mesh-recovery.call.kept-points.node~NODE",
|
||||||
|
"mesh.seat.mesh-recovery.call.restore-kept.node~NODE",
|
||||||
|
"mesh.seat.mesh-recovery.call.snapshot-kept.node~NODE",
|
||||||
|
"mesh.seat.oci-artifact-registry.call.versions.node~NODE",
|
||||||
"mesh.seat.mesh-catalog.call.seat-definitions.node~NODE",
|
"mesh.seat.mesh-catalog.call.seat-definitions.node~NODE",
|
||||||
"mesh.seat.node-backup.call.backed-up.NODE.node~NODE",
|
"mesh.seat.node-backup.call.backed-up.NODE.node~NODE",
|
||||||
"mesh.seat.node-backup.call.now.NODE.node~NODE",
|
"mesh.seat.node-backup.call.now.NODE.node~NODE",
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ import (
|
|||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
"github.com/novox/mesh-host/internal/buckets"
|
"github.com/novox/mesh-host/internal/buckets"
|
||||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
"maps"
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -143,13 +146,7 @@ func (s *Shadow) composeCandidate(ctx context.Context, c *Composer, ask nodeengi
|
|||||||
a.Verdict = nec.Unready
|
a.Verdict = nec.Unready
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
group, heads, err := nec.ParseCompositionKey(ask.Candidate)
|
key, err := nec.ParseCandidateKey(ask.Candidate)
|
||||||
if err != nil {
|
|
||||||
return refuse(err.Error())
|
|
||||||
}
|
|
||||||
// The ask names the check (the composition key, `<group>.<heads hash>`); the indexer keys the group's candidate by
|
|
||||||
// the group alone (buckets.CandidateKey) and holds its heads hash in the value.
|
|
||||||
ckey, err := buckets.CandidateKey(group)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return refuse(err.Error())
|
return refuse(err.Error())
|
||||||
}
|
}
|
||||||
@@ -157,21 +154,48 @@ func (s *Shadow) composeCandidate(ctx context.Context, c *Composer, ask nodeengi
|
|||||||
return unready(errNotReady.Error())
|
return unready(errNotReady.Error())
|
||||||
}
|
}
|
||||||
base := run.add(c.scratch())
|
base := run.add(c.scratch())
|
||||||
raw, err := base.get(ctx, buckets.Candidates, ckey)
|
var cand meshcatalog.CandidatesByGroupValue
|
||||||
if err != nil {
|
var group, heads string
|
||||||
return unready(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
if key.Kind == nec.CandidateRevision {
|
||||||
}
|
// A branch pipeline's catalog graph revision (A-226b): its entries are read through the seat mesh-catalog's verb
|
||||||
if raw == nil {
|
// revision and composed as the candidate, each module at the revision's fingerprint.
|
||||||
return refuse("the indexer holds no candidate " + ask.Candidate)
|
var answered bool
|
||||||
}
|
cand, answered, err = s.revisionCandidate(ctx, base, key)
|
||||||
cand, err := meshcatalog.DecodeCandidatesByGroupValue(raw)
|
if err != nil {
|
||||||
if err != nil {
|
return unready(err.Error())
|
||||||
return refuse(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
}
|
||||||
}
|
if !answered {
|
||||||
if cand.Heads != heads {
|
return refuse(fmt.Sprintf("the catalog holds no revision %d of the branch %s", key.Revision, key.Branch))
|
||||||
// The group moved to other heads: the check asked is replaced, and this node composes not a candidate it was
|
}
|
||||||
// not asked about. No answer (ADR 0593 §9), never a verdict on the wrong heads.
|
} else {
|
||||||
return unready(fmt.Sprintf("the indexer's candidate of the group %s is at heads %s, not %s: the check asked is replaced", group, cand.Heads, heads))
|
group, heads = key.Group, key.HeadsHash
|
||||||
|
if key.Kind == nec.CandidateRun {
|
||||||
|
// A run on request's candidate is the indexer's `candidates.run-<id>`, read by its group as a check's is, with no
|
||||||
|
// heads to compare: the run is asked for by its id alone (A-226c).
|
||||||
|
group, heads = "run-"+key.Run, ""
|
||||||
|
}
|
||||||
|
// The ask names the check (the composition key, `<group>.<heads hash>`); the indexer keys the group's candidate by
|
||||||
|
// the group alone (buckets.CandidateKey) and holds its heads hash in the value.
|
||||||
|
ckey, err := buckets.CandidateKey(group)
|
||||||
|
if err != nil {
|
||||||
|
return refuse(err.Error())
|
||||||
|
}
|
||||||
|
raw, err := base.get(ctx, buckets.Candidates, ckey)
|
||||||
|
if err != nil {
|
||||||
|
return unready(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||||
|
}
|
||||||
|
if raw == nil {
|
||||||
|
return refuse("the indexer holds no candidate " + ask.Candidate)
|
||||||
|
}
|
||||||
|
cand, err = meshcatalog.DecodeCandidatesByGroupValue(raw)
|
||||||
|
if err != nil {
|
||||||
|
return refuse(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||||
|
}
|
||||||
|
if key.Kind == nec.CandidateCheck && cand.Heads != heads {
|
||||||
|
// The group moved to other heads: the check asked is replaced, and this node composes not a candidate it was
|
||||||
|
// not asked about. No answer (ADR 0593 §9), never a verdict on the wrong heads.
|
||||||
|
return unready(fmt.Sprintf("the indexer's candidate of the group %s is at heads %s, not %s: the check asked is replaced", group, cand.Heads, heads))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Every module's manifest is read before either composition, several at once, into the shadow's own: a composition
|
// Every module's manifest is read before either composition, several at once, into the shadow's own: a composition
|
||||||
// reads every manifest in the mesh one by one, which off the control-node took about 35 s each (issue 1126).
|
// reads every manifest in the mesh one by one, which off the control-node took about 35 s each (issue 1126).
|
||||||
@@ -214,7 +238,9 @@ func (s *Shadow) composeCandidate(ctx context.Context, c *Composer, ask nodeengi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if sentSize > maxSentInput {
|
// An ask with a call token takes the input in chunks, whatever its size (A-237b); one with none is the checker's, answered
|
||||||
|
// inline until G removes the checker (G-6 §321, A-237c), so past what the bus carries in one answer it is refused.
|
||||||
|
if sentSize > maxSentInput && ask.Call == "" {
|
||||||
// Past what the bus carries in one answer, the checker would hear nothing: refused, saying so.
|
// Past what the bus carries in one answer, the checker would hear nothing: refused, saying so.
|
||||||
size := sentSize
|
size := sentSize
|
||||||
a.Input = nil
|
a.Input = nil
|
||||||
@@ -464,7 +490,7 @@ func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed
|
|||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.wants = wants
|
c.wants = wants
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow()}
|
scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow(), RunningManifest: c.runningFor(node)}
|
||||||
if input != nil {
|
if input != nil {
|
||||||
input(scope, fps)
|
input(scope, fps)
|
||||||
}
|
}
|
||||||
@@ -481,3 +507,71 @@ func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed
|
|||||||
// candidateNoneNoModule is the words the indexer writes in a candidate's module that the merge preview names no manifest
|
// candidateNoneNoModule is the words the indexer writes in a candidate's module that the merge preview names no manifest
|
||||||
// for: the change removes the module. It is the indexer's text, kept here until the catalogue client names it.
|
// for: the change removes the module. It is the indexer's text, kept here until the catalogue client names it.
|
||||||
const candidateNoneNoModule = "the merge preview names no manifest for the module's directory"
|
const candidateNoneNoModule = "the merge preview names no manifest for the module's directory"
|
||||||
|
|
||||||
|
// revisionCandidate reads the catalog graph revision key names, whole, page by page, through the seat mesh-catalog's verb
|
||||||
|
// revision (the Entry call, the engine's own name), and makes the candidate it composes as: one pull per repository and
|
||||||
|
// commit with each module's fingerprint and manifest digest, and a module the base holds that the revision does not marked as
|
||||||
|
// removed. answered is false when the catalog holds no such revision.
|
||||||
|
func (s *Shadow) revisionCandidate(ctx context.Context, base *Composer, key nec.Candidate) (cand meshcatalog.CandidatesByGroupValue, answered bool, err error) {
|
||||||
|
call := base.env.Entry
|
||||||
|
if call == nil {
|
||||||
|
return cand, false, errors.New("this node's engine cannot ask the catalog for a revision")
|
||||||
|
}
|
||||||
|
in := meshcatalog.RevisionInput{Branch: keys.EscapeName(key.Branch), Revision: key.Revision}
|
||||||
|
type group struct{ repository, commit string }
|
||||||
|
pulls := map[group]map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for {
|
||||||
|
raw, err := call(meshcatalogclient.RevisionVerb, in)
|
||||||
|
if err != nil {
|
||||||
|
return cand, false, fmt.Errorf("the catalog's revision %d of %s cannot be read: %w", key.Revision, key.Branch, err)
|
||||||
|
}
|
||||||
|
body, said, ok := buscalls.Unwrap(raw)
|
||||||
|
if !ok {
|
||||||
|
return cand, false, fmt.Errorf("the catalog's revision %d of %s cannot be read: %s", key.Revision, key.Branch, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.RevisionAnswer
|
||||||
|
if err := json.Unmarshal(body, &a); err != nil {
|
||||||
|
return cand, false, fmt.Errorf("the catalog's revision %d of %s is not a revision answer: %w", key.Revision, key.Branch, err)
|
||||||
|
}
|
||||||
|
if a.NoneYet || a.Revision == nil || a.Revision.Revision != key.Revision {
|
||||||
|
return cand, false, nil
|
||||||
|
}
|
||||||
|
for _, e := range a.Entries {
|
||||||
|
seen[e.Module] = true
|
||||||
|
if e.Fp == "" {
|
||||||
|
continue // no build at the revision: composed as the trunk holds it
|
||||||
|
}
|
||||||
|
g := group{e.Repository, e.Commit}
|
||||||
|
if pulls[g] == nil {
|
||||||
|
pulls[g] = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||||
|
}
|
||||||
|
// The catalog entry's manifest-digest is the `sha256:`-prefixed form (the seat's definition, entryManifest); a candidate's
|
||||||
|
// module and the manifests and verdicts keys carry the 64 hex digits alone (ADR 0429 clause 16, meshcatalogclient).
|
||||||
|
pulls[g][e.Module] = meshcatalog.CandidatesByGroupValuePullsItemFpsValue{Fp2: e.Fp, Manifest: strings.TrimPrefix(e.ManifestDigest, "sha256:")}
|
||||||
|
}
|
||||||
|
if a.Next == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
in.After = a.Next
|
||||||
|
}
|
||||||
|
removed := map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||||
|
base.mu.Lock()
|
||||||
|
for module := range base.modules {
|
||||||
|
if !seen[module] {
|
||||||
|
removed[module] = meshcatalog.CandidatesByGroupValuePullsItemFpsValue{None2: candidateNoneNoModule}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.mu.Unlock()
|
||||||
|
cand.Group = key.Branch
|
||||||
|
for g, fps := range pulls {
|
||||||
|
cand.Pulls = append(cand.Pulls, meshcatalog.CandidatesByGroupValuePullsItem{Repository: g.repository, Head: g.commit, Fps: fps})
|
||||||
|
}
|
||||||
|
sort.Slice(cand.Pulls, func(i, j int) bool {
|
||||||
|
return cand.Pulls[i].Repository+cand.Pulls[i].Head < cand.Pulls[j].Repository+cand.Pulls[j].Head
|
||||||
|
})
|
||||||
|
if len(removed) > 0 {
|
||||||
|
cand.Pulls = append(cand.Pulls, meshcatalog.CandidatesByGroupValuePullsItem{Fps: removed})
|
||||||
|
}
|
||||||
|
return cand, true, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,7 +85,18 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
entry := meshcatalog.CatalogEntry{Module: "lemurs", Fp: fp, Manifest: manifest, Repository: "novox/x", Commit: "c", ManifestDigest: digest}
|
entry := meshcatalog.CatalogEntry{Module: "lemurs", Fp: fp, Manifest: manifest, Repository: "novox/x", Commit: "c", ManifestDigest: digest}
|
||||||
env.Entry = EntryCall(func(_ context.Context, _, _ string, _ any) (json.RawMessage, error) {
|
// A-226b: the revision a branch pipeline names is read through the verb revision: revision 362 of main holds lemurs at its
|
||||||
|
// new build and manifest; no other revision is held.
|
||||||
|
env.Entry = EntryCall(func(_ context.Context, _, verb string, args any) (json.RawMessage, error) {
|
||||||
|
if verb == meshcatalog.VerbRevision {
|
||||||
|
in, _ := args.(meshcatalog.RevisionInput)
|
||||||
|
if in.Revision != 362 || in.Branch != "main" {
|
||||||
|
return json.Marshal(meshcatalog.RevisionAnswer{NoneYet: true})
|
||||||
|
}
|
||||||
|
moved := entry
|
||||||
|
moved.Fp, moved.ManifestDigest = fpNew, "sha256:"+digest2 // the entry carries the prefixed form
|
||||||
|
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Branch: "main", Revision: 362}, Entries: []meshcatalog.CatalogEntry{moved}})
|
||||||
|
}
|
||||||
return json.Marshal(meshcatalog.EntryAnswer{Entry: entry})
|
return json.Marshal(meshcatalog.EntryAnswer{Entry: entry})
|
||||||
})
|
})
|
||||||
var handed atomic.Int64
|
var handed atomic.Int64
|
||||||
@@ -141,6 +152,27 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
|||||||
if _, err := nec.EncodeAnswer(r); err != nil {
|
if _, err := nec.EncodeAnswer(r); err != nil {
|
||||||
t.Errorf("the refused answer does not fit the seat's shape: %v", err)
|
t.Errorf("the refused answer does not fit the seat's shape: %v", err)
|
||||||
}
|
}
|
||||||
|
// A-226b: a branch pipeline's revision composes as the candidate, each module at the revision's build; one the catalog does
|
||||||
|
// not hold, and a run on request's key, are refused in words.
|
||||||
|
revKey, _ := nec.RevisionKey("main", 362)
|
||||||
|
rv := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: revKey})
|
||||||
|
if rv.Verdict != nec.Composed || len(rv.Modules) != 1 || rv.Modules[0].Fp != fpNew || !rv.Modules[0].Changed {
|
||||||
|
t.Errorf("a catalog revision answered %+v", rv)
|
||||||
|
}
|
||||||
|
noRev, _ := nec.RevisionKey("main", 999)
|
||||||
|
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRev}); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no revision 999") {
|
||||||
|
t.Errorf("a revision the catalog does not hold answered %+v", m)
|
||||||
|
}
|
||||||
|
// A-226c: a run's key reads the indexer's candidates.run-<id> by its group, with no heads compared; one it holds none of is refused.
|
||||||
|
candidateOf("run-r1", digest2)
|
||||||
|
runKey, _ := nec.RunKey("r1")
|
||||||
|
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: runKey}); m.Verdict != nec.Composed || len(m.Modules) != 1 || m.Modules[0].Fp != fpNew || !m.Modules[0].Changed {
|
||||||
|
t.Errorf("a run's key answered %+v", m)
|
||||||
|
}
|
||||||
|
noRun, _ := nec.RunKey("r2")
|
||||||
|
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRun}); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no candidate") {
|
||||||
|
t.Errorf("a run the indexer holds none of answered %+v", m)
|
||||||
|
}
|
||||||
missing, _ := nec.CompositionKey("novox/x#8", "0123456789ab")
|
missing, _ := nec.CompositionKey("novox/x#8", "0123456789ab")
|
||||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: missing}); !strings.Contains(m.Refused, "holds no candidate") {
|
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: missing}); !strings.Contains(m.Refused, "holds no candidate") {
|
||||||
t.Errorf("a candidate the indexer does not hold answered %+v", m)
|
t.Errorf("a candidate the indexer does not hold answered %+v", m)
|
||||||
|
|||||||
+411
-44
@@ -12,6 +12,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
@@ -21,6 +22,8 @@ import (
|
|||||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
|
||||||
"github.com/novox/mesh-host/internal/agent"
|
"github.com/novox/mesh-host/internal/agent"
|
||||||
|
"github.com/novox/mesh-host/internal/compose/resolution"
|
||||||
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// **The catalog half, read by fingerprint** (design 47 G §421, §683, §698; the lead's answers A-47 and A-50). The node-engine
|
// **The catalog half, read by fingerprint** (design 47 G §421, §683, §698; the lead's answers A-47 and A-50). The node-engine
|
||||||
@@ -150,9 +153,42 @@ func (c *Composer) entryChanged(row meshcatalogclient.EntryRow) {
|
|||||||
c.keep(entryKey(row.Fingerprint), meshcatalog.EntryAnswer{Entry: *row.Entry})
|
c.keep(entryKey(row.Fingerprint), meshcatalog.EntryAnswer{Entry: *row.Entry})
|
||||||
}
|
}
|
||||||
c.tellNotFound(row.Fingerprint, row.State == meshcatalogclient.EntryNotFound)
|
c.tellNotFound(row.Fingerprint, row.State == meshcatalogclient.EntryNotFound)
|
||||||
|
if row.State == meshcatalogclient.EntryAnswered {
|
||||||
|
c.handAgainFor(row.Fingerprint)
|
||||||
|
}
|
||||||
c.askRehand()
|
c.askRehand()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handAgainFor forgets what was handed of each module of this node whose want or running build is fp, so the next pass hands it
|
||||||
|
// again and the node agent, which waits for this entry to judge a move (agent.keptStep), settles it again.
|
||||||
|
func (c *Composer) handAgainFor(fp string) {
|
||||||
|
var running []engcomp.Composed
|
||||||
|
if c.env.Running != nil {
|
||||||
|
running = c.env.Running()
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
for module, w := range c.wants {
|
||||||
|
if module == agent.NodeModule || w.Fp == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Only a move is judged by the entries (agent.keptStep): a module that runs the build its want names has none to wait on.
|
||||||
|
moves, runs := false, false
|
||||||
|
for _, r := range running {
|
||||||
|
if r.Module == module {
|
||||||
|
moves = moves || r.FP != w.Fp
|
||||||
|
runs = runs || r.FP == fp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !moves || (w.Fp != fp && !runs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if key, err := engcomp.Key(c.env.Node, module, w.Fp); err == nil {
|
||||||
|
delete(c.handed, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// tellNotFound tells the finding entry-not-found once when fp's entry is not found, and once when it no longer is (design 47 G §614, A-117).
|
// tellNotFound tells the finding entry-not-found once when fp's entry is not found, and once when it no longer is (design 47 G §614, A-117).
|
||||||
func (c *Composer) tellNotFound(fp string, notFound bool) {
|
func (c *Composer) tellNotFound(fp string, notFound bool) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
@@ -222,12 +258,23 @@ func (c *Composer) entryOf(fp string) (meshcatalog.CatalogEntry, meshcatalogclie
|
|||||||
// wantedBuilds is each fingerprint a want of this node or a running heard names, of the new form, with whether a want names it.
|
// wantedBuilds is each fingerprint a want of this node or a running heard names, of the new form, with whether a want names it.
|
||||||
func (c *Composer) wantedBuilds() map[string]bool {
|
func (c *Composer) wantedBuilds() map[string]bool {
|
||||||
out := map[string]bool{}
|
out := map[string]bool{}
|
||||||
|
// Read before the lock: what the node runs is the agent's, and a read of it may wait.
|
||||||
|
var running []engcomp.Composed
|
||||||
|
if c.env.Running != nil {
|
||||||
|
running = c.env.Running()
|
||||||
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
for module, w := range c.wants {
|
for module, w := range c.wants {
|
||||||
if module != agent.NodeModule && strings.HasPrefix(w.Fp, meshcatalogclient.SourcePrefix2) {
|
if module != agent.NodeModule && strings.HasPrefix(w.Fp, meshcatalogclient.SourcePrefix2) {
|
||||||
out[w.Fp] = true
|
out[w.Fp] = true
|
||||||
}
|
}
|
||||||
|
// The build its want says is being built describes, for resolution alone, a module whose wanted build has no entry (A-405, A-407).
|
||||||
|
if module != agent.NodeModule && strings.HasPrefix(w.Newest, meshcatalogclient.SourcePrefix2) {
|
||||||
|
if _, named := out[w.Newest]; !named {
|
||||||
|
out[w.Newest] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, mods := range c.heard {
|
for _, mods := range c.heard {
|
||||||
for _, run := range mods {
|
for _, run := range mods {
|
||||||
@@ -238,6 +285,26 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// The build the assignment places for another node's module stands for its want where the running build has no entry, or
|
||||||
|
// none is heard (A-461, A-461d).
|
||||||
|
for node, p := range c.assignments {
|
||||||
|
for _, pm := range p.Modules {
|
||||||
|
if built := c.placedBuild(node, pm.Module); c.needsAddressOf(node, pm.Module) && c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) {
|
||||||
|
if _, named := out[built]; !named {
|
||||||
|
out[built] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held
|
||||||
|
// for the judgement of a move's data forms though the catalog half dropped it and no event of the stream names it.
|
||||||
|
for _, r := range running {
|
||||||
|
if r.Module != agent.NodeModule && strings.HasPrefix(r.FP, meshcatalogclient.SourcePrefix2) {
|
||||||
|
if _, named := out[r.FP]; !named {
|
||||||
|
out[r.FP] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +312,7 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
|||||||
// composes from, and lays the picture frombus reads (c.modules, c.manifests) from the entries it holds. It runs at the start of
|
// composes from, and lays the picture frombus reads (c.modules, c.manifests) from the entries it holds. It runs at the start of
|
||||||
// each pass.
|
// each pass.
|
||||||
func (c *Composer) syncEntries(ctx context.Context) {
|
func (c *Composer) syncEntries(ctx context.Context) {
|
||||||
|
c.askTrunkBuilds()
|
||||||
need := c.wantedBuilds()
|
need := c.wantedBuilds()
|
||||||
for fp := range need {
|
for fp := range need {
|
||||||
c.entryOf(fp)
|
c.entryOf(fp)
|
||||||
@@ -309,18 +377,29 @@ func (c *Composer) syncEntries(ctx context.Context) {
|
|||||||
// layModules lays c.modules and c.manifests from the entries held: what each node was heard to run first, then each module this
|
// layModules lays c.modules and c.manifests from the entries held: what each node was heard to run first, then each module this
|
||||||
// node's want names, at the want's fingerprint (a want wins).
|
// node's want names, at the want's fingerprint (a want wins).
|
||||||
func (c *Composer) layModules() {
|
func (c *Composer) layModules() {
|
||||||
|
var said []string
|
||||||
|
defer func() {
|
||||||
|
for _, line := range said {
|
||||||
|
c.sayOnceEach(line)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// Read before the lock: what the node runs is the agent's, and a read of it may wait.
|
||||||
|
var running []engcomp.Composed
|
||||||
|
if c.env.Running != nil {
|
||||||
|
running = c.env.Running()
|
||||||
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
||||||
lay := func(module, fp string) {
|
lay := func(module, fp string) bool {
|
||||||
k, ok := c.keptEnt[fp]
|
k, ok := c.keptEnt[fp]
|
||||||
if !ok || k.entry.Module == "" {
|
if !ok || k.entry.Module == "" {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
e := k.entry
|
e := k.entry
|
||||||
digest, raw, err := entryManifest(e)
|
digest, raw, err := entryManifest(e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
m := meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: e.Repository, Commit: e.Commit, Path: e.Path,
|
m := meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: e.Repository, Commit: e.Commit, Path: e.Path,
|
||||||
Needs: e.Needs, Packages: e.Packages, Verdict: e.Verdict}
|
Needs: e.Needs, Packages: e.Packages, Verdict: e.Verdict}
|
||||||
@@ -329,6 +408,23 @@ func (c *Composer) layModules() {
|
|||||||
}
|
}
|
||||||
modules[module] = m
|
modules[module] = m
|
||||||
c.manifests[digest] = raw
|
c.manifests[digest] = raw
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// layAnswer lays a module from the manifest the one place read of the build it runs (A-484): the entry's own fields, or the
|
||||||
|
// trunk's answer, which holds none of an entry's checks.
|
||||||
|
layAnswer := func(module string, a runningAnswer) bool {
|
||||||
|
if a.Said != "" {
|
||||||
|
said = append(said, a.Said)
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case !a.Known:
|
||||||
|
return false
|
||||||
|
case a.Source == SourceTrunk || a.Source == SourceStatement:
|
||||||
|
modules[module] = meshcatalog.ModulesByModuleValue{Fp2: a.FP, Manifest: a.Digest, Repository: a.Repository, Commit: a.Commit, Path: a.Path}
|
||||||
|
c.manifests[a.Digest] = a.Raw
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return lay(module, a.FP)
|
||||||
}
|
}
|
||||||
nodes := make([]string, 0, len(c.heard))
|
nodes := make([]string, 0, len(c.heard))
|
||||||
for node := range c.heard {
|
for node := range c.heard {
|
||||||
@@ -338,14 +434,67 @@ func (c *Composer) layModules() {
|
|||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
for module, run := range c.heard[node] {
|
for module, run := range c.heard[node] {
|
||||||
if !run.stopped && run.fingerprint != "" {
|
if !run.stopped && run.fingerprint != "" {
|
||||||
lay(module, run.fingerprint)
|
// Where the running build has no entry, the module is laid from the entry of the build the assignment places
|
||||||
|
// for that node, the mesh's truth of what it runs there (A-461); with neither it stays name-only below.
|
||||||
|
if !lay(module, run.fingerprint) && node != c.env.Node {
|
||||||
|
layAnswer(module, c.runningLocked(running, node, module, ""))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for module, w := range c.wants {
|
// A module placed on another node and not heard running (or stopped, or running no build it names) is one whose running build has
|
||||||
if module != agent.NodeModule && w.Fp != "" {
|
// no entry (A-461d): laid, where not laid yet, from the build its placement names, or its trunk build (A-461b).
|
||||||
lay(module, w.Fp)
|
placedOn := make([]string, 0, len(c.assignments))
|
||||||
|
for node := range c.assignments {
|
||||||
|
placedOn = append(placedOn, node)
|
||||||
|
}
|
||||||
|
sort.Strings(placedOn)
|
||||||
|
for _, node := range placedOn {
|
||||||
|
if node == c.env.Node {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
for _, pm := range c.assignments[node].Modules {
|
||||||
|
if _, laid := modules[pm.Module]; laid || !c.needsAddressOf(node, pm.Module) || !c.lacksEntry(node, pm.Module) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
layAnswer(pm.Module, c.runningLocked(running, node, pm.Module, ""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for module, w := range c.wants {
|
||||||
|
if module == agent.NodeModule || w.Fp == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if k, ok := c.keptEnt[w.Fp]; ok && k.entry.Module != "" {
|
||||||
|
lay(module, w.Fp)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// A module the node runs whose wanted build has no entry stands as the build its want says is being built, for resolution
|
||||||
|
// alone: what that entry provides, claims and requires stands for the running build. Its want stays held (entryHolds), at
|
||||||
|
// the want's fingerprint, and nothing new of it is composed (A-405, A-407).
|
||||||
|
if k, ok := c.keptEnt[w.Newest]; ok && w.Newest != "" && k.entry.Module != "" && c.runsHere(module) {
|
||||||
|
lay(module, w.Newest)
|
||||||
|
if m, laid := modules[module]; laid {
|
||||||
|
m.Fp2 = w.Fp
|
||||||
|
modules[module] = m
|
||||||
|
said = append(said, fmt.Sprintf("%s runs a build whose entry the catalog half does not hold, so the node resolves around it as the build %s its want says is being built; its want stays held", module, w.Newest))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Running here with no entry of its wanted build and none of the newest: it stands, for resolution alone, as the manifest of
|
||||||
|
// the build it runs, from the one place (A-484), so the module that requires what it provides is no "nothing provides";
|
||||||
|
// its want stays held. An answer from the entry of the running build is not laid here: that entry is laid where its module is heard
|
||||||
|
// (above), and laying it for a module that is not (heard nowhere yet, its want moving) made the node compose and apply the move twice
|
||||||
|
// (TestNatsTheBusServerIsTakenOver..., one run in five); a held module's offer reads that entry through the one place alone.
|
||||||
|
if _, laid := modules[module]; !laid && c.countsAsRunning(module) {
|
||||||
|
if a := c.runningLocked(running, c.env.Node, module, ""); a.Source != SourceEntry && layAnswer(module, a) {
|
||||||
|
m := modules[module]
|
||||||
|
m.Fp2 = w.Fp
|
||||||
|
modules[module] = m
|
||||||
|
said = append(said, fmt.Sprintf("%s runs a build whose entry the node does not hold, so it counts the manifest read from %s; its want stays held", module, a.Source))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lay(module, w.Fp)
|
||||||
}
|
}
|
||||||
// A module an assignment places whose entry is not held (not wanted here, not heard running, or its entry asked and not
|
// A module an assignment places whose entry is not held (not wanted here, not heard running, or its entry asked and not
|
||||||
// answered) stands in the catalogue as its name alone, so the placement still finds it: a module held for its entry offers
|
// answered) stands in the catalogue as its name alone, so the placement still finds it: a module held for its entry offers
|
||||||
@@ -366,6 +515,176 @@ func (c *Composer) layModules() {
|
|||||||
c.modules = modules
|
c.modules = modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; empty
|
||||||
|
// where the placement names none (the one place then asks the trunk's manifest, A-484).
|
||||||
|
func (c *Composer) placedBuild(node, module string) string {
|
||||||
|
for _, pm := range c.assignments[node].Modules {
|
||||||
|
if pm.Module == module {
|
||||||
|
return pm.Build
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// lacksEntry says whether the build another node's module runs has no entry held, or none is heard (c.mu held): the only cases the
|
||||||
|
// placed build stands in (A-461b, A-461d). It is never so for this node's own modules.
|
||||||
|
func (c *Composer) lacksEntry(node, module string) bool {
|
||||||
|
if node == c.env.Node {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
run, heard := c.heard[node][module]
|
||||||
|
if !heard || run.stopped || run.fingerprint == "" {
|
||||||
|
return true // placed there, and not heard running (A-461d), stopped or running no build it names
|
||||||
|
}
|
||||||
|
k, ok := c.keptEnt[run.fingerprint]
|
||||||
|
return !ok || k.entry.Module == ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// needsAddressOf says whether this node needs the address of module on node (c.mu held): it holds a store seat there (the image
|
||||||
|
// seats' holders), or a module placed here is bound to it as the provider of a requirement (A-461).
|
||||||
|
func (c *Composer) needsAddressOf(node, module string) bool {
|
||||||
|
for _, h := range c.assignments[node].Holds {
|
||||||
|
if h.Module == module && slices.Contains(resolution.StoreSeats, h.Claim) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, pm := range c.assignments[c.env.Node].Modules {
|
||||||
|
for _, b := range pm.Bindings {
|
||||||
|
if b.Module == module && b.Node == node {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk
|
||||||
|
// build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call.
|
||||||
|
func (c *Composer) askTrunkBuilds() (wait func()) {
|
||||||
|
type ask struct{ node, module, running string }
|
||||||
|
var asks []ask
|
||||||
|
var sayLines []string
|
||||||
|
var running []engcomp.Composed
|
||||||
|
if c.env.Running != nil {
|
||||||
|
running = c.env.Running()
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
// The module whose running build's manifest the one place reads from the trunk, where neither its entry nor its composition
|
||||||
|
// answers (A-484): the modules this node runs, and another node's module this node needs the address of (A-461, A-461d).
|
||||||
|
for node, p := range c.assignments {
|
||||||
|
for _, pm := range p.Modules {
|
||||||
|
module := pm.Module
|
||||||
|
if c.trunkAsking[module] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if node == c.env.Node {
|
||||||
|
if !c.countsAsRunning(module) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else if !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
a := c.runningLocked(running, node, module, "")
|
||||||
|
if a.Said != "" {
|
||||||
|
sayLines = append(sayLines, a.Said)
|
||||||
|
}
|
||||||
|
if a.NeedTrunk {
|
||||||
|
if r, backing := c.trunkRetry[module]; backing && c.now().Before(r.next) {
|
||||||
|
continue // the catalog gave none and its backoff runs: asked again at its end or at a catalog-revision (A-487a)
|
||||||
|
}
|
||||||
|
if had, asked := c.trunkBuilds[module]; !asked || had.running != a.RunFP {
|
||||||
|
asks = append(asks, ask{node, module, a.RunFP})
|
||||||
|
if c.trunkAsking == nil {
|
||||||
|
c.trunkAsking = map[string]bool{}
|
||||||
|
}
|
||||||
|
c.trunkAsking[module] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
for _, line := range sayLines {
|
||||||
|
c.sayOnceEach(line)
|
||||||
|
}
|
||||||
|
// Asked beside the pass, a few at a time: no pass waits on the catalog half's answer, and a module that waits for it is only
|
||||||
|
// the one needing that address (A-461e). An answer asks a pass.
|
||||||
|
var all sync.WaitGroup
|
||||||
|
work := make(chan ask)
|
||||||
|
for i := 0; i < 3 && i < len(asks); i++ {
|
||||||
|
all.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer all.Done()
|
||||||
|
for a := range work {
|
||||||
|
t, why := c.trunkOf(a.module)
|
||||||
|
fp := t.fp
|
||||||
|
var wait time.Duration
|
||||||
|
c.mu.Lock()
|
||||||
|
delete(c.trunkAsking, a.module)
|
||||||
|
if fp != "" {
|
||||||
|
if c.trunkBuilds == nil {
|
||||||
|
c.trunkBuilds = map[string]trunkBuild{}
|
||||||
|
}
|
||||||
|
t.running = a.running
|
||||||
|
c.trunkBuilds[a.module] = t
|
||||||
|
delete(c.trunkWhy, a.module)
|
||||||
|
delete(c.trunkRetry, a.module)
|
||||||
|
} else {
|
||||||
|
if c.trunkWhy == nil {
|
||||||
|
c.trunkWhy = map[string]string{}
|
||||||
|
}
|
||||||
|
c.trunkWhy[a.module] = why
|
||||||
|
wait = c.trunkBackoffLocked(a.module)
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if fp == "" {
|
||||||
|
// Said with its reason, and asked again at a catalog-revision or after its backoff, whichever comes first, never
|
||||||
|
// at every pass (A-461e, A-487a); the backoff wakes a pass at its end.
|
||||||
|
c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again in %s or when the catalog says a revision: %s", a.module, a.node, wait, why))
|
||||||
|
time.AfterFunc(wait, c.askRehand)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.askRehand()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
for _, a := range asks {
|
||||||
|
work <- a
|
||||||
|
}
|
||||||
|
close(work)
|
||||||
|
}()
|
||||||
|
return all.Wait
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkBackoff is the asks of a module's trunk build that gave none, in a row, and the time before which it is not asked again.
|
||||||
|
type trunkBackoff struct {
|
||||||
|
tries int
|
||||||
|
next time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkBackoffLocked notes one more ask of the module's trunk build that gave none and returns the wait before it is asked again:
|
||||||
|
// laterAgain's, 5 s growing to 5 minutes (A-487a). Under mu.
|
||||||
|
func (c *Composer) trunkBackoffLocked(module string) time.Duration {
|
||||||
|
if c.trunkRetry == nil {
|
||||||
|
c.trunkRetry = map[string]trunkBackoff{}
|
||||||
|
}
|
||||||
|
r := c.trunkRetry[module]
|
||||||
|
wait := LaterWait(r.tries)
|
||||||
|
c.trunkRetry[module] = trunkBackoff{tries: r.tries + 1, next: c.now().Add(wait)}
|
||||||
|
return wait
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkRetryCleared ends the wait of every module whose trunk build the catalog gave none of, on the catalog's word that it holds a
|
||||||
|
// new revision: the next pass asks them again (A-487a). The asks in a row are kept, so one that fails again waits longer.
|
||||||
|
func (c *Composer) trunkRetryCleared() {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
for m, r := range c.trunkRetry {
|
||||||
|
r.next = time.Time{}
|
||||||
|
c.trunkRetry[m] = r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// entryManifest is an entry's manifest as a reader takes it, with its digest: the one the indexer set at take-in, or, where it set
|
// entryManifest is an entry's manifest as a reader takes it, with its digest: the one the indexer set at take-in, or, where it set
|
||||||
// none, the digest of the manifest's bytes.
|
// none, the digest of the manifest's bytes.
|
||||||
func entryManifest(e meshcatalog.CatalogEntry) (digest string, raw []byte, err error) {
|
func entryManifest(e meshcatalog.CatalogEntry) (digest string, raw []byte, err error) {
|
||||||
@@ -404,7 +723,7 @@ func (c *Composer) entryHolds() map[string]string {
|
|||||||
out[module] = fmt.Sprintf("%s the catalog half holds no entry of the build %s, so the node composes nothing new of %s",
|
out[module] = fmt.Sprintf("%s the catalog half holds no entry of the build %s, so the node composes nothing new of %s",
|
||||||
agent.EntryMissing, w.Fp, module)
|
agent.EntryMissing, w.Fp, module)
|
||||||
default:
|
default:
|
||||||
if missing := partsMissing(e, w); missing != "" {
|
if _, missing := c.partsOf(module, e, w); missing != "" {
|
||||||
out[module] = fmt.Sprintf("the want of %s names no digest for %s, so the node composes nothing new of it", module, missing)
|
out[module] = fmt.Sprintf("the want of %s names no digest for %s, so the node composes nothing new of it", module, missing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,19 +731,7 @@ func (c *Composer) entryHolds() map[string]string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// partsMissing names the artifacts of e whose digest w's parts do not give; "" when each has one.
|
// referenceOf is an artifact's reference made from the digest its want's part names, or its version resolves (A-430a), in the form the artifact store is
|
||||||
func partsMissing(e meshcatalog.CatalogEntry, w meshwants.WantsByWantNodeModuleValue) string {
|
|
||||||
var out []string
|
|
||||||
for _, a := range e.Artifacts {
|
|
||||||
if w.Parts[a.Ref] == "" {
|
|
||||||
out = append(out, a.Ref)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(out)
|
|
||||||
return strings.Join(out, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// referenceOf is an artifact's reference made from the digest its want's part names, in the form the artifact store is
|
|
||||||
// addressed by (the lead's answer A-50): artifact-store://<module>/<artifact>/blobs/<digest>.
|
// addressed by (the lead's answer A-50): artifact-store://<module>/<artifact>/blobs/<digest>.
|
||||||
func referenceOf(module, artifact, digest string) string {
|
func referenceOf(module, artifact, digest string) string {
|
||||||
return "artifact-store://" + module + "/" + artifact + "/blobs/" + digest
|
return "artifact-store://" + module + "/" + artifact + "/blobs/" + digest
|
||||||
@@ -439,7 +746,11 @@ func (c *Composer) buildOf(module, fp string) *builds.BuilderBuild {
|
|||||||
w, wanted := c.wants[module]
|
w, wanted := c.wants[module]
|
||||||
k, ok := c.keptEnt[fp]
|
k, ok := c.keptEnt[fp]
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
if !wanted || w.Fp != fp || !ok || partsMissing(k.entry, w) != "" {
|
if !wanted || w.Fp != fp || !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
parts, missing := c.partsOf(module, k.entry, w)
|
||||||
|
if missing != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
digest, raw, err := entryManifest(k.entry)
|
digest, raw, err := entryManifest(k.entry)
|
||||||
@@ -452,7 +763,7 @@ func (c *Composer) buildOf(module, fp string) *builds.BuilderBuild {
|
|||||||
b := builds.BuilderBuild{State: builds.BuildDone, Manifest: digest}
|
b := builds.BuilderBuild{State: builds.BuildDone, Manifest: digest}
|
||||||
for _, a := range k.entry.Artifacts {
|
for _, a := range k.entry.Artifacts {
|
||||||
_, name, _ := strings.Cut(a.Ref, ":")
|
_, name, _ := strings.Cut(a.Ref, ":")
|
||||||
digest := w.Parts[a.Ref]
|
digest := parts[a.Ref]
|
||||||
b.Artifacts = append(b.Artifacts, builds.BuiltArtifact{Name: name, Kind: a.Kind, Digest: digest,
|
b.Artifacts = append(b.Artifacts, builds.BuiltArtifact{Name: name, Kind: a.Kind, Digest: digest,
|
||||||
Reference: referenceOf(module, name, digest)})
|
Reference: referenceOf(module, name, digest)})
|
||||||
}
|
}
|
||||||
@@ -546,9 +857,34 @@ func (c *Composer) FormChanges(_ context.Context, module, runningFp, appliedFp s
|
|||||||
}
|
}
|
||||||
return catalogue.Decode(raw)
|
return catalogue.Decode(raw)
|
||||||
}
|
}
|
||||||
running, err := read(runningFp)
|
// The manifest of the build the module runs is read in the one place (A-484): its entry, else the composition this node runs of
|
||||||
if err != nil {
|
// it, else the trunk's manifest. Where it reads no manifest, the composition says whether the running build keeps data: with
|
||||||
return nil, fmt.Errorf("%s's running manifest: %w", module, err)
|
// none on either side no form can change and the move goes on; where either keeps data, the move waits (A-113, A-483), with
|
||||||
|
// the words naming the three sources tried.
|
||||||
|
// The entry of the running build is asked of the catalog half (once), and kept when answered, as every entry the composer reads.
|
||||||
|
if e, state := c.entryOf(runningFp); state == meshcatalogclient.EntryAnswered && e.Module != "" {
|
||||||
|
c.mu.Lock()
|
||||||
|
if _, kept := c.keptEnt[runningFp]; !kept {
|
||||||
|
c.keptEnt[runningFp] = keptEntry{entry: e, since: c.now()}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
|
ra := c.runningManifest(c.env.Node, module, runningFp)
|
||||||
|
var running catalogue.Manifest
|
||||||
|
if ra.Known {
|
||||||
|
var err error
|
||||||
|
if running, err = catalogue.Decode(ra.Raw); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s's running manifest: %w", module, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wanted, werr := read(appliedFp)
|
||||||
|
if werr != nil {
|
||||||
|
return nil, fmt.Errorf("%s's wanted manifest: %w", module, werr)
|
||||||
|
}
|
||||||
|
if ra.Source == SourceComposition && !ra.Data && len(wanted.DataItems()) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("%s's running manifest: %s", module, ra.Why)
|
||||||
}
|
}
|
||||||
applied, err := read(appliedFp)
|
applied, err := read(appliedFp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -582,30 +918,45 @@ func (c *Composer) syncShadowEntries(ctx context.Context) (pending bool) {
|
|||||||
// moduleVerb is the seat mesh-catalog's verb `module`: one module's trunk fingerprint and manifest by name.
|
// moduleVerb is the seat mesh-catalog's verb `module`: one module's trunk fingerprint and manifest by name.
|
||||||
const moduleVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbModule
|
const moduleVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbModule
|
||||||
|
|
||||||
|
// trunkOf is a module's trunk build, by the seat's verb `module`: its fingerprint, manifest and where it is built from; empty with
|
||||||
|
// why where the catalog half gives none.
|
||||||
|
func (c *Composer) trunkOf(module string) (t trunkBuild, why string) {
|
||||||
|
if c.env.Entry == nil {
|
||||||
|
return t, "this node reads no module of the catalog half"
|
||||||
|
}
|
||||||
|
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
|
||||||
|
if err != nil {
|
||||||
|
return t, fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
||||||
|
}
|
||||||
|
answer, said, ok := buscalls.Unwrap(raw)
|
||||||
|
if !ok {
|
||||||
|
return t, fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.ModuleAnswer
|
||||||
|
if err := json.Unmarshal(answer, &a); err != nil {
|
||||||
|
return t, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
||||||
|
}
|
||||||
|
if a.Module.Fp == "" {
|
||||||
|
return t, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
||||||
|
}
|
||||||
|
return trunkBuild{fp: a.Module.Fp, manifest: a.Module.Manifest, repository: a.Module.Repository, commit: a.Module.Commit, path: a.Module.Path}, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkFp is the fingerprint of a module's trunk build (trunkOf); empty with why where the catalog half gives none.
|
||||||
|
func (c *Composer) trunkFp(module string) (fp, why string) {
|
||||||
|
t, why := c.trunkOf(module)
|
||||||
|
return t.fp, why
|
||||||
|
}
|
||||||
|
|
||||||
// addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the
|
// addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the
|
||||||
// fingerprint the seat's verb `module` answers, then its entry by the verb `entry` as for a wanted module (design 47 G §421, A-312).
|
// fingerprint the seat's verb `module` answers, then its entry by the verb `entry` as for a wanted module (design 47 G §421, A-312).
|
||||||
// A call, not a watch: nothing of the catalog is kept. It answers the entry when held; otherwise why not: a module with no
|
// A call, not a watch: nothing of the catalog is kept. It answers the entry when held; otherwise why not: a module with no
|
||||||
// fingerprint says the verb's reason, an entry asked says so (its answer wakes the shadow, which composes again).
|
// fingerprint says the verb's reason, an entry asked says so (its answer wakes the shadow, which composes again).
|
||||||
func (c *Composer) addedModule(ctx context.Context, module string) (fp string, entry meshcatalog.CatalogEntry, held, pending bool, why string) {
|
func (c *Composer) addedModule(ctx context.Context, module string) (fp string, entry meshcatalog.CatalogEntry, held, pending bool, why string) {
|
||||||
if c.env.Entry == nil {
|
fp, why = c.trunkFp(module)
|
||||||
return "", entry, false, false, "this node reads no module of the catalog half"
|
if fp == "" {
|
||||||
|
return "", entry, false, false, why
|
||||||
}
|
}
|
||||||
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
|
|
||||||
if err != nil {
|
|
||||||
return "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
|
||||||
}
|
|
||||||
answer, said, ok := buscalls.Unwrap(raw)
|
|
||||||
if !ok {
|
|
||||||
return "", entry, false, false, fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
|
||||||
}
|
|
||||||
var a meshcatalog.ModuleAnswer
|
|
||||||
if err := json.Unmarshal(answer, &a); err != nil {
|
|
||||||
return "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
|
||||||
}
|
|
||||||
if a.Module.Fp == "" {
|
|
||||||
return "", entry, false, false, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
|
||||||
}
|
|
||||||
fp = a.Module.Fp
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
if c.addedFps == nil {
|
if c.addedFps == nil {
|
||||||
c.addedFps = map[string]bool{}
|
c.addedFps = map[string]bool{}
|
||||||
@@ -651,3 +1002,19 @@ func (c *Composer) askBuildsEntries(fps map[string]string) (pending string) {
|
|||||||
}
|
}
|
||||||
return pending
|
return pending
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runsHere says whether this node runs the module: heard to, or in what the node runs now (c.mu held; env.Running reads the
|
||||||
|
// agent's own record).
|
||||||
|
func (c *Composer) runsHere(module string) bool {
|
||||||
|
if run, ok := c.heard[c.env.Node][module]; ok && !run.stopped {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if c.env.Running != nil {
|
||||||
|
for _, r := range c.env.Running() {
|
||||||
|
if r.Module == module {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ func composeFromEntries(t *testing.T) {
|
|||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var asked []string
|
var asked []string
|
||||||
ask := func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) {
|
ask := func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) {
|
||||||
in := args.(meshcatalog.EntryInput)
|
in, isEntry := args.(meshcatalog.EntryInput)
|
||||||
|
if !isEntry {
|
||||||
|
t.Errorf("the trunk build is asked (%s %v) of a module nothing says runs here (A-482)", verb, args)
|
||||||
|
return nil, errors.New("the catalog half holds no trunk build here")
|
||||||
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
asked = append(asked, in.Fingerprint)
|
asked = append(asked, in.Fingerprint)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
@@ -259,3 +263,511 @@ func (c *Composer) holdEntry(t *testing.T, module, fp, body string) {
|
|||||||
}
|
}
|
||||||
c.keptEnt[fp] = keptEntry{entry: half[fp]}
|
c.keptEnt[fp] = keptEntry{entry: half[fp]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A-405, A-407: a module the node runs whose wanted build has no entry stands, for resolution alone, as the build its want says
|
||||||
|
// is being built, at the want's fingerprint, so its want stays held; one not running here, or whose want names no newer build the
|
||||||
|
// half holds, stands as its name alone.
|
||||||
|
func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) {
|
||||||
|
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||||
|
newest := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||||
|
body := `{"module":"postgres","version":"2"}`
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
runs bool
|
||||||
|
newest string
|
||||||
|
holds bool
|
||||||
|
laid bool
|
||||||
|
wantFp string
|
||||||
|
stopped bool // A-480a: heard stopped
|
||||||
|
trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none)
|
||||||
|
have string // A-482: the phase its have says, naming the build it runs ("" for none)
|
||||||
|
named string // A-480a: the manifest its running event names ("held": one this node holds, "unread": one it does not)
|
||||||
|
}{
|
||||||
|
{"runs, newest entry held", true, newest, true, true, old, false, false, "", ""},
|
||||||
|
{"not running here", false, newest, true, false, old, false, false, "", ""},
|
||||||
|
{"names no newer build", true, "", false, false, old, false, false, "", ""},
|
||||||
|
{"newest entry not held", true, newest, false, false, old, false, false, "", ""},
|
||||||
|
{"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true, "", ""},
|
||||||
|
{"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", ""},
|
||||||
|
{"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", ""},
|
||||||
|
{"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", ""},
|
||||||
|
{"its running event names a manifest this node holds (A-484a)", true, "", false, true, old, false, true, "", "held"},
|
||||||
|
{"its running event names a manifest this node cannot read (A-480a)", true, "", false, true, old, false, true, "", "unread"},
|
||||||
|
{"runs a composition at another build, no manifest read (A-480a)", true, "", false, true, old, false, true, "other", ""},
|
||||||
|
{"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", ""},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
trunkFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("4", 64)
|
||||||
|
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||||
|
if verb == meshcatalog.VerbModule && tc.trunk {
|
||||||
|
var man map[string]any
|
||||||
|
_ = json.Unmarshal([]byte(body), &man)
|
||||||
|
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp, Manifest: man}})
|
||||||
|
}
|
||||||
|
return nil, errors.New("not held")
|
||||||
|
})
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.wants["postgres"] = meshwants.WantsByWantNodeModuleValue{Fp: old, Newest: tc.newest}
|
||||||
|
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "postgres"}}}
|
||||||
|
if tc.runs {
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}}
|
||||||
|
}
|
||||||
|
if tc.named != "" {
|
||||||
|
digest := "sha256:" + strings.Repeat("9", 64)
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, manifest: digest}}}
|
||||||
|
if tc.named == "held" {
|
||||||
|
c.manifests[digest] = []byte(body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc.have != "" {
|
||||||
|
c.haveRuns["postgres"] = true
|
||||||
|
}
|
||||||
|
if tc.have == "other" {
|
||||||
|
c.env.Running = func() []compositions.Composed {
|
||||||
|
return []compositions.Composed{{Node: "n1", Module: "postgres", FP: meshcatalogclient.SourcePrefix2 + strings.Repeat("5", 64)}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc.stopped {
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, stopped: true}}}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if tc.holds {
|
||||||
|
c.holdEntry(t, "postgres", newest, body)
|
||||||
|
}
|
||||||
|
if tc.trunk {
|
||||||
|
c.holdEntry(t, "postgres", trunkFp, body)
|
||||||
|
}
|
||||||
|
c.askTrunkBuilds()()
|
||||||
|
if got := c.wantedBuilds()[newest]; tc.newest != "" && got {
|
||||||
|
t.Errorf("the newest build is named by a want, want only asked")
|
||||||
|
}
|
||||||
|
c.layModules()
|
||||||
|
c.mu.Lock()
|
||||||
|
m, ok := c.modules["postgres"]
|
||||||
|
raw := c.manifests[m.Manifest]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if !ok || m.Fp2 != tc.wantFp {
|
||||||
|
t.Fatalf("modules[postgres] = %+v (%v), want fingerprint %s", m, ok, tc.wantFp)
|
||||||
|
}
|
||||||
|
if got := strings.Contains(string(raw), `"version":"2"`); got != tc.laid {
|
||||||
|
t.Errorf("manifest of the newest build laid = %v, want %v (%s)", got, tc.laid, raw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The node judges a move's data forms from the entry it kept of the build it runs, though the catalog half dropped that entry and no
|
||||||
|
// running event names it; and an answered entry has the composition handed again, which the agent waits on (novox, mesh-hand-acts).
|
||||||
|
func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||||
|
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||||
|
next := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
env.Running = func() []compositions.Composed {
|
||||||
|
return []compositions.Composed{{Node: "n1", Module: "hand", FP: old}}
|
||||||
|
}
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.wants["hand"] = meshwants.WantsByWantNodeModuleValue{Fp: next}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if named, ok := c.wantedBuilds()[old]; !ok || named {
|
||||||
|
t.Errorf("the running build %s is asked of no want yet kept: %v, %v", old, named, ok)
|
||||||
|
}
|
||||||
|
key, _ := compositions.Key("n1", "hand", next)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.handed[key] = "d"
|
||||||
|
c.mu.Unlock()
|
||||||
|
c.entryChanged(meshcatalogclient.EntryRow{Fingerprint: old, State: meshcatalogclient.EntryAnswered,
|
||||||
|
Entry: &meshcatalog.CatalogEntry{Module: "hand", Fp: old}})
|
||||||
|
c.mu.Lock()
|
||||||
|
_, still := c.handed[key]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if still {
|
||||||
|
t.Error("an entry of the running build was answered, and the composition was not handed again")
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-483: a running build with no entry is read from the composition it runs here: where neither it nor the wanted build's manifest
|
||||||
|
// keeps data on the bus no form can change and the move goes on; where either does, or no composition is run, it still waits.
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
runs, data bool // a composition of the module runs here, keeping data
|
||||||
|
wantedData bool
|
||||||
|
wantedHeld bool
|
||||||
|
moves bool
|
||||||
|
}{
|
||||||
|
{"no entry of the running build, its composition and the wanted build keep no data", true, false, false, true, true},
|
||||||
|
{"no entry, its composition keeps data", true, true, false, true, false},
|
||||||
|
{"no entry, the wanted build keeps data", true, false, true, true, false},
|
||||||
|
{"no entry, no composition of it runs here", false, false, false, true, false},
|
||||||
|
{"no entry, the wanted build's entry is not held either", true, false, false, false, false},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
env.Running = func() []compositions.Composed {
|
||||||
|
if !tc.runs {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return []compositions.Composed{{Node: "n1", Module: "feh", FP: old, Data: tc.data}}
|
||||||
|
}
|
||||||
|
c := New(env)
|
||||||
|
if tc.wantedHeld {
|
||||||
|
body := `{"module":"feh","version":"2"}`
|
||||||
|
if tc.wantedData {
|
||||||
|
body = `{"module":"feh","version":"2","data":{"own":[{"id":"state","kind":"state"}]}}`
|
||||||
|
}
|
||||||
|
c.holdEntry(t, "feh", next, body)
|
||||||
|
}
|
||||||
|
changes, err := c.FormChanges(context.Background(), "feh", old, next)
|
||||||
|
if (err == nil) != tc.moves || len(changes) != 0 {
|
||||||
|
t.Errorf("FormChanges = %v, %v; the move goes on: %v", changes, err, tc.moves)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-484: where neither the entry nor a composition answers, the trunk's manifest is the running build's: a form change is judged
|
||||||
|
// against it, and its words name the three sources where the trunk answered none either.
|
||||||
|
for _, trunk := range []bool{true, false} {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
c := New(env)
|
||||||
|
c.holdEntry(t, "feh", next, `{"module":"feh","version":"2","data":{"own":[{"id":"state","kind":"state"}]}}`)
|
||||||
|
if trunk {
|
||||||
|
c.mu.Lock()
|
||||||
|
c.trunkBuilds = map[string]trunkBuild{"feh": {running: old, fp: next, manifest: map[string]any{"module": "feh", "version": "1"}}}
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
|
changes, err := c.FormChanges(context.Background(), "feh", old, next)
|
||||||
|
switch {
|
||||||
|
case trunk && err != nil:
|
||||||
|
t.Errorf("the trunk's manifest answers, FormChanges = %v, %v", changes, err)
|
||||||
|
case !trunk && (err == nil || !strings.Contains(err.Error(), SourceEntry) || !strings.Contains(err.Error(), SourceStatement) || !strings.Contains(err.Error(), SourceTrunk)):
|
||||||
|
t.Errorf("no source answers, FormChanges says %v, want the three named", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-484, A-484a, A-482: the manifest of the build a module runs here is answered in one place, from the entry of the running build,
|
||||||
|
// else the manifest its running statement names, else the module's trunk manifest; the composition says whether it keeps data. It
|
||||||
|
// says its source once per module and source, whoever asks, and where none answers its words name the three.
|
||||||
|
{
|
||||||
|
running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||||
|
other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||||
|
body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}`
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
entry string // the entry held, by fingerprint ("running", "other") or none
|
||||||
|
composition string // the composition this node runs: its build ("running", "other") or none
|
||||||
|
data bool
|
||||||
|
trunk bool
|
||||||
|
statement bool // the running event names a manifest this node holds (A-484a)
|
||||||
|
haveOnly bool // heard no running event: only its have names the build it runs (A-482)
|
||||||
|
wantSource string
|
||||||
|
wantKnown bool
|
||||||
|
}{
|
||||||
|
{"its entry answers first", "running", "running", false, true, false, false, SourceEntry, true},
|
||||||
|
{"the entry of the composition's build is the running build's", "other", "other", true, true, false, false, SourceEntry, true},
|
||||||
|
{"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, false, false, SourceTrunk, true},
|
||||||
|
{"a composition and no trunk answer: its build and its data alone", "", "running", true, false, false, false, SourceComposition, false},
|
||||||
|
{"the trunk alone", "", "", false, true, false, false, SourceTrunk, true},
|
||||||
|
{"its running statement's manifest comes before the trunk's", "", "running", true, true, true, false, SourceStatement, true},
|
||||||
|
{"only its have names the build, whose entry is held (A-482)", "running", "", false, false, false, true, SourceEntry, true},
|
||||||
|
{"none answers", "", "", false, false, false, false, "", false},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
var said []string
|
||||||
|
env.Say = func(s string) { said = append(said, s) }
|
||||||
|
if tc.composition != "" {
|
||||||
|
fp := map[string]string{"running": running, "other": other}[tc.composition]
|
||||||
|
env.Running = func() []compositions.Composed {
|
||||||
|
return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}}
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}}
|
||||||
|
if tc.haveOnly {
|
||||||
|
c.heard = map[string]map[string]heardRun{}
|
||||||
|
c.haveRuns["xorg"], c.haveFp["xorg"] = true, running
|
||||||
|
}
|
||||||
|
if tc.statement {
|
||||||
|
digest := "sha256:" + strings.Repeat("9", 64)
|
||||||
|
c.heard["n1"]["xorg"] = heardRun{fingerprint: running, manifest: digest}
|
||||||
|
c.manifests[digest] = []byte(body)
|
||||||
|
}
|
||||||
|
if tc.trunk {
|
||||||
|
var man map[string]any
|
||||||
|
_ = json.Unmarshal([]byte(body), &man)
|
||||||
|
c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if tc.entry != "" {
|
||||||
|
c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body)
|
||||||
|
}
|
||||||
|
c.askTrunkBuilds()()
|
||||||
|
c.layModules()
|
||||||
|
a := c.runningManifest("n1", "xorg", "")
|
||||||
|
again := c.runningManifest("n1", "xorg", "")
|
||||||
|
if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) {
|
||||||
|
t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown)
|
||||||
|
}
|
||||||
|
sources := 0
|
||||||
|
for _, line := range said {
|
||||||
|
if strings.Contains(line, "runs a build whose manifest is read from "+tc.wantSource) {
|
||||||
|
sources++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc.wantSource != "" && (sources != 1 || again.Said != a.Said) {
|
||||||
|
t.Errorf("said %q, want its source once", said)
|
||||||
|
}
|
||||||
|
if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry && a.Source != SourceStatement {
|
||||||
|
t.Errorf("the composition's data = %v, want %v", a.Data, tc.data)
|
||||||
|
}
|
||||||
|
if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceStatement) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) {
|
||||||
|
t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// A module counted as running here alone answers a held module's offer and what the module keeps (A-482): one wanted here that
|
||||||
|
// runs nothing and whose have names no build answers nothing, and HoldsData reads the manifest the one place read.
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
c := New(env)
|
||||||
|
c.holdEntry(t, "xorg", running, body)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.wants["xorg"] = meshwants.WantsByWantNodeModuleValue{Fp: other}
|
||||||
|
c.haveFp["xorg"] = running
|
||||||
|
c.mu.Unlock()
|
||||||
|
if _, ok := c.runningFor("n1")("xorg"); ok {
|
||||||
|
t.Error("a module wanted here that runs nothing answered a manifest as running")
|
||||||
|
}
|
||||||
|
if data, known := c.HoldsData(context.Background(), "xorg"); data || !known {
|
||||||
|
t.Errorf("HoldsData = %v, %v, want a manifest read that declares no data", data, known)
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
c.haveRuns["xorg"] = true
|
||||||
|
c.mu.Unlock()
|
||||||
|
if man, ok := c.runningFor("n1")("xorg"); !ok || len(man.Provides) != 1 {
|
||||||
|
t.Error("a module its have says runs answered no manifest")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment
|
||||||
|
// places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name
|
||||||
|
// alone, and this node's own module is never laid from a placement.
|
||||||
|
placedFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("3", 64)
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
node string
|
||||||
|
build, trunk string
|
||||||
|
holds, laid bool
|
||||||
|
heard string // A-461d: what is heard of it: "" its running build, "none", "stopped", "no-build"
|
||||||
|
}{
|
||||||
|
{"placed build has an entry", "n2", placedFp, "", true, true, ""},
|
||||||
|
{"neither build has an entry", "n2", placedFp, "", false, false, ""},
|
||||||
|
{"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true, ""},
|
||||||
|
{"placement names no build, trunk names none", "n2", "", "", false, false, ""},
|
||||||
|
{"this node's own module is not laid from a placement", "n1", placedFp, "", true, false, ""},
|
||||||
|
{"placed, not heard, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "none"},
|
||||||
|
{"placed, not heard, placed build has an entry (A-461d)", "n2", placedFp, "", true, true, "none"},
|
||||||
|
{"placed, stopped there, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "stopped"},
|
||||||
|
{"placed, heard with no build, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "no-build"},
|
||||||
|
{"placed, not heard, trunk names none (A-461d)", "n2", "", "", false, false, "none"},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||||
|
if verb == meshcatalog.VerbModule {
|
||||||
|
var man map[string]any
|
||||||
|
if tc.trunk != "" {
|
||||||
|
man = map[string]any{"module": "distribution", "version": "2"}
|
||||||
|
}
|
||||||
|
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk, Manifest: man}})
|
||||||
|
}
|
||||||
|
return nil, errors.New("not held")
|
||||||
|
})
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}},
|
||||||
|
Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}}
|
||||||
|
c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}}
|
||||||
|
switch tc.heard {
|
||||||
|
case "none":
|
||||||
|
c.heard = map[string]map[string]heardRun{}
|
||||||
|
case "stopped":
|
||||||
|
c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old, stopped: true}}}
|
||||||
|
case "no-build":
|
||||||
|
c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {}}}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if tc.holds {
|
||||||
|
c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`)
|
||||||
|
}
|
||||||
|
c.askTrunkBuilds()()
|
||||||
|
c.mu.Lock()
|
||||||
|
_, kept := c.trunkBuilds["distribution"]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if tc.node == "n2" && tc.build == "" && tc.trunk == "" && kept {
|
||||||
|
t.Error("a trunk build that could not be had was kept, so it is asked once per process (A-461e)")
|
||||||
|
}
|
||||||
|
if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && tc.build != "") {
|
||||||
|
t.Errorf("the placed build asked = %v", asked)
|
||||||
|
}
|
||||||
|
c.layModules()
|
||||||
|
c.mu.Lock()
|
||||||
|
m, ok := c.modules["distribution"]
|
||||||
|
raw := c.manifests[m.Manifest]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if got := ok && strings.Contains(string(raw), `"version":"2"`); got != tc.laid {
|
||||||
|
t.Errorf("laid from the placed build = %v, want %v (%+v %s)", got, tc.laid, m, raw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-461, A-461e: a node asks the trunk build only of what it needs of another node's placement (the store's holder, the provider
|
||||||
|
// it is bound to), never of every module placed there, and beside the pass.
|
||||||
|
func TestOnlyWhatTheNodeNeedsOfAnotherNodesPlacementIsAsked(t *testing.T) {
|
||||||
|
t.Run("a trunk build the catalog gave none of waits its backoff or a catalog-revision (A-487a)", trunkAskBackoffAndCatalogRevision)
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
var mu sync.Mutex
|
||||||
|
asked := map[string]int{}
|
||||||
|
env.Entry = EntryCall(func(_ context.Context, _, verb string, in any) (json.RawMessage, error) {
|
||||||
|
if verb == meshcatalog.VerbModule {
|
||||||
|
mu.Lock()
|
||||||
|
asked[in.(meshcatalog.ModuleInput).Module]++
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
return nil, errors.New("not held")
|
||||||
|
})
|
||||||
|
c := New(env)
|
||||||
|
var unrelated []meshmoduleassigner.PlacedModule
|
||||||
|
for i := 0; i < 40; i++ {
|
||||||
|
unrelated = append(unrelated, meshmoduleassigner.PlacedModule{Module: fmt.Sprintf("unrelated%d", i)})
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
c.assignments["n2"] = meshmoduleassigner.Assignments{Node: "n2",
|
||||||
|
Modules: append(unrelated, meshmoduleassigner.PlacedModule{Module: "distribution"}, meshmoduleassigner.PlacedModule{Module: "provider"}),
|
||||||
|
Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}}
|
||||||
|
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{
|
||||||
|
{Module: "app", Bindings: map[string]meshmoduleassigner.Provider{"postgres-database": {Module: "provider", Node: "n2"}}}}}
|
||||||
|
c.mu.Unlock()
|
||||||
|
c.askTrunkBuilds()()
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
if len(asked) != 2 || asked["distribution"] != 1 || asked["provider"] != 1 {
|
||||||
|
t.Errorf("the trunk builds asked are %v, want the store's holder and the bound provider alone", asked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-487a (A-461e): a trunk build the catalog gave none of is not asked again at every pass: it waits laterAgain's step for the module
|
||||||
|
// (5 s, then 15 s), and the seat's event catalog-revision ends the wait at once; an answer starts the steps again from 5 s. The
|
||||||
|
// event is heard through Env.Hear on the contract's subject; a refused subscription is said once and tried again.
|
||||||
|
func trunkAskBackoffAndCatalogRevision(t *testing.T) {
|
||||||
|
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||||
|
now := time.Date(2026, 11, 19, 10, 0, 0, 0, time.UTC)
|
||||||
|
var asks int
|
||||||
|
answers := false
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
env.Now = func() time.Time { return now }
|
||||||
|
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||||
|
if verb != meshcatalog.VerbModule {
|
||||||
|
return nil, errors.New("not held")
|
||||||
|
}
|
||||||
|
asks++
|
||||||
|
if !answers {
|
||||||
|
return nil, errors.New("the catalog is busy")
|
||||||
|
}
|
||||||
|
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: old, Manifest: map[string]any{"module": "postgres"}}})
|
||||||
|
})
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.wants["postgres"] = meshwants.WantsByWantNodeModuleValue{Fp: old}
|
||||||
|
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "postgres"}}}
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}}
|
||||||
|
c.mu.Unlock()
|
||||||
|
pass := func(want int, what string) {
|
||||||
|
t.Helper()
|
||||||
|
c.askTrunkBuilds()()
|
||||||
|
if asks != want {
|
||||||
|
t.Fatalf("%s: the catalog was asked %d times, want %d", what, asks, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pass(1, "first pass")
|
||||||
|
pass(1, "a second pass at once")
|
||||||
|
now = now.Add(4 * time.Second)
|
||||||
|
pass(1, "within the 5 s step")
|
||||||
|
now = now.Add(2 * time.Second)
|
||||||
|
pass(2, "after the 5 s step")
|
||||||
|
now = now.Add(14 * time.Second)
|
||||||
|
pass(2, "within the 15 s step")
|
||||||
|
c.trunkRetryCleared() // what hearing catalog-revision does
|
||||||
|
pass(3, "after catalog-revision")
|
||||||
|
pass(3, "the revision's ask gave none again: a step waits again")
|
||||||
|
answers = true
|
||||||
|
now = now.Add(time.Minute)
|
||||||
|
pass(4, "after the longer step")
|
||||||
|
if _, backing := c.trunkRetry["postgres"]; backing {
|
||||||
|
t.Errorf("an answer came and the backoff of the module stands: %+v", c.trunkRetry)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The wiring: the composer hears the seat's event on the contract's subject. A subscription Hear refuses is said once with the subject
|
||||||
|
// and the error, never refuses Watch, and is tried again (principle 3); once it holds, an event clears the waits.
|
||||||
|
setFor(t, &laterAgain, []time.Duration{time.Nanosecond})
|
||||||
|
b := newFakeBus()
|
||||||
|
env.Say = b.env().Say
|
||||||
|
attempts := make(chan struct{}, 8)
|
||||||
|
heard := make(chan []byte) // unbuffered: a second send returns only when the first event was handled
|
||||||
|
var tries int
|
||||||
|
env.Hear = func(subject string) (<-chan []byte, func(), error) {
|
||||||
|
if subject != meshcatalog.SubjectCatalogRevisionAll {
|
||||||
|
return make(chan []byte), func() {}, nil
|
||||||
|
}
|
||||||
|
tries++
|
||||||
|
attempts <- struct{}{}
|
||||||
|
if tries < 2 {
|
||||||
|
return nil, nil, errors.New("permissions violation")
|
||||||
|
}
|
||||||
|
return heard, func() {}, nil
|
||||||
|
}
|
||||||
|
answers = false
|
||||||
|
c = New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.trunkRetry = map[string]trunkBackoff{"postgres": {tries: 1, next: now.Add(time.Hour)}}
|
||||||
|
c.mu.Unlock()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
if _, err := c.Watch(ctx, "n1.>"); err != nil {
|
||||||
|
t.Fatalf("a refused catalog-revision subscription refused Watch: %v", err)
|
||||||
|
}
|
||||||
|
<-attempts
|
||||||
|
<-attempts // the second attempt comes after the refusal was said
|
||||||
|
said := 0
|
||||||
|
b.mu.Lock()
|
||||||
|
for _, line := range b.said {
|
||||||
|
if strings.Contains(line, meshcatalog.SubjectCatalogRevisionAll) && strings.Contains(line, "permissions violation") {
|
||||||
|
said++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.mu.Unlock()
|
||||||
|
if said != 1 {
|
||||||
|
t.Errorf("the refusal was said %d times, want once", said)
|
||||||
|
}
|
||||||
|
heard <- []byte(`{}`)
|
||||||
|
heard <- []byte(`{}`)
|
||||||
|
c.mu.Lock()
|
||||||
|
next := c.trunkRetry["postgres"].next
|
||||||
|
c.mu.Unlock()
|
||||||
|
if !next.IsZero() {
|
||||||
|
t.Error("catalog-revision was heard and the wait of the module stands")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,9 +16,20 @@ func (c *Composer) KeptBuildOf(_ context.Context, module, digest string) (node,
|
|||||||
if !ok || w.Fp == "" || w.KeptOn == "" {
|
if !ok || w.Fp == "" || w.KeptOn == "" {
|
||||||
return "", "", false, nil
|
return "", "", false, nil
|
||||||
}
|
}
|
||||||
if len(w.Parts) > 0 {
|
parts := w.Parts
|
||||||
|
if len(parts) == 0 && w.Version != "" {
|
||||||
|
// A want naming its version names its digests through the registry seats (A-430a): the resolution the composing made.
|
||||||
|
c.mu.Lock()
|
||||||
|
r := c.resolved[resolvedKey{module, w.Fp, w.Version}]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if r.parts == nil {
|
||||||
|
return "", "", false, nil
|
||||||
|
}
|
||||||
|
parts = r.parts
|
||||||
|
}
|
||||||
|
if len(parts) > 0 {
|
||||||
named := false
|
named := false
|
||||||
for _, d := range w.Parts {
|
for _, d := range parts {
|
||||||
if strings.TrimPrefix(d, "sha256:") == strings.TrimPrefix(digest, "sha256:") {
|
if strings.TrimPrefix(d, "sha256:") == strings.TrimPrefix(digest, "sha256:") {
|
||||||
named = true
|
named = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,242 @@
|
|||||||
|
package selfcompose
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The one place that answers "the manifest of the build a module runs here" (design 47 G A-484, joining A-480, A-480a, A-483 and
|
||||||
|
// A-461d). Every step that needs it reads it here and nowhere else: what the module provides (a held module keeps providing
|
||||||
|
// what it runs, frombus.Scope.RunningManifest), what it keeps on the bus and whether that changes form (FormChanges), the
|
||||||
|
// artifact store's holder (layModules, A-461d), and the picture of the catalog the composer resolves from. It answers in this
|
||||||
|
// order: the entry of the running build; else the manifest its running statement names, when held (A-484a); else the module's trunk manifest
|
||||||
|
// through the seat mesh-catalog's verb `module`. The composition answers no manifest, only whether the build keeps data (A-483).
|
||||||
|
|
||||||
|
// The three sources of the one place, in the words it says them in.
|
||||||
|
const (
|
||||||
|
SourceEntry = "the entry of the running build"
|
||||||
|
SourceStatement = "the manifest its running statement names"
|
||||||
|
// SourceComposition answers no manifest: only the build and whether it keeps data on the bus (A-484a).
|
||||||
|
SourceComposition = "the composition this node runs of it"
|
||||||
|
SourceTrunk = "the module's trunk manifest in the catalog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// runningAnswer is what the one place answers of one module.
|
||||||
|
type runningAnswer struct {
|
||||||
|
// Source is the source that answered; empty when none did, and Why then names the three.
|
||||||
|
Source string
|
||||||
|
// FP is the build the answer is of: the running build for an entry, the composition's build, or the trunk's.
|
||||||
|
FP string
|
||||||
|
// Known says the manifest itself was read (an entry or the trunk); a composition names its build and whether it keeps
|
||||||
|
// data, which is all it holds of the manifest.
|
||||||
|
Known bool
|
||||||
|
Manifest catalogue.Manifest
|
||||||
|
Raw []byte
|
||||||
|
Digest string
|
||||||
|
// Data is, from the composition, whether the running build keeps data on the bus.
|
||||||
|
Data bool
|
||||||
|
// Repository, Commit and Path are where the manifest's entry or the trunk's answer says it is built from.
|
||||||
|
Repository, Commit, Path string
|
||||||
|
// Why names what each of the three said, when none answered.
|
||||||
|
Why string
|
||||||
|
// RunFP is the running build the trunk manifest is asked for and kept against (A-461b).
|
||||||
|
RunFP string
|
||||||
|
// NeedTrunk says the trunk manifest is the one source left and is not held yet: the composer asks it beside the pass.
|
||||||
|
NeedTrunk bool
|
||||||
|
// Said is the line saying the source, for sayOnceEach (once per module and source, principle 3); empty when none answered.
|
||||||
|
Said string
|
||||||
|
}
|
||||||
|
|
||||||
|
// runningFpsLocked are the fingerprints of the build module runs on node, as the node's own record says (c.mu held), most direct
|
||||||
|
// first: the build its running event names; on this node else the hint the caller knows and the build of the composition it runs;
|
||||||
|
// on another node also the build its placement names, the mesh's truth of what runs there (A-461).
|
||||||
|
func (c *Composer) runningFpsLocked(running []engcomp.Composed, node, module, hint string) (fps []string) {
|
||||||
|
add := func(fp string) {
|
||||||
|
if fp != "" && !slices.Contains(fps, fp) {
|
||||||
|
fps = append(fps, fp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r, ok := c.heard[node][module]; ok && !r.stopped {
|
||||||
|
add(r.fingerprint)
|
||||||
|
}
|
||||||
|
if node != c.env.Node {
|
||||||
|
add(c.placedBuild(node, module))
|
||||||
|
return fps
|
||||||
|
}
|
||||||
|
add(hint)
|
||||||
|
add(c.haveFp[module]) // the build its have names (A-482)
|
||||||
|
for _, r := range running {
|
||||||
|
if r.Module == module {
|
||||||
|
add(r.FP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fps
|
||||||
|
}
|
||||||
|
|
||||||
|
// runningLocked answers the manifest of the build module runs on node (c.mu held; running is what this node runs, read before
|
||||||
|
// the lock), from the three sources in order, and says which answered once per module and source.
|
||||||
|
func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint string) runningAnswer {
|
||||||
|
fps := c.runningFpsLocked(running, node, module, hint)
|
||||||
|
fp := ""
|
||||||
|
if len(fps) > 0 {
|
||||||
|
fp = fps[0]
|
||||||
|
}
|
||||||
|
var a runningAnswer
|
||||||
|
entryWhy, compWhy, trunkWhy := "", "", ""
|
||||||
|
// 1. The entry of the running build.
|
||||||
|
for _, f := range fps {
|
||||||
|
k, ok := c.keptEnt[f]
|
||||||
|
if !ok || k.entry.Module == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if digest, raw, err := entryManifest(k.entry); err == nil {
|
||||||
|
if man, err := catalogue.Decode(raw); err == nil {
|
||||||
|
a = runningAnswer{Source: SourceEntry, FP: f, Known: true, Manifest: man, Raw: raw, Digest: digest,
|
||||||
|
Repository: k.entry.Repository, Commit: k.entry.Commit, Path: k.entry.Path}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. The manifest its running statement (the running event) names, when this node holds it (A-484a).
|
||||||
|
statementWhy := "its running event names no manifest"
|
||||||
|
if r, ok := c.heard[node][module]; ok && !r.stopped && a.Source == "" && r.manifest != "" {
|
||||||
|
if raw, held := c.manifests[r.manifest]; held {
|
||||||
|
if man, err := catalogue.Decode(raw); err == nil {
|
||||||
|
a = runningAnswer{Source: SourceStatement, FP: r.fingerprint, Known: true, Manifest: man, Raw: raw, Digest: r.manifest}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statementWhy = "this node holds no manifest " + r.manifest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if a.Source == "" {
|
||||||
|
entryWhy = fmt.Sprintf("no entry of the build %s is held", orNone(fp))
|
||||||
|
// The composition this node runs of that build, whatever the want's build: it answers whether the build keeps data (A-483, A-484a).
|
||||||
|
if node == c.env.Node {
|
||||||
|
for _, r := range running {
|
||||||
|
if r.Module != module || r.FP == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// The composition holds no manifest, only its build and whether that keeps data; its build's entry, if held, was
|
||||||
|
// read as the running build's above.
|
||||||
|
a = runningAnswer{Source: SourceComposition, FP: r.FP, Data: r.Data}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if a.Source == "" {
|
||||||
|
compWhy = "this node runs no composition of it"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
compWhy = "only the node itself runs compositions of its modules"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 3. The module's trunk manifest through the seat's verb `module`.
|
||||||
|
if !a.Known {
|
||||||
|
if t, ok := c.trunkBuilds[module]; ok && t.running == fp && len(t.manifest) > 0 {
|
||||||
|
if raw, err := json.Marshal(t.manifest); err == nil {
|
||||||
|
if man, err := catalogue.Decode(raw); err == nil {
|
||||||
|
keep := a // the composition's words stay: it says whether the build keeps data
|
||||||
|
a = runningAnswer{Source: SourceTrunk, FP: t.fp, Known: true, Manifest: man, Raw: raw, Digest: digestOf(raw),
|
||||||
|
Repository: t.repository, Commit: t.commit, Path: t.path, Data: keep.Data}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !a.Known {
|
||||||
|
trunkWhy = c.trunkWhy[module]
|
||||||
|
if trunkWhy == "" {
|
||||||
|
trunkWhy = "the seat mesh-catalog's verb module has not answered"
|
||||||
|
}
|
||||||
|
a.NeedTrunk, a.RunFP = true, fp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if a.Source == "" || (!a.Known && a.Source == SourceComposition) {
|
||||||
|
a.Why = fmt.Sprintf("the manifest of the build %s runs here is read from none of: %s (%s); %s (%s); %s (%s)", module,
|
||||||
|
SourceEntry, orWords(entryWhy, "its entry is held without a manifest"), SourceStatement, statementWhy, SourceTrunk, trunkWhy)
|
||||||
|
if a.Source == SourceComposition {
|
||||||
|
a.Why += fmt.Sprintf("; its composition names the build %s and says whether it keeps data: %v", a.FP, a.Data)
|
||||||
|
} else if compWhy != "" {
|
||||||
|
a.Why += "; " + compWhy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if a.Source != "" {
|
||||||
|
// Said once per module and source by sayOnceEach, by whoever uses the answer (principle 3).
|
||||||
|
where := ""
|
||||||
|
if node != c.env.Node {
|
||||||
|
where = " on " + node
|
||||||
|
}
|
||||||
|
a.Said = fmt.Sprintf("%s%s runs a build whose manifest is read from %s", module, where, a.Source)
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// runningManifest is runningLocked with the lock taken here: what runs is read first, since the agent's record may wait.
|
||||||
|
func (c *Composer) runningManifest(node, module, hint string) runningAnswer {
|
||||||
|
var running []engcomp.Composed
|
||||||
|
if c.env.Running != nil {
|
||||||
|
running = c.env.Running()
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
a := c.runningLocked(running, node, module, hint)
|
||||||
|
c.mu.Unlock()
|
||||||
|
if a.Said != "" {
|
||||||
|
c.sayOnceEach(a.Said)
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// countsAsRunning says this node holds module on as it runs it (A-482, c.mu held): it is heard running here, in what the agent
|
||||||
|
// runs, or its have names a build in the phase running or held. A module wanted here with none of these runs nothing here.
|
||||||
|
func (c *Composer) countsAsRunning(module string) bool {
|
||||||
|
if run := c.heard[c.env.Node][module]; run.stopped {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return c.runsHere(module) || c.haveRuns[module]
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunningManifest is what the one place says of module's running build here, in words, for the tool composition: the source that
|
||||||
|
// answered with its build, or the words naming the three it tried.
|
||||||
|
func (c *Composer) RunningManifest(module string) (source, fp, words string) {
|
||||||
|
a := c.runningManifest(c.env.Node, module, "")
|
||||||
|
if a.Source == "" || (!a.Known && a.Why != "") {
|
||||||
|
return a.Source, a.FP, a.Why
|
||||||
|
}
|
||||||
|
return a.Source, a.FP, fmt.Sprintf("the manifest of the build %s runs here is read from %s", module, a.Source)
|
||||||
|
}
|
||||||
|
|
||||||
|
// runningFor is the manifest of the build a module runs on node, for frombus.Scope.RunningManifest: only a module counted as
|
||||||
|
// running here (A-482) answers, and only a manifest read, never a composition alone.
|
||||||
|
func (c *Composer) runningFor(node string) func(module string) (catalogue.Manifest, bool) {
|
||||||
|
return func(module string) (catalogue.Manifest, bool) {
|
||||||
|
c.mu.Lock()
|
||||||
|
counts := node != c.env.Node || c.countsAsRunning(module)
|
||||||
|
c.mu.Unlock()
|
||||||
|
if !counts {
|
||||||
|
return catalogue.Manifest{}, false
|
||||||
|
}
|
||||||
|
a := c.runningManifest(node, module, "")
|
||||||
|
return a.Manifest, a.Known
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func digestOf(raw []byte) string {
|
||||||
|
sum := sha256.Sum256(raw)
|
||||||
|
return "sha256:" + hex.EncodeToString(sum[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func orNone(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return "(none named)"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func orWords(s, otherwise string) string {
|
||||||
|
if s == "" {
|
||||||
|
return otherwise
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
@@ -136,6 +136,9 @@ type Env struct {
|
|||||||
// Set, the composer reads the catalog half by the fingerprints its wants and the runnings it heard name and nothing else of
|
// Set, the composer reads the catalog half by the fingerprints its wants and the runnings it heard name and nothing else of
|
||||||
// the indexer's or the builder's states (design 47 G §421, §628); a composer is made with it.
|
// the indexer's or the builder's states (design 47 G §421, §628); a composer is made with it.
|
||||||
Entry meshcatalogclient.Call
|
Entry meshcatalogclient.Call
|
||||||
|
// Registry asks the registry seats' verb versions (oci-artifact-registry, container-image-registry) in the engine's own
|
||||||
|
// name: a want naming its version is resolved to its artifacts' digests through it (design 47 G A-430a).
|
||||||
|
Registry meshcatalogclient.Call
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManifestOf is the digest of the manifest of the build a module runs at fp, from the composer's picture of the catalog half;
|
// ManifestOf is the digest of the manifest of the build a module runs at fp, from the composer's picture of the catalog half;
|
||||||
@@ -176,7 +179,12 @@ type Composer struct {
|
|||||||
records map[string]nodeengine.NodeRecord
|
records map[string]nodeengine.NodeRecord
|
||||||
// inOwn is, by module, whether this node's have of it names no fingerprint of the new form (mesh-wireguard, a module
|
// inOwn is, by module, whether this node's have of it names no fingerprint of the new form (mesh-wireguard, a module
|
||||||
// at a build of the old form): the node runs it inside its own composition, and composes it there again (issue 1126).
|
// at a build of the old form): the node runs it inside its own composition, and composes it there again (issue 1126).
|
||||||
inOwn map[string]bool
|
inOwn map[string]bool
|
||||||
|
// haveRuns is, by module, whether this node's have of it names a build in the phase running or held: a module that
|
||||||
|
// keeps running what it runs, though no running event says it (design 47 G A-482).
|
||||||
|
haveRuns map[string]bool
|
||||||
|
// haveFp is, by module, the build that have names, where haveRuns says it runs: one of the builds the one place reads (A-482, A-484).
|
||||||
|
haveFp map[string]string
|
||||||
modules map[string]meshcatalog.ModulesByModuleValue
|
modules map[string]meshcatalog.ModulesByModuleValue
|
||||||
told map[string]bool // lines said once each (sayOnceEach)
|
told map[string]bool // lines said once each (sayOnceEach)
|
||||||
values map[string]map[string]any // by module, this node's
|
values map[string]map[string]any // by module, this node's
|
||||||
@@ -193,7 +201,9 @@ type Composer struct {
|
|||||||
entries *meshcatalogclient.Entries
|
entries *meshcatalogclient.Entries
|
||||||
keptEnt map[string]keptEntry
|
keptEnt map[string]keptEntry
|
||||||
// notFound is each fingerprint whose entry-not-found the composer told, so it is told once and cleared once.
|
// notFound is each fingerprint whose entry-not-found the composer told, so it is told once and cleared once.
|
||||||
notFound map[string]bool
|
notFound map[string]bool
|
||||||
|
// resolved is each wanted build's digests as its version resolved them through the registry seats (versions.go, A-430a).
|
||||||
|
resolved map[resolvedKey]versionParts
|
||||||
keptWantVal map[string]keptWant
|
keptWantVal map[string]keptWant
|
||||||
keptWants map[string]bool
|
keptWants map[string]bool
|
||||||
keptWrite sync.Mutex
|
keptWrite sync.Mutex
|
||||||
@@ -204,8 +214,17 @@ type Composer struct {
|
|||||||
addedFps map[string]bool
|
addedFps map[string]bool
|
||||||
// heard is, by node and module, what each node's event running last said it runs, kept from the seat's stream by this
|
// heard is, by node and module, what each node's event running last said it runs, kept from the seat's stream by this
|
||||||
// node's own consumer (NoteRunning), under mu; heardRead is whether the first read of the stream ended (RunningRead).
|
// node's own consumer (NoteRunning), under mu; heardRead is whether the first read of the stream ended (RunningRead).
|
||||||
heard map[string]map[string]heardRun
|
heard map[string]map[string]heardRun
|
||||||
heardRead bool
|
// trunkBuilds is, by module, the trunk build asked for another node's module whose placement names none, with the running build it was asked for (A-461b).
|
||||||
|
trunkBuilds map[string]trunkBuild
|
||||||
|
// trunkAsking is, by module, a trunk build being asked beside the pass (askTrunkBuilds), under mu.
|
||||||
|
trunkAsking map[string]bool
|
||||||
|
// trunkWhy is, by module, why the last ask of its trunk build gave none, for the words of the one place (A-484).
|
||||||
|
trunkWhy map[string]string
|
||||||
|
// trunkRetry is, by module, the backoff of asking its trunk build again after an answer that was none: the asks made in a row
|
||||||
|
// without an answer and the time before which it is not asked (A-487a), under mu.
|
||||||
|
trunkRetry map[string]trunkBackoff
|
||||||
|
heardRead bool
|
||||||
// ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that
|
// ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that
|
||||||
// ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293).
|
// ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293).
|
||||||
ends map[string]builds.BuildEnded
|
ends map[string]builds.BuildEnded
|
||||||
@@ -414,7 +433,7 @@ func New(env Env) *Composer {
|
|||||||
|
|
||||||
func newComposer(env Env) *Composer {
|
func newComposer(env Env) *Composer {
|
||||||
return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, assignments: map[string]meshmoduleassigner.Assignments{}, assignmentKeys: meshmoduleassignerclient.NewKeys(),
|
return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, assignments: map[string]meshmoduleassigner.Assignments{}, assignmentKeys: meshmoduleassignerclient.NewKeys(),
|
||||||
records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{},
|
records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, haveRuns: map[string]bool{}, haveFp: map[string]string{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{},
|
||||||
manifests: map[string][]byte{}, archives: map[string][]byte{}, handed: map[string]string{}, notTaken: map[string]string{}, unmadeSaid: map[string]string{}, rehand: make(chan struct{}, 1), sealedOwn: map[string]ownSealed{},
|
manifests: map[string][]byte{}, archives: map[string][]byte{}, handed: map[string]string{}, notTaken: map[string]string{}, unmadeSaid: map[string]string{}, rehand: make(chan struct{}, 1), sealedOwn: map[string]ownSealed{},
|
||||||
pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)}
|
pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)}
|
||||||
}
|
}
|
||||||
@@ -524,6 +543,12 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
|
|||||||
}(i, ch)
|
}(i, ch)
|
||||||
}
|
}
|
||||||
if c.env.Hear != nil {
|
if c.env.Hear != nil {
|
||||||
|
go c.hearCatalogRevisions(ctx, func() {
|
||||||
|
select {
|
||||||
|
case merged <- tagged{in: -1, ok: true}:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
})
|
||||||
heard, stop, err := c.env.Hear(VaultSecretChanged)
|
heard, stop, err := c.env.Hear(VaultSecretChanged)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("the node composes again when a secret changes, and cannot hear the vault say so: %w", err)
|
return nil, fmt.Errorf("the node composes again when a secret changes, and cannot hear the vault say so: %w", err)
|
||||||
@@ -681,6 +706,41 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hearCatalogRevisions hears the seat mesh-catalog's event catalog-revision: each one clears the backoffs of the trunk builds the
|
||||||
|
// catalog gave none of and wakes a pass (A-487a). A wake-up only, the backoff bounds the asks without it: a subscription refused
|
||||||
|
// is said once with its subject and error (principle 3), the composer goes on composing, and the subscription is tried again on
|
||||||
|
// laterAgain's steps until it holds.
|
||||||
|
func (c *Composer) hearCatalogRevisions(ctx context.Context, wake func()) {
|
||||||
|
said := false
|
||||||
|
for try := 0; ; try++ {
|
||||||
|
revisions, stop, err := c.env.Hear(meshcatalog.SubjectCatalogRevisionAll)
|
||||||
|
if err == nil {
|
||||||
|
defer stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case _, ok := <-revisions:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.trunkRetryCleared()
|
||||||
|
wake()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !said {
|
||||||
|
said = true
|
||||||
|
c.env.Say(fmt.Sprintf("the node cannot hear %s: %v; it asks the trunk builds again on a backoff alone and tries to hear it again", meshcatalog.SubjectCatalogRevisionAll, err))
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-time.After(LaterWait(try)):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func all(b []bool) bool {
|
func all(b []bool) bool {
|
||||||
for _, v := range b {
|
for _, v := range b {
|
||||||
if !v {
|
if !v {
|
||||||
@@ -718,7 +778,9 @@ func (c *Composer) entry(bucket, key string) (v any, has, known bool) {
|
|||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
switch bucket {
|
switch bucket {
|
||||||
case buckets.Wants:
|
case buckets.Wants:
|
||||||
// A want is composed by its fingerprint alone (fingerprints); its words, rule and newest change nothing composed.
|
// A want is composed by its fingerprint, version, parts and keeping node (design 47 G §525); its words, rule and newest
|
||||||
|
// change nothing composed. Judged by its fingerprint alone, a want that gained its parts at the same fingerprint asked no
|
||||||
|
// pass, and the agent waited for a composition never made (lead-47 2026-11-16, the indexer on novox).
|
||||||
module := agent.NodeModule
|
module := agent.NodeModule
|
||||||
if _, ok := meshwants.ParseWantsByWantNodeNodeKey(key); !ok {
|
if _, ok := meshwants.ParseWantsByWantNodeNodeKey(key); !ok {
|
||||||
node, m, ok := meshwants.ParseWantsByWantNodeModuleKey(key)
|
node, m, ok := meshwants.ParseWantsByWantNodeModuleKey(key)
|
||||||
@@ -728,7 +790,10 @@ func (c *Composer) entry(bucket, key string) (v any, has, known bool) {
|
|||||||
module = m
|
module = m
|
||||||
}
|
}
|
||||||
w, ok := c.wants[module]
|
w, ok := c.wants[module]
|
||||||
return w.Fp, ok, true
|
return struct {
|
||||||
|
Fp, Version, KeptOn string
|
||||||
|
Parts map[string]string
|
||||||
|
}{w.Fp, w.Version, w.KeptOn, w.Parts}, ok, true
|
||||||
case buckets.Assignments:
|
case buckets.Assignments:
|
||||||
// Any key of a node, its node key, a module key or its legacy key, stands for the node's whole assignment: a
|
// Any key of a node, its node key, a module key or its legacy key, stands for the node's whole assignment: a
|
||||||
// module key written before its node key names it changes nothing composed.
|
// module key written before its node key names it changes nothing composed.
|
||||||
@@ -848,9 +913,11 @@ func (c *Composer) takeModuleHave(u agent.Update) bool {
|
|||||||
if err != nil || isNode || node != c.env.Node {
|
if err != nil || isNode || node != c.env.Node {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
in := false
|
in, runs, haveFp := false, false, ""
|
||||||
if !u.Deleted {
|
if !u.Deleted {
|
||||||
if h, err := nodeengineclient.DecodeHave(u.Value); err == nil {
|
if h, err := nodeengineclient.DecodeHave(u.Value); err == nil {
|
||||||
|
haveFp = h.Fp
|
||||||
|
runs = (h.Phase == nodeengineclient.PhaseRunning || h.Phase == nodeengineclient.PhaseHeld) && h.Fp != ""
|
||||||
// A have that names nothing it runs, failed (the node could not compose a module it never ran: NotComposed), is
|
// A have that names nothing it runs, failed (the node could not compose a module it never ran: NotComposed), is
|
||||||
// no module run inside the node's own composition: taken as one, it was composed from its manifest past its
|
// no module run inside the node's own composition: taken as one, it was composed from its manifest past its
|
||||||
// build (issue 1126, review round 1 of the builds).
|
// build (issue 1126, review round 1 of the builds).
|
||||||
@@ -865,8 +932,16 @@ func (c *Composer) takeModuleHave(u agent.Update) bool {
|
|||||||
}
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
changed := c.haveRuns[module] != runs
|
||||||
|
if runs {
|
||||||
|
c.haveRuns[module] = true
|
||||||
|
c.haveFp[module] = haveFp
|
||||||
|
} else {
|
||||||
|
delete(c.haveRuns, module)
|
||||||
|
delete(c.haveFp, module)
|
||||||
|
}
|
||||||
if c.inOwn[module] == in {
|
if c.inOwn[module] == in {
|
||||||
return false
|
return changed
|
||||||
}
|
}
|
||||||
if in {
|
if in {
|
||||||
c.inOwn[module] = true
|
c.inOwn[module] = true
|
||||||
@@ -1012,7 +1087,7 @@ func (c *Composer) compose(ctx context.Context) []agent.Update {
|
|||||||
var keptMu sync.Mutex
|
var keptMu sync.Mutex
|
||||||
var holds map[string]compose.Hold
|
var holds map[string]compose.Hold
|
||||||
fromManifest := map[string]string{} // by module, why it is composed from the indexer's manifest and not a build
|
fromManifest := map[string]string{} // by module, why it is composed from the indexer's manifest and not a build
|
||||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) {
|
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) {
|
||||||
keptMu.Lock()
|
keptMu.Lock()
|
||||||
defer keptMu.Unlock()
|
defer keptMu.Unlock()
|
||||||
if !slices.Contains(keptRuns[module], words) {
|
if !slices.Contains(keptRuns[module], words) {
|
||||||
@@ -1388,25 +1463,15 @@ func (c *Composer) Policy(ctx context.Context, module string) string {
|
|||||||
return policy
|
return policy
|
||||||
}
|
}
|
||||||
|
|
||||||
// HoldsData says whether a module's manifest declares data (catalogue.Manifest.DataItems), as a composition's Data says
|
// HoldsData says whether the manifest of the build a module runs here declares data (catalogue.Manifest.DataItems), as a
|
||||||
// it, and whether the manifest could be read: the agent's Data for what runs of a module from the kept declaration
|
// composition's Data says it, and whether that manifest could be read, from the one place (A-484): the agent's Data for what runs of a module from the kept declaration
|
||||||
// (agent.Env.HoldsData, issue 924).
|
// (agent.Env.HoldsData, issue 924).
|
||||||
func (c *Composer) HoldsData(ctx context.Context, module string) (data, known bool) {
|
func (c *Composer) HoldsData(_ context.Context, module string) (data, known bool) {
|
||||||
c.mu.Lock()
|
a := c.runningManifest(c.env.Node, module, "")
|
||||||
m, ok := c.modules[module]
|
if !a.Known {
|
||||||
c.mu.Unlock()
|
|
||||||
if !ok || m.Manifest == "" {
|
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
raw, err := reader{c: c}.Manifest(ctx, m.Manifest)
|
return len(a.Manifest.DataItems()) > 0, true
|
||||||
if err != nil {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
parsed, held, err := c.taken(module, m, raw)
|
|
||||||
if err != nil || held != "" {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
return len(parsed.DataItems()) > 0, true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// taken is a module's manifest as this engine reads it (novox/hq ADR 0578 §3): decoded leniently, judging nothing, with
|
// taken is a module's manifest as this engine reads it (novox/hq ADR 0578 §3): decoded leniently, judging nothing, with
|
||||||
@@ -1875,7 +1940,7 @@ func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string
|
|||||||
if c.env.Running != nil {
|
if c.env.Running != nil {
|
||||||
running = c.env.Running()
|
running = c.env.Running()
|
||||||
}
|
}
|
||||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow()}
|
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node)}
|
||||||
comps, _, held, err := frombus.Compose(ctx, reader{c: c}, c.env.Mesh, scope, fps)
|
comps, _, held, err := frombus.Compose(ctx, reader{c: c}, c.env.Mesh, scope, fps)
|
||||||
if err != nil || held[module] != "" {
|
if err != nil || held[module] != "" {
|
||||||
return "", false
|
return "", false
|
||||||
@@ -2301,6 +2366,14 @@ func (c *Composer) WhyUnmade(module string) string {
|
|||||||
return c.last.Unmade[module]
|
return c.last.Unmade[module]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trunkBuild is a module's trunk build as the seat mesh-catalog's verb module answered it for the running build it was asked for
|
||||||
|
// (A-461b, A-484): its fingerprint, its manifest and where it is built from.
|
||||||
|
type trunkBuild struct {
|
||||||
|
running, fp string
|
||||||
|
manifest map[string]any
|
||||||
|
repository, commit, path string
|
||||||
|
}
|
||||||
|
|
||||||
// heardRun is one running event as the composer keeps it, with when it was said.
|
// heardRun is one running event as the composer keeps it, with when it was said.
|
||||||
type heardRun struct {
|
type heardRun struct {
|
||||||
at time.Time
|
at time.Time
|
||||||
|
|||||||
@@ -96,6 +96,58 @@ func (b *fakeBus) put(t *testing.T, bucket, key string, value []byte) {
|
|||||||
b.send(bucket, agent.Update{Key: key, Value: value})
|
b.send(bucket, agent.Update{Key: key, Value: value})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Design 47 G A-461c: the golden node grant (called from the test of what the node reads under it) is checked against the node-engine's manifest. Every seat verb it invokes has its
|
||||||
|
// call subject in the grant, in the form the grants part writes: a grant to call a seat's verb is `mesh.seat.<seat>.tool.<verb>`
|
||||||
|
// and `.tool.<verb>.*` (mesh-grants internal/buscompose nats.go:1960-1969, invokedSubjects), and each is also written under the
|
||||||
|
// `call` kind with the caller's own token last (callers.go:75-91, calledPublish; the token is the user with each dot a `~`):
|
||||||
|
// `mesh.seat.<seat>.call.<verb>.node~<node>` and `mesh.seat.<seat>.call.<verb>.*.node~<node>`. A verb of a seat held per node
|
||||||
|
// may be granted for the one node, `.call.<verb>.<node>.node~<node>`, which is the same grant in the node's own form. A verb the
|
||||||
|
// composer asks that the golden grant lacks is refused in the real bus and hangs the pass to its bound (the verb module, #233).
|
||||||
|
func checkGrantHoldsEveryInvokedVerb(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
raw, err := os.ReadFile("../../module.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var m struct {
|
||||||
|
Invokes []json.RawMessage `json:"invokes"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(raw, &m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
p := nodegrant.For("it1")
|
||||||
|
seen := 0
|
||||||
|
for _, r := range m.Invokes {
|
||||||
|
var verb string
|
||||||
|
if json.Unmarshal(r, &verb) != nil {
|
||||||
|
var o struct {
|
||||||
|
Verb string `json:"verb"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(r, &o); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
verb = o.Verb
|
||||||
|
}
|
||||||
|
rest, isSeat := strings.CutPrefix(verb, "seat:")
|
||||||
|
if !isSeat {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seat, name, ok := strings.Cut(rest, ".")
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("the invoke %q names no verb", verb)
|
||||||
|
}
|
||||||
|
seen++
|
||||||
|
base := "mesh.seat." + seat + ".call." + name + "."
|
||||||
|
forms := []string{base + "node~it1", base + "*.node~it1", base + "it1.node~it1"}
|
||||||
|
if !slices.ContainsFunc(forms, func(f string) bool { return slices.Contains(p.Publish, f) }) {
|
||||||
|
t.Errorf("the node's grant holds no call subject for %s: want one of %v", verb, forms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if seen == 0 {
|
||||||
|
t.Fatal("the manifest invokes no seat verb: the test reads nothing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// grantAllows says whether the node's grant (the grants part's, nodegrant.For) lets it watch or read pattern of
|
// grantAllows says whether the node's grant (the grants part's, nodegrant.For) lets it watch or read pattern of
|
||||||
// bucket: the consumer a watch or a get makes (`$JS.API.CONSUMER.CREATE.KV_<bucket>.<name>.$KV.<bucket>.<pattern>`)
|
// bucket: the consumer a watch or a get makes (`$JS.API.CONSUMER.CREATE.KV_<bucket>.<name>.$KV.<bucket>.<pattern>`)
|
||||||
// and the stream's information, matched as the bus matches a permission against a subject.
|
// and the stream's information, matched as the bus matches a permission against a subject.
|
||||||
@@ -158,6 +210,8 @@ func quiet(t *testing.T, out <-chan agent.Update) {
|
|||||||
// names any more is taken back; a node that cannot compose says so once and hands nothing.
|
// names any more is taken back; a node that cannot compose says so once and hands nothing.
|
||||||
func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||||
t.Run("it reads the catalog half by the fingerprints its wants name", composeFromEntries)
|
t.Run("it reads the catalog half by the fingerprints its wants name", composeFromEntries)
|
||||||
|
t.Run("a running module without an entry stands as the newest build", runningModuleWithoutEntryStandsAsTheNewestBuild)
|
||||||
|
t.Run("a want naming its version is resolved through the registry seats", aWantNamingItsVersionIsResolvedThroughTheRegistrySeats)
|
||||||
b := newFakeBus()
|
b := newFakeBus()
|
||||||
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
||||||
digest := meshcatalogclient.ManifestDigest([]byte(lemurs))
|
digest := meshcatalogclient.ManifestDigest([]byte(lemurs))
|
||||||
@@ -195,6 +249,9 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
secretChanged := make(chan []byte, 1)
|
secretChanged := make(chan []byte, 1)
|
||||||
env.Hear = func(subject string) (<-chan []byte, func(), error) {
|
env.Hear = func(subject string) (<-chan []byte, func(), error) {
|
||||||
|
if subject == meshcatalog.SubjectCatalogRevisionAll {
|
||||||
|
return make(chan []byte), func() {}, nil
|
||||||
|
}
|
||||||
if subject != VaultSecretChanged {
|
if subject != VaultSecretChanged {
|
||||||
t.Errorf("heard %s", subject)
|
t.Errorf("heard %s", subject)
|
||||||
}
|
}
|
||||||
@@ -1551,6 +1608,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
|||||||
if got, err := r.Served(ctx, "n2", "mailer", []string{"domain"}); err != nil || fmt.Sprint(got) != "map[domain:example.org]" {
|
if got, err := r.Served(ctx, "n2", "mailer", []string{"domain"}); err != nil || fmt.Sprint(got) != "map[domain:example.org]" {
|
||||||
t.Errorf("what n2's mailer serves: %v, %v", got, err)
|
t.Errorf("what n2's mailer serves: %v, %v", got, err)
|
||||||
}
|
}
|
||||||
|
checkGrantHoldsEveryInvokedVerb(t) // A-461c
|
||||||
served := nodegrant.For("n1", "n2.mailer.domain")
|
served := nodegrant.For("n1", "n2.mailer.domain")
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
for _, read := range b.reads {
|
for _, read := range b.reads {
|
||||||
@@ -1773,22 +1831,24 @@ func TestAHaveSaysWhetherItsModuleRunsInsideTheNodesOwn(t *testing.T) {
|
|||||||
in bool
|
in bool
|
||||||
// heldToday says the shadow counts the module held today (issue 1126: a seed holding it too holds it as today).
|
// heldToday says the shadow counts the module held today (issue 1126: a seed holding it too holds it as today).
|
||||||
heldToday bool
|
heldToday bool
|
||||||
|
// runs says the have names a build in the phase running or held: it keeps running what it runs (A-482).
|
||||||
|
runs bool
|
||||||
}{
|
}{
|
||||||
{"failed, naming nothing it runs", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseFailed, Health: nodeengineclient.HealthFailed,
|
{"failed, naming nothing it runs", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseFailed, Health: nodeengineclient.HealthFailed,
|
||||||
Detail: "the node cannot compose it, and keeps running what it ran: no build"}, false, true},
|
Detail: "the node cannot compose it, and keeps running what it ran: no build"}, false, true, false},
|
||||||
{"failed at a build fingerprint", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseFailed,
|
{"failed at a build fingerprint", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseFailed,
|
||||||
Health: nodeengineclient.HealthFailed, Detail: "the node cannot compose it, and keeps running what it ran: no build"}, true, true},
|
Health: nodeengineclient.HealthFailed, Detail: "the node cannot compose it, and keeps running what it ran: no build"}, true, true, false},
|
||||||
// The live have of novox's de-spiegel (2026-10-28): a build of the old form, named by `build`, and no `fp`.
|
// The live have of novox's de-spiegel (2026-10-28): a build of the old form, named by `build`, and no `fp`.
|
||||||
{"running a build of the old form", nodeengine.HaveByNodeModuleValue{Build: "build-1790368817085312877", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, true},
|
{"running a build of the old form", nodeengine.HaveByNodeModuleValue{Build: "build-1790368817085312877", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, true, false},
|
||||||
{"running a build of the new form", nodeengine.HaveByNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64), Composed: "sha256:" + strings.Repeat("c", 64),
|
{"running a build of the new form", nodeengine.HaveByNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64), Composed: "sha256:" + strings.Repeat("c", 64),
|
||||||
Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, false, false},
|
Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, false, false, true},
|
||||||
{"running with no fingerprint (mesh-wireguard)", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, false},
|
{"running with no fingerprint (mesh-wireguard)", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, false, false},
|
||||||
{"held today", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseHeld,
|
{"held today", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseHeld,
|
||||||
Health: nodeengineclient.HealthWaits, Detail: "held: a required config value is unset"}, true, true},
|
Health: nodeengineclient.HealthWaits, Detail: "held: a required config value is unset"}, true, true, true},
|
||||||
// novox's postgres (2026-10-31), its have written before mesh-host #189: held by a backup the node agent's stop
|
// novox's postgres (2026-10-31), its have written before mesh-host #189: held by a backup the node agent's stop
|
||||||
// interrupted and naming nothing; counted in, it was composed from its manifest and refused for its secret reader.
|
// interrupted and naming nothing; counted in, it was composed from its manifest and refused for its secret reader.
|
||||||
{"held by an interrupted backup, naming nothing", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseHeld, Health: nodeengineclient.HealthWaits,
|
{"held by an interrupted backup, naming nothing", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseHeld, Health: nodeengineclient.HealthWaits,
|
||||||
Detail: agent.BackupInterrupted}, false, true},
|
Detail: agent.BackupInterrupted}, false, true, false},
|
||||||
} {
|
} {
|
||||||
t.Run(row.name, func(t *testing.T) {
|
t.Run(row.name, func(t *testing.T) {
|
||||||
c := New(Env{Node: "n1"})
|
c := New(Env{Node: "n1"})
|
||||||
@@ -1804,6 +1864,9 @@ func TestAHaveSaysWhetherItsModuleRunsInsideTheNodesOwn(t *testing.T) {
|
|||||||
if c.inOwn["web"] != row.in {
|
if c.inOwn["web"] != row.in {
|
||||||
t.Errorf("web counted inside the node's own composition: %v, want %v", c.inOwn["web"], row.in)
|
t.Errorf("web counted inside the node's own composition: %v, want %v", c.inOwn["web"], row.in)
|
||||||
}
|
}
|
||||||
|
if c.haveRuns["web"] != row.runs {
|
||||||
|
t.Errorf("web counted as running by its have: %v, want %v", c.haveRuns["web"], row.runs)
|
||||||
|
}
|
||||||
s := &Shadow{c: c, ran: map[string]string{}}
|
s := &Shadow{c: c, ran: map[string]string{}}
|
||||||
s.takeRan(agent.Update{Key: key, Value: value})
|
s.takeRan(agent.Update{Key: key, Value: value})
|
||||||
if _, got := s.heldToday(nil)["web"]; got != row.heldToday {
|
if _, got := s.heldToday(nil)["web"]; got != row.heldToday {
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
|||||||
}
|
}
|
||||||
// The module is built from its entry and the parts the candidate gives (A-316); an artifact it gives no part for holds it.
|
// The module is built from its entry and the parts the candidate gives (A-316); an artifact it gives no part for holds it.
|
||||||
w := meshwants.WantsByWantNodeModuleValue{Fp: fp, Parts: own.c.Added[pm.Module].Parts, Version: own.c.Added[pm.Module].Version}
|
w := meshwants.WantsByWantNodeModuleValue{Fp: fp, Parts: own.c.Added[pm.Module].Parts, Version: own.c.Added[pm.Module].Version}
|
||||||
if missing := partsMissing(entry, w); missing != "" {
|
if _, missing := c.partsOf(pm.Module, entry, w); missing != "" {
|
||||||
heldAdded[pm.Module] = fmt.Sprintf("the candidate gives no part for %s of %s's build %s, so the node composes nothing new of it", missing, pm.Module, fp)
|
heldAdded[pm.Module] = fmt.Sprintf("the candidate gives no part for %s of %s's build %s, so the node composes nothing new of it", missing, pm.Module, fp)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -682,7 +682,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
|||||||
given[node] = &without
|
given[node] = &without
|
||||||
}
|
}
|
||||||
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn,
|
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn,
|
||||||
SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded)}, fps, running, proposal, rev)
|
SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded), RunningManifest: c.runningFor(node)}, fps, running, proposal, rev)
|
||||||
for _, module := range slices.Sorted(maps.Keys(heldAdded)) {
|
for _, module := range slices.Sorted(maps.Keys(heldAdded)) {
|
||||||
a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: module, Why: heldAdded[module]})
|
a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: module, Why: heldAdded[module]})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,217 @@
|
|||||||
|
package selfcompose
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/ociartifactregistry"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
)
|
||||||
|
|
||||||
|
// **A want names its version; the node-engine resolves the digests** (design 47 G A-430, A-430a, the lead's answer A-430b).
|
||||||
|
// A want of a released build names the module's version and no parts: each artifact of the build's entry is looked up at that
|
||||||
|
// version through the verb `versions` of the registry seat of its kind (oci-artifact-registry for a bundle or an archive,
|
||||||
|
// container-image-registry for an image), under the name the builder numbered it by: `<module>/<artifact>`, or the entry's
|
||||||
|
// package name for a package. An upstream copy is not numbered (it is mirrored by its pinned digest): its digest is the one its
|
||||||
|
// manifest's `from` pins. A want that names parts (a build no version is known of) is read by its parts as before. A lookup that
|
||||||
|
// fails is said in the journal, naming the module, the version and the seat, and the module is held whole: never composed partly.
|
||||||
|
|
||||||
|
// resolveAgain is how long a failed lookup stands before it is asked again; a pass is asked then.
|
||||||
|
const resolveAgain = time.Minute
|
||||||
|
|
||||||
|
// versionsVerb is the verb a lookup asks.
|
||||||
|
const versionsVerb = "versions"
|
||||||
|
|
||||||
|
// resolvedKey names one resolution: a module's build at a version.
|
||||||
|
type resolvedKey struct{ module, fp, version string }
|
||||||
|
|
||||||
|
// versionParts is a module's build at a version as resolved: its digests by artifact reference, or why not, and when that was found.
|
||||||
|
type versionParts struct {
|
||||||
|
parts map[string]string
|
||||||
|
failed string
|
||||||
|
at time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// registryVersions is the answer of either seat's verb `versions`: the two seats answer the same shape.
|
||||||
|
type registryVersions struct {
|
||||||
|
Versions []struct {
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
Tag string `json:"tag,omitempty"`
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
} `json:"versions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// seatOfKind is the registry seat an artifact of kind is numbered in, and whether one is (design 51 *The seats*).
|
||||||
|
func seatOfKind(kind string) (string, bool) {
|
||||||
|
switch kind {
|
||||||
|
case catalogue.ArtifactImage:
|
||||||
|
return containerimageregistry.Seat, true
|
||||||
|
case catalogue.ArtifactBundle, catalogue.ArtifactArchive:
|
||||||
|
return ociartifactregistry.Seat, true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
// registryName is the name an artifact of module is numbered under: `<module>/<artifact>`, or a package's name in its
|
||||||
|
// ecosystem as the entry gives it.
|
||||||
|
func registryName(module string, a meshcatalog.Artifact) string {
|
||||||
|
_, artifact, _ := strings.Cut(a.Ref, ":")
|
||||||
|
if a.Kind == catalogue.ArtifactPackage && a.Package != nil && a.Package.Name != "" {
|
||||||
|
return a.Package.Name
|
||||||
|
}
|
||||||
|
return module + "/" + artifact
|
||||||
|
}
|
||||||
|
|
||||||
|
// partsOf is the digest of each artifact of e for want w, by artifact reference, and the artifacts it names no digest for ("" when
|
||||||
|
// each has one). A want with parts gives them; a want with a version and no parts is resolved through the registry seats.
|
||||||
|
func (c *Composer) partsOf(module string, e meshcatalog.CatalogEntry, w meshwants.WantsByWantNodeModuleValue) (map[string]string, string) {
|
||||||
|
parts := w.Parts
|
||||||
|
if len(parts) == 0 && w.Version != "" && len(e.Artifacts) > 0 {
|
||||||
|
var why string
|
||||||
|
if parts, why = c.resolve(module, e, w); why != "" {
|
||||||
|
return nil, why
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts, partsMissing(e, parts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// partsMissing names the artifacts of e whose digest parts does not give; "" when each has one.
|
||||||
|
func partsMissing(e meshcatalog.CatalogEntry, parts map[string]string) string {
|
||||||
|
var out []string
|
||||||
|
for _, a := range e.Artifacts {
|
||||||
|
if parts[a.Ref] == "" {
|
||||||
|
out = append(out, a.Ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return strings.Join(out, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve is the digests of module's build at w's version, from what is resolved already or asked of the seats now. why names
|
||||||
|
// what failed; a failure stands resolveAgain, then is asked again.
|
||||||
|
func (c *Composer) resolve(module string, e meshcatalog.CatalogEntry, w meshwants.WantsByWantNodeModuleValue) (map[string]string, string) {
|
||||||
|
key := resolvedKey{module, w.Fp, w.Version}
|
||||||
|
now := c.now()
|
||||||
|
c.mu.Lock()
|
||||||
|
r, ok := c.resolved[key]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if ok && (r.failed == "" || now.Sub(r.at) < resolveAgain) {
|
||||||
|
return r.parts, r.failed
|
||||||
|
}
|
||||||
|
parts, failed := c.lookUp(module, e, w)
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.resolved == nil {
|
||||||
|
c.resolved = map[resolvedKey]versionParts{}
|
||||||
|
}
|
||||||
|
// Only the resolutions of the builds a want names now are kept.
|
||||||
|
for k := range c.resolved {
|
||||||
|
if cur, wanted := c.wants[k.module]; k.module != module && (!wanted || cur.Fp != k.fp || cur.Version != k.version) {
|
||||||
|
delete(c.resolved, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.resolved[key] = versionParts{parts: parts, failed: failed, at: now}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if failed != "" {
|
||||||
|
time.AfterFunc(resolveAgain, c.askRehand)
|
||||||
|
return nil, failed
|
||||||
|
}
|
||||||
|
return parts, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookUp asks each artifact's digest at w's version of the seat of its kind. Every failure is said, naming the module, the version
|
||||||
|
// and the seat; any failure resolves nothing of the build.
|
||||||
|
func (c *Composer) lookUp(module string, e meshcatalog.CatalogEntry, w meshwants.WantsByWantNodeModuleValue) (map[string]string, string) {
|
||||||
|
parts := map[string]string{}
|
||||||
|
var failed []string
|
||||||
|
fail := func(seat, ref, why string) {
|
||||||
|
line := fmt.Sprintf("%s at version %s: the seat %s's verb versions resolves no digest of %s: %s, so the node holds %s and composes nothing of it",
|
||||||
|
module, w.Version, seat, ref, why, module)
|
||||||
|
c.sayOnceEach(line)
|
||||||
|
failed = append(failed, fmt.Sprintf("%s (seat %s: %s)", ref, seat, why))
|
||||||
|
}
|
||||||
|
var manifest *catalogue.Manifest
|
||||||
|
for _, a := range e.Artifacts {
|
||||||
|
_, artifact, _ := strings.Cut(a.Ref, ":")
|
||||||
|
if a.Kind == catalogue.ArtifactUpstream {
|
||||||
|
if manifest == nil {
|
||||||
|
_, raw, err := entryManifest(e)
|
||||||
|
m, derr := catalogue.Decode(raw)
|
||||||
|
if err != nil || derr != nil {
|
||||||
|
fail("(none)", a.Ref, "the entry's manifest cannot be read for the digest its upstream copy pins")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
manifest = &m
|
||||||
|
}
|
||||||
|
if d := pinnedDigest(*manifest, artifact); d != "" {
|
||||||
|
parts[a.Ref] = d
|
||||||
|
} else {
|
||||||
|
fail("(none)", a.Ref, "the manifest pins no digest of the upstream copy")
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seat, numbered := seatOfKind(a.Kind)
|
||||||
|
if !numbered {
|
||||||
|
fail("(none)", a.Ref, "no registry seat the node-engine reads numbers an artifact of kind "+a.Kind)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
digest, why := c.versionDigest(seat, registryName(module, a), w)
|
||||||
|
if why != "" {
|
||||||
|
fail(seat, a.Ref, why)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts[a.Ref] = digest
|
||||||
|
}
|
||||||
|
if len(failed) > 0 {
|
||||||
|
sort.Strings(failed)
|
||||||
|
return nil, "no digest is resolved at version " + w.Version + " for " + strings.Join(failed, ", ")
|
||||||
|
}
|
||||||
|
return parts, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// versionDigest is the digest the seat's verb versions answers for name at w's version (its version or its tag), the newest
|
||||||
|
// first: a version names one build (A-430a), so the version alone is matched.
|
||||||
|
func (c *Composer) versionDigest(seat, name string, w meshwants.WantsByWantNodeModuleValue) (string, string) {
|
||||||
|
if c.env.Registry == nil {
|
||||||
|
return "", "this node-engine reads no registry seat"
|
||||||
|
}
|
||||||
|
raw, err := c.env.Registry("seat:"+seat+"."+versionsVerb, map[string]string{"name": name})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Sprintf("the call for %s failed: %v", name, err)
|
||||||
|
}
|
||||||
|
answer, said, ok := buscalls.Unwrap(raw)
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Sprintf("the seat refused %s: %s", name, said)
|
||||||
|
}
|
||||||
|
var v registryVersions
|
||||||
|
if err := json.Unmarshal(answer, &v); err != nil {
|
||||||
|
return "", fmt.Sprintf("its answer for %s cannot be read: %v", name, err)
|
||||||
|
}
|
||||||
|
for _, a := range v.Versions {
|
||||||
|
if (a.Version == w.Version || a.Tag == w.Version) && a.Digest != "" {
|
||||||
|
return a.Digest, ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Sprintf("it holds no version %s of %s", w.Version, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pinnedDigest is the digest the manifest's upstream artifact pins in its from (`<image>@sha256:<hex>`); "" when none.
|
||||||
|
func pinnedDigest(m catalogue.Manifest, artifact string) string {
|
||||||
|
if m.Build == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
for _, a := range m.Build.Artifacts {
|
||||||
|
if a.Name == artifact {
|
||||||
|
if _, d, ok := strings.Cut(a.From, "@"); ok && strings.HasPrefix(d, "sha256:") {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package selfcompose
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G A-430, A-430a (the lead's answer A-430b): a want naming its version and no parts is resolved to its artifacts'
|
||||||
|
// digests through the verb versions of the registry seat of each artifact's kind, under `<module>/<artifact>`; an upstream copy
|
||||||
|
// by the digest its manifest pins. The build is made from those digests. A lookup that fails is said, naming the module, the
|
||||||
|
// version and the seat, and holds the module whole; a want with parts is read by its parts as before.
|
||||||
|
func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) {
|
||||||
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
||||||
|
d := func(c string) string { return "sha256:" + strings.Repeat(c, 64) }
|
||||||
|
manifest := map[string]any{"module": "mail", "version": "1", "build": map[string]any{"artifacts": []any{
|
||||||
|
map[string]any{"name": "server", "kind": "upstream", "from": "alpine@" + d("9")},
|
||||||
|
map[string]any{"name": "files", "kind": "archive", "from": "files"},
|
||||||
|
map[string]any{"name": "web", "kind": "image", "from": "Dockerfile"},
|
||||||
|
}}}
|
||||||
|
entry := meshcatalog.CatalogEntry{Module: "mail", Fp: fp, Manifest: manifest, Artifacts: []meshcatalog.Artifact{
|
||||||
|
{Ref: "mail:server", Kind: "upstream"}, {Ref: "mail:files", Kind: "archive"}, {Ref: "mail:web", Kind: "image"}}}
|
||||||
|
// The seats hold mail/files and mail/web; versions newest first.
|
||||||
|
held := map[string]string{
|
||||||
|
"oci-artifact-registry.mail/files": `{"name":"mail/files","versions":[{"name":"mail/files","kind":"archive","digest":"` + d("2") + `","version":"1.3.0"},{"name":"mail/files","kind":"archive","digest":"` + d("1") + `","version":"1.2.3"}]}`,
|
||||||
|
"container-image-registry.mail/web": `{"name":"mail/web","versions":[{"name":"mail/web","kind":"image","digest":"` + d("3") + `","version":"1.2.3"}]}`,
|
||||||
|
"container-image-registry.mail/other": `{"name":"mail/other","versions":[]}`,
|
||||||
|
}
|
||||||
|
for name, row := range map[string]struct {
|
||||||
|
want meshwants.WantsByWantNodeModuleValue
|
||||||
|
down string // a seat whose call fails
|
||||||
|
parts map[string]string
|
||||||
|
missing string // a word the reason holds
|
||||||
|
said []string
|
||||||
|
}{
|
||||||
|
"resolved": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true},
|
||||||
|
parts: map[string]string{"mail:server": d("9"), "mail:files": d("1"), "mail:web": d("3")}},
|
||||||
|
"a version a seat does not hold": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "2.0.0", Self: true},
|
||||||
|
missing: "2.0.0", said: []string{"mail at version 2.0.0", "oci-artifact-registry", "container-image-registry"}},
|
||||||
|
"a seat that does not answer": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}, down: "container-image-registry",
|
||||||
|
missing: "mail:web", said: []string{"mail at version 1.2.3: the seat container-image-registry"}},
|
||||||
|
"parts as before": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true,
|
||||||
|
Parts: map[string]string{"mail:server": d("9"), "mail:files": d("5"), "mail:web": d("6")}},
|
||||||
|
parts: map[string]string{"mail:server": d("9"), "mail:files": d("5"), "mail:web": d("6")}},
|
||||||
|
} {
|
||||||
|
var mu sync.Mutex
|
||||||
|
var said []string
|
||||||
|
env := Env{Say: func(line string) { mu.Lock(); said = append(said, line); mu.Unlock() }}
|
||||||
|
calls := 0
|
||||||
|
env.Registry = EntryCall(func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) {
|
||||||
|
calls++
|
||||||
|
if verb != "versions" {
|
||||||
|
t.Errorf("%s: asked %s.%s", name, seat, verb)
|
||||||
|
}
|
||||||
|
if seat == row.down {
|
||||||
|
return nil, errors.New("no responders")
|
||||||
|
}
|
||||||
|
answer, ok := held[seat+"."+args.(map[string]string)["name"]]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not held")
|
||||||
|
}
|
||||||
|
return json.RawMessage(answer), nil
|
||||||
|
})
|
||||||
|
env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
|
||||||
|
return nil, errors.New("not asked")
|
||||||
|
})
|
||||||
|
c := New(env)
|
||||||
|
c.wants["mail"] = row.want
|
||||||
|
c.keptEnt[fp] = keptEntry{entry: entry}
|
||||||
|
parts, missing := c.partsOf("mail", entry, row.want)
|
||||||
|
b := c.buildOf("mail", fp)
|
||||||
|
if row.missing != "" {
|
||||||
|
if parts != nil || b != nil || !strings.Contains(missing, row.missing) {
|
||||||
|
t.Errorf("%s: parts %v, build %v, missing %q: want the module held whole, naming %s", name, parts, b, missing, row.missing)
|
||||||
|
}
|
||||||
|
if c.entryHolds()["mail"] == "" {
|
||||||
|
t.Errorf("%s: the module is not held", name)
|
||||||
|
}
|
||||||
|
for _, w := range row.said {
|
||||||
|
if !strings.Contains(strings.Join(said, "\n"), w) {
|
||||||
|
t.Errorf("%s: said %q, want a line naming %q", name, said, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if missing != "" || len(parts) != len(row.parts) {
|
||||||
|
t.Fatalf("%s: parts %v, missing %q", name, parts, missing)
|
||||||
|
}
|
||||||
|
for ref, digest := range row.parts {
|
||||||
|
if parts[ref] != digest {
|
||||||
|
t.Errorf("%s: %s at %s, want %s", name, ref, parts[ref], digest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if b == nil || len(b.Artifacts) != 3 {
|
||||||
|
t.Fatalf("%s: build %+v", name, b)
|
||||||
|
}
|
||||||
|
for _, a := range b.Artifacts {
|
||||||
|
if a.Digest != row.parts["mail:"+a.Name] || a.Reference != referenceOf("mail", a.Name, a.Digest) {
|
||||||
|
t.Errorf("%s: artifact %+v", name, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A resolution is asked once, and it names the node keeping the build its digests are of.
|
||||||
|
before := calls
|
||||||
|
c.partsOf("mail", entry, row.want)
|
||||||
|
if calls != before {
|
||||||
|
t.Errorf("%s: resolved again: %d calls, then %d", name, before, calls)
|
||||||
|
}
|
||||||
|
c.wants["mail"] = meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: row.want.Version, Parts: row.want.Parts, KeptOn: "g14", Self: true}
|
||||||
|
if node, _, kept, _ := c.KeptBuildOf(context.Background(), "mail", row.parts["mail:files"]); !kept || node != "g14" {
|
||||||
|
t.Errorf("%s: kept on %q %v, want g14", name, node, kept)
|
||||||
|
}
|
||||||
|
if _, _, kept, _ := c.KeptBuildOf(context.Background(), "mail", d("7")); kept {
|
||||||
|
t.Errorf("%s: a digest the want does not resolve to is said kept", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -40,6 +40,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"invokes": [
|
"invokes": [
|
||||||
|
"seat:container-image-registry.versions",
|
||||||
"seat:mesh-catalog.entry",
|
"seat:mesh-catalog.entry",
|
||||||
"seat:mesh-catalog.module",
|
"seat:mesh-catalog.module",
|
||||||
{"verb": "seat:mesh-catalog.revision", "fields": ["none-yet"]},
|
{"verb": "seat:mesh-catalog.revision", "fields": ["none-yet"]},
|
||||||
@@ -48,9 +49,11 @@
|
|||||||
"seat:mesh-module-assigner.assignments",
|
"seat:mesh-module-assigner.assignments",
|
||||||
"seat:mesh-recovery.kept-points",
|
"seat:mesh-recovery.kept-points",
|
||||||
"seat:mesh-recovery.restore-kept",
|
"seat:mesh-recovery.restore-kept",
|
||||||
"seat:mesh-recovery.snapshot-kept"
|
"seat:mesh-recovery.snapshot-kept",
|
||||||
|
"seat:oci-artifact-registry.versions"
|
||||||
],
|
],
|
||||||
"consumes": [
|
"consumes": [
|
||||||
|
"mesh-catalog.catalog-revision",
|
||||||
"mesh-catalog.seat-definition-changed",
|
"mesh-catalog.seat-definition-changed",
|
||||||
"mesh-catalog.seat-definition-removed",
|
"mesh-catalog.seat-definition-removed",
|
||||||
"mesh-conditions.findings-asked",
|
"mesh-conditions.findings-asked",
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func TestTheManifestConsumesTheBackupEvent(t *testing.T) {
|
|||||||
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
|
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
|
||||||
}
|
}
|
||||||
// The backup event, the status view's settled, and the two events of the seat that serves the seat list (ADR 0636 §4), the keeper's ask (design 47 G §387), the seat's running (§199) and the builder's build ends (A-293).
|
// The backup event, the status view's settled, and the two events of the seat that serves the seat list (ADR 0636 §4), the keeper's ask (design 47 G §387), the seat's running (§199) and the builder's build ends (A-293).
|
||||||
if want := []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
|
if want := []string{"mesh-catalog.catalog-revision", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
|
||||||
t.Fatalf("consumes %v, want %v", m.Consumes, want)
|
t.Fatalf("consumes %v, want %v", m.Consumes, want)
|
||||||
}
|
}
|
||||||
// 774: the acts bucket mesh-host_acts is not declared as state for now: a declared state of a module with no account
|
// 774: the acts bucket mesh-host_acts is not declared as state for now: a declared state of a module with no account
|
||||||
|
|||||||
Reference in New Issue
Block a user