Files
mesh-delivery/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names_test.go
T
jschoubben 058b2458fb §626 (teller, bridge, runner, watchman): the own-module guards are folded into an existing test each
The four TestNoCode...OwnModule functions became helpers called by TestTheNamesAreTheManifests, TestMergeCallsTheToolOnceAndWritesTheMergedMessage, TestTools and TestNoTickerTimerOrSleep, so no module ends with more tests than its merge base for them.

Builds: design 47 G §626, §428, A-296

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 22:58:54 +01:00

91 lines
4.0 KiB
Go

package main
import (
"encoding/json"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
)
// TestTheNamesAreTheManifests: the holders, tools and buckets the teller names are its manifest's (its module, what it invokes
// and consumes, its own states answers and teller-marks, no `reads`), since no contract names a holder (novox/hq ADR 0634 §1;
// design 47 G §653, A-175, A-178).
func TestTheNamesAreTheManifests(t *testing.T) {
noCodeNamesTheTellersOwnModule(t)
raw, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
}
var m struct {
Module string `json:"module"`
Reads []string `json:"reads"`
Invokes []string `json:"invokes"`
Consumes []string `json:"consumes"`
Emits []string `json:"emits"`
State []struct {
Name string `json:"name"`
} `json:"state"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
if m.Module != tellerModule {
t.Errorf("the manifest's module is %q, the teller names itself %q", m.Module, tellerModule)
}
if len(m.Reads) != 0 {
t.Errorf("the teller reads no other module's state, its manifest's reads are %v", m.Reads)
}
// Design 47 G §717: the assigner's asks are the seat mesh-wants' view, followed in seat form; no invoke names its tool.
if want := "seat:mesh-wants.views." + meshwants.StateAsks; !slices.Contains(m.Consumes, want) || slices.ContainsFunc(m.Invokes, func(e string) bool { return strings.HasPrefix(e, "mesh-delivery-assigner.") }) {
t.Errorf("the teller follows %s and invokes nothing of the assigner's, its manifest's consumes are %v and invokes %v", want, m.Consumes, m.Invokes)
}
// Design 47 G §717: the view's answers are the seat mesh-delivery-view's view, followed in seat form; no invoke names its tool.
if want := "seat:mesh-delivery-view.views." + viewstate.ViewAnswersState; !slices.Contains(m.Consumes, want) || slices.ContainsFunc(m.Invokes, func(e string) bool { return strings.HasPrefix(e, "mesh-delivery-view.") }) {
t.Errorf("the teller follows %s and invokes nothing of the view's, its manifest's consumes are %v and invokes %v", want, m.Consumes, m.Invokes)
}
// Design 47 G §717, §614: the holders are heard from the seat-holders view of the claimant the catalog half names, so the
// manifest follows that view in seat form and the catalog half's first views and events, and no code names the assigner
// or the status view.
for _, want := range []string{"seat:mesh-module-assigner.views.seat-holders", "mesh-catalog.catalog-revision", "mesh-delivery.source-moved", "mesh-catalog.registration-changed"} {
if !slices.Contains(m.Consumes, want) {
t.Errorf("the teller follows %s, its manifest's consumes are %v", want, m.Consumes)
}
}
for _, want := range []string{"seat:mesh-catalog.revision", "seat:mesh-catalog.registrations", "seat:mesh-delivery.source"} {
if !slices.Contains(m.Invokes, want) {
t.Errorf("the teller asks %s, its manifest's invokes are %v", want, m.Invokes)
}
}
files, _ := filepath.Glob("*.go")
for _, f := range files {
if strings.HasSuffix(f, "_test.go") {
continue
}
code, _ := os.ReadFile(f)
for _, name := range []string{`"mesh-delivery-assigner`, `"mesh-delivery-view"`, `"mesh-delivery-view.`} {
if strings.Contains(string(code), name) {
t.Errorf("%s names the module %s", f, name)
}
}
}
if want := "views." + answersState; !slices.Contains(m.Emits, want) {
t.Errorf("the teller says %s, its manifest's emits are %v", want, m.Emits)
}
// A-296: the teller's own buckets are named from its credential's module, each a state its manifest keeps.
var own []string
for _, s := range m.State {
own = append(own, "a-teller_"+s.Name)
}
b := bucketsOf("a-teller")
for _, want := range []string{b.answers, b.asked, b.widensSaid, b.firstViews, b.marks} { // findings is a requires state
if !slices.Contains(own, want) {
t.Errorf("the teller keeps %s, its manifest's states are %v", want, own)
}
}
}