Each queue gets a named worker filtered to accept.<queue>.*; an asker is granted accept.<queue>.<its seat> for the queues of the kinds it is a caller of, read from the definitions' callers lists; main's accept.<queue> is the checker's and the builder's alone. The purge of named subjects and workers (grants_named_purge) is not in this commit. Builds: design 47 G §543, §544, §600, §601, A-163, A-170, A-184 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
70 lines
3.2 KiB
Go
70 lines
3.2 KiB
Go
package buscompose
|
|
|
|
import "testing"
|
|
|
|
// Design 47 G §543, §544, §600: a build seat's ask names its asker, each queue has a named worker beside main's, an asker
|
|
// is granted the queues of its kinds under its own seat's name alone, and main's subject is the checker's and the builder's.
|
|
func TestNamedAsks(t *testing.T) {
|
|
build := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery", "check", "recheck"}, PulledByKind: true,
|
|
AcceptCallers: map[string][]string{
|
|
"delivery": {"mesh-builds"},
|
|
"check": {"mesh-pipeline-runner", "mesh-catalog", "mesh-delivery-checker"},
|
|
"recheck": {"mesh-delivery-checker"},
|
|
}}
|
|
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."
|
|
for _, c := range []struct {
|
|
who Principal
|
|
want map[string]bool
|
|
}{
|
|
{asker("runner-module", "mesh-pipeline-runner"), map[string]bool{
|
|
base + "check.mesh-pipeline-runner": true, base + "delivery.mesh-pipeline-runner": false,
|
|
base + "check.mesh-catalog": false, base + "check": false, base + "delivery": false}},
|
|
{asker("an-indexer", "mesh-catalog"), map[string]bool{
|
|
base + "check.mesh-catalog": true, base + "check.mesh-pipeline-runner": false, base + "recheck.mesh-catalog": false}},
|
|
{asker("the-builder", "mesh-builds"), map[string]bool{
|
|
base + "delivery.mesh-builds": true, base + "delivery": true, base + "check": true, base + "check.mesh-builds": false}},
|
|
{asker("the-checker", "mesh-delivery-checker"), map[string]bool{
|
|
base + "check.mesh-delivery-checker": true, base + "recheck.mesh-delivery-checker": true, base + "recheck": true,
|
|
base + "delivery.mesh-delivery-checker": false}},
|
|
{asker("a-stranger"), map[string]bool{base + "check": false, base + "delivery": false, base + "check.a-stranger": false}},
|
|
} {
|
|
perms, err := PermissionsFor(c.who)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for subject, want := range c.want {
|
|
if got := MayPublish(perms, subject); got != want {
|
|
t.Errorf("%s may publish %s: %v, want %v", c.who.Module, subject, got, want)
|
|
}
|
|
}
|
|
}
|
|
// 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}
|
|
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))
|
|
}
|
|
}
|