Grants: compose each seat's one shared worker; the builder binds it again after a deletion (H-A-468) #324
@@ -113,4 +113,29 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
}
|
||||
runtime.Gosched()
|
||||
}
|
||||
// H-A-468 (2): the worker deleted and made again by the broker's part is bound again, and an ask put after it is ended.
|
||||
if err := b.js.DeleteConsumer(b.ctx, stream, worker); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.awaitSaid(t, "work queue "+worker+" on "+stream+" was deleted")
|
||||
b.seatQueue(t)
|
||||
b.awaitSaid(t, "pulling the seat "+meshbuilds.Seat+"'s asks from "+worker)
|
||||
run.Pipeline = "main.3.netcheck"
|
||||
data, _ = json.Marshal(run)
|
||||
msg = nats.NewMsg(meshbuilds.AcceptSubjectStep)
|
||||
msg.Data = data
|
||||
msg.Header.Set("x-event-id", "ask-3")
|
||||
msg.Header.Set(nats.MsgIdHdr, "ask-3")
|
||||
if _, err := b.js.PublishMsg(b.ctx, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case m := <-ended:
|
||||
var end meshbuilds.StepEnded
|
||||
if err := json.Unmarshal(m.Data, &end); err != nil || end.ID != "ask-3" || end.Outcome != meshbuilds.StepEndedOutcomePassed {
|
||||
t.Fatalf("step-ended = %+v, %v; want the ask ask-3 passed through the worker made again", end, err)
|
||||
}
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended for ask-3 within 20 s of the worker made again: the builder did not bind it again")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,46 +255,71 @@ func inProgressOf(def func() (seatdef.Definition, bool), ackWait func() time.Dur
|
||||
|
||||
// serveSteps pulls the seat's work queue through its one shared worker, every ask waiting at once (at most the worker's
|
||||
// max ack pending), once the broker made it: a worker not there yet is said, and bound when the bus says it was created.
|
||||
// The advisories are heard for as long as the builder runs (design 47 H2 H-A-468 (2)): a worker deleted is let go and said,
|
||||
// and bound again when the bus says it was created again.
|
||||
func serveSteps(ctx context.Context, conn *nats.Conn, js jetstream.JetStream, q *stepQueue, ackWait *atomic.Int64) error {
|
||||
stream, worker := buscompose.SeatQueueStreamName(meshbuilds.Seat), buscompose.SeatQueueWorkerName(meshbuilds.Seat)
|
||||
var once sync.Once
|
||||
var mu sync.Mutex
|
||||
var pulling jetstream.ConsumeContext
|
||||
bind := func() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if pulling != nil {
|
||||
return true
|
||||
}
|
||||
c, err := js.Consumer(ctx, stream, worker)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
bound := false
|
||||
once.Do(func() {
|
||||
bound = true
|
||||
info := c.CachedInfo()
|
||||
if info != nil && info.Config.AckWait > 0 {
|
||||
ackWait.Store(int64(info.Config.AckWait))
|
||||
}
|
||||
pending := 1000
|
||||
if info != nil && info.Config.MaxAckPending > 0 {
|
||||
pending = info.Config.MaxAckPending
|
||||
}
|
||||
cc, err := c.Consume(func(m jetstream.Msg) { q.take(ctx, m) }, jetstream.PullMaxMessages(pending))
|
||||
if err != nil {
|
||||
q.logf("the seat %s's work queue %s is not pulled: %v", meshbuilds.Seat, worker, err)
|
||||
return
|
||||
}
|
||||
q.logf("pulling the seat %s's asks from %s", meshbuilds.Seat, worker)
|
||||
go func() { <-ctx.Done(); cc.Stop() }()
|
||||
})
|
||||
return bound
|
||||
info := c.CachedInfo()
|
||||
if info != nil && info.Config.AckWait > 0 {
|
||||
ackWait.Store(int64(info.Config.AckWait))
|
||||
}
|
||||
pending := 1000
|
||||
if info != nil && info.Config.MaxAckPending > 0 {
|
||||
pending = info.Config.MaxAckPending
|
||||
}
|
||||
cc, err := c.Consume(func(m jetstream.Msg) { q.take(ctx, m) }, jetstream.PullMaxMessages(pending))
|
||||
if err != nil {
|
||||
q.logf("the seat %s's work queue %s is not pulled: %v", meshbuilds.Seat, worker, err)
|
||||
return false
|
||||
}
|
||||
pulling = cc
|
||||
q.logf("pulling the seat %s's asks from %s", meshbuilds.Seat, worker)
|
||||
return true
|
||||
}
|
||||
if bind() {
|
||||
return nil
|
||||
release := func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if pulling == nil {
|
||||
return
|
||||
}
|
||||
pulling.Stop()
|
||||
pulling = nil
|
||||
q.logf("the seat %s's work queue %s on %s was deleted: its asks wait on it, and it is pulled again when the bus says it was created", meshbuilds.Seat, worker, stream)
|
||||
}
|
||||
q.logf("the seat %s's work queue %s on %s is not there yet: its asks wait on it, and it is pulled when the bus says it was created", meshbuilds.Seat, worker, stream)
|
||||
sub, err := conn.Subscribe("$JS.EVENT.ADVISORY.CONSUMER.CREATED."+stream+"."+worker, func(*nats.Msg) { go bind() })
|
||||
created, err := conn.Subscribe("$JS.EVENT.ADVISORY.CONSUMER.CREATED."+stream+"."+worker, func(*nats.Msg) { go bind() })
|
||||
if err != nil {
|
||||
return fmt.Errorf("hearing the creation of the seat %s's work queue: %w", meshbuilds.Seat, err)
|
||||
}
|
||||
go func() { <-ctx.Done(); _ = sub.Unsubscribe() }()
|
||||
if bind() { // made between the first look and the subscription
|
||||
_ = sub.Unsubscribe()
|
||||
deleted, err := conn.Subscribe("$JS.EVENT.ADVISORY.CONSUMER.DELETED."+stream+"."+worker, func(*nats.Msg) {
|
||||
go func() {
|
||||
release()
|
||||
bind() // made again before the deletion was heard
|
||||
}()
|
||||
})
|
||||
if err != nil {
|
||||
_ = created.Unsubscribe()
|
||||
return fmt.Errorf("hearing the deletion of the seat %s's work queue: %w", meshbuilds.Seat, err)
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
_ = created.Unsubscribe()
|
||||
_ = deleted.Unsubscribe()
|
||||
release()
|
||||
}()
|
||||
if !bind() {
|
||||
q.logf("the seat %s's work queue %s on %s is not there yet: its asks wait on it, and it is pulled when the bus says it was created", meshbuilds.Seat, worker, stream)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -291,6 +291,12 @@ func (g keptGate) Definitions() map[string]seatdef.Definition {
|
||||
return map[string]seatdef.Definition{g.def.Seat: g.def}
|
||||
}
|
||||
|
||||
// seatsGate is a seat list that has been read and holds these definitions.
|
||||
type seatsGate map[string]seatdef.Definition
|
||||
|
||||
func (seatsGate) MayAct(...string) bool { return true }
|
||||
func (g seatsGate) Definitions() map[string]seatdef.Definition { return g }
|
||||
|
||||
func newFakeBus() *fakeBus {
|
||||
return &fakeBus{states: map[string]map[string][]byte{}, refused: map[string]bool{}, own: map[string]map[string][]byte{},
|
||||
revs: map[string]uint64{}, refuseTo: map[string]bool{}}
|
||||
@@ -2262,6 +2268,49 @@ func TestGrants(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// H-A-468 (design 47 H2): a seat with an accept that is not pulled by kind gets its one shared worker, SeatQueue's, made by
|
||||
// the grants part where the bus lacks it (its holders bind it, never make it); a seat pulled by kind gets none (its
|
||||
// per-queue workers are its holders' seat traffic's); a worker the bus holds is left as it is, and no pass deletes it.
|
||||
t.Run("a seat's shared worker is made where the bus lacks it", func(t *testing.T) {
|
||||
raw, err := os.ReadFile("module.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := fixture()
|
||||
b.manifestOf("mesh-grants", string(raw))
|
||||
b.assign("a", "mesh-grants")
|
||||
b.loaded = shadowOf(t, b)
|
||||
p := partOn(b)
|
||||
p.Create, p.Consumers = b, b
|
||||
p.SeatList = seatsGate{
|
||||
"mesh-builds": {Seat: "mesh-builds", Accepts: []seatdef.Message{{Name: "step", AckWait: "2m", MaxDeliveries: 3}}},
|
||||
"node-build-go": {Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{{Name: "check"}}},
|
||||
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
|
||||
}
|
||||
b.consumers = map[string][]map[string]any{"SEAT_MESH_WANTS": {{"name": "SEAT_MESH_WANTS_worker", "filters": []string{"mesh.seat.mesh-wants.accept.>"}, "max_deliver": 9}}}
|
||||
res := p.Compose()
|
||||
var made map[string]any
|
||||
for _, c := range b.consumers["SEAT_MESH_BUILDS"] {
|
||||
if c["name"] == "SEAT_MESH_BUILDS_worker" {
|
||||
made = c
|
||||
}
|
||||
}
|
||||
if made == nil || made["max_deliver"] != 3 || !slices.Equal(made["filters"].([]string), []string{"mesh.seat.mesh-builds.accept.>"}) ||
|
||||
!slices.Contains(res.Consumers.Created, "SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker") {
|
||||
t.Errorf("the builds seat's worker = %v (created %v)", made, res.Consumers.Created)
|
||||
}
|
||||
if strings.Contains(fmt.Sprint(b.consumerCreates), "SEAT_NODE_BUILD_GO_worker") {
|
||||
t.Errorf("a seat pulled by kind got a shared worker: %v", b.consumerCreates)
|
||||
}
|
||||
if len(b.consumers["SEAT_MESH_WANTS"]) != 1 || b.consumers["SEAT_MESH_WANTS"][0]["max_deliver"] != 9 {
|
||||
t.Errorf("the wants seat's held worker was changed: %v", b.consumers["SEAT_MESH_WANTS"])
|
||||
}
|
||||
p.Compose()
|
||||
if len(b.consumers["SEAT_MESH_BUILDS"]) != 1 || len(b.consumers["SEAT_MESH_WANTS"]) != 1 {
|
||||
t.Errorf("a pass changed the seats' workers: %v", b.consumers)
|
||||
}
|
||||
})
|
||||
|
||||
// 774 (ADR 0563 §2, §3): the node-engine's manifest (mesh-host) is placed on every node though no node is assigned it,
|
||||
// so its declared state acts is created as a placed module's, and composed for the user list's create right.
|
||||
t.Run("assertions: a held stream gains the subjects its manifest names, and loses, changes nothing else", func(t *testing.T) {
|
||||
|
||||
@@ -16,7 +16,7 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
|
||||
// alone, whatever another module's reads say; the controller's copy grants any module that declares it.
|
||||
{Module: "mesh-vault", State: []Bucket{{Module: "mesh-vault", Name: "bus-accounts"}}},
|
||||
{Module: "spy", Serves: []string{"spy_x"}, Reads: []string{VaultBusAccounts}},
|
||||
{Module: "mesh-delivery-builder",
|
||||
{Module: "mesh-delivery-builder", Holds: []Seat{{Name: "mesh-builds", Scope: "mesh", Accepts: []string{"step"}}},
|
||||
State: []Bucket{{Module: "mesh-delivery-builder", Name: "steps", History: 5}},
|
||||
Logs: []Log{{Module: "mesh-delivery-builder", Name: "builds"}},
|
||||
Streams: []ModuleStream{{Module: "mesh-delivery-builder", Name: "BUILDASKS", Events: []string{"ask"}}}},
|
||||
@@ -29,6 +29,8 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
|
||||
}},
|
||||
// The node-engine's own manifest, placed on every node though no node is assigned it (novox/hq ADR 0563 §2, §3).
|
||||
Engine: &Declared{Module: EngineModule, State: []Bucket{{Module: EngineModule, Name: EngineActsState}}},
|
||||
// A seat's one shared worker (H-A-468): the grants part makes it where the bus lacks it.
|
||||
AskWorkers: []Consumer{{Name: "SEAT_MESH_BUILDS_worker", Stream: "SEAT_MESH_BUILDS", Filters: []string{"mesh.seat.mesh-builds.accept.>"}}},
|
||||
}
|
||||
users, err := Users(records)
|
||||
if err != nil {
|
||||
@@ -71,6 +73,8 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
|
||||
{GrantsModule, "$JS.API.STREAM.PURGE.KV_mesh-delivery-builder_steps", false},
|
||||
{GrantsModule, "$JS.API.STREAM.CREATE.KV_mesh-delivery-builder_undeclared", false},
|
||||
{GrantsModule, "$JS.API.STREAM.CREATE.EVENTS", false},
|
||||
{GrantsModule, "$JS.API.CONSUMER.CREATE.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", true},
|
||||
{GrantsModule, "$JS.API.CONSUMER.DELETE.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", false},
|
||||
{GrantsModule, "$JS.API.STREAM.CREATE.ASSIGNMENTS", false},
|
||||
// Research 072 row 33: a runtime reads its membership from the grants part's state, never the assignments stream.
|
||||
{"mesh-delivery-builder", "$JS.API.DIRECT.GET.ASSIGNMENTS.mesh.assignment.novox.mesh-delivery-builder", false},
|
||||
@@ -144,6 +148,11 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.STREAM.CREATED.KV_mesh-grants_assertions", false},
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.STREAM.CREATED.LOG_mesh-delivery-builder_builds", false},
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.STREAM.DELETED.KV_mesh-delivery-builder_steps", false},
|
||||
// H-A-468 addendum: the holder of a seat with an accept hears its shared worker created and deleted, no other's.
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.CONSUMER.CREATED.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", true},
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.CONSUMER.DELETED.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", true},
|
||||
{"mesh-delivery-builder", "$JS.EVENT.ADVISORY.CONSUMER.CREATED.SEAT_MESH_WANTS.SEAT_MESH_WANTS_worker", false},
|
||||
{"spy", "$JS.EVENT.ADVISORY.CONSUMER.CREATED.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", false},
|
||||
} {
|
||||
if got := MaySubscribe(perms[row.who], row.subject); got != row.may {
|
||||
t.Errorf("%s may hear %s: %v, want %v", row.who, row.subject, got, row.may)
|
||||
|
||||
@@ -299,6 +299,17 @@ func AccountConsumers(users []Principal) []ModuleConsumer {
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
|
||||
}
|
||||
}
|
||||
// Each seat's one shared worker on its work queue (design 47 H2 H-A-468): its holders bind it and never make it, so the
|
||||
// grants part makes it where the bus lacks it, as it makes the seat's stream.
|
||||
for _, p := range users {
|
||||
for _, c := range p.SeatWorkers {
|
||||
if made[c.Stream+"."+c.Name] {
|
||||
continue
|
||||
}
|
||||
made[c.Stream+"."+c.Name] = true
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@@ -133,13 +133,17 @@ func SplitKept(kept []KeptEvent, consumes []string) (rest []string, hears []Hear
|
||||
// a JetStream publish of an ask is answered by the bus. Before G the controller made these; a seat whose queues came with G
|
||||
// (mesh-builds, mesh-wants) had none, so every ask to it timed out unanswered (lead-47, 2026-11-15). A seat whose
|
||||
// settings SeatQueue refuses is named in refused and gets no stream. Sorted by stream.
|
||||
func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamConfig, refused []string) {
|
||||
//
|
||||
// workers are the one shared worker SeatQueue names for each such seat that is not pulled by kind (design 47 H2 H-A-468):
|
||||
// the grants part creates it where the bus lacks it, as it creates the seat's stream, for its holders bind it and never
|
||||
// make it; a seat pulled by kind keeps its per-queue workers (SeatTrafficOf). Sorted by stream.
|
||||
func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamConfig, workers []Consumer, refused []string) {
|
||||
for _, name := range slices.Sorted(maps.Keys(defs)) {
|
||||
d := defs[name]
|
||||
if len(d.Accepts) == 0 || !safeSubject.MatchString(d.Seat) {
|
||||
continue
|
||||
}
|
||||
st, _, ok, err := sdkbc.SeatQueue(d.Seat, d.Accepts)
|
||||
st, w, ok, err := sdkbc.SeatQueue(d.Seat, d.Accepts)
|
||||
if err != nil {
|
||||
refused = append(refused, err.Error())
|
||||
continue
|
||||
@@ -151,7 +155,15 @@ func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamCon
|
||||
Retention: jetstream.WorkQueuePolicy, Storage: jetstream.FileStorage, Replicas: 1,
|
||||
MaxAge: time.Duration(st.MaxAge) * time.Second, MaxMsgs: int64(st.MaxMsgs),
|
||||
Duplicates: time.Duration(st.DuplicatesSeconds) * time.Second})
|
||||
if !d.PulledByKind {
|
||||
// SeatQueue's worker as it returns it, every setting the two types share (its in-progress is the holder's beat,
|
||||
// no setting of the bus's): the grants part makes no derivation of its own (H-A-468 second addendum).
|
||||
workers = append(workers, Consumer{Name: w.Name, Stream: w.Stream, Filters: w.Filters, Queue: w.Queue, Push: w.Push,
|
||||
TakesOverFrom: w.TakesOverFrom, DeliverSubject: w.DeliverSubject, AckWaitSeconds: w.AckWaitSeconds,
|
||||
MaxDeliver: w.MaxDeliver, MaxAckPending: w.MaxAckPending, FromNow: w.FromNow, Why: w.Why, Resettable: w.Resettable})
|
||||
}
|
||||
}
|
||||
slices.SortFunc(out, func(a, b jetstream.StreamConfig) int { return strings.Compare(a.Name, b.Name) })
|
||||
return out, refused
|
||||
slices.SortFunc(workers, func(a, b Consumer) int { return strings.Compare(a.Stream, b.Stream) })
|
||||
return out, workers, refused
|
||||
}
|
||||
|
||||
@@ -308,6 +308,10 @@ type Principal struct {
|
||||
// (novox/hq ADR 0561 §6): each placed module's on EVENTS and each process's on its work queue (AccountConsumers), by
|
||||
// stream and name. Created only, never updated or deleted.
|
||||
CreatesConsumers []ModuleConsumer
|
||||
// SeatWorkers are the seats' shared workers the grants part's principal makes where the bus lacks them (Records'
|
||||
// AskWorkers, design 47 H2 H-A-468): AccountConsumers names each as this principal's, so it is granted and created
|
||||
// as an account consumer is, never deleted by a pass.
|
||||
SeatWorkers []Consumer
|
||||
|
||||
// Login is a node principal's login when it is not `node.<n>`: its second login, `node.<n>--b`, composed beside or
|
||||
// in place of the first as the vault's node-logins says (novox/hq ADR 0583 §1, issue 774). Each login is granted
|
||||
@@ -1158,6 +1162,11 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
if s.Name == meshbroker.Seat {
|
||||
s.Serves = withoutActing(s.Serves)
|
||||
}
|
||||
// A seat with an accept not pulled by kind has its one shared worker, made by the grants part (H-A-468): its holder
|
||||
// hears the bus say it was created and deleted, so it binds it when it appears and again after a deletion.
|
||||
if len(s.Accepts) > 0 && !s.PulledByKind && safeSubject.MatchString(s.Name) {
|
||||
sub = append(sub, seatWorkerAdvisories(s.Name)...)
|
||||
}
|
||||
if s.isNewTraffic() {
|
||||
// Composed by SeatTrafficOf below, worker and all; only its tools are served here.
|
||||
for _, t := range s.Serves {
|
||||
@@ -1795,6 +1804,13 @@ func CreateConsumerGrants(consumers []ModuleConsumer) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// seatWorkerAdvisories are the bus's advisories that a seat's one shared worker was created and deleted (H-A-468
|
||||
// addendum), heard by each holder of the seat.
|
||||
func seatWorkerAdvisories(seat string) []string {
|
||||
stream, worker := seatStreamName(seat), WorkerName(seat, "")
|
||||
return []string{"$JS.EVENT.ADVISORY.CONSUMER.CREATED." + stream + "." + worker, "$JS.EVENT.ADVISORY.CONSUMER.DELETED." + stream + "." + worker}
|
||||
}
|
||||
|
||||
// GrantsModule is the one module whose principal publishes the modules' memberships (novox/hq ADR 0547 §5): the grants
|
||||
// part, which composes them from the manifests and assignments. It defines no stream and is granted no other subject here.
|
||||
const GrantsModule = "mesh-grants"
|
||||
|
||||
@@ -48,7 +48,7 @@ accounts {
|
||||
} }
|
||||
{ user: "one.telegram", password: "$2a$11$tttttttttttttttttttttt", permissions: {
|
||||
publish: { allow: ["$JS.ACK.EVENTS.one_telegram.>", "$JS.ACK.EVENTS.one_telegram_tools.>", "$JS.ACK.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker.>", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.one.telegram", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.INFO.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.MSG.NEXT.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.one.telegram", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.one~telegram", "mesh.seat.*.call.*.one~telegram", "mesh.seat.*.tool.>", "mesh.seat.telegram-sender.event.delivered", "mesh.seat.telegram-sender.event.failed"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
subscribe: { allow: ["$SRV.INFO", "$SRV.INFO.telegram", "$SRV.INFO.telegram.>", "$SRV.PING", "$SRV.PING.telegram", "$SRV.PING.telegram.>", "$SRV.STATS", "$SRV.STATS.telegram", "$SRV.STATS.telegram.>", "_INBOX.one.telegram.>", "mesh.mod.telegram.call.>", "mesh.mod.telegram.tool.>", "mesh.seat.telegram-sender.accept.send"] }
|
||||
subscribe: { allow: ["$JS.EVENT.ADVISORY.CONSUMER.CREATED.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.EVENT.ADVISORY.CONSUMER.DELETED.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$SRV.INFO", "$SRV.INFO.telegram", "$SRV.INFO.telegram.>", "$SRV.PING", "$SRV.PING.telegram", "$SRV.PING.telegram.>", "$SRV.STATS", "$SRV.STATS.telegram", "$SRV.STATS.telegram.>", "_INBOX.one.telegram.>", "mesh.mod.telegram.call.>", "mesh.mod.telegram.tool.>", "mesh.seat.telegram-sender.accept.send"] }
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
{ user: "two.audit", password: "$2a$11$aaaaaaaaaaaaaaaaaaaaaa", permissions: {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -178,6 +178,9 @@ type Records struct {
|
||||
Kept []KeptEvent
|
||||
// AskStreams are the seats' ask streams the grants part makes where the bus lacks them (AskStreamsOf), each its to create.
|
||||
AskStreams []string
|
||||
// AskWorkers are the seats' shared workers the grants part makes where the bus lacks them (AskStreamsOf's workers,
|
||||
// design 47 H2 H-A-468), each its to create.
|
||||
AskWorkers []Consumer
|
||||
// Chunked is every verb the seat definitions say sends chunks (chunks.go, design 47 G §681): their subjects are granted to the
|
||||
// principal that answers the verb and to an account naming it in `invokes`.
|
||||
Chunked []ChunkVerb
|
||||
@@ -365,6 +368,7 @@ func Users(r Records) ([]Principal, error) {
|
||||
}
|
||||
if d.Module == GrantsModule {
|
||||
out[len(out)-1].CreatesStreams = declaredStreamsOf(r)
|
||||
out[len(out)-1].SeatWorkers = r.AskWorkers
|
||||
grants = len(out) - 1
|
||||
}
|
||||
// **The vault's holder asks the desks and the issuing providers itself** (issue 723), under the
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -8,6 +11,7 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
sdkbc "git.novox.be/novox/mesh-sdk/go/buscompose"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
|
||||
"mesh-grants/internal/buscompose"
|
||||
@@ -37,8 +41,20 @@ func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) {
|
||||
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
|
||||
"git": {Seat: "git"},
|
||||
"two-ways": {Seat: "two-ways", Accepts: []seatdef.Message{{Name: "a", MaxAge: "1h"}, {Name: "b", MaxAge: "2h"}}},
|
||||
"node-build": {Seat: "node-build", PulledByKind: true, Accepts: []seatdef.Message{{Name: "check"}}},
|
||||
}
|
||||
asks, refused := buscompose.AskStreamsOf(defs)
|
||||
asks, workers, refused := buscompose.AskStreamsOf(defs)
|
||||
// Each seat that accepts work and is not pulled by kind has its one shared worker, SeatQueue's (H-A-468); the seat pulled
|
||||
// by kind has its stream and no shared worker.
|
||||
if len(workers) != 2 || workers[0].Name != "SEAT_MESH_BUILDS_worker" || workers[0].Stream != "SEAT_MESH_BUILDS" ||
|
||||
!slices.Equal(workers[0].Filters, []string{"mesh.seat.mesh-builds.accept.>"}) || workers[0].MaxDeliver != 5 ||
|
||||
workers[0].AckWaitSeconds != 60 || workers[1].Name != "SEAT_MESH_WANTS_worker" {
|
||||
t.Errorf("workers = %+v", workers)
|
||||
}
|
||||
if len(asks) != 3 || asks[2].Name != "SEAT_NODE_BUILD" {
|
||||
t.Fatalf("ask streams = %+v", asks)
|
||||
}
|
||||
asks = asks[:2]
|
||||
if len(asks) != 2 || asks[0].Name != "SEAT_MESH_BUILDS" || asks[0].Retention != jetstream.WorkQueuePolicy ||
|
||||
!slices.Equal(asks[0].Subjects, []string{"mesh.seat.mesh-builds.accept.>"}) || asks[0].MaxAge != 24*time.Hour ||
|
||||
asks[0].MaxMsgs != 10000 || asks[0].Duplicates != 2*time.Minute || asks[1].MaxAge != 7*24*time.Hour {
|
||||
@@ -54,3 +70,29 @@ func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) {
|
||||
t.Errorf("made %v (not %v), created %v: want only the builds seat's, the wants seat's being held", made, notMade, c.made)
|
||||
}
|
||||
}
|
||||
|
||||
// The worker the grants part creates for the seat mesh-builds is SeatQueue's, setting by setting (H-A-468 second addendum):
|
||||
// the one the builder's whole test makes from SeatQueue, so the two cannot differ.
|
||||
func TestTheSeatsWorkerIsSeatQueues(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("..", "..", "..", "mesh-delivery-contracts", "seats", "mesh-builds", "seat.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
def, err := seatdef.Parse(raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, w, ok, err := sdkbc.SeatQueue(def.Seat, def.Accepts)
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("SeatQueue: %v %v", ok, err)
|
||||
}
|
||||
_, workers, refused := buscompose.AskStreamsOf(map[string]seatdef.Definition{def.Seat: def})
|
||||
if len(workers) != 1 || len(refused) != 0 {
|
||||
t.Fatalf("workers %+v, refused %v", workers, refused)
|
||||
}
|
||||
want := jetstream.ConsumerConfig{Durable: w.Name, FilterSubjects: w.Filters, AckPolicy: jetstream.AckExplicitPolicy,
|
||||
AckWait: time.Duration(w.AckWaitSeconds) * time.Second, MaxDeliver: w.MaxDeliver, MaxAckPending: w.MaxAckPending, Description: w.Why}
|
||||
if got := buscompose.ConsumerConfig(workers[0]); workers[0].Stream != w.Stream || !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("the created worker on %s = %+v, want SeatQueue's %+v on %s", workers[0].Stream, got, want, w.Stream)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +193,8 @@ type Inputs struct {
|
||||
Kept []buscompose.KeptEvent
|
||||
// AskStreams are the seats' ask streams (buscompose.AskStreamsOf), made where the bus lacks them.
|
||||
AskStreams []jetstream.StreamConfig
|
||||
// AskWorkers are the seats' shared workers (buscompose.AskStreamsOf), made where the bus lacks them (H-A-468).
|
||||
AskWorkers []buscompose.Consumer
|
||||
// Chunked is every verb the seat list says sends its answer's file in chunks (design 47 G §681): the part grants their subjects.
|
||||
Chunked []buscompose.ChunkVerb
|
||||
// EventSubjects are, by seat, the subjects of its events that carry parts, by the event's local name, as the definitions
|
||||
@@ -386,7 +388,7 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
|
||||
if d, ok := gate.(SeatDefinitions); ok {
|
||||
in.Kept = buscompose.KeptEventsOf(d.Definitions())
|
||||
var refused []string
|
||||
in.AskStreams, refused = buscompose.AskStreamsOf(d.Definitions())
|
||||
in.AskStreams, in.AskWorkers, refused = buscompose.AskStreamsOf(d.Definitions())
|
||||
for _, why := range refused {
|
||||
in.Gaps = append(in.Gaps, Gap{Input: "seat work queues", Why: why})
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) {
|
||||
out := buscompose.Records{Assigned: map[string][]buscompose.Declared{}, People: map[string][]string{},
|
||||
Interchangeable: map[string]bool{}, Enrolling: slices.Clone(in.Enrolling),
|
||||
// And each node's logins (ADR 0583 §1): both while it rotates.
|
||||
NodeLogins: in.NodeLogins, Kept: in.Kept, AskStreams: askStreamNames(in.AskStreams), Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat],
|
||||
NodeLogins: in.NodeLogins, Kept: in.Kept, AskStreams: askStreamNames(in.AskStreams), AskWorkers: in.AskWorkers, Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat],
|
||||
// What the bus module's process may define: every manifest's bus state, and what it said it created (DLV-G2).
|
||||
BusState: map[string][]catalogue.BusStateEntry{}, Bound: in.Bound,
|
||||
// Each node's capability reading and what each node-engine said running (design 46 approval mark §6).
|
||||
|
||||
Reference in New Issue
Block a user