Files
mesh-host/internal/compose/resolution/process_bus_test.go
T
jschoubben 687509adf7 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
2026-11-22 11:37:09 +01:00

112 lines
4.2 KiB
Go

package resolution
import (
"testing"
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
)
// A process resource may declare `bus` (novox/hq ADR 0436 §1): what it emits, the module's own work-queue
// streams it consumes, the module's own state it reads and writes, whether it reads the router's records of
// this module's own asks, and the tools and seat verbs it calls. The fixture is mesh-mail's future manifest
// 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, key, value string) string {
t.Helper()
process := `{"id":"send","type":"process","run":["./mesh-mail","send"],"user":"mesh-mail-send"`
if value != "" {
process += `,"` + key + `":` + value
}
process += `}`
// The stream itself is plain here, not retention work-queue: 1179 checks only that a process names a
// stream the module owns, never its retention — that rule is 1178's (WorkQueueStreamProblems), and is
// tested against its own fixture there (work_queue_consumer_test.go) so this one stays accepted whether
// or not a process currently names "mail-sends" in bus.queues.
return `{"module":"mesh-mail","version":"1","emits":["mail.send.sent","mail.send.failed"],` +
`"state":["sends"],"streams":[{"name":"mail-sends","events":["mail.send.approved"],"max-age-days":1,` +
`"max-mib":64}],"resources":[{"id":"account","type":"user","name":"mesh-mail-send"},` + process + `]}`
}
const mailSenderBus = `{"emits":["mail.send.sent","mail.send.failed"],"queues":["mail-sends"],` +
`"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. 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) {
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)
}
})
}
}
func mapsEqual(a, b map[string]any) bool {
if len(a) != len(b) {
return false
}
for k, v := range a {
bv, ok := b[k]
if !ok {
return false
}
if av, ok := v.([]any); ok {
bbv, ok := bv.([]any)
if !ok || len(av) != len(bbv) {
return false
}
for i := range av {
if av[i] != bbv[i] {
return false
}
}
continue
}
if v != bv {
return false
}
}
return true
}