Files
mesh-delivery/modules/mesh-grants/internal/buscompose/names_test.go
T
jschoubben 6b43adafca G1 (in progress): the grants part reads no callers and no verdicts
Every account may call every verb: the grants part reads no definition's
callers (callerOf, the verb and accept callers, admits) and grants every
module's account every verb of every seat (mesh.seat.*.tool.> and its
caller-named form), a sent store to every module invoking a verb of its
claimant's seat, and every queue's named ask to every asker. grants_callers
goes; grants_why_refused answers the bus's own verdict. The indexer keeps
no verdicts: their first view, events, invoke and the engine's read go, and
a want names its build alone (no newest). internal/... and cmd/... tests are
green; the root package's grants_test.go still reads the verdicts (rows at
grants_test.go:303-307, 741, 1184, 3700-3870, 4560-4615) and does not compile.

Builds: design 47 H §745, §750, §752, §764 (every seat contract: the callers lists); lead answers H-A-37, H-A-66, H-A-79, H-A-113 (hq f599b761)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:28:04 +01:00

79 lines
3.2 KiB
Go

package buscompose
import (
"encoding/json"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"os"
"slices"
"strings"
"testing"
)
// namesAreTheManifests (a subtest of TestTheCopiedComposerComposesAsTheControllers): the holders and states of other parts that the grants part names are the ones its manifest
// lists in `reads` and `invokes` (no contract names a holder: novox/hq ADR 0634 §1), and a state's bucket is its holder's
// name and the state's.
func namesAreTheManifests(t *testing.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"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
if m.Module != GrantsModule {
t.Errorf("the manifest's module is %q, the part names itself %q", m.Module, GrantsModule)
}
for _, c := range []struct{ list, name, bucket string }{
{"reads", HaveBucket[:strings.Index(HaveBucket, "_")] + ".have", HaveBucket},
{"reads", NodeLoginsRead, NodeLoginsBucket},
{"reads", EnrolmentsRead, EnrolmentsBucket},
{"invokes", AssignmentsRead, AssignmentsBucket},
{"invokes", AssignerModule + ".wants", AssignerWantsBucket},
{"invokes", IndexerModule + ".modules", ModulesBucket},
{"invokes", IndexerModule + ".manifests", ManifestsBucket},
} {
list := m.Reads
if c.list == "invokes" {
list = m.Invokes
}
if c.list != "" && !slices.Contains(list, c.name) {
t.Errorf("the part names %s, its manifest's %s are %v", c.name, c.list, list)
}
if got := strings.Replace(c.name, ".", "_", 1); got != c.bucket {
t.Errorf("%s is kept in %s, the part names the bucket %s", c.name, got, c.bucket)
}
}
}
// busGrantsAreTheDeclared (a subtest of TestTheCopiedComposerComposesAsTheControllers): a removal is its grants, the leftovers' for
// the nodes given too, one outside the set is refused, and the watchman hears the self-check's word and the dead letters;
// the functions are the grants part's published package busgrants'.
func busGrantsAreTheDeclared(t *testing.T) {
got, err := BusRemovalGrants([]string{catalogue.RemovesEngineActs, catalogue.RemovesControllerLeftovers}, []string{"novox", "a b"})
if err != nil {
t.Fatal(err)
}
for _, want := range []string{"$KV.mesh-host_acts.>", "$JS.API.CONSUMER.DELETE.EVENTS.controller", "$JS.API.CONSUMER.DELETE.EVENTS.novox_mesh-host",
"$JS.API.STREAM.DELETE.OBJ_declaration-files-novox", "$JS.API.STREAM.DELETE.KV_mesh-controller_lease", "$JS.API.STREAM.DELETE.ASSIGNMENTS"} {
if !slices.Contains(got, want) {
t.Errorf("the grants lack %s", want)
}
}
if slices.ContainsFunc(got, func(s string) bool {
return s == "$JS.API.STREAM.DELETE.OBJ_declaration-files-a b" || s == "$JS.API.CONSUMER.DELETE.EVENTS.a b_mesh-host"
}) {
t.Errorf("a node name that is not a subject token widened the grants: %v", got)
}
if _, err := BusRemovalGrants([]string{"everything"}, nil); err == nil {
t.Error("a removal outside the set was granted")
}
if hears := WatchmanHears(); !slices.Contains(hears, "mesh.seat.mesh-self-check.event.checked") || !slices.Contains(hears, "mesh.events.dead.>") {
t.Errorf("the watchman hears %v", hears)
}
}