Announce the states the delivery gate keeps (issue 1790, ADR 0495 §2 §5)

This commit is contained in:
2026-10-22 18:02:11 +02:00
parent b07a101caf
commit 8e791896f1
6 changed files with 96 additions and 17 deletions
@@ -0,0 +1,12 @@
package main
import "git.novox.be/novox/mesh-sdk/go/announce"
// Kept is every state this module keeps on the bus and whether other modules may read it (novox/hq ADR 0495 clause 2;
// issue 1790): the module says it itself, from its code, before it serves, and a reader is granted what it said
// (clause 3). A state is readable when another module's manifest reads it. keeps_test.go holds the list to the
// manifest's `state`, and keeps_integration_test.go that the module announces it on a bus.
var Kept = []announce.State{{Name: "asks"}, {Name: "deliveries"}, {Name: "groups"}, {Name: "merges"}, {Name: "owed"}, {Name: "pulls"}, {Name: "source"}}
// announceKept says Kept through keeps, which is stdio.Keeps.
func announceKept(keeps func(...announce.State) error) error { return keeps(Kept...) }
@@ -0,0 +1,26 @@
//go:build integration
package main
import (
"testing"
"git.novox.be/novox/mesh-sdk/go/announce"
"git.novox.be/novox/mesh-sdk/go/announcetest"
"git.novox.be/novox/mesh-sdk/go/process"
)
// 1790/S (ADR 0495 clause 5): started against a bus of the test's own, the module announces on it every state it keeps,
// readable as other modules' manifests need.
func TestTheModuleAnnouncesEveryStateItKeepsOnTheBus(t *testing.T) {
announcetest.Check(t, "mesh-delivery-gate", Kept, func(url string) func() {
conn, err := process.Connect(process.Account{URL: url, Module: "mesh-delivery-gate", Node: "ace", User: "u", Password: "p"})
if err != nil {
t.Fatal(err)
}
if err := announceKept(func(s ...announce.State) error { return conn.Keeps(s...) }); err != nil {
t.Fatal(err)
}
return conn.Close
})
}
@@ -0,0 +1,51 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"
)
// 1790/S: the states the module announces are the states its manifest declares, no more, no fewer, and the readable
// ones are the states other modules' manifests read.
func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
State []json.RawMessage `json:"state"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
declared := []string{}
for _, s := range m.State {
var name string
if json.Unmarshal(s, &name) != nil {
var o struct{ Name string }
if err := json.Unmarshal(s, &o); err != nil {
t.Fatal(err)
}
name = o.Name
}
declared = append(declared, name)
}
announced := []string{}
for _, s := range Kept {
announced = append(announced, s.Name)
}
slices.Sort(declared)
slices.Sort(announced)
if !slices.Equal(declared, announced) {
t.Errorf("announces %v, the manifest declares %v", announced, declared)
}
want := map[string]bool{}
for _, s := range Kept {
if s.Readable != want[s.Name] {
t.Errorf("state %s readable = %v, other modules' manifests read it: %v", s.Name, s.Readable, want[s.Name])
}
}
}
@@ -77,6 +77,10 @@ func main() {
h.init()
l := &listening{now: "not yet: starting"}
go run(h, l, occupancy)
if err := announceKept(stdio.Keeps); err != nil {
logf("%v", err)
os.Exit(1)
}
if err := stdio.Serve("", tools(h, l)); err != nil {
logf("%v", err)
os.Exit(1)