The module mesh-delivery-checker goes whole with its manifest, and its seat's definition leaves the seat list. The status view reads no tries: build_usage answers no tries running and counts no step as a try. The grants part grants main's accept subject to the builder alone. The tests name no checker as an asker or a seat. The seat's generated packages, the indexer's readers and the assigner's verdict constants go in the join's cleanup, once those branches stand on this one (the lead, 2026-11-20). Builds: design 47 H §764 (the checker (H1): mesh-delivery-checker whole); lead answer H-A-57 (hq f599b761) Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
164 lines
7.5 KiB
Go
164 lines
7.5 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Design 47 G §543, §544, §600: a build seat's ask names its asker and each queue has a named worker beside main's; any module may
|
|
// put any ask (principle 6, the operator 2026-11-15).
|
|
func TestNamedAsks(t *testing.T) {
|
|
build := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery", "check", "recheck"}, PulledByKind: true}
|
|
asker := func(module string, held ...string) Principal {
|
|
p := Principal{Kind: KindModule, Node: "one", Module: module, Uses: []Seat{build}}
|
|
for _, h := range held {
|
|
p.Holds = append(p.Holds, Seat{Name: h})
|
|
}
|
|
return p
|
|
}
|
|
const base = "mesh.seat.node-build-go.accept."
|
|
// Principle 6 (the operator, 2026-11-15): every module's account may put an ask on any queue of any seat, under any asker's
|
|
// name or none (AnySeatSubject); the callers lists withhold nothing.
|
|
for _, who := range []Principal{asker("runner-module", "mesh-pipeline-runner"), asker("an-indexer", "mesh-catalog"),
|
|
asker("the-builder", "mesh-builds"), asker("a-stranger")} {
|
|
perms, err := PermissionsFor(who)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, subject := range []string{base + "check", base + "delivery", base + "check.mesh-catalog", base + "recheck.mesh-builds",
|
|
base + "check." + who.Module} {
|
|
if !MayPublish(perms, subject) {
|
|
t.Errorf("%s may not publish %s", who.Module, subject)
|
|
}
|
|
}
|
|
}
|
|
// Each queue's workers: main's and the named one, filtered to subjects that overlap nothing.
|
|
held := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery", "check"}, PulledByKind: true}
|
|
// Main's subject, which names no asker, is the builder's alone: the checker is gone (design 47 H §764).
|
|
for holder, main := range map[string]bool{"mesh-builds": true, "mesh-delivery-checker": false} {
|
|
tr := SeatTrafficOf("m", []Seat{{Name: holder, Scope: "mesh"}}, []Seat{held}, nil)
|
|
if got := slices.Contains(tr.Publish, base+"check"); got != main {
|
|
t.Errorf("a holder of %s is granted main's %scheck: %v, want %v", holder, base, got, main)
|
|
}
|
|
}
|
|
tr := SeatTrafficOf("go-module", []Seat{held}, nil, nil)
|
|
filters := map[string]string{}
|
|
for _, w := range tr.Workers {
|
|
filters[w.Consumer] = w.Filter
|
|
}
|
|
for consumer, filter := range map[string]string{
|
|
"SEAT_NODE_BUILD_GO_CHECK_worker": base + "check",
|
|
"SEAT_NODE_BUILD_GO_CHECK_named_worker": base + "check.*",
|
|
"SEAT_NODE_BUILD_GO_DELIVERY_worker": base + "delivery",
|
|
"SEAT_NODE_BUILD_GO_DELIVERY_named_worker": base + "delivery.*",
|
|
} {
|
|
if filters[consumer] != filter {
|
|
t.Errorf("worker %s filters %q, want %q", consumer, filters[consumer], filter)
|
|
}
|
|
}
|
|
_, consumers := SeatTrafficObjects([]Principal{{Kind: KindModule, Node: "one", Module: "go-module", Holds: []Seat{held}}})
|
|
if len(consumers) != 4 {
|
|
t.Errorf("the work queue's consumers: %d, want 4 (a main and a named worker for each of two queues)", len(consumers))
|
|
}
|
|
// A-413: the part makes the named workers (AccountConsumers), never only names them in a membership.
|
|
named := 0
|
|
for _, mc := range AccountConsumers([]Principal{{Kind: KindModule, Node: "one", Module: "go-module", Holds: []Seat{held}}}) {
|
|
if strings.HasSuffix(mc.Consumer.Name, "_named_worker") {
|
|
named++
|
|
}
|
|
}
|
|
if named != 2 {
|
|
t.Errorf("account consumers hold %d named workers, want 2", named)
|
|
}
|
|
}
|
|
|
|
// Design 47 H §752, H-A-113 (2): every module's account may call every verb of every seat, invoked or not, in its own name,
|
|
// so no definition's callers withhold one; another account's name it may not take.
|
|
func TestEveryModuleMayCallEveryVerb(t *testing.T) {
|
|
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"kept-artifact", "freed", "run"}}
|
|
invoker := Principal{Kind: KindModule, Node: "one", Module: "an-invoker", Uses: []Seat{build}, Invokes: []string{"seat:node-build-go.kept-artifact"}}
|
|
stranger := Principal{Kind: KindModule, Node: "one", Module: "a-stranger"}
|
|
for _, who := range []Principal{invoker, stranger} {
|
|
perms, err := PermissionsFor(who)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, subject := range []string{"mesh.seat.node-build-go.tool.freed.ace", "mesh.seat.node-build-go.tool.run",
|
|
"mesh.seat.mesh-wants.tool.upgrade", "mesh.seat.mesh-wants.call.upgrade." + CallerToken(who.Username())} {
|
|
if !MayPublish(perms, subject) {
|
|
t.Errorf("%s may not publish %s", who.Module, subject)
|
|
}
|
|
}
|
|
if MayPublish(perms, "mesh.seat.mesh-wants.call.upgrade.someone~else") {
|
|
t.Errorf("%s may call in another's name", who.Module)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 G §544: the grants part's account alone is granted the purge of a build seat's stream and the delete of its
|
|
// named workers, for every queue of a build seat a composed user holds.
|
|
func TestTheGrantsPartAlonePurgesTheNamedAsks(t *testing.T) {
|
|
held := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"check"}, PulledByKind: true}
|
|
users, err := Users(Records{Nodes: []string{"one"}, Assigned: map[string][]Declared{"one": {
|
|
{Module: GrantsModule}, {Module: "go-module", Holds: []Seat{held}}}}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, u := range users {
|
|
perms, err := PermissionsFor(u)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, subject := range []string{"$JS.API.STREAM.PURGE.SEAT_NODE_BUILD_GO",
|
|
"$JS.API.CONSUMER.DELETE.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_named_worker"} {
|
|
if got, want := MayPublish(perms, subject), u.Module == GrantsModule && u.Kind == KindModule; got != want {
|
|
t.Errorf("%s may publish %s: %v, want %v", u.Username(), subject, got, want)
|
|
}
|
|
}
|
|
if u.Module == GrantsModule && MayPublish(perms, "$JS.API.CONSUMER.DELETE.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_worker") {
|
|
t.Errorf("the grants part may delete main's worker")
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 G, lead answer A-393: a verb of a node-scoped seat asked with no machine is answered by any one holder, so each
|
|
// holder is granted the verb's subject without the machine (tool and call forms) beside its machine's, and a caller of the
|
|
// verb may publish on it; a verb of a seat held once for the mesh gains nothing, and a stranger is granted nothing.
|
|
func TestANodeSeatVerbIsAlsoGrantedWithoutTheMachine(t *testing.T) {
|
|
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"steps"}}
|
|
holder := Principal{Kind: KindModule, Node: "shanks", Module: "mesh-build-go", Holds: []Seat{build}}
|
|
caller := Principal{Kind: KindModule, Node: "shanks", Module: "an-indexer", Uses: []Seat{build},
|
|
Invokes: []string{"seat:node-build-go.steps"}}
|
|
stranger := Principal{Kind: KindModule, Node: "shanks", Module: "a-stranger", Uses: []Seat{build}}
|
|
const tool = "mesh.seat.node-build-go.tool.steps"
|
|
call := "mesh.seat.node-build-go.call.steps."
|
|
for _, c := range []struct {
|
|
name string
|
|
who Principal
|
|
subject string
|
|
sub bool
|
|
want bool
|
|
}{
|
|
{"holder hears its machine's", holder, tool + ".shanks", true, true},
|
|
{"holder hears the node-less tool", holder, tool, true, true},
|
|
{"holder hears the node-less call", holder, call + "someone", true, true},
|
|
{"caller asks the node-less tool", caller, tool, false, true},
|
|
{"caller asks a machine's", caller, tool + ".shanks", false, true},
|
|
{"caller asks the node-less call in its name", caller, call + CallerToken(caller.Username()), false, true},
|
|
{"stranger asks the node-less tool: every account may call every verb (design 47 H §752)", stranger, tool, false, true},
|
|
} {
|
|
perms, err := PermissionsFor(c.who)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := MayPublish(perms, c.subject)
|
|
if c.sub {
|
|
got = MaySubscribe(perms, c.subject)
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("%s: %v, want %v", c.name, got, c.want)
|
|
}
|
|
}
|
|
}
|