From 687509adf75668dc5327fa1c644f26750ad6e65a Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 11:37:09 +0100 Subject: [PATCH 1/2] The composer strips every manifest-only process key, serves beside bus The composer stripped a process's bus before the declaration but not its serves, so the node-engine's strict declaration read refused every module whose process declares serves (the builder, the bus module's keeper, mesh-recovery): "a process does not use serves, and it is set". The keys are now one set, built from the SDK's constants, so a later manifest-only key joins it in one place; the bus test gains a row for serves. Builds: design 47 H2 H-A-469 --- internal/compose/resolution/declaration.go | 15 +++- .../compose/resolution/process_bus_test.go | 90 ++++++++++--------- 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/internal/compose/resolution/declaration.go b/internal/compose/resolution/declaration.go index 8ac7537b..1d443db4 100644 --- a/internal/compose/resolution/declaration.go +++ b/internal/compose/resolution/declaration.go @@ -42,6 +42,11 @@ func renderingMachinePort(r mcat.Rendering, module string, wanted int) int { return wanted } +// manifestOnlyProcessKeys is every key a process resource declares in its manifest that the composer strips before the +// declaration (design 47 H2 H-A-469): the node-engine's strict declaration read knows none of them, and refuses a process +// that carries one. A later manifest-only process key the SDK names joins here, and nowhere else. +var manifestOnlyProcessKeys = []string{mcat.ProcessBusField, mcat.ProcessServesField} + // Declaration is everything the resolved modules put on the node, with settings applied. // // Resource identities are prefixed with the module they came from. Two modules may reasonably @@ -940,10 +945,12 @@ func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, filter delete(copied, mcat.SecretsInEnvironment) delete(copied, mcat.NamesOnPurpose) delete(copied, mcat.TrustedField) - // A process's bus stays controller-side (novox/hq ADR 0436 §1): never composed onto the - // node-engine's process resource, whose wire declaration is mesh-host's own, vendored, with a - // strict decoder that refuses an unknown key. - delete(copied, mcat.ProcessBusField) + // A process's manifest-only keys stay controller-side (novox/hq ADR 0436 §1; design 47 H2 + // H-A-469): never composed onto the node-engine's process resource, whose strict decoder + // refuses an unknown key. + for _, key := range manifestOnlyProcessKeys { + delete(copied, key) + } // **An operator's value, from the assignment** (novox/hq ADR 0112, ADR 0155): what a // definition may not carry because it is true of one installation only. Filled from // the same layers a mergeable file takes, and refused when no layer set it. diff --git a/internal/compose/resolution/process_bus_test.go b/internal/compose/resolution/process_bus_test.go index 09e5e192..4c55cac4 100644 --- a/internal/compose/resolution/process_bus_test.go +++ b/internal/compose/resolution/process_bus_test.go @@ -12,11 +12,11 @@ import ( // shape (ADR 0436 §7, §8), copied from mesh-catalog/modules/mesh-mail/module.json and extended as settled by // the lead: process id "send" is the manifest's own `id` (internal/catalogue/runtime.go:72-74 is the model for // a process id); the account file uses the controller's real JSON tags (modules.go:1041-1056 issueWith). -func mailSenderProcessManifest(t *testing.T, bus string) string { +func mailSenderProcessManifest(t *testing.T, key, value string) string { t.Helper() process := `{"id":"send","type":"process","run":["./mesh-mail","send"],"user":"mesh-mail-send"` - if bus != "" { - process += `,"bus":` + bus + if value != "" { + process += `,"` + key + `":` + value } process += `}` // The stream itself is plain here, not retention work-queue: 1179 checks only that a process names a @@ -32,45 +32,53 @@ const mailSenderBus = `{"emits":["mail.send.sent","mail.send.failed"],"queues":[ `"state":["sends"],"asks":true,"invokes":["seat:operator-channel.tell"]}` // 1179/AC5: a process declaring bus is composed with no bus key on the wire, and is otherwise byte for byte -// what main composes for the same process without bus. +// what main composes for the same process without bus. Design 47 H2 H-A-469: the same for every manifest-only +// process key, its serves among them (the strict declaration read refused every process declaring serves). func TestAProcessesBusNeverReachesTheWire(t *testing.T) { - withBus, err := decodeForTest([]byte(mailSenderProcessManifest(t, mailSenderBus))) - if err != nil { - t.Fatal(err) - } - withoutBus, err := decodeForTest([]byte(mailSenderProcessManifest(t, ""))) - if err != nil { - t.Fatal(err) - } - with := mcat.Rendering{Needed: map[string]map[string]string{}} - outWith, err := Declaration(mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{withBus}}, with) - if err != nil { - t.Fatalf("composing with bus: %v", err) - } - outWithout, err := Declaration(mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{withoutBus}}, with) - if err != nil { - t.Fatalf("composing without bus: %v", err) - } - var withProcess, withoutProcess map[string]any - for _, r := range outWith { - if r["id"] == "mesh-mail.send" { - withProcess = r - } - } - for _, r := range outWithout { - if r["id"] == "mesh-mail.send" { - withoutProcess = r - } - } - if withProcess == nil || withoutProcess == nil { - t.Fatalf("the process was not composed at all: with=%v without=%v", withProcess, withoutProcess) - } - if _, has := withProcess["bus"]; has { - t.Fatalf("the process resource carried a bus key onto the wire: %v", withProcess) - } - delete(withProcess, "bus") - if !mapsEqual(withProcess, withoutProcess) { - t.Fatalf("with bus declared, the process composed differently: %+v\nwant: %+v", withProcess, withoutProcess) + for _, row := range []struct{ key, value string }{ + {mcat.ProcessBusField, mailSenderBus}, + {mcat.ProcessServesField, `["seat:mesh-mail.send"]`}, + } { + t.Run(row.key, func(t *testing.T) { + withKey, err := decodeForTest([]byte(mailSenderProcessManifest(t, row.key, row.value))) + if err != nil { + t.Fatal(err) + } + withoutKey, err := decodeForTest([]byte(mailSenderProcessManifest(t, row.key, ""))) + if err != nil { + t.Fatal(err) + } + with := mcat.Rendering{Needed: map[string]map[string]string{}} + outWith, err := Declaration(mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{withKey}}, with) + if err != nil { + t.Fatalf("composing with %s: %v", row.key, err) + } + outWithout, err := Declaration(mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{withoutKey}}, with) + if err != nil { + t.Fatalf("composing without %s: %v", row.key, err) + } + var withProcess, withoutProcess map[string]any + for _, r := range outWith { + if r["id"] == "mesh-mail.send" { + withProcess = r + } + } + for _, r := range outWithout { + if r["id"] == "mesh-mail.send" { + withoutProcess = r + } + } + if withProcess == nil || withoutProcess == nil { + t.Fatalf("the process was not composed at all: with=%v without=%v", withProcess, withoutProcess) + } + if _, has := withProcess[row.key]; has { + t.Fatalf("the process resource carried a %s key onto the wire: %v", row.key, withProcess) + } + if !mapsEqual(withProcess, withoutProcess) { + t.Fatalf("with %s declared, the process composed differently: %+v\nwant: %+v", row.key, withProcess, + withoutProcess) + } + }) } } From 23e6e9e2627648784edca5c79bbf6330e8e22d99 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 11:49:49 +0100 Subject: [PATCH 2/2] Compose every catalogue manifest and read its declaration, so no manifest-only key leaks again serves reached the wire because nothing composed the catalogue's own manifests and read what came out with the node-engine's strict decoder. The test composes each manifest of the catalogue placed beside the repository on one machine, with what it needs there, and fails when a key the node-engine does not know reaches a declaration; every other refusal is the catalogue's own fault and is logged. Against the catalogue's main it fails at the parent commit for nats (keeper) and mesh-recovery. Builds: design 47 H2 H-A-469, H-A-469 addendum --- .../compose/catalogue_declarations_test.go | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 internal/compose/catalogue_declarations_test.go diff --git a/internal/compose/catalogue_declarations_test.go b/internal/compose/catalogue_declarations_test.go new file mode 100644 index 00000000..a60fdc4b --- /dev/null +++ b/internal/compose/catalogue_declarations_test.go @@ -0,0 +1,204 @@ +package compose + +import ( + "crypto/sha256" + "fmt" + "path/filepath" + "slices" + "sort" + "strings" + "testing" + + "git.novox.be/novox/mesh-sdk/go/catalogue" + "github.com/novox/mesh-host/internal/beside" + "github.com/novox/mesh-host/internal/compose/resolution" +) + +// Design 47 H2 H-A-469: every manifest of the catalogue placed beside this repository (internal/beside: the clone beside a +// merge check, elsewhere the captured copy) is composed onto a machine and its declaration read by the node-engine's own +// validator, so a key a manifest declares that only the mesh reads (a process's bus, its serves, the next one) cannot reach +// the wire unseen again: the strict declaration read refused every process declaring serves on the running node-engine. +// +// Each manifest is composed on anchor with what it needs beside it there: a provider of each name it wants and a holder of +// each seat it depends on, the first of the catalogue's by name, the artifact store's holder (so a module that fetches from +// it is not left out), each artifact it builds stood in for by a build, and each value only the operator sets (a required +// config key) given. A manifest that does not compose so, or whose resources the composition leaves out (it needs what +// only a running mesh answers, such as a provider helper's), is named with why in the log: none of it reaches the wire, so +// nothing of it can leak there. The test fails when a declaration composed is refused for a key the node-engine does not +// know ("does not use X, and it is set"), or when fewer than half of the catalogue's manifests reached a declaration read; +// any other refusal is the catalogue's own fault, judged by its checks, and is logged (H-A-469 addendum). +func TestEveryCatalogueManifestsDeclarationIsRead(t *testing.T) { + root := beside.Dir(t, "mesh-catalog") + paths, err := filepath.Glob(filepath.Join(root, "modules", "*", "module.json")) + if err != nil || len(paths) == 0 { + t.Fatalf("no manifests under %s: %v", root, err) + } + shelf := map[string]catalogue.Manifest{} + capabilities := map[string]bool{} + for _, p := range paths { + m, err := catalogue.ReadTreeManifest(root, filepath.Dir(p)) + if err != nil { + continue // TestEveryCatalogueManifestParses (internal/compose/resolution) names it + } + var built []catalogue.Built + if m.Build != nil { + for _, a := range m.Build.Artifacts { + digest := fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(m.Module+"/"+a.Name))) + built = append(built, catalogue.Built{Name: a.Name, Kind: a.Kind, Digest: digest, + Reference: catalogue.ArtifactStoreScheme + m.Module + "/" + a.Name + "@" + digest}) + } + } + if resolved, err := m.Resolve(built); err == nil { + m = resolved + } + shelf[m.Module] = m + for _, c := range m.Capabilities { + capabilities[c] = true + } + } + names := make([]string, 0, len(shelf)) + for n := range shelf { + names = append(names, n) + } + sort.Strings(names) + first := func(is func(catalogue.Manifest) bool) string { + for _, n := range names { + if is(shelf[n]) { + return n + } + } + return "" + } + providerOf := func(want string) string { + return first(func(m catalogue.Manifest) bool { + if m.Module == want { + return true + } + for _, o := range m.Provides { + if o.Name == want { + return true + } + } + return false + }) + } + holderOf := func(seat string) string { + return first(func(m catalogue.Manifest) bool { + for _, c := range m.Claims { + if c.Name == seat { + return true + } + } + return false + }) + } + withWhatItNeeds := func(module string) []string { + in := map[string]bool{} + out := []string{} + var add func(string) + add = func(n string) { + if n == "" || in[n] { + return + } + in[n] = true + out = append(out, n) + for _, w := range shelf[n].Wants() { + add(providerOf(w)) + } + for _, s := range catalogue.DependsOn(shelf, shelf[n]) { + add(holderOf(s)) + } + } + add(module) + return out + } + store := first(func(m catalogue.Manifest) bool { + for _, c := range m.Claims { + if seat, ok := catalogue.SeatNamed(c.Name); ok && c.At() == catalogue.ScopeMesh && + slices.Contains(resolution.StoreSeats, seat.Name) { + return true + } + } + return false + }) + if store == "" { + t.Fatal("no module of the catalogue holds the artifact store, so every module that fetches from it is left out") + } + operatorsValues := func(m catalogue.Manifest) map[string]any { + values := map[string]any{} + for k, d := range m.Settings { + switch { + case !d.Required: + case len(d.Enum) > 0: + values[k] = d.Enum[0] + case d.Type == "number": + values[k] = float64(1) + case d.Type == "boolean": + values[k] = true + default: + values[k] = "example" + } + } + return values + } + + read, nothing := 0, 0 + for _, module := range names { + in := aMesh(t) + for n, m := range shelf { + in.Catalogue[n] = m + } + anchor := nodeOf(t, &in, "anchor") + anchor.Assigned = append(anchor.Assigned, withWhatItNeeds(module)...) + for _, n := range withWhatItNeeds(store) { + if !slices.Contains(anchor.Assigned, n) { + anchor.Assigned = append(anchor.Assigned, n) + } + } + anchor.SealingKey, anchor.Account, anchor.AccountHome = "sealing-key", "operator", "/home/operator" + anchor.PublicDomain, anchor.OutwardLinks = "example.org", []string{"eth0"} + for c := range capabilities { + anchor.Capabilities[c] = true + } + anchor.Settings = map[string][]catalogue.Layer{} + for _, n := range anchor.Assigned { + if values := operatorsValues(shelf[n]); len(values) > 0 { + anchor.Settings[n] = []catalogue.Layer{{From: "anchor", Values: values}} + } + } + d, problems, err := Compose(in, "anchor") + if err != nil { + t.Logf("%s does not compose here, so no declaration of it is read: %s", module, + strings.ReplaceAll(err.Error(), "\n", " ")) + continue + } + if len(problems) > 0 { + // A key the node-engine does not know, and only that, is this repository's to strip (H-A-469 addendum): every + // other refusal is the catalogue's own fault, judged by its checks, and is said here only. + for _, p := range problems { + if strings.Contains(p, "does not use \"") && strings.Contains(p, "\", and it is set") { + t.Errorf("%s: a key the node-engine does not know reaches its declaration: %s", module, p) + } else { + t.Logf("%s: its declaration is refused for the catalogue's own fault, not judged here: %s", module, p) + } + } + continue + } + reached := false + for _, r := range d.Resources { + reached = reached || strings.HasPrefix(fmt.Sprint(r["id"]), module+".") + } + switch { + case reached: + read++ + case len(shelf[module].Resources) == 0: + nothing++ + default: + t.Logf("%s composes here with none of its resources, so none is read: %s", module, d.LeftOutWhy[module]) + } + } + t.Logf("%d of %d manifests reached a declaration read; %d declare no resource", read, len(names), nothing) + if read*2 < len(names) { + t.Fatalf("only %d of %d manifests reached a declaration read, so this proved little", read, len(names)) + } +}